From ae768f53a4f3adb6cfebe10d35d5e89eaccd5eeb Mon Sep 17 00:00:00 2001 From: kijai <40791699+kijai@users.noreply.github.com> Date: Sat, 6 Sep 2025 19:28:16 +0300 Subject: [PATCH] Make merge_lora switches with multiple loras behave like it used to and how the tooltip indicates --- nodes_model_loading.py | 8 +++----- utils.py | 10 +++++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/nodes_model_loading.py b/nodes_model_loading.py index 8d10280..b96c24f 100644 --- a/nodes_model_loading.py +++ b/nodes_model_loading.py @@ -866,7 +866,6 @@ def load_weights(transformer, sd=None, weight_dtype=None, base_dtype=None, if cnt % 100 == 0: pbar.update(100) - pbar.update_absolute(param_count) pbar.update_absolute(0) def patch_control_lora(transformer, device): @@ -995,9 +994,8 @@ class WanVideoModelLoader: extra_model = vace_model lora_low_mem_load = merge_loras = False if lora is not None: - for l in lora: - lora_low_mem_load = l.get("low_mem_load", False) - merge_loras = l.get("merge_loras", True) + merge_loras = any(l.get("merge_loras", True) for l in lora) + lora_low_mem_load = any(l.get("low_mem_load", False) for l in lora) transformer = None mm.unload_all_models() @@ -1372,7 +1370,7 @@ class WanVideoModelLoader: log.info("Merging LoRA to the model...") patcher = apply_lora( patcher, device, transformer_load_device, params_to_keep=params_to_keep, dtype=weight_dtype, base_dtype=base_dtype, state_dict=sd, - low_mem_load=lora_low_mem_load, control_lora=control_lora, scale_weights=scale_weights,) + low_mem_load=lora_low_mem_load, control_lora=control_lora, scale_weights=scale_weights) if not control_lora: scale_weights.clear() patcher.patches.clear() diff --git a/utils.py b/utils.py index b00b811..ac58556 100644 --- a/utils.py +++ b/utils.py @@ -173,7 +173,8 @@ def apply_lora(model, device_to, transformer_load_device, params_to_keep=None, d to_load.append((n, m, params)) to_load.sort(reverse=True) - #pbar = ProgressBar(len(to_load)) + cnt = 0 + pbar = ProgressBar(len(to_load)) for x in tqdm(to_load, desc="Loading model and applying LoRA weights:", leave=True): name = x[0] m = x[1] @@ -207,8 +208,11 @@ def apply_lora(model, device_to, transformer_load_device, params_to_keep=None, d except: continue m.comfy_patched_weights = True - #pbar.update(1) - + cnt += 1 + if cnt % 100 == 0: + pbar.update(100) + + # After LoRA patching, scale weights that have scale_weight but are NOT LoRA patched if len(scale_weights) > 0 and not getattr(model, "scale_weights_applied", False): for name, param in model.model.diffusion_model.named_parameters():