diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-07-19 04:59:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-19 04:59:39 +0000 |
commit | 0a334b447ff0c41519bb9e280050736913ad9cf8 (patch) | |
tree | e27963f76b7357ff0cb7b2c3fdcb720ab64f0e50 /extensions-builtin/Lora/lyco_helpers.py | |
parent | 6094310704f4b3853bfa5d05d9c1ace58b2deee7 (diff) | |
parent | c2b975485708791b29d44d79ee1a48d3abd838b7 (diff) | |
download | stable-diffusion-webui-gfx803-0a334b447ff0c41519bb9e280050736913ad9cf8.tar.gz stable-diffusion-webui-gfx803-0a334b447ff0c41519bb9e280050736913ad9cf8.tar.bz2 stable-diffusion-webui-gfx803-0a334b447ff0c41519bb9e280050736913ad9cf8.zip |
Merge branch 'dev' into allow-no-venv-install
Diffstat (limited to 'extensions-builtin/Lora/lyco_helpers.py')
-rw-r--r-- | extensions-builtin/Lora/lyco_helpers.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/extensions-builtin/Lora/lyco_helpers.py b/extensions-builtin/Lora/lyco_helpers.py new file mode 100644 index 00000000..279b34bc --- /dev/null +++ b/extensions-builtin/Lora/lyco_helpers.py @@ -0,0 +1,21 @@ +import torch
+
+
+def make_weight_cp(t, wa, wb):
+ temp = torch.einsum('i j k l, j r -> i r k l', t, wb)
+ return torch.einsum('i j k l, i r -> r j k l', temp, wa)
+
+
+def rebuild_conventional(up, down, shape, dyn_dim=None):
+ up = up.reshape(up.size(0), -1)
+ down = down.reshape(down.size(0), -1)
+ if dyn_dim is not None:
+ up = up[:, :dyn_dim]
+ down = down[:dyn_dim, :]
+ return (up @ down).reshape(shape)
+
+
+def rebuild_cp_decomposition(up, down, mid):
+ up = up.reshape(up.size(0), -1)
+ down = down.reshape(down.size(0), -1)
+ return torch.einsum('n m k l, i n, m j -> i j k l', mid, up, down)
|