From 412401becbf53c6c28d2fa46b9fe7d06cc2eaa79 Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Thu, 3 Oct 2024 19:42:55 +0900 Subject: [PATCH] backup only for needed weights required by lora --- extensions-builtin/Lora/networks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 78d7407a0..0ad5f3e71 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -429,6 +429,18 @@ def network_backup_weights(self): current_names = getattr(self, "network_current_names", ()) wanted_names = tuple((x.name, x.te_multiplier, x.unet_multiplier, x.dyn_dim) for x in loaded_networks) + need_backup = False + for net in loaded_networks: + if network_layer_name in net.modules: + need_backup = True + break + elif network_layer_name + "_q_proj" in net.modules: + need_backup = True + break + + if not need_backup: + return + weights_backup = getattr(self, "network_weights_backup", None) if weights_backup is None and wanted_names != (): if current_names != () and not allowed_layer_without_weight(self):