lycoris-lora 2.2.0.dev11__tar.gz → 2.2.0.post1__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 (50) hide show
  1. {lycoris_lora-2.2.0.dev11/lycoris_lora.egg-info → lycoris_lora-2.2.0.post1}/PKG-INFO +1 -1
  2. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/README.md +20 -16
  3. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/kohya/__init__.py +2 -2
  4. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/boft.py +66 -25
  5. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/diag_oft.py +59 -12
  6. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/locon.py +3 -4
  7. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/loha.py +1 -1
  8. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/lokr.py +2 -4
  9. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/wrapper.py +2 -2
  10. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1/lycoris_lora.egg-info}/PKG-INFO +1 -1
  11. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/setup.py +1 -1
  12. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/LICENSE.md +0 -0
  13. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/__init__.py +0 -0
  14. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/config.py +0 -0
  15. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/hcp/__init__.py +0 -0
  16. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/hcp/base.py +0 -0
  17. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/hcp/diag_oft.py +0 -0
  18. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/hcp/loha.py +0 -0
  19. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/hcp/lokr.py +0 -0
  20. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/kohya/model_utils.py +0 -0
  21. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/kohya/original_unet.py +0 -0
  22. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/kohya/sdxl_model_util.py +0 -0
  23. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/kohya/sdxl_original_unet.py +0 -0
  24. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/kohya/test_hyperdream.py +0 -0
  25. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/kohya/utils.py +0 -0
  26. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/logging.py +0 -0
  27. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/__init__.py +0 -0
  28. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/attention.py +0 -0
  29. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/base.py +0 -0
  30. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/dylora.py +0 -0
  31. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/full.py +0 -0
  32. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/glokr.py +0 -0
  33. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/glora.py +0 -0
  34. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/hypernet/__init__.py +0 -0
  35. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/hypernet/generater.py +0 -0
  36. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/hypernet/text_encoder.py +0 -0
  37. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/ia3.py +0 -0
  38. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/lilora.py +0 -0
  39. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/modules/norms.py +0 -0
  40. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/utils/__init__.py +0 -0
  41. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/utils/bnb.py +0 -0
  42. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/utils/logger.py +0 -0
  43. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/utils/preset.py +0 -0
  44. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris/utils/xformers_utils.py +0 -0
  45. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris_lora.egg-info/SOURCES.txt +0 -0
  46. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris_lora.egg-info/dependency_links.txt +0 -0
  47. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris_lora.egg-info/not-zip-safe +0 -0
  48. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris_lora.egg-info/requires.txt +0 -0
  49. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/lycoris_lora.egg-info/top_level.txt +0 -0
  50. {lycoris_lora-2.2.0.dev11 → lycoris_lora-2.2.0.post1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 2.2.0.dev11
3
+ Version: 2.2.0.post1
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
@@ -153,6 +153,10 @@ forward_with_lyco = your_model(x)
153
153
 
154
154
  You can check my [HakuPhi](https://github.com/KohakuBlueleaf/HakuPhi) project to see how I utilize LyCORIS to finetune the Phi-1.5 models.
155
155
 
156
+ #### Bitsandbytes support
157
+
158
+ See [bnb_example.py](bnb_example.py) for example. Basically as same as standalone wrapper.
159
+
156
160
  #### Graphical interfaces and Colabs (via kohya trainer)
157
161
 
158
162
  You can also train LyCORIS with the following graphical interfaces
@@ -236,30 +240,30 @@ See [docs/Conversion-scripts.md](docs/Conversion-scripts.md) for more informatio
236
240
 
237
241
  For full log, please see [Change.md](Change.md)
238
242
 
239
- ## 2024/02/18 update to 2.1.0
243
+ ## 2024/03/15 update to 2.2.0 - QLyCORIS and DoRA
240
244
 
241
245
  #### New Algo
242
246
 
243
- * [BOFT (Butterfly OFT)](https://arxiv.org/abs/2311.06243)
247
+ * DoRA
248
+ * Ref: [DoRA: Weight-Decomposed Low-Rank Adaptation](https://github.com/KohakuBlueleaf/LyCORIS)
249
+ * Weight decompose for LoHa and LoKr. (A.K.A DoHa/DoKr)
250
+ * DoRA/DoHa/DoKr will require smaller Learning rate!
244
251
 
245
- #### Improvements
252
+ #### New Features
246
253
 
247
- * Faster, better extract script
248
- * support kohya-ss/sd-scripts image gen
249
- * support regex name in kohya-ss/sd-scripts
250
- * support resume on:
251
- * full
252
- * loha
253
- * oft
254
- * boft
255
- * Add logger into LyCORIS
254
+ * Support "bypass" (a.k.a. adapter) mode for LoHa/LoKr/OFT/BOFT
255
+ * LoHa will require 2xFLOPs since we rebuild full diff weight and then do one more forward.
256
+ * LoKr, OFT, BOFT should be more efficient than LoHa in bypass mode.
257
+ * Support [bnb 8bit/4bit Linear layer](https://github.com/TimDettmers/bitsandbytes) (a.k.a. QLyCORIS) with LoHa/LoKr/OFT/BOFT.
258
+ * This will force module to enable bypass mode.
256
259
 
257
260
  #### Fixes, slight changes
258
261
 
259
- * Update HCP convert for the case where only UNet or TE is trained.
260
- * Change arg names for conversion scripts.
261
- * Fix wrong TE prefix in merge scripts.
262
- * Fix warnings and confusing logging.
262
+ * Refine some details about code quality. Based on the report from GitRoll. (Thx you gitroll!)
263
+ * Remove redundant calculation in BOFT
264
+ * rank_dropout has been removed from OFT/BOFT temporarily untill we ensure how to apply it.
265
+ * Fix bugs in lokr when `lokr_w1_a` not exist.
266
+ * Fix bugs in conversion scritps.
263
267
 
264
268
  ## Todo list
265
269
 
@@ -350,10 +350,10 @@ class LycorisNetworkKohya(LycorisNetwork):
350
350
  **kwargs,
351
351
  )
352
352
  lora = None
353
- if module.__class__.__name__ == "Linear" and lora_dim > 0:
353
+ if isinstance(module, torch.nn.Linear) and lora_dim > 0:
354
354
  dim = dim or lora_dim
355
355
  alpha = alpha or self.alpha
356
- elif module.__class__.__name__ == "Conv2d":
356
+ elif isinstance(module, torch.nn.Conv2d):
357
357
  k_size, *_ = module.kernel_size
358
358
  if k_size == 1 and lora_dim > 0:
359
359
  dim = dim or lora_dim
@@ -8,7 +8,8 @@ import torch.nn.functional as F
8
8
  from einops import rearrange
9
9
 
10
10
  from .base import ModuleCustomSD
11
- from lycoris.logging import logger
11
+ from ..logging import logger
12
+ from ..utils.bnb import LinearNF4, QuantLinears, log_bypass
12
13
 
13
14
 
14
15
  @cache
@@ -67,6 +68,7 @@ class ButterflyOFTModule(ModuleCustomSD):
67
68
  rank_dropout_scale=False,
68
69
  constrain=0,
69
70
  rescaled=False,
71
+ bypass_mode=False,
70
72
  **kwargs,
71
73
  ):
72
74
  """if alpha == 0 or None, alpha is rank (no scaling)."""
@@ -89,7 +91,13 @@ class ButterflyOFTModule(ModuleCustomSD):
89
91
  else:
90
92
  raise NotImplementedError
91
93
 
92
- out_dim = org_module.weight.shape[0]
94
+ if isinstance(org_module, QuantLinears):
95
+ if not bypass_mode:
96
+ log_bypass()
97
+ bypass_mode = True
98
+ self.bypass_mode = bypass_mode
99
+
100
+ out_dim = self.dim
93
101
  b, m_exp = butterfly_factor(out_dim, lora_dim)
94
102
  self.block_size = b
95
103
  self.block_num = m_exp
@@ -146,14 +154,6 @@ class ButterflyOFTModule(ModuleCustomSD):
146
154
  return r
147
155
 
148
156
  def make_weight(self, scale=1, device=None):
149
- if self.rank_dropout and self.training:
150
- drop = torch.rand(self.dim, device=device) < self.rank_dropout
151
- drop = drop.to(self.oft_blocks.dtype)
152
- if self.rank_dropout_scale:
153
- drop /= drop.mean()
154
- else:
155
- drop = 1
156
-
157
157
  m = self.boft_m
158
158
  b = self.boft_b
159
159
  r_b = b // 2
@@ -173,10 +173,7 @@ class ButterflyOFTModule(ModuleCustomSD):
173
173
  inp = rearrange(inp, "d b ... -> (d b) ...")
174
174
  inp = rearrange(inp, "(c k g) ... -> (c g k) ...", g=2, k=2**i * r_b)
175
175
 
176
- weight = inp
177
- if self.rescaled:
178
- weight = self.rescale * weight
179
- return weight * drop
176
+ return inp
180
177
 
181
178
  @torch.no_grad()
182
179
  def apply_max_norm(self, max_norm, device=None):
@@ -191,23 +188,67 @@ class ButterflyOFTModule(ModuleCustomSD):
191
188
 
192
189
  return scaled, orig_norm * ratio
193
190
 
191
+ def bypass_forward(self, x, scale=1):
192
+ m = self.boft_m
193
+ b = self.boft_b
194
+ r_b = b // 2
195
+ r = self.get_r()
196
+ inp = self.org_forward(x)
197
+
198
+ for i in range(m):
199
+ bi = r[i] # b_num, b_size, b_size
200
+ if i == 0:
201
+ # Apply multiplier/scale and rescale into first weight
202
+ bi = bi * scale + (1 - scale) * self.I
203
+ if self.rescaled:
204
+ bi = bi * self.rescale
205
+ inp = rearrange(inp, "... (c g k) ->... (c k g)", g=2, k=2**i * r_b)
206
+ inp = rearrange(inp, "... (d b) -> ... d b", b=b)
207
+ inp = torch.einsum("b i j, ... b j -> ... b i", bi, inp)
208
+ inp = rearrange(inp, "... d b -> ... (d b)")
209
+ inp = rearrange(inp, "... (c k g) -> ... (c g k)", g=2, k=2**i * r_b)
210
+
211
+ return inp
212
+
194
213
  def forward(self, x):
195
214
  if self.module_dropout and self.training:
196
215
  if torch.rand(1) < self.module_dropout:
197
216
  return self.org_forward(x)
198
217
  scale = self.multiplier
199
218
 
200
- w = self.make_weight(scale, x.device)
201
- kw_dict = self.kw_dict | {"weight": w, "bias": self.org_module[0].bias}
202
- return self.op(x, **kw_dict)
219
+ if self.bypass_mode:
220
+ return self.bypass_forward(x, scale)
221
+ else:
222
+ w = self.make_weight(scale, x.device)
223
+ kw_dict = self.kw_dict | {"weight": w, "bias": self.org_module[0].bias}
224
+ return self.op(x, **kw_dict)
203
225
 
204
226
 
205
227
  if __name__ == "__main__":
206
- dim = 320
207
- test_layer = nn.Linear(dim, dim)
208
- test_layer.weight = nn.Parameter(torch.eye(dim))
209
- test_boft = ButterflyOFTModule("test", test_layer, lora_dim=16)
210
- test_boft.oft_blocks = nn.Parameter(torch.randn_like(test_boft.oft_blocks))
211
-
212
- print(test_boft.make_weight(1, "cpu").shape)
213
- print(torch.count_nonzero(test_boft.make_weight(1, "cpu")), dim * dim)
228
+ base = nn.Linear(128, 128).cuda()
229
+ lokr = ButterflyOFTModule("test", base, 1, 4, 1, weight_decompose=True).cuda()
230
+ print(lokr)
231
+ test_input = torch.randn(1, 128).cuda()
232
+ test_output = lokr(test_input)
233
+ print(test_output.shape)
234
+ print(F.mse_loss(test_output, lokr.bypass_forward(test_input)))
235
+
236
+ base_4bit = LinearNF4(128, 128)
237
+ base_4bit.load_state_dict(base.state_dict())
238
+ base_4bit.cuda()
239
+ qlocon = ButterflyOFTModule(
240
+ "test", base_4bit, 1, 4, 1, weight_decompose=False
241
+ ).cuda()
242
+ print(qlocon)
243
+ test_input = torch.randn(1, 128).cuda()
244
+ test_output = qlocon(test_input)
245
+ print(test_output.shape)
246
+
247
+ base = nn.Conv2d(128, 128, 3, 1, 1)
248
+ lokr = ButterflyOFTModule(
249
+ "test", base, 1, 4, 1, weight_decompose=True, use_tucker=True
250
+ )
251
+ print(lokr)
252
+ test_input = torch.randn(1, 128, 16, 16)
253
+ test_output = lokr(test_input)
254
+ print(test_output.shape)
@@ -9,6 +9,7 @@ from einops import rearrange
9
9
  from .base import ModuleCustomSD
10
10
  from .lokr import factorization
11
11
  from ..logging import logger
12
+ from ..utils.bnb import LinearNF4, QuantLinears, log_bypass
12
13
 
13
14
 
14
15
  @cache
@@ -40,6 +41,7 @@ class DiagOFTModule(ModuleCustomSD):
40
41
  rank_dropout_scale=False,
41
42
  constrain=0,
42
43
  rescaled=False,
44
+ bypass_mode=False,
43
45
  **kwargs,
44
46
  ):
45
47
  """if alpha == 0 or None, alpha is rank (no scaling)."""
@@ -62,7 +64,13 @@ class DiagOFTModule(ModuleCustomSD):
62
64
  else:
63
65
  raise NotImplementedError
64
66
 
65
- out_dim = org_module.weight.shape[0]
67
+ if isinstance(org_module, QuantLinears):
68
+ if not bypass_mode:
69
+ log_bypass()
70
+ bypass_mode = True
71
+ self.bypass_mode = bypass_mode
72
+
73
+ out_dim = self.dim
66
74
  self.block_size, self.block_num = factorization(out_dim, lora_dim)
67
75
  # block_num > block_size
68
76
  self.rescaled = rescaled
@@ -120,14 +128,6 @@ class DiagOFTModule(ModuleCustomSD):
120
128
  return r
121
129
 
122
130
  def make_weight(self, scale=1, device=None):
123
- if self.rank_dropout and self.training:
124
- drop = torch.rand(self.dim, device=device) < self.rank_dropout
125
- drop = drop.to(self.oft_blocks.dtype)
126
- if self.rank_dropout_scale:
127
- drop /= drop.mean()
128
- else:
129
- drop = 1
130
-
131
131
  r = self.get_r()
132
132
  org_weight = self.org_module[0].weight.to(device, dtype=r.dtype)
133
133
  org_weight = rearrange(
@@ -160,12 +160,59 @@ class DiagOFTModule(ModuleCustomSD):
160
160
 
161
161
  return scaled, orig_norm * ratio
162
162
 
163
+ def bypass_forward(self, x, scale=1):
164
+ r = self.get_r()
165
+ org_out = self.org_forward(x)
166
+ if self.op == F.conv2d:
167
+ org_out = org_out.transpose(1, -1)
168
+ org_out = rearrange(
169
+ org_out,
170
+ "... (k n) ->... k n",
171
+ k=self.block_num,
172
+ n=self.block_size,
173
+ )
174
+ oft_out = torch.einsum(
175
+ "k n m, ... k n -> ... k m", r * scale + (1 - scale) * self.I, org_out
176
+ )
177
+ out = rearrange(oft_out, "... k m -> ... (k m)")
178
+ if self.op == F.conv2d:
179
+ out = out.transpose(1, -1)
180
+ return out
181
+
163
182
  def forward(self, x):
164
183
  if self.module_dropout and self.training:
165
184
  if torch.rand(1) < self.module_dropout:
166
185
  return self.org_forward(x)
167
186
  scale = self.multiplier
168
187
 
169
- w = self.make_weight(scale, x.device)
170
- kw_dict = self.kw_dict | {"weight": w, "bias": self.org_module[0].bias}
171
- return self.op(x, **kw_dict)
188
+ if self.bypass_mode:
189
+ return self.bypass_forward(x, scale)
190
+ else:
191
+ w = self.make_weight(scale, x.device)
192
+ kw_dict = self.kw_dict | {"weight": w, "bias": self.org_module[0].bias}
193
+ return self.op(x, **kw_dict)
194
+
195
+
196
+ if __name__ == "__main__":
197
+ base = nn.Linear(128, 128).cuda()
198
+ lokr = DiagOFTModule("test", base, 1, 4, 1, weight_decompose=True).cuda()
199
+ print(lokr)
200
+ test_input = torch.randn(1, 128).cuda()
201
+ test_output = lokr(test_input)
202
+ print(test_output.shape)
203
+
204
+ base_4bit = LinearNF4(128, 128)
205
+ base_4bit.load_state_dict(base.state_dict())
206
+ base_4bit.cuda()
207
+ qlocon = DiagOFTModule("test", base_4bit, 1, 4, 1, weight_decompose=False).cuda()
208
+ print(qlocon)
209
+ test_input = torch.randn(1, 128).cuda()
210
+ test_output = qlocon(test_input)
211
+ print(test_output.shape)
212
+
213
+ base = nn.Conv2d(128, 128, 3, 1, 1)
214
+ lokr = DiagOFTModule("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True)
215
+ print(lokr)
216
+ test_input = torch.randn(1, 128, 16, 16)
217
+ test_output = lokr(test_input)
218
+ print(test_output.shape)
@@ -133,7 +133,6 @@ class LoConModule(ModuleCustomSD):
133
133
  if use_scalar:
134
134
  self.scalar = nn.Parameter(torch.tensor(0.0))
135
135
  else:
136
- self.scalar: torch.FloatTensor
137
136
  self.register_buffer("scalar", torch.tensor(1.0), persistent=False)
138
137
  # same as microsoft's
139
138
  torch.nn.init.kaiming_uniform_(self.lora_down.weight, a=math.sqrt(5))
@@ -225,11 +224,11 @@ class LoConModule(ModuleCustomSD):
225
224
  return self.org_forward(x)
226
225
  scale = self.scale * self.multiplier
227
226
 
228
- dtype_device = next(self.parameters())
227
+ dtype = next(self.parameters()).dtype
229
228
  if not self.bypass_mode:
230
229
  weight = (
231
- self.org_module[0].weight.data.to(dtype_device)
232
- + self.make_weight(x.device).to(dtype_device) * scale
230
+ self.org_module[0].weight.data.to(device=x.device, dtype=dtype)
231
+ + self.make_weight(x.device).to(device=x.device, dtype=dtype) * scale
233
232
  )
234
233
  if self.wd:
235
234
  weight = self.apply_weight_decompose(weight)
@@ -281,7 +281,7 @@ class LohaModule(ModuleCustomSD):
281
281
 
282
282
  @torch.no_grad()
283
283
  def apply_max_norm(self, max_norm, device=None):
284
- orig_norm = (self.get_weight() * self.scalar).norm()
284
+ orig_norm = (self.get_weight(self.shape) * self.scalar).norm()
285
285
  norm = torch.clamp(orig_norm, max_norm / 2)
286
286
  desired = torch.clamp(norm, max=max_norm)
287
287
  ratio = desired.cpu() / norm.cpu()
@@ -352,7 +352,7 @@ class LokrModule(ModuleCustomSD):
352
352
 
353
353
  @torch.no_grad()
354
354
  def apply_max_norm(self, max_norm, device=None):
355
- orig_norm = self.get_weight().norm()
355
+ orig_norm = self.get_weight(self.shape).norm()
356
356
  norm = torch.clamp(orig_norm, max_norm / 2)
357
357
  desired = torch.clamp(norm, max=max_norm)
358
358
  ratio = desired.cpu() / norm.cpu()
@@ -448,9 +448,7 @@ class LokrModule(ModuleCustomSD):
448
448
 
449
449
  if __name__ == "__main__":
450
450
  base = nn.Linear(128, 128).cuda()
451
- lokr = LokrModule(
452
- "test", base, 1, 4, 1, weight_decompose=True, factor=8
453
- ).cuda()
451
+ lokr = LokrModule("test", base, 1, 4, 1, weight_decompose=True, factor=8).cuda()
454
452
  print(lokr)
455
453
  test_input = torch.randn(1, 77, 128).cuda()
456
454
  test_output = lokr(test_input)
@@ -292,10 +292,10 @@ class LycorisNetwork(torch.nn.Module):
292
292
  **kwargs,
293
293
  )
294
294
  lora = None
295
- if module.__class__.__name__ == "Linear" and lora_dim > 0:
295
+ if isinstance(module, torch.nn.Linear) and lora_dim > 0:
296
296
  dim = dim or lora_dim
297
297
  alpha = alpha or self.alpha
298
- elif module.__class__.__name__ == "Conv2d":
298
+ elif isinstance(module, torch.nn.Conv2d):
299
299
  k_size, *_ = module.kernel_size
300
300
  if k_size == 1 and lora_dim > 0:
301
301
  dim = dim or lora_dim
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 2.2.0.dev11
3
+ Version: 2.2.0.post1
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="2.2.0.dev11",
7
+ version="2.2.0.post1",
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",