lycoris-lora 3.0.0.dev6__tar.gz → 3.0.0.dev8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {lycoris_lora-3.0.0.dev6/lycoris_lora.egg-info → lycoris_lora-3.0.0.dev8}/PKG-INFO +1 -1
  2. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/functional/loha.py +1 -3
  3. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/kohya.py +2 -8
  4. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/__init__.py +2 -1
  5. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/dylora.py +3 -0
  6. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/full.py +4 -0
  7. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/glora.py +8 -7
  8. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/locon.py +5 -3
  9. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/loha.py +4 -3
  10. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/lokr.py +4 -2
  11. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/utils/__init__.py +3 -3
  12. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8/lycoris_lora.egg-info}/PKG-INFO +1 -1
  13. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/setup.py +1 -1
  14. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/LICENSE.md +0 -0
  15. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/README.md +0 -0
  16. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/__init__.py +0 -0
  17. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/config.py +0 -0
  18. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/functional/__init__.py +0 -0
  19. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/functional/general.py +0 -0
  20. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/functional/locon.py +0 -0
  21. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/logging.py +0 -0
  22. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/base.py +0 -0
  23. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/boft.py +0 -0
  24. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/diag_oft.py +0 -0
  25. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/ia3.py +0 -0
  26. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/modules/norms.py +0 -0
  27. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/utils/bnb.py +0 -0
  28. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/utils/general.py +0 -0
  29. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/utils/logger.py +0 -0
  30. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/utils/preset.py +0 -0
  31. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/utils/xformers_utils.py +0 -0
  32. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris/wrapper.py +0 -0
  33. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris_lora.egg-info/SOURCES.txt +0 -0
  34. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris_lora.egg-info/dependency_links.txt +0 -0
  35. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris_lora.egg-info/not-zip-safe +0 -0
  36. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris_lora.egg-info/requires.txt +0 -0
  37. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/lycoris_lora.egg-info/top_level.txt +0 -0
  38. {lycoris_lora-3.0.0.dev6 → lycoris_lora-3.0.0.dev8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.0.dev6
3
+ Version: 3.0.0.dev8
4
4
  Summary: Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion
5
5
  Home-page: https://github.com/KohakuBlueleaf/LyCORIS
6
6
  Author: Shih-Ying Yeh(KohakuBlueLeaf), Yu-Guan Hsieh, Zhidong Gao
@@ -174,9 +174,7 @@ def loha_bypass_forward_diff(
174
174
 
175
175
  if __name__ == "__main__":
176
176
  w = torch.randn(128, 128, 3, 3, 3)
177
- w1d, w2d, w1u, w2u, t1, t2 = loha_weight_gen(
178
- w, 4, tucker=True
179
- )
177
+ w1d, w2d, w1u, w2u, t1, t2 = loha_weight_gen(w, 4, tucker=True)
180
178
  w1u += 0.01
181
179
  extra_args = {"padding": 1}
182
180
 
@@ -611,11 +611,8 @@ class LycorisNetworkKohya(LycorisNetwork):
611
611
  # Precalculate model hashes to save time on indexing
612
612
  if metadata is None:
613
613
  metadata = {}
614
- model_hash, legacy_hash = precalculate_safetensors_hashes(
615
- state_dict, metadata
616
- )
614
+ model_hash = precalculate_safetensors_hashes(state_dict)
617
615
  metadata["sshs_model_hash"] = model_hash
618
- metadata["sshs_legacy_hash"] = legacy_hash
619
616
 
620
617
  save_file(state_dict, file, metadata)
621
618
  else:
@@ -845,11 +842,8 @@ class IA3Network(torch.nn.Module):
845
842
  # Precalculate model hashes to save time on indexing
846
843
  if metadata is None:
847
844
  metadata = {}
848
- model_hash, legacy_hash = precalculate_safetensors_hashes(
849
- state_dict, metadata
850
- )
845
+ model_hash = precalculate_safetensors_hashes(state_dict)
851
846
  metadata["sshs_model_hash"] = model_hash
852
- metadata["sshs_legacy_hash"] = legacy_hash
853
847
 
854
848
  save_file(state_dict, file, metadata)
855
849
  else:
@@ -1,6 +1,7 @@
1
1
  import torch
2
2
  import torch.nn as nn
3
3
 
4
+ from .base import LycorisBaseModule
4
5
  from .locon import LoConModule
5
6
  from .loha import LohaModule
6
7
  from .lokr import LokrModule
@@ -57,7 +58,7 @@ def make_module(lyco_type, params, lora_name, orig_module):
57
58
  module.dora_scale.copy_(dora_scale)
58
59
  elif lyco_type == "kron":
59
60
  w1, w1a, w1b, w2, w2a, w2b, _, t2, alpha, dora_scale = params
60
- full_matrix=False
61
+ full_matrix = False
61
62
  if w1a is not None:
62
63
  lora_dim = w1a.size(1)
63
64
  elif w2a is not None:
@@ -80,6 +80,9 @@ class DyLoraModule(LycorisBaseModule):
80
80
  for v in self.up_list:
81
81
  torch.nn.init.zeros_(v)
82
82
 
83
+ def load_state_dict(self, state_dict, strict: bool = True, assign: bool = False):
84
+ return
85
+
83
86
  def custom_state_dict(self):
84
87
  destination = {}
85
88
  destination["alpha"] = self.alpha
@@ -1,3 +1,4 @@
1
+ from typing import Mapping
1
2
  import torch
2
3
  import torch.nn as nn
3
4
 
@@ -76,6 +77,9 @@ class FullModule(LycorisBaseModule):
76
77
  else:
77
78
  self.org_bias = None
78
79
 
80
+ def load_state_dict(self, state_dict, strict: bool = True, assign: bool = False):
81
+ return
82
+
79
83
  def custom_state_dict(self):
80
84
  sd = {"diff": self.weight.data.cpu() - self._org_weight[0]}
81
85
  if self.bias is not None:
@@ -66,17 +66,17 @@ class GLoRAModule(LycorisBaseModule):
66
66
  stride = org_module.stride
67
67
  padding = org_module.padding
68
68
  out_dim = org_module.out_channels
69
- self.tucker = use_tucker and k_size != (1, 1)
69
+ self.tucker = use_tucker and all(i == 1 for i in k_size)
70
70
  self.down_op = self.op
71
71
  self.up_op = self.op
72
72
 
73
73
  # A
74
- self.a2 = self.module(in_dim, lora_dim, (1, 1), bias=False)
75
- self.a1 = self.module(lora_dim, in_dim, (1, 1), bias=False)
74
+ self.a2 = self.module(in_dim, lora_dim, 1, bias=False)
75
+ self.a1 = self.module(lora_dim, in_dim, 1, bias=False)
76
76
 
77
77
  # B
78
- if use_tucker and k_size != (1, 1):
79
- self.b2 = self.module(in_dim, lora_dim, (1, 1), bias=False)
78
+ if use_tucker and any(i != 1 for i in k_size):
79
+ self.b2 = self.module(in_dim, lora_dim, 1, bias=False)
80
80
  self.bm = self.module(
81
81
  lora_dim, lora_dim, k_size, stride, padding, bias=False
82
82
  )
@@ -85,7 +85,7 @@ class GLoRAModule(LycorisBaseModule):
85
85
  self.b2 = self.module(
86
86
  in_dim, lora_dim, k_size, stride, padding, bias=False
87
87
  )
88
- self.b1 = self.module(lora_dim, out_dim, (1, 1), bias=False)
88
+ self.b1 = self.module(lora_dim, out_dim, 1, bias=False)
89
89
  else:
90
90
  self.isconv = False
91
91
  self.down_op = F.linear
@@ -123,6 +123,7 @@ class GLoRAModule(LycorisBaseModule):
123
123
  def make_weight(self, device=None):
124
124
  wa1 = self.a1.weight.view(self.a1.weight.size(0), -1)
125
125
  wa2 = self.a2.weight.view(self.a2.weight.size(0), -1)
126
+ orig = self.org_weight
126
127
 
127
128
  if self.tucker:
128
129
  wb = tucker_weight_from_conv(self.b1.weight, self.b2.weight, self.bm.weight)
@@ -130,7 +131,7 @@ class GLoRAModule(LycorisBaseModule):
130
131
  wb1 = self.b1.weight.view(self.b1.weight.size(0), -1)
131
132
  wb2 = self.b2.weight.view(self.b2.weight.size(0), -1)
132
133
  wb = wb1 @ wb2
133
- orig = self.org_weight
134
+ wb = wb.view(*orig.shape)
134
135
  if orig.dim() > 2:
135
136
  w_wa1 = torch.einsum("o i ..., i j -> o j ...", orig, wa1)
136
137
  w_wa2 = torch.einsum("o i ..., i j -> o j ...", w_wa1, wa2)
@@ -70,10 +70,10 @@ class LoConModule(LycorisBaseModule):
70
70
  stride = org_module.stride
71
71
  padding = org_module.padding
72
72
  out_dim = org_module.out_channels
73
- self.tucker = use_tucker and k_size != (1, 1)
73
+ self.tucker = use_tucker and any(i != 1 for i in k_size)
74
74
  self.down_op = self.op
75
75
  self.up_op = self.op
76
- if use_tucker and k_size != (1, 1):
76
+ if use_tucker and any(i != 1 for i in k_size):
77
77
  self.lora_down = self.module(in_dim, lora_dim, (1, 1), bias=False)
78
78
  self.lora_mid = self.module(
79
79
  lora_dim, lora_dim, k_size, stride, padding, bias=False
@@ -97,7 +97,7 @@ class LoConModule(LycorisBaseModule):
97
97
 
98
98
  self.wd = weight_decompose
99
99
  if self.wd:
100
- org_weight: nn.Parameter = org_module.weight
100
+ org_weight = org_module.weight.cpu().clone().float()
101
101
  self.dora_norm_dims = org_weight.dim() - 1
102
102
  self.dora_scale = nn.Parameter(
103
103
  torch.norm(
@@ -148,6 +148,8 @@ class LoConModule(LycorisBaseModule):
148
148
  del missing_keys[missing_keys.index(key)]
149
149
  if isinstance(self.scalar, nn.Parameter):
150
150
  self.scalar.data.copy_(torch.ones_like(self.scalar))
151
+ elif getattr(self, "scalar", None) is not None:
152
+ self.scalar.copy_(torch.ones_like(self.scalar))
151
153
  else:
152
154
  self.register_buffer(
153
155
  "scalar", torch.ones_like(self.scalar), persistent=False
@@ -58,12 +58,11 @@ class LohaModule(LycorisBaseModule):
58
58
  k_size = org_module.kernel_size
59
59
  out_dim = org_module.out_channels
60
60
  self.shape = (out_dim, in_dim, *k_size)
61
- self.tucker = use_tucker and k_size != (1, 1)
61
+ self.tucker = use_tucker and any(i != 1 for i in k_size)
62
62
  if self.tucker:
63
63
  w_shape = (out_dim, in_dim, *k_size)
64
64
  else:
65
65
  w_shape = (out_dim, in_dim * torch.tensor(k_size).prod().item())
66
- self.op = F.conv2d
67
66
 
68
67
  if self.tucker:
69
68
  self.hada_t1 = nn.Parameter(torch.empty(lora_dim, lora_dim, *w_shape[2:]))
@@ -90,7 +89,7 @@ class LohaModule(LycorisBaseModule):
90
89
 
91
90
  self.wd = weight_decompose
92
91
  if self.wd:
93
- org_weight: nn.Parameter = org_module.weight
92
+ org_weight = org_module.weight.cpu().clone().float()
94
93
  self.dora_norm_dims = org_weight.dim() - 1
95
94
  self.dora_scale = nn.Parameter(
96
95
  torch.norm(
@@ -140,6 +139,8 @@ class LohaModule(LycorisBaseModule):
140
139
  del missing_keys[missing_keys.index(key)]
141
140
  if isinstance(self.scalar, nn.Parameter):
142
141
  self.scalar.data.copy_(torch.ones_like(self.scalar))
142
+ elif getattr(self, "scalar", None) is not None:
143
+ self.scalar.copy_(torch.ones_like(self.scalar))
143
144
  else:
144
145
  self.register_buffer(
145
146
  "scalar", torch.ones_like(self.scalar), persistent=False
@@ -93,7 +93,7 @@ class LokrModule(LycorisBaseModule):
93
93
  if unbalanced_factorization:
94
94
  out_l, out_k = out_k, out_l
95
95
  shape = ((out_l, out_k), (in_m, in_n), *k_size) # ((a, b), (c, d), *k_size)
96
- self.tucker = use_tucker and k_size != (1, 1)
96
+ self.tucker = use_tucker and any(i != 1 for i in k_size)
97
97
  if (
98
98
  decompose_both
99
99
  and lora_dim < max(shape[0][0], shape[1][0]) / 2
@@ -166,7 +166,7 @@ class LokrModule(LycorisBaseModule):
166
166
 
167
167
  self.wd = weight_decompose
168
168
  if self.wd:
169
- org_weight: nn.Parameter = org_module.weight
169
+ org_weight = org_module.weight.cpu().clone().float()
170
170
  self.dora_norm_dims = org_weight.dim() - 1
171
171
  self.dora_scale = nn.Parameter(
172
172
  torch.norm(
@@ -232,6 +232,8 @@ class LokrModule(LycorisBaseModule):
232
232
  del missing_keys[missing_keys.index(key)]
233
233
  if isinstance(self.scalar, nn.Parameter):
234
234
  self.scalar.data.copy_(torch.ones_like(self.scalar))
235
+ elif getattr(self, "scalar", None) is not None:
236
+ self.scalar.copy_(torch.ones_like(self.scalar))
235
237
  else:
236
238
  self.register_buffer(
237
239
  "scalar", torch.ones_like(self.scalar), persistent=False
@@ -469,12 +469,12 @@ def get_module(lyco_state_dict: Dict, lora_name):
469
469
  def tucker_weight_from_conv(up, down, mid):
470
470
  up = up.reshape(up.size(0), up.size(1))
471
471
  down = down.reshape(down.size(0), down.size(1))
472
- return torch.einsum("m n w h, i m, n j -> i j w h", mid, up, down)
472
+ return torch.einsum("m n ..., i m, n j -> i j ...", mid, up, down)
473
473
 
474
474
 
475
475
  def tucker_weight(wa, wb, t):
476
- temp = torch.einsum("i j k l, j r -> i r k l", t, wb)
477
- return torch.einsum("i j k l, i r -> r j k l", temp, wa)
476
+ temp = torch.einsum("i j ..., j r -> i r ...", t, wb)
477
+ return torch.einsum("i j ..., i r -> r j ...", temp, wa)
478
478
 
479
479
 
480
480
  def apply_dora_scale(org_weight, rebuild, dora_scale, scale):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.0.dev6
3
+ Version: 3.0.0.dev8
4
4
  Summary: Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion
5
5
  Home-page: https://github.com/KohakuBlueleaf/LyCORIS
6
6
  Author: Shih-Ying Yeh(KohakuBlueLeaf), Yu-Guan Hsieh, Zhidong Gao
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
4
4
  setup(
5
5
  name="lycoris_lora",
6
6
  packages=find_packages(),
7
- version="3.0.0.dev6",
7
+ version="3.0.0.dev8",
8
8
  url="https://github.com/KohakuBlueleaf/LyCORIS",
9
9
  description="Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion",
10
10
  author="Shih-Ying Yeh(KohakuBlueLeaf), Yu-Guan Hsieh, Zhidong Gao",