make loras before 0.4.0 ALSO work

This commit is contained in:
AUTOMATIC 2023-01-23 18:52:55 +03:00
parent 171a5b3bb9
commit c6f20f7262
1 changed files with 2 additions and 1 deletions

View File

@ -57,6 +57,7 @@ class LoraUpDownModule:
def __init__(self):
self.up = None
self.down = None
self.alpha = None
def assign_lora_names_to_compvis_modules(sd_model):
@ -165,7 +166,7 @@ def lora_forward(module, input, res):
for lora in loaded_loras:
module = lora.modules.get(lora_layer_name, None)
if module is not None:
res = res + module.up(module.down(input)) * lora.multiplier * module.alpha / module.up.weight.shape[1]
res = res + module.up(module.down(input)) * lora.multiplier * (module.alpha / module.up.weight.shape[1] if module.alpha else 1.0)
return res