From 3a633e539bafcdabbe1b830790af037fec8e93c6 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Fri, 1 Nov 2024 11:58:08 -0400 Subject: [PATCH] better lora enum Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 1 + extensions-builtin/Lora/networks.py | 13 +++++-------- modules/script_loading.py | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d087ec68d..fbb1d4498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - list diffusers remove duplicates - fix legacy extensions access to shared objects - fix diffusers load from folder + - fix lora enum logging on windows - move dowwloads of some auxillary models to hfcache instead of models folder ## Update for 2024-10-29 diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 83aa6b40b..59758e0f1 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -533,18 +533,14 @@ def network_MultiheadAttention_load_state_dict(self, *args, **kwargs): def list_available_networks(): + t0 = time.time() available_networks.clear() available_network_aliases.clear() forbidden_network_aliases.clear() available_network_hash_lookup.clear() forbidden_network_aliases.update({"none": 1, "Addams": 1}) - directories = [] - if os.path.exists(shared.cmd_opts.lora_dir): - directories.append(shared.cmd_opts.lora_dir) - else: + if not os.path.exists(shared.cmd_opts.lora_dir): shared.log.warning(f'LoRA directory not found: path="{shared.cmd_opts.lora_dir}"') - if os.path.exists(shared.cmd_opts.lyco_dir) and shared.cmd_opts.lyco_dir != shared.cmd_opts.lora_dir: - directories.append(shared.cmd_opts.lyco_dir) def add_network(filename): if not os.path.isfile(filename): @@ -565,11 +561,12 @@ def list_available_networks(): except OSError as e: # should catch FileNotFoundError and PermissionError etc. shared.log.error(f'LoRA: filename="{filename}" {e}') - candidates = list(files_cache.list_files(*directories, ext_filter=[".pt", ".ckpt", ".safetensors"])) + candidates = list(files_cache.list_files(shared.cmd_opts.lora_dir, ext_filter=[".pt", ".ckpt", ".safetensors"])) with concurrent.futures.ThreadPoolExecutor(max_workers=shared.max_workers) as executor: for fn in candidates: executor.submit(add_network, fn) - shared.log.info(f'Available LoRAs: items={len(available_networks)} folders={len(forbidden_network_aliases)}') + t1 = time.time() + shared.log.info(f'Available LoRAs: path="{shared.cmd_opts.lora_dir}" items={len(available_networks)} folders={len(forbidden_network_aliases)} time={t1 - t0:.2f}') def infotext_pasted(infotext, params): # pylint: disable=W0613 diff --git a/modules/script_loading.py b/modules/script_loading.py index f39394625..37f64b33f 100644 --- a/modules/script_loading.py +++ b/modules/script_loading.py @@ -14,7 +14,7 @@ def load_module(path): module_spec = importlib.util.spec_from_file_location(os.path.basename(path), path) module = importlib.util.module_from_spec(module_spec) try: - if '/sd-extension-' in path or '/Lora' in path: # safe extensions without stdout intercept + if 'sd-extension-' in path or 'Lora' in path: # safe extensions without stdout intercept module_spec.loader.exec_module(module) else: if debug: