From 5fd638f14d75a71a37157ded5d33c716ab9eb8ca Mon Sep 17 00:00:00 2001 From: ruocaled Date: Sat, 15 Oct 2022 02:00:46 -0700 Subject: [PATCH 01/13] fix download section layout --- modules/ui.py | 4 ++-- style.css | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index c9b53247..3206113e 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -619,7 +619,7 @@ def create_ui(wrap_gradio_gpu_call): txt2img_preview = gr.Image(elem_id='txt2img_preview', visible=False) txt2img_gallery = gr.Gallery(label='Output', show_label=False, elem_id='txt2img_gallery').style(grid=4) - with gr.Group(): + with gr.Column(): with gr.Row(): save = gr.Button('Save') send_to_img2img = gr.Button('Send to img2img') @@ -834,7 +834,7 @@ def create_ui(wrap_gradio_gpu_call): img2img_preview = gr.Image(elem_id='img2img_preview', visible=False) img2img_gallery = gr.Gallery(label='Output', show_label=False, elem_id='img2img_gallery').style(grid=4) - with gr.Group(): + with gr.Column(): with gr.Row(): save = gr.Button('Save') img2img_send_to_img2img = gr.Button('Send to img2img') diff --git a/style.css b/style.css index b534f950..920c32ab 100644 --- a/style.css +++ b/style.css @@ -237,13 +237,6 @@ fieldset span.text-gray-500, .gr-block.gr-box span.text-gray-500, label.block s margin: 0; } -.gr-panel div.flex-col div.justify-between div{ - position: absolute; - top: -0.1em; - right: 1em; - padding: 0 0.5em; -} - #settings .gr-panel div.flex-col div.justify-between div{ position: relative; z-index: 200; From 703e6d9e4e161d36b9328eefb5200e1c44fb4afd Mon Sep 17 00:00:00 2001 From: AngelBottomless <35677394+aria1th@users.noreply.github.com> Date: Sat, 15 Oct 2022 21:47:08 +0900 Subject: [PATCH 02/13] check NaN for hypernetwork tuning --- modules/hypernetworks/hypernetwork.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/hypernetworks/hypernetwork.py b/modules/hypernetworks/hypernetwork.py index a2b3bc0a..4905710e 100644 --- a/modules/hypernetworks/hypernetwork.py +++ b/modules/hypernetworks/hypernetwork.py @@ -272,15 +272,17 @@ def train_hypernetwork(hypernetwork_name, learn_rate, batch_size, data_root, log optimizer.zero_grad() loss.backward() optimizer.step() - - pbar.set_description(f"loss: {losses.mean():.7f}") + mean_loss = losses.mean() + if torch.isnan(mean_loss): + raise RuntimeError("Loss diverged.") + pbar.set_description(f"loss: {mean_loss:.7f}") if hypernetwork.step > 0 and hypernetwork_dir is not None and hypernetwork.step % save_hypernetwork_every == 0: last_saved_file = os.path.join(hypernetwork_dir, f'{hypernetwork_name}-{hypernetwork.step}.pt') hypernetwork.save(last_saved_file) textual_inversion.write_loss(log_directory, "hypernetwork_loss.csv", hypernetwork.step, len(ds), { - "loss": f"{losses.mean():.7f}", + "loss": f"{mean_loss:.7f}", "learn_rate": scheduler.learn_rate }) @@ -328,7 +330,7 @@ def train_hypernetwork(hypernetwork_name, learn_rate, batch_size, data_root, log shared.state.textinfo = f"""

-Loss: {losses.mean():.7f}
+Loss: {mean_loss:.7f}
Step: {hypernetwork.step}
Last prompt: {html.escape(entries[0].cond_text)}
Last saved embedding: {html.escape(last_saved_file)}
From 9e846083b702a498fdb60accd72f075fa26701d9 Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Fri, 14 Oct 2022 14:50:25 +0100 Subject: [PATCH 03/13] add vector size to embed text --- modules/textual_inversion/textual_inversion.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py index e754747e..6f549d62 100644 --- a/modules/textual_inversion/textual_inversion.py +++ b/modules/textual_inversion/textual_inversion.py @@ -327,10 +327,16 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc info.add_text("sd-ti-embedding", embedding_to_b64(data)) title = "<{}>".format(data.get('name', '???')) + + try: + vectorSize = list(data['string_to_param'].values())[0].shape[0] + except Exception as e: + vectorSize = '?' + checkpoint = sd_models.select_checkpoint() footer_left = checkpoint.model_name footer_mid = '[{}]'.format(checkpoint.hash) - footer_right = '{}'.format(embedding.step) + footer_right = 'v{} {}s'.format(vectorSize, embedding.step) captioned_image = caption_image_overlay(image, title, footer_left, footer_mid, footer_right) captioned_image = insert_image_data_embed(captioned_image, data) From 939f16529a72fe48c2ce3ef31bdaba785925a33c Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Fri, 14 Oct 2022 14:55:05 +0100 Subject: [PATCH 04/13] only save 1 image per embedding --- modules/textual_inversion/textual_inversion.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py index 6f549d62..1d697c90 100644 --- a/modules/textual_inversion/textual_inversion.py +++ b/modules/textual_inversion/textual_inversion.py @@ -242,6 +242,7 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc last_saved_file = "" last_saved_image = "" + embedding_yet_to_be_embedded = False ititial_step = embedding.step or 0 if ititial_step > steps: @@ -281,6 +282,7 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc if embedding.step > 0 and embedding_dir is not None and embedding.step % save_embedding_every == 0: last_saved_file = os.path.join(embedding_dir, f'{embedding_name}-{embedding.step}.pt') embedding.save(last_saved_file) + embedding_yet_to_be_embedded = True write_loss(log_directory, "textual_inversion_loss.csv", embedding.step, len(ds), { "loss": f"{losses.mean():.7f}", @@ -318,7 +320,7 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc shared.state.current_image = image - if save_image_with_stored_embedding and os.path.exists(last_saved_file): + if save_image_with_stored_embedding and os.path.exists(last_saved_file) and embedding_yet_to_be_embedded: last_saved_image_chunks = os.path.join(images_embeds_dir, f'{embedding_name}-{embedding.step}.png') @@ -342,6 +344,7 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc captioned_image = insert_image_data_embed(captioned_image, data) captioned_image.save(last_saved_image_chunks, "PNG", pnginfo=info) + embedding_yet_to_be_embedded = False image.save(last_saved_image) From 9a1dcd78edbf9caf68b9e6286d7b5ca81500e243 Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:14:02 +0100 Subject: [PATCH 05/13] add webp for embed load --- modules/textual_inversion/textual_inversion.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py index 1d697c90..c07bffc3 100644 --- a/modules/textual_inversion/textual_inversion.py +++ b/modules/textual_inversion/textual_inversion.py @@ -96,6 +96,10 @@ class EmbeddingDatabase: else: data = extract_image_data_embed(embed_image) name = data.get('name', name) + elif filename.upper().endswith('.WEBP'): + embed_image = Image.open(path) + data = extract_image_data_embed(embed_image) + name = data.get('name', name) else: data = torch.load(path, map_location="cpu") From ddf6899df0cf87d4da77cb2ce223061f4a5edf18 Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:23:20 +0100 Subject: [PATCH 06/13] generalise to popular lossless formats --- modules/textual_inversion/textual_inversion.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py index c07bffc3..b99df3b1 100644 --- a/modules/textual_inversion/textual_inversion.py +++ b/modules/textual_inversion/textual_inversion.py @@ -88,18 +88,14 @@ class EmbeddingDatabase: data = [] - if filename.upper().endswith('.PNG'): + if os.path.splitext(filename.upper())[-1] in ['.PNG', '.WEBP', '.JXL', '.AVIF']: embed_image = Image.open(path) - if 'sd-ti-embedding' in embed_image.text: + if hasattr(embed_image, 'text') and 'sd-ti-embedding' in embed_image.text: data = embedding_from_b64(embed_image.text['sd-ti-embedding']) name = data.get('name', name) else: data = extract_image_data_embed(embed_image) name = data.get('name', name) - elif filename.upper().endswith('.WEBP'): - embed_image = Image.open(path) - data = extract_image_data_embed(embed_image) - name = data.get('name', name) else: data = torch.load(path, map_location="cpu") From b6e3b96dab94a00f51725f9cc977eebc6b4072ab Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Sat, 15 Oct 2022 15:17:21 +0100 Subject: [PATCH 07/13] Change vector size footer label --- modules/textual_inversion/textual_inversion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py index b99df3b1..2ed345b1 100644 --- a/modules/textual_inversion/textual_inversion.py +++ b/modules/textual_inversion/textual_inversion.py @@ -338,7 +338,7 @@ def train_embedding(embedding_name, learn_rate, batch_size, data_root, log_direc checkpoint = sd_models.select_checkpoint() footer_left = checkpoint.model_name footer_mid = '[{}]'.format(checkpoint.hash) - footer_right = 'v{} {}s'.format(vectorSize, embedding.step) + footer_right = '{}v {}s'.format(vectorSize, embedding.step) captioned_image = caption_image_overlay(image, title, footer_left, footer_mid, footer_right) captioned_image = insert_image_data_embed(captioned_image, data) From 606519813dd998140a741096f9029c732ee52d2a Mon Sep 17 00:00:00 2001 From: guaneec Date: Sat, 15 Oct 2022 22:10:39 +0800 Subject: [PATCH 08/13] Prevent modal content from being selected --- style.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/style.css b/style.css index 920c32ab..33832ebf 100644 --- a/style.css +++ b/style.css @@ -309,6 +309,8 @@ input[type="range"]{ height: 100%; overflow: auto; background-color: rgba(20, 20, 20, 0.95); + user-select: none; + -webkit-user-select: none; } .modalControls { @@ -513,4 +515,4 @@ img2maskimg, #img2maskimg > .h-60, #img2maskimg > .h-60 > div, #img2maskimg > .h height: 480px !important; max-height: 480px !important; min-height: 480px !important; -} \ No newline at end of file +} From 74a9ee70020ffa2746c82300c533de3f7e523f22 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 15 Oct 2022 17:25:35 +0300 Subject: [PATCH 09/13] fix saving images compatibility with gradio update --- modules/ui.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 3206113e..b867d40f 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -154,10 +154,7 @@ def save_files(js_data, images, do_make_zip, index): writer.writerow(["prompt", "seed", "width", "height", "sampler", "cfgs", "steps", "filename", "negative_prompt"]) for image_index, filedata in enumerate(images, start_index): - if filedata.startswith("data:image/png;base64,"): - filedata = filedata[len("data:image/png;base64,"):] - - image = Image.open(io.BytesIO(base64.decodebytes(filedata.encode('utf-8')))) + image = image_from_url_text(filedata) is_grid = image_index < p.index_of_first_image i = 0 if is_grid else (image_index - p.index_of_first_image) From 09814e3cf384bf4189d57d1573483f72b38fb99f Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:06:34 +0300 Subject: [PATCH 10/13] Update launch.py --- launch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/launch.py b/launch.py index 537670a3..e3208553 100644 --- a/launch.py +++ b/launch.py @@ -107,6 +107,7 @@ def prepare_enviroment(): xformers = '--xformers' in args deepdanbooru = '--deepdanbooru' in args ngrok = '--ngrok' in args + reinstall_xformers = '--reinstall-xformers' in args try: commit = run(f"{git} rev-parse HEAD").strip() @@ -128,9 +129,9 @@ def prepare_enviroment(): if not is_installed("clip"): run_pip(f"install {clip_package}", "clip") - if not is_installed("xformers") and xformers and platform.python_version().startswith("3.10"): + if (not is_installed("xformers") or reinstall_xformers) and xformers and platform.python_version().startswith("3.10"): if platform.system() == "Windows": - run_pip("install https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/c/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl", "xformers") + run_pip("install -U -I --no-deps https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl", "xformers") elif platform.system() == "Linux": run_pip("install xformers", "xformers") From 529afbf4d70165a0dfd19eb9c2ec22416b794a1d Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:19:54 +0300 Subject: [PATCH 11/13] Update sd_hijack.py --- modules/sd_hijack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py index c81722a0..984b35c4 100644 --- a/modules/sd_hijack.py +++ b/modules/sd_hijack.py @@ -24,7 +24,7 @@ def apply_optimizations(): ldm.modules.diffusionmodules.model.nonlinearity = silu - if cmd_opts.force_enable_xformers or (cmd_opts.xformers and shared.xformers_available and torch.version.cuda and (6, 0) <= torch.cuda.get_device_capability(shared.device) <= (8, 6)): + if cmd_opts.force_enable_xformers or (cmd_opts.xformers and shared.xformers_available and torch.version.cuda and (6, 0) <= torch.cuda.get_device_capability(shared.device) <= (9, 0)): print("Applying xformers cross attention optimization.") ldm.modules.attention.CrossAttention.forward = sd_hijack_optimizations.xformers_attention_forward ldm.modules.diffusionmodules.model.AttnBlock.forward = sd_hijack_optimizations.xformers_attnblock_forward From 8fb0b991522658d938ae43de77f708555aa1902b Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Sat, 15 Oct 2022 20:17:51 +0300 Subject: [PATCH 12/13] Update launch.py --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch.py b/launch.py index e3208553..5ec2b926 100644 --- a/launch.py +++ b/launch.py @@ -104,10 +104,10 @@ def prepare_enviroment(): args = shlex.split(commandline_args) args, skip_torch_cuda_test = extract_arg(args, '--skip-torch-cuda-test') + args, reinstall_xformers = extract_argg(args, '--reinstall-xformers') xformers = '--xformers' in args deepdanbooru = '--deepdanbooru' in args ngrok = '--ngrok' in args - reinstall_xformers = '--reinstall-xformers' in args try: commit = run(f"{git} rev-parse HEAD").strip() From be1596ce30b1ead6998da0c62003003dcce5eb2c Mon Sep 17 00:00:00 2001 From: C43H66N12O12S2 <36072735+C43H66N12O12S2@users.noreply.github.com> Date: Sat, 15 Oct 2022 20:19:16 +0300 Subject: [PATCH 13/13] fix typo --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch.py b/launch.py index 5ec2b926..2e6b3369 100644 --- a/launch.py +++ b/launch.py @@ -104,7 +104,7 @@ def prepare_enviroment(): args = shlex.split(commandline_args) args, skip_torch_cuda_test = extract_arg(args, '--skip-torch-cuda-test') - args, reinstall_xformers = extract_argg(args, '--reinstall-xformers') + args, reinstall_xformers = extract_arg(args, '--reinstall-xformers') xformers = '--xformers' in args deepdanbooru = '--deepdanbooru' in args ngrok = '--ngrok' in args