NNCF fix Lora support without reloading

This commit is contained in:
Disty0
2024-06-21 15:18:09 +03:00
parent f38fc17906
commit 0aaabfc2e6
3 changed files with 2 additions and 9 deletions
+2 -1
View File
@@ -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)
-5
View File
@@ -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)
-3
View File
@@ -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()