From 3f50b7d71cf68877a82806649fce08dd1537b781 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Tue, 23 May 2023 14:07:00 +0300 Subject: [PATCH 1/5] fix bad styling for thumbs view in extra networks #10639 --- style.css | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/style.css b/style.css index ba12723a..571f4cf4 100644 --- a/style.css +++ b/style.css @@ -756,13 +756,22 @@ footer { .extra-network-cards .card .metadata-button, .extra-network-thumbs .card .metadata-button{ display: none; position: absolute; - right: 0; color: white; + right: 0; +} +.extra-network-cards .card .metadata-button { text-shadow: 2px 2px 3px black; padding: 0.25em; font-size: 22pt; width: 1.5em; } +.extra-network-thumbs .card .metadata-button { + text-shadow: 1px 1px 2px black; + padding: 0; + font-size: 16pt; + width: 1em; + top: -0.25em; +} .extra-network-cards .card:hover .metadata-button, .extra-network-thumbs .card:hover .metadata-button{ display: inline-block; } @@ -787,6 +796,13 @@ footer { position: relative; } +.extra-network-thumbs .card .preview{ + position: absolute; + object-fit: cover; + width: 100%; + height:100%; +} + .extra-network-thumbs .card:hover .additional a { display: inline-block; } From b186045fee0d384addcdc2a759fd33dba51b070e Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Tue, 23 May 2023 18:02:09 +0300 Subject: [PATCH 2/5] possible fix for empty list of optimizations #10605 --- modules/sd_hijack.py | 21 +++++++++++++++------ webui.py | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py index 08d31080..f93df0a6 100644 --- a/modules/sd_hijack.py +++ b/modules/sd_hijack.py @@ -48,6 +48,11 @@ def apply_optimizations(): undo_optimizations() + if len(optimizers) == 0: + # a script can access the model very early, and optimizations would not be filled by then + current_optimizer = None + return '' + ldm.modules.diffusionmodules.model.nonlinearity = silu ldm.modules.diffusionmodules.openaimodel.th = sd_hijack_unet.th @@ -67,8 +72,9 @@ def apply_optimizations(): matching_optimizer = optimizers[0] if matching_optimizer is not None: - print(f"Applying optimization: {matching_optimizer.name}") + print(f"Applying optimization: {matching_optimizer.name}... ", end='') matching_optimizer.apply() + print("done.") current_optimizer = matching_optimizer return current_optimizer.name else: @@ -149,6 +155,13 @@ class StableDiffusionModelHijack: def __init__(self): self.embedding_db.add_embedding_dir(cmd_opts.embeddings_dir) + def apply_optimizations(self): + try: + self.optimization_method = apply_optimizations() + except Exception as e: + errors.display(e, "applying cross attention optimization") + undo_optimizations() + def hijack(self, m): if type(m.cond_stage_model) == xlmr.BertSeriesModelWithTransformation: model_embeddings = m.cond_stage_model.roberta.embeddings @@ -168,11 +181,7 @@ class StableDiffusionModelHijack: if m.cond_stage_key == "edit": sd_hijack_unet.hijack_ddpm_edit() - try: - self.optimization_method = apply_optimizations() - except Exception as e: - errors.display(e, "applying cross attention optimization") - undo_optimizations() + self.apply_optimizations() self.clip = m.cond_stage_model diff --git a/webui.py b/webui.py index d4402f55..f0ffbbbf 100644 --- a/webui.py +++ b/webui.py @@ -291,9 +291,20 @@ def initialize_rest(*, reload_script_modules=False): modules.sd_hijack.list_optimizers() startup_timer.record("scripts list_optimizers") - # load model in parallel to other startup stuff - # (when reloading, this does nothing) - Thread(target=lambda: shared.sd_model).start() + def load_model(): + """ + Accesses shared.sd_model property to load model. + After it's available, if it has been loaded before this access by some extension, + its optimization may be None because the list of optimizaers has neet been filled + by that time, so we apply optimization again. + """ + + shared.sd_model # noqa: B018 + + if modules.sd_hijack.current_optimizer is None: + modules.sd_hijack.apply_optimizations() + + Thread(target=load_model).start() shared.reload_hypernetworks() startup_timer.record("reload hypernetworks") From dd377637caad1e9c2037ddc2796444086aa3bec2 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 27 May 2023 20:16:33 +0300 Subject: [PATCH 3/5] update the changelog to mention 1.3.0 version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e46d707a..6c6ab5e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## Upcoming 1.3.0 +## 1.3.0 ### Features: * add UI to edit defaults From 6095ade1479d5f86f5fc62872af1efde922905dc Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 27 May 2023 19:06:49 +0300 Subject: [PATCH 4/5] fix serving images that have already been saved without temp files function that broke after updating gradio --- modules/ui_tempdir.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/ui_tempdir.py b/modules/ui_tempdir.py index f05049e1..7f6b42ae 100644 --- a/modules/ui_tempdir.py +++ b/modules/ui_tempdir.py @@ -4,6 +4,7 @@ from collections import namedtuple from pathlib import Path import gradio as gr +import gradio.components from PIL import PngImagePlugin @@ -31,13 +32,16 @@ def check_tmp_file(gradio, filename): return False -def save_pil_to_file(pil_image, dir=None): +def save_pil_to_file(self, pil_image, dir=None): already_saved_as = getattr(pil_image, 'already_saved_as', None) if already_saved_as and os.path.isfile(already_saved_as): register_tmp_file(shared.demo, already_saved_as) + filename = already_saved_as - file_obj = Savedfile(f'{already_saved_as}?{os.path.getmtime(already_saved_as)}') - return file_obj + if not shared.opts.save_images_add_number: + filename += f'?{os.path.getmtime(already_saved_as)}' + + return filename if shared.opts.temp_dir != "": dir = shared.opts.temp_dir @@ -51,11 +55,11 @@ def save_pil_to_file(pil_image, dir=None): file_obj = tempfile.NamedTemporaryFile(delete=False, suffix=".png", dir=dir) pil_image.save(file_obj, pnginfo=(metadata if use_metadata else None)) - return file_obj + return file_obj.name # override save to file function so that it also writes PNG info -gr.processing_utils.save_pil_to_file = save_pil_to_file +gradio.components.IOComponent.pil_to_temp_file = save_pil_to_file def on_tmpdir_changed(): From 20ae71faa8ef035c31aa3a410b707d792c8203a3 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 27 May 2023 20:23:16 +0300 Subject: [PATCH 5/5] fix linter issue for 1.3.0 --- modules/ui_tempdir.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ui_tempdir.py b/modules/ui_tempdir.py index 7f6b42ae..9fc7d764 100644 --- a/modules/ui_tempdir.py +++ b/modules/ui_tempdir.py @@ -3,7 +3,6 @@ import tempfile from collections import namedtuple from pathlib import Path -import gradio as gr import gradio.components from PIL import PngImagePlugin