From 9a33292ce41b01252cdb8ab6214a11d274e32fa0 Mon Sep 17 00:00:00 2001 From: zhengxiaoyao0716 <1499383852@qq.com> Date: Sat, 15 Oct 2022 01:04:47 +0800 Subject: [PATCH 1/9] reload javascript files when custom script bodies --- modules/ui.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index b867d40f..90b8646b 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -12,7 +12,7 @@ import time import traceback import platform import subprocess as sp -from functools import reduce +from functools import partial, reduce import numpy as np import torch @@ -1491,6 +1491,7 @@ Requested path was: {f} def reload_scripts(): modules.scripts.reload_script_body_only() + reload_javascript() # need to refresh the html page reload_script_bodies.click( fn=reload_scripts, @@ -1738,22 +1739,25 @@ Requested path was: {f} return demo -with open(os.path.join(script_path, "script.js"), "r", encoding="utf8") as jsfile: - javascript = f'' +def load_javascript(raw_response): + with open(os.path.join(script_path, "script.js"), "r", encoding="utf8") as jsfile: + javascript = f'' -jsdir = os.path.join(script_path, "javascript") -for filename in sorted(os.listdir(jsdir)): - with open(os.path.join(jsdir, filename), "r", encoding="utf8") as jsfile: - javascript += f"\n" + jsdir = os.path.join(script_path, "javascript") + for filename in sorted(os.listdir(jsdir)): + with open(os.path.join(jsdir, filename), "r", encoding="utf8") as jsfile: + javascript += f"\n" - -if 'gradio_routes_templates_response' not in globals(): def template_response(*args, **kwargs): - res = gradio_routes_templates_response(*args, **kwargs) - res.body = res.body.replace(b'', f'{javascript}'.encode("utf8")) + res = raw_response(*args, **kwargs) + res.body = res.body.replace( + b'', f'{javascript}'.encode("utf8")) res.init_headers() return res - gradio_routes_templates_response = gradio.routes.templates.TemplateResponse gradio.routes.templates.TemplateResponse = template_response + +reload_javascript = partial(load_javascript, + gradio.routes.templates.TemplateResponse) +reload_javascript() From 2fd7935ef4ed296db5dfd8c7fea99244816f8cf0 Mon Sep 17 00:00:00 2001 From: Cheka Date: Tue, 18 Oct 2022 20:28:28 -0300 Subject: [PATCH 2/9] Remove wrong self reference in CUDA support for invokeai --- modules/sd_hijack_optimizations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sd_hijack_optimizations.py b/modules/sd_hijack_optimizations.py index a3345bb9..98123fbf 100644 --- a/modules/sd_hijack_optimizations.py +++ b/modules/sd_hijack_optimizations.py @@ -181,7 +181,7 @@ def einsum_op_cuda(q, k, v): mem_free_torch = mem_reserved - mem_active mem_free_total = mem_free_cuda + mem_free_torch # Divide factor of safety as there's copying and fragmentation - return self.einsum_op_tensor_mem(q, k, v, mem_free_total / 3.3 / (1 << 20)) + return einsum_op_tensor_mem(q, k, v, mem_free_total / 3.3 / (1 << 20)) def einsum_op(q, k, v): if q.device.type == 'cuda': From bcfbb33e50a48b237d8d961cc2be038db53774d5 Mon Sep 17 00:00:00 2001 From: Anastasius Date: Mon, 17 Oct 2022 13:35:20 -0700 Subject: [PATCH 3/9] Added time left estimation --- modules/ui.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/ui.py b/modules/ui.py index ca46343f..9a54aa16 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -261,6 +261,15 @@ def wrap_gradio_call(func, extra_outputs=None): return f +def calc_time_left(progress): + if progress == 0: + return "N/A" + else: + time_since_start = time.time() - shared.state.time_start + eta = (time_since_start/progress) + return time.strftime('%H:%M:%S', time.gmtime(eta-time_since_start)) + + def check_progress_call(id_part): if shared.state.job_count == 0: return "", gr_show(False), gr_show(False), gr_show(False) @@ -272,11 +281,13 @@ def check_progress_call(id_part): if shared.state.sampling_steps > 0: progress += 1 / shared.state.job_count * shared.state.sampling_step / shared.state.sampling_steps + time_left = calc_time_left( progress ) + progress = min(progress, 1) progressbar = "" if opts.show_progressbar: - progressbar = f"""
{str(int(progress*100))+"%" if progress > 0.01 else ""}
""" + progressbar = f"""
{str(int(progress*100))+"% ETA:"+time_left if progress > 0.01 else ""}
""" image = gr_show(False) preview_visibility = gr_show(False) @@ -308,6 +319,7 @@ def check_progress_call_initial(id_part): shared.state.current_latent = None shared.state.current_image = None shared.state.textinfo = None + shared.state.time_start = time.time() return check_progress_call(id_part) From 442dbedc159bb7e9cf94f0c3626f8a409e0a50eb Mon Sep 17 00:00:00 2001 From: Anastasius Date: Tue, 18 Oct 2022 10:38:07 -0700 Subject: [PATCH 4/9] Estimated time displayed if jobs take more 60 sec --- modules/ui.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 9a54aa16..fa54110b 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -261,13 +261,17 @@ def wrap_gradio_call(func, extra_outputs=None): return f -def calc_time_left(progress): +def calc_time_left(progress, threshold, label, force_display): if progress == 0: - return "N/A" + return "" else: time_since_start = time.time() - shared.state.time_start eta = (time_since_start/progress) - return time.strftime('%H:%M:%S', time.gmtime(eta-time_since_start)) + eta_relative = eta-time_since_start + if eta_relative > threshold or force_display: + return label + time.strftime('%H:%M:%S', time.gmtime(eta_relative)) + else: + return "" def check_progress_call(id_part): @@ -281,13 +285,15 @@ def check_progress_call(id_part): if shared.state.sampling_steps > 0: progress += 1 / shared.state.job_count * shared.state.sampling_step / shared.state.sampling_steps - time_left = calc_time_left( progress ) + time_left = calc_time_left( progress, 60, " ETA:", shared.state.time_left_force_display ) + if time_left != "": + shared.state.time_left_force_display = True progress = min(progress, 1) progressbar = "" if opts.show_progressbar: - progressbar = f"""
{str(int(progress*100))+"% ETA:"+time_left if progress > 0.01 else ""}
""" + progressbar = f"""
{str(int(progress*100))+"%"+time_left if progress > 0.01 else ""}
""" image = gr_show(False) preview_visibility = gr_show(False) @@ -320,6 +326,7 @@ def check_progress_call_initial(id_part): shared.state.current_image = None shared.state.textinfo = None shared.state.time_start = time.time() + shared.state.time_left_force_display = False return check_progress_call(id_part) From 1d4aa376e6111e90888a30ae24d2bcd7f978ec51 Mon Sep 17 00:00:00 2001 From: Anastasius Date: Tue, 18 Oct 2022 12:42:39 -0700 Subject: [PATCH 5/9] Predictable long operation check for time estimation --- modules/ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ui.py b/modules/ui.py index fa54110b..38ba1138 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -268,7 +268,7 @@ def calc_time_left(progress, threshold, label, force_display): time_since_start = time.time() - shared.state.time_start eta = (time_since_start/progress) eta_relative = eta-time_since_start - if eta_relative > threshold or force_display: + if (eta_relative > threshold and progress > 0.02) or force_display: return label + time.strftime('%H:%M:%S', time.gmtime(eta_relative)) else: return "" From 83a517eb96cc36cf1dc0915a9ebde43a7e05c7da Mon Sep 17 00:00:00 2001 From: realryo1 <60560430+realryo1@users.noreply.github.com> Date: Wed, 19 Oct 2022 04:48:00 +0900 Subject: [PATCH 6/9] Fixed performance, vram style disorder --- style.css | 5 ----- 1 file changed, 5 deletions(-) diff --git a/style.css b/style.css index 9dc4b696..9bd408cd 100644 --- a/style.css +++ b/style.css @@ -34,9 +34,6 @@ .performance { font-size: 0.85em; color: #444; - display: flex; - justify-content: space-between; - white-space: nowrap; } .performance .time { @@ -44,8 +41,6 @@ } .performance .vram { - margin-left: 0; - text-align: right; } #txt2img_generate, #img2img_generate { From bb0e7232b301d1706bbd0e09367dece3bb7ac07c Mon Sep 17 00:00:00 2001 From: Ikko Ashimine Date: Wed, 19 Oct 2022 02:18:56 +0900 Subject: [PATCH 7/9] Fix typo in prompt_parser.py assoicated -> associated --- modules/prompt_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/prompt_parser.py b/modules/prompt_parser.py index 919d5d31..f70872c4 100644 --- a/modules/prompt_parser.py +++ b/modules/prompt_parser.py @@ -275,7 +275,7 @@ re_attention = re.compile(r""" def parse_prompt_attention(text): """ - Parses a string with attention tokens and returns a list of pairs: text and its assoicated weight. + Parses a string with attention tokens and returns a list of pairs: text and its associated weight. Accepted tokens are: (abc) - increases attention to abc by a multiplier of 1.1 (abc:3.12) - increases attention to abc by a multiplier of 3.12 From 9931c0bd48346dc5af23864117becfac33347a7c Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Wed, 19 Oct 2022 12:01:31 +0300 Subject: [PATCH 8/9] remove the unneeded line break introduced by #3092 --- style.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/style.css b/style.css index 9bd408cd..26ae36a5 100644 --- a/style.css +++ b/style.css @@ -36,6 +36,10 @@ color: #444; } +.performance p{ + display: inline-block; +} + .performance .time { margin-right: 0; } From f894dd552f68bea27476f1f360ab8e79f3a65b4f Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Wed, 19 Oct 2022 12:45:30 +0300 Subject: [PATCH 9/9] fix for broken checkpoint merger --- modules/sd_models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/sd_models.py b/modules/sd_models.py index 7ad6d474..eae22e87 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -148,7 +148,10 @@ def get_state_dict_from_checkpoint(pl_sd): if new_key is not None: sd[new_key] = v - return sd + pl_sd.clear() + pl_sd.update(sd) + + return pl_sd def load_model_weights(model, checkpoint_info):