diff --git a/backend/memory_management.py b/backend/memory_management.py index 3ca0b886..7b26faea 100644 --- a/backend/memory_management.py +++ b/backend/memory_management.py @@ -547,9 +547,19 @@ else: if total_vram > (15 * 1024): EXTRA_RESERVED_VRAM += 100 * 1024 * 1024 +SETTING_RESERVED_VRAM = -1 + + +def set_reserved_memory(val: float): + global SETTING_RESERVED_VRAM + SETTING_RESERVED_VRAM = (1.0 - val) * total_vram * 1024 * 1024 + if SETTING_RESERVED_VRAM == 0.0: + return + logger.info("Manually Reserving {:0.0f} MB VRAM".format(SETTING_RESERVED_VRAM / (1024 * 1024))) + def extra_reserved_memory() -> float: - return EXTRA_RESERVED_VRAM + return max(SETTING_RESERVED_VRAM, EXTRA_RESERVED_VRAM) def minimum_inference_memory() -> float: diff --git a/modules/initialize_util.py b/modules/initialize_util.py index 5855ce9e..395e916e 100644 --- a/modules/initialize_util.py +++ b/modules/initialize_util.py @@ -168,11 +168,19 @@ def configure_sigint_handler(): signal.signal(signal.SIGINT, sigint_handler) +def reserve_memory(): + from backend.memory_management import set_reserved_memory + from modules.shared import opts + + set_reserved_memory(opts.setting_allocated_vram) + + def configure_opts_onchange(): from modules import shared, ui_tempdir shared.opts.onchange("temp_dir", ui_tempdir.on_tmpdir_changed) shared.opts.onchange("gradio_theme", shared.reload_gradio_theme) + shared.opts.onchange("setting_allocated_vram", reserve_memory) startup_timer.record("opts onchange") diff --git a/modules/shared_options.py b/modules/shared_options.py index 6cbf6639..36fafca2 100644 --- a/modules/shared_options.py +++ b/modules/shared_options.py @@ -164,6 +164,7 @@ options_templates.update( options_section( ("system", "System", "system"), { + "setting_allocated_vram": OptionInfo(1.0, "GPU Weights", gr.Slider, {"minimum": 0.0, "maximum": 1.0, "step": 0.05}).info("amount of VRAM that Forge can access").info("in % of total vram"), "auto_launch_browser": OptionInfo("Local", "Launch the webui in browser on startup", gr.Radio, {"choices": ("Disable", "Local", "Remote")}).info("Remote = always automatically start; Local = only when not sharing the server, such as --share"), "enable_console_prompts": OptionInfo(False, "Print the generation prompts to console"), "samples_log_stdout": OptionInfo(False, "Print the generation infotxt to console"),