diff options
author | v0xie <28695009+v0xie@users.noreply.github.com> | 2023-10-22 16:27:48 +0000 |
---|---|---|
committer | v0xie <28695009+v0xie@users.noreply.github.com> | 2023-10-22 16:27:48 +0000 |
commit | 3b8515d2c9abad7f0ccaac0215803716e861ee0e (patch) | |
tree | 18cd6db4d76b3e4bca727c0abc481478d7242199 /extensions-builtin/Lora | |
parent | 4a50c9638c3eac860fb05ae603cd61aabf4cd1a9 (diff) | |
download | stable-diffusion-webui-gfx803-3b8515d2c9abad7f0ccaac0215803716e861ee0e.tar.gz stable-diffusion-webui-gfx803-3b8515d2c9abad7f0ccaac0215803716e861ee0e.tar.bz2 stable-diffusion-webui-gfx803-3b8515d2c9abad7f0ccaac0215803716e861ee0e.zip |
fix: multiplier applied twice in finalize_updown
Diffstat (limited to 'extensions-builtin/Lora')
-rw-r--r-- | extensions-builtin/Lora/network_oft.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/extensions-builtin/Lora/network_oft.py b/extensions-builtin/Lora/network_oft.py index 3034a407..efbdd296 100644 --- a/extensions-builtin/Lora/network_oft.py +++ b/extensions-builtin/Lora/network_oft.py @@ -54,7 +54,8 @@ class NetworkModuleOFT(network.NetworkModule): return R def calc_updown(self, orig_weight): - R = self.get_weight(self.oft_blocks, self.multiplier()) + multiplier = self.multiplier() * self.calc_scale() + R = self.get_weight(self.oft_blocks, multiplier) merged_weight = self.merge_weight(R, orig_weight) updown = merged_weight.to(orig_weight.device, dtype=orig_weight.dtype) - orig_weight @@ -62,3 +63,23 @@ class NetworkModuleOFT(network.NetworkModule): orig_weight = orig_weight return self.finalize_updown(updown, orig_weight, output_shape) + + # override to remove the multiplier/scale factor; it's already multiplied in get_weight + def finalize_updown(self, updown, orig_weight, output_shape, ex_bias=None): + #return super().finalize_updown(updown, orig_weight, output_shape, ex_bias) + + if self.bias is not None: + updown = updown.reshape(self.bias.shape) + updown += self.bias.to(orig_weight.device, dtype=orig_weight.dtype) + updown = updown.reshape(output_shape) + + if len(output_shape) == 4: + updown = updown.reshape(output_shape) + + if orig_weight.size().numel() == updown.size().numel(): + updown = updown.reshape(orig_weight.shape) + + if ex_bias is not None: + ex_bias = ex_bias * self.multiplier() + + return updown, ex_bias |