From a6dbdf664b2efa965926aa38c81a278817fb48c5 Mon Sep 17 00:00:00 2001 From: Olivia Godone-Maresca Date: Fri, 19 May 2023 19:05:32 -0400 Subject: [PATCH 1/4] Add Clip Skip to metadata files Also, force the properties to be in a consistent order so that, for example, LoRA strength will always be the line below LoRA model. I've rearranged the properties so that they are saved in the same order that the properties are laid out in the UI --- ui/easydiffusion/renderer.py | 2 +- ui/easydiffusion/utils/save_utils.py | 72 ++++++++++++++-------------- ui/media/js/dnd.js | 1 + 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/ui/easydiffusion/renderer.py b/ui/easydiffusion/renderer.py index f685d038..e26b4389 100644 --- a/ui/easydiffusion/renderer.py +++ b/ui/easydiffusion/renderer.py @@ -72,7 +72,7 @@ def make_images( def print_task_info(req: GenerateImageRequest, task_data: TaskData): - req_str = pprint.pformat(get_printable_request(req)).replace("[", "\[") + req_str = pprint.pformat(get_printable_request(req, task_data)).replace("[", "\[") task_str = pprint.pformat(task_data.dict()).replace("[", "\[") log.info(f"request: {req_str}") log.info(f"task data: {task_str}") diff --git a/ui/easydiffusion/utils/save_utils.py b/ui/easydiffusion/utils/save_utils.py index a7043f27..24b2198c 100644 --- a/ui/easydiffusion/utils/save_utils.py +++ b/ui/easydiffusion/utils/save_utils.py @@ -15,23 +15,24 @@ img_number_regex = re.compile("([0-9]{5,})") # keep in sync with `ui/media/js/dnd.js` TASK_TEXT_MAPPING = { "prompt": "Prompt", + "negative_prompt": "Negative Prompt", + "seed": "Seed", + "use_stable_diffusion_model": "Stable Diffusion model", + "clip_skip": "Clip Skip", + "use_vae_model": "VAE model", + "sampler_name": "Sampler", "width": "Width", "height": "Height", - "seed": "Seed", "num_inference_steps": "Steps", "guidance_scale": "Guidance Scale", "prompt_strength": "Prompt Strength", + "use_lora_model": "LoRA model", + "lora_alpha": "LoRA Strength", + "use_hypernetwork_model": "Hypernetwork model", + "hypernetwork_strength": "Hypernetwork Strength", "use_face_correction": "Use Face Correction", "use_upscale": "Use Upscaling", "upscale_amount": "Upscale By", - "sampler_name": "Sampler", - "negative_prompt": "Negative Prompt", - "use_stable_diffusion_model": "Stable Diffusion model", - "use_vae_model": "VAE model", - "use_hypernetwork_model": "Hypernetwork model", - "hypernetwork_strength": "Hypernetwork Strength", - "use_lora_model": "LoRA model", - "lora_alpha": "LoRA Strength", } time_placeholders = { @@ -179,27 +180,7 @@ def save_images_to_disk(images: list, filtered_images: list, req: GenerateImageR def get_metadata_entries_for_request(req: GenerateImageRequest, task_data: TaskData): - metadata = get_printable_request(req) - metadata.update( - { - "use_stable_diffusion_model": task_data.use_stable_diffusion_model, - "use_vae_model": task_data.use_vae_model, - "use_hypernetwork_model": task_data.use_hypernetwork_model, - "use_lora_model": task_data.use_lora_model, - "use_face_correction": task_data.use_face_correction, - "use_upscale": task_data.use_upscale, - } - ) - if metadata["use_upscale"] is not None: - metadata["upscale_amount"] = task_data.upscale_amount - if task_data.use_hypernetwork_model is None: - del metadata["hypernetwork_strength"] - if task_data.use_lora_model is None: - if "lora_alpha" in metadata: - del metadata["lora_alpha"] - app_config = app.getConfig() - if not app_config.get("test_diffusers", False) and "use_lora_model" in metadata: - del metadata["use_lora_model"] + metadata = get_printable_request(req, task_data) # if text, format it in the text format expected by the UI is_txt_format = task_data.metadata_output_format.lower() == "txt" @@ -213,12 +194,33 @@ def get_metadata_entries_for_request(req: GenerateImageRequest, task_data: TaskD return entries -def get_printable_request(req: GenerateImageRequest): - metadata = req.dict() - del metadata["init_image"] - del metadata["init_image_mask"] - if req.init_image is None: +def get_printable_request(req: GenerateImageRequest, task_data: TaskData): + req_metadata = req.dict() + task_data_metadata = task_data.dict() + + # Save the metadata in the order defined in TASK_TEXT_MAPPING + metadata = {} + for key in TASK_TEXT_MAPPING.keys(): + if key in req_metadata: + metadata[key] = req_metadata[key] + elif key in task_data_metadata: + metadata[key] = task_data_metadata[key] + + # Clean up the metadata + if req.init_image is None and "prompt_strength" in metadata: del metadata["prompt_strength"] + if task_data.use_upscale is None and "upscale_amount" in metadata: + del metadata["upscale_amount"] + if task_data.use_hypernetwork_model is None and "hypernetwork_strength" in metadata: + del metadata["hypernetwork_strength"] + if task_data.use_lora_model is None and "lora_alpha" in metadata: + del metadata["lora_alpha"] + + app_config = app.getConfig() + if not app_config.get("test_diffusers", False): + for key in (x for x in ["use_lora_model", "lora_alpha", "clip_skip"] if x in metadata): + del metadata[key] + return metadata diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index 02848266..8b66a3a4 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -37,6 +37,7 @@ function parseBoolean(stringValue) { } } +// keep in sync with `ui/easydiffusion/utils/save_utils.py` const TASK_MAPPING = { prompt: { name: "Prompt", From 70a3beeaa2c44c21b7f43c58ba98548a5e485535 Mon Sep 17 00:00:00 2001 From: JeLuF Date: Sun, 21 May 2023 17:42:47 +0200 Subject: [PATCH 2/4] Automatically use 'Low' when VRAM<4.5GB --- ui/media/js/auto-save.js | 16 ++++++++++++++++ ui/media/js/main.js | 2 +- ui/media/js/parameters.js | 4 +++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ui/media/js/auto-save.js b/ui/media/js/auto-save.js index ee01ba98..49d3c751 100644 --- a/ui/media/js/auto-save.js +++ b/ui/media/js/auto-save.js @@ -169,6 +169,22 @@ function loadSettings() { } }) CURRENTLY_LOADING_SETTINGS = false + } else if (localStorage.length < 2) { + // localStorage is too short for OldSettings + // So this is likely the first time Easy Diffusion is running. + // Initialize vram_usage_level based on the available VRAM + function initGPUProfile(event) { + if ( "detail" in event + && "active" in event.detail + && "cuda:0" in event.detail.active + && event.detail.active["cuda:0"].mem_total <4.5 ) + { + vramUsageLevelField.value = "low" + vramUsageLevelField.dispatchEvent(new Event("change")) + } + document.removeEventListener("system_info_update", initGPUProfile) + } + document.addEventListener("system_info_update", initGPUProfile) } else { CURRENTLY_LOADING_SETTINGS = true tryLoadOldSettings() diff --git a/ui/media/js/main.js b/ui/media/js/main.js index c69535df..0ce32f2b 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -239,7 +239,7 @@ function setServerStatus(event) { break } if (SD.serverState.devices) { - setDeviceInfo(SD.serverState.devices) + document.dispatchEvent(new CustomEvent("system_info_update", { detail: SD.serverState.devices})) } } diff --git a/ui/media/js/parameters.js b/ui/media/js/parameters.js index e48e2e04..30cdda78 100644 --- a/ui/media/js/parameters.js +++ b/ui/media/js/parameters.js @@ -586,7 +586,7 @@ async function getSystemInfo() { $("#use_gpus").val(activeDeviceIds) } - setDeviceInfo(devices) + document.dispatchEvent(new CustomEvent("system_info_update", { detail: devices})) setHostInfo(res["hosts"]) let force = false if (res["enforce_output_dir"] !== undefined) { @@ -657,3 +657,5 @@ saveSettingsBtn.addEventListener("click", function() { saveSettingsBtn.classList.add("active") Promise.all([savePromise, asyncDelay(300)]).then(() => saveSettingsBtn.classList.remove("active")) }) + +document.addEventListener("system_info_update", (e) => setDeviceInfo(e.detail)) From cac4bd11d2337b2bcb5108cec87ad51078eaf6ef Mon Sep 17 00:00:00 2001 From: JeLuF Date: Sun, 21 May 2023 17:59:06 +0200 Subject: [PATCH 3/4] Network settings - Fix typo. The 'Please restart' text should be part of the note, not the label --- ui/media/js/parameters.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/media/js/parameters.js b/ui/media/js/parameters.js index e48e2e04..ac011263 100644 --- a/ui/media/js/parameters.js +++ b/ui/media/js/parameters.js @@ -181,8 +181,8 @@ var PARAMETERS = [ { id: "listen_to_network", type: ParameterType.checkbox, - label: "Make Stable Diffusion available on your network. Please restart the program after changing this.", - note: "Other devices on your network can access this web page", + label: "Make Stable Diffusion available on your network", + note: "Other devices on your network can access this web page. Please restart the program after changing this.", icon: "fa-network-wired", default: true, saveInAppConfig: true, From 0f6caaec3319c82427e1bf2274a58091974b8c9c Mon Sep 17 00:00:00 2001 From: JeLuF Date: Mon, 22 May 2023 10:21:19 +0200 Subject: [PATCH 4/4] get_config: return default value if conf file is corrupted --- scripts/get_config.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/get_config.py b/scripts/get_config.py index 02523364..9cdfb2fe 100644 --- a/scripts/get_config.py +++ b/scripts/get_config.py @@ -1,5 +1,6 @@ import os import argparse +import sys # The config file is in the same directory as this script config_directory = os.path.dirname(__file__) @@ -21,16 +22,16 @@ if os.path.isfile(config_yaml): try: config = yaml.safe_load(configfile) except Exception as e: - print(e) - exit() + print(e, file=sys.stderr) + config = {} elif os.path.isfile(config_json): import json with open(config_json, 'r') as configfile: try: config = json.load(configfile) except Exception as e: - print(e) - exit() + print(e, file=sys.stderr) + config = {} else: config = {}