fix(lora): restore native weights when LoRA removed on diffusers-path models

Flux2/Klein loads LoRAs as native modules through the diffusers method
path. network_activate() was only called when new native modules existed,
so removing a LoRA from the prompt left backed-up weights unrestored.

Check applied_layers to detect previously active native modules and
trigger network_activate() for the restore path.
This commit is contained in:
CalamitousFelicitousness
2026-04-29 02:00:33 +01:00
parent 6ddc4ff455
commit a028b56687
+4 -2
View File
@@ -339,9 +339,11 @@ def network_load(names, te_multipliers=None, unet_multipliers=None, dyn_dims=Non
shared.sd_model = sd_models.apply_balanced_offload(shared.sd_model, force=True, silent=True) # some layers may end up on cpu without hook
# Activate native modules loaded via diffusers path (e.g., LoKR on Flux2)
# Also restore backed-up weights when previously active native modules are removed
from modules.lora import networks
native_nets = [net for net in l.loaded_networks if len(net.modules) > 0]
if native_nets:
from modules.lora import networks
had_native = len(networks.applied_layers) > 0
if native_nets or had_native:
networks.network_activate()
if len(l.loaded_networks) > 0 and l.debug: