From 0aaabfc2e6b2e343f9c16d058253e6b5fcc0c5fd Mon Sep 17 00:00:00 2001 From: Disty0 Date: Fri, 21 Jun 2024 15:18:09 +0300 Subject: [PATCH] NNCF fix Lora support without reloading --- extensions-builtin/Lora/network_lora.py | 3 ++- extensions-builtin/Lora/networks.py | 5 ----- modules/sd_models_compile.py | 3 --- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/extensions-builtin/Lora/network_lora.py b/extensions-builtin/Lora/network_lora.py index 76a8322da..5194222a0 100644 --- a/extensions-builtin/Lora/network_lora.py +++ b/extensions-builtin/Lora/network_lora.py @@ -24,7 +24,8 @@ class NetworkModuleLora(network.NetworkModule): weight = weights.get(key) if weight is None and none_ok: return None - is_linear = type(self.sd_module) in [torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, diffusers_lora.LoRACompatibleLinear] + linear_modules = [torch.nn.Linear, torch.nn.modules.linear.NonDynamicallyQuantizableLinear, torch.nn.MultiheadAttention, diffusers_lora.LoRACompatibleLinear] + is_linear = type(self.sd_module) in linear_modules or self.sd_module.__class__.__name__ == "NNCFLinear" is_conv = type(self.sd_module) in [torch.nn.Conv2d, diffusers_lora.LoRACompatibleConv] if is_linear: weight = weight.reshape(weight.shape[0], -1) diff --git a/extensions-builtin/Lora/networks.py b/extensions-builtin/Lora/networks.py index 3ebad5f17..71b5b29dc 100644 --- a/extensions-builtin/Lora/networks.py +++ b/extensions-builtin/Lora/networks.py @@ -185,13 +185,10 @@ def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=No shared.compiled_model_state.lora_model = [] if recompile_model: backup_cuda_compile = shared.opts.cuda_compile - backup_nncf_compress_weights = shared.opts.nncf_compress_weights sd_models.unload_model_weights(op='model') shared.opts.cuda_compile = False - shared.opts.nncf_compress_weights = [] sd_models.reload_model_weights(op='model') shared.opts.cuda_compile = backup_cuda_compile - shared.opts.nncf_compress_weights = backup_nncf_compress_weights loaded_networks.clear() for i, (network_on_disk, name) in enumerate(zip(networks_on_disk, names)): @@ -235,8 +232,6 @@ def load_networks(names, te_multipliers=None, unet_multipliers=None, dyn_dims=No if recompile_model: shared.log.info("LoRA recompiling model") backup_lora_model = shared.compiled_model_state.lora_model - if shared.opts.nncf_compress_weights and not (shared.opts.cuda_compile and shared.opts.cuda_compile_backend == "openvino_fx"): - shared.sd_model = sd_models_compile.nncf_compress_weights(shared.sd_model) if shared.opts.cuda_compile: shared.sd_model = sd_models_compile.compile_diffusers(shared.sd_model) diff --git a/modules/sd_models_compile.py b/modules/sd_models_compile.py index 6e629788c..ed3109869 100644 --- a/modules/sd_models_compile.py +++ b/modules/sd_models_compile.py @@ -140,9 +140,6 @@ def nncf_compress_weights(sd_model): from installer import install install('nncf==2.7.0', quiet=True) - shared.compiled_model_state = CompiledModelState() - shared.compiled_model_state.is_compiled = True - sd_model = apply_compile_to_model(sd_model, nncf_compress_model, shared.opts.nncf_compress_weights, op="nncf") t1 = time.time()