Use vram_usage_level while starting webui

This commit is contained in:
cmdr2 2024-10-07 13:33:25 +05:30
parent 5a5d37ba52
commit c1193377b6
3 changed files with 11 additions and 5 deletions

View File

@ -268,11 +268,6 @@ def get_env():
env_entries["GIT"] = [f"{dir}/bin/git"]
env_entries["venv_dir"] = ["-"]
if config.get("render_devices", "auto") == "cpu" or (
OS_NAME in ("Windows", "Linux") and not has_discrete_graphics_card()
):
env_entries["COMMANDLINE_ARGS"][0] += " --always-cpu"
if OS_NAME == "Darwin":
# based on https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/e26abf87ecd1eefd9ab0a198eee56f9c643e4001/webui-macos-env.sh
# hack - have to define these here, otherwise webui-macos-env.sh will overwrite COMMANDLINE_ARGS
@ -284,6 +279,14 @@ def get_env():
env_entries["TORCH_COMMAND"] = ["pip install torch==2.1.2 torchvision==0.16.2"]
else:
env_entries["TORCH_COMMAND"] = ["pip install torch==2.3.1 torchvision==0.18.1"]
else:
vram_usage_level = config.get("vram_usage_level", "balanced")
if config.get("render_devices", "auto") == "cpu" or not has_discrete_graphics_card():
env_entries["COMMANDLINE_ARGS"][0] += " --always-cpu"
elif vram_usage_level == "low":
env_entries["COMMANDLINE_ARGS"][0] += " --always-low-vram"
elif vram_usage_level == "high":
env_entries["COMMANDLINE_ARGS"][0] += " --always-high-vram"
env = {}
for key, paths in env_entries.items():

View File

@ -71,6 +71,7 @@ class SetAppConfigRequest(BaseModel, extra=Extra.allow):
use_v3_engine: bool = True
backend: str = "ed_diffusers"
models_dir: str = None
vram_usage_level: str = "balanced"
def init():
@ -188,6 +189,7 @@ def set_app_config_internal(req: SetAppConfigRequest):
config["use_v3_engine"] = req.backend == "ed_diffusers"
config["backend"] = req.backend
config["models_dir"] = req.models_dir
config["vram_usage_level"] = req.vram_usage_level
for property, property_value in req.dict().items():
if property_value is not None and property not in req.__fields__ and property not in PROTECTED_CONFIG_KEYS:

View File

@ -161,6 +161,7 @@ var PARAMETERS = [
"<b>Low:</b> slowest, recommended for GPUs with 3 to 4 GB memory",
icon: "fa-forward",
default: "balanced",
saveInAppConfig: true,
options: [
{ value: "balanced", label: "Balanced" },
{ value: "high", label: "High" },