From c8045c5ad4f99deb3a19add06e0457de1df62b05 Mon Sep 17 00:00:00 2001 From: SGKoishi Date: Sun, 16 Oct 2022 10:08:23 -0700 Subject: The hide_ui_dir_config flag also restrict write attempt to path settings --- modules/shared.py | 10 ++++++++++ modules/ui.py | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/shared.py b/modules/shared.py index dcab0af9..c2775603 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -77,6 +77,16 @@ parser.add_argument("--disable-safe-unpickle", action='store_true', help="disabl cmd_opts = parser.parse_args() +restricted_opts = [ + "samples_filename_pattern", + "outdir_samples", + "outdir_txt2img_samples", + "outdir_img2img_samples", + "outdir_extras_samples", + "outdir_grids", + "outdir_txt2img_grids", + "outdir_save", +] devices.device, devices.device_interrogate, devices.device_gfpgan, devices.device_bsrgan, devices.device_esrgan, devices.device_scunet, devices.device_codeformer = \ (devices.cpu if any(y in cmd_opts.use_cpu for y in [x, 'all']) else devices.get_optimal_device() for x in ['sd', 'interrogate', 'gfpgan', 'bsrgan', 'esrgan', 'scunet', 'codeformer']) diff --git a/modules/ui.py b/modules/ui.py index 7b0d5a92..43dc88fc 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -25,7 +25,7 @@ import gradio.routes from modules import sd_hijack, sd_models from modules.paths import script_path -from modules.shared import opts, cmd_opts +from modules.shared import opts, cmd_opts, restricted_opts if cmd_opts.deepdanbooru: from modules.deepbooru import get_deepbooru_tags import modules.shared as shared @@ -1430,6 +1430,9 @@ Requested path was: {f} if comp_args and isinstance(comp_args, dict) and comp_args.get('visible') is False: continue + if cmd_opts.hide_ui_dir_config and key in restricted_opts: + continue + oldval = opts.data.get(key, None) opts.data[key] = value @@ -1447,6 +1450,9 @@ Requested path was: {f} if not opts.same_type(value, opts.data_labels[key].default): return gr.update(visible=True), opts.dumpjson() + if cmd_opts.hide_ui_dir_config and key in restricted_opts: + return gr.update(value=oldval), opts.dumpjson() + oldval = opts.data.get(key, None) opts.data[key] = value -- cgit v1.2.3 From 0fd130767102ebcf90e97c6c191ecf199a2d4091 Mon Sep 17 00:00:00 2001 From: MrCheeze Date: Sun, 16 Oct 2022 18:44:39 -0400 Subject: improve performance of 3-way merge on machines with not enough ram, by only accessing two of the models at a time --- modules/extras.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/modules/extras.py b/modules/extras.py index 0819ed37..340a45fd 100644 --- a/modules/extras.py +++ b/modules/extras.py @@ -175,11 +175,14 @@ def run_pnginfo(image): def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_name, interp_method, multiplier, save_as_half, custom_name): - def weighted_sum(theta0, theta1, theta2, alpha): + def weighted_sum(theta0, theta1, alpha): return ((1 - alpha) * theta0) + (alpha * theta1) - def add_difference(theta0, theta1, theta2, alpha): - return theta0 + (theta1 - theta2) * alpha + def get_difference(theta1, theta2): + return theta1 - theta2 + + def add_difference(theta0, theta1_2_diff, alpha): + return theta0 + (alpha * theta1_2_diff) primary_model_info = sd_models.checkpoints_list[primary_model_name] secondary_model_info = sd_models.checkpoints_list[secondary_model_name] @@ -201,20 +204,24 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam theta_2 = None theta_funcs = { - "Weighted sum": weighted_sum, - "Add difference": add_difference, + "Weighted sum": (None, weighted_sum), + "Add difference": (get_difference, add_difference), } - theta_func = theta_funcs[interp_method] + theta_func1, theta_func2 = theta_funcs[interp_method] print(f"Merging...") + if theta_func1: + for key in tqdm.tqdm(theta_1.keys()): + if 'model' in key: + t2 = theta_2.get(key, torch.zeros_like(theta_1[key])) + theta_1[key] = theta_func1(theta_1[key], t2) + del theta_2, teritary_model + for key in tqdm.tqdm(theta_0.keys()): if 'model' in key and key in theta_1: - t2 = (theta_2 or {}).get(key) - if t2 is None: - t2 = torch.zeros_like(theta_0[key]) - theta_0[key] = theta_func(theta_0[key], theta_1[key], t2, multiplier) + theta_0[key] = theta_func2(theta_0[key], theta_1[key], multiplier) if save_as_half: theta_0[key] = theta_0[key].half() -- cgit v1.2.3 From 6f7b7a3dcdc471ebe63baa8a7731952557859c5b Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Mon, 17 Oct 2022 07:56:08 +0300 Subject: only read files with .py extension from the scripts dir --- modules/scripts.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules') diff --git a/modules/scripts.py b/modules/scripts.py index 45230f9a..ac66d448 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -58,6 +58,9 @@ def load_scripts(basedir): for filename in sorted(os.listdir(basedir)): path = os.path.join(basedir, filename) + if os.path.splitext(path)[1].lower() != '.py': + continue + if not os.path.isfile(path): continue -- cgit v1.2.3 From 58f3ef77336663bce2321f5b692cf2aeacd3ac1c Mon Sep 17 00:00:00 2001 From: DenkingOfficial Date: Mon, 17 Oct 2022 03:10:59 +0500 Subject: Fix CLIP Interrogator and disable ranks for it --- modules/interrogate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/interrogate.py b/modules/interrogate.py index 9263d65a..d85d7dcc 100644 --- a/modules/interrogate.py +++ b/modules/interrogate.py @@ -157,9 +157,9 @@ class InterrogateModels: matches = self.rank(image_features, items, top_count=topn) for match, score in matches: if include_ranks: - res += ", " + match - else: res += f", ({match}:{score})" + else: + res += ", " + match except Exception: print(f"Error interrogating", file=sys.stderr) -- cgit v1.2.3 From 5c94aaf290f8ad7bf4499a91c268ad0791b0432f Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Mon, 17 Oct 2022 08:28:18 +0300 Subject: fix bug for latest model merge RAM improvement --- modules/extras.py | 1 + 1 file changed, 1 insertion(+) (limited to 'modules') diff --git a/modules/extras.py b/modules/extras.py index 340a45fd..8dbab240 100644 --- a/modules/extras.py +++ b/modules/extras.py @@ -201,6 +201,7 @@ def run_modelmerger(primary_model_name, secondary_model_name, teritary_model_nam teritary_model = torch.load(teritary_model_info.filename, map_location='cpu') theta_2 = sd_models.get_state_dict_from_checkpoint(teritary_model) else: + teritary_model = None theta_2 = None theta_funcs = { -- cgit v1.2.3 From b99d3cf6dd9bc817e51d0d0a6e8eb12c7c0ac6af Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Mon, 17 Oct 2022 08:41:02 +0300 Subject: make CLIP interrogate ranks output sane values --- modules/interrogate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules') diff --git a/modules/interrogate.py b/modules/interrogate.py index d85d7dcc..64b91eb4 100644 --- a/modules/interrogate.py +++ b/modules/interrogate.py @@ -123,7 +123,7 @@ class InterrogateModels: return caption[0] - def interrogate(self, pil_image, include_ranks=False): + def interrogate(self, pil_image): res = None try: @@ -156,8 +156,8 @@ class InterrogateModels: for name, topn, items in self.categories: matches = self.rank(image_features, items, top_count=topn) for match, score in matches: - if include_ranks: - res += f", ({match}:{score})" + if shared.opts.interrogate_return_ranks: + res += f", ({match}:{score/100:.3f})" else: res += ", " + match -- cgit v1.2.3 From 62edfae257e8982cd620d03862c7bdd44159d18f Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Sun, 16 Oct 2022 20:28:15 +0100 Subject: print list of embeddings on reload --- modules/textual_inversion/textual_inversion.py | 1 + 1 file changed, 1 insertion(+) (limited to 'modules') diff --git a/modules/textual_inversion/textual_inversion.py b/modules/textual_inversion/textual_inversion.py index 7ec75018..3be69562 100644 --- a/modules/textual_inversion/textual_inversion.py +++ b/modules/textual_inversion/textual_inversion.py @@ -137,6 +137,7 @@ class EmbeddingDatabase: continue print(f"Loaded a total of {len(self.word_embeddings)} textual inversion embeddings.") + print("Embeddings:", ', '.join(self.word_embeddings.keys())) def find_embedding_at_position(self, tokens, offset): token = tokens[offset] -- cgit v1.2.3