lycoris-lora 3.2.0.dev1__tar.gz → 3.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 (48) hide show
  1. {lycoris_lora-3.2.0.dev1/lycoris_lora.egg-info → lycoris_lora-3.2.0.post1}/PKG-INFO +10 -2
  2. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/README.md +6 -6
  3. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/config.py +19 -14
  4. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/functional/lokr.py +2 -2
  5. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/kohya.py +53 -19
  6. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/base.py +32 -0
  7. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/locon.py +1 -1
  8. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/loha.py +1 -1
  9. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/lokr.py +1 -1
  10. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/wrapper.py +10 -2
  11. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1/lycoris_lora.egg-info}/PKG-INFO +10 -2
  12. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris_lora.egg-info/SOURCES.txt +2 -0
  13. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/setup.py +1 -1
  14. lycoris_lora-3.2.0.post1/test/compile.py +69 -0
  15. lycoris_lora-3.2.0.post1/test/restore.py +56 -0
  16. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/LICENSE.md +0 -0
  17. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/__init__.py +0 -0
  18. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/functional/__init__.py +0 -0
  19. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/functional/boft.py +0 -0
  20. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/functional/diag_oft.py +0 -0
  21. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/functional/general.py +0 -0
  22. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/functional/locon.py +0 -0
  23. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/functional/loha.py +0 -0
  24. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/logging.py +0 -0
  25. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/__init__.py +0 -0
  26. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/boft.py +0 -0
  27. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/diag_oft.py +0 -0
  28. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/dylora.py +0 -0
  29. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/full.py +0 -0
  30. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/glora.py +0 -0
  31. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/ia3.py +0 -0
  32. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/modules/norms.py +0 -0
  33. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/utils/__init__.py +0 -0
  34. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/utils/general.py +0 -0
  35. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/utils/logger.py +0 -0
  36. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/utils/preset.py +0 -0
  37. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/utils/quant.py +0 -0
  38. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris/utils/xformers_utils.py +0 -0
  39. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris_lora.egg-info/dependency_links.txt +0 -0
  40. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris_lora.egg-info/not-zip-safe +0 -0
  41. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris_lora.egg-info/requires.txt +0 -0
  42. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/lycoris_lora.egg-info/top_level.txt +0 -0
  43. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/setup.cfg +0 -0
  44. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/test/__init__.py +0 -0
  45. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/test/functional.py +0 -0
  46. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/test/kohya.py +0 -0
  47. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/test/module.py +0 -0
  48. {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.post1}/test/wrapper.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: lycoris_lora
3
- Version: 3.2.0.dev1
3
+ Version: 3.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
@@ -23,3 +23,11 @@ Requires-Dist: torch
23
23
  Requires-Dist: einops
24
24
  Requires-Dist: toml
25
25
  Requires-Dist: tqdm
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: home-page
30
+ Dynamic: license-file
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
@@ -259,21 +259,21 @@ See [docs/Conversion-scripts.md](docs/Conversion-scripts.md) for more informatio
259
259
 
260
260
  For full log, please see [Change.md](Change.md)
261
261
 
262
-
263
- ### 2024/12/09 update to 3.1.1
262
+ ### 2025/04/23 update to 3.2.0
264
263
 
265
264
  #### New Features
266
265
 
267
- * use `wd_on_output=True` can enable "correct" weight-decomposition implementation which use the output dimension of weight to calc the norm. The original implementation in LyCORIS calculate things on input dimension due to ambiguos annotation in paper.
266
+ * Support lora-plus learning rate scaling
267
+ * Support HunYuanVideo model and Wan2.1 model
268
+ * LyCORIS now have `onfly_merge` and `onfly_restore` method. Which can be used in inference time to merge the weights of LyCORIS into the original model. This will save the memory and speed up the inference time.
268
269
 
269
270
  #### Improvements
270
271
 
271
- * BOFT now have more efficient implementation which avoid einops.rearrange.
272
- * `.merge_to()` will automatically match the device and dtype now.
272
+ * [BREAKING CHANGES] Now LyCORIS will use `wd_on_output=True` by default. This will make the weight norm more consistent with the original paper.
273
273
 
274
274
  #### Bug fixes
275
275
 
276
- * `scale_weight_norm` working correctly now.
276
+ * `bypass_mode=False` will turn off the bypass mode correctly now.
277
277
 
278
278
  ## Todo list
279
279
 
@@ -6,12 +6,13 @@ PRESET = {
6
6
  "ResnetBlock2D",
7
7
  "Downsample2D",
8
8
  "Upsample2D",
9
- "HunYuanDiTBlock", #HunYuanDiT
10
- "DoubleStreamBlock", #Flux
11
- "SingleStreamBlock", #Flux
12
- "SingleDiTBlock", #SD3.5
13
- "MMDoubleStreamBlock", #HunYuanVideo
14
- "MMSingleStreamBlock", #HunYuanVideo
9
+ "HunYuanDiTBlock", # HunYuanDiT
10
+ "DoubleStreamBlock", # Flux
11
+ "SingleStreamBlock", # Flux
12
+ "SingleDiTBlock", # SD3.5
13
+ "MMDoubleStreamBlock", # HunYuanVideo
14
+ "MMSingleStreamBlock", # HunYuanVideo
15
+ "WanAttentionBlock", # Wan
15
16
  ],
16
17
  "unet_target_name": [
17
18
  "conv_in",
@@ -37,8 +38,9 @@ PRESET = {
37
38
  "DoubleStreamBlock",
38
39
  "SingleStreamBlock",
39
40
  "SingleDiTBlock",
40
- "MMDoubleStreamBlock", #HunYuanVideo
41
- "MMSingleStreamBlock", #HunYuanVideo
41
+ "MMDoubleStreamBlock", # HunYuanVideo
42
+ "MMSingleStreamBlock", # HunYuanVideo
43
+ "WanAttentionBlock", # Wan
42
44
  ],
43
45
  "unet_target_name": [
44
46
  "time_embedding.linear_1",
@@ -61,8 +63,9 @@ PRESET = {
61
63
  "DoubleStreamBlock",
62
64
  "SingleStreamBlock",
63
65
  "SingleDiTBlock",
64
- "MMDoubleStreamBlock", #HunYuanVideo
65
- "MMSingleStreamBlock", #HunYuanVideo
66
+ "MMDoubleStreamBlock", # HunYuanVideo
67
+ "MMSingleStreamBlock", # HunYuanVideo
68
+ "WanAttentionBlock", # Wan
66
69
  ],
67
70
  "unet_target_name": [],
68
71
  "text_encoder_target_module": [
@@ -100,8 +103,9 @@ PRESET = {
100
103
  "DoubleStreamBlock",
101
104
  "SingleStreamBlock",
102
105
  "SingleDiTBlock",
103
- "MMDoubleStreamBlock", #HunYuanVideo
104
- "MMSingleStreamBlock", #HunYuanVideo
106
+ "MMDoubleStreamBlock", # HunYuanVideo
107
+ "MMSingleStreamBlock", # HunYuanVideo
108
+ "WanAttentionBlock", # Wan
105
109
  ],
106
110
  "unet_target_name": [
107
111
  "conv_in",
@@ -120,8 +124,9 @@ PRESET = {
120
124
  "DoubleStreamBlock",
121
125
  "SingleStreamBlock",
122
126
  "SingleDiTBlock",
123
- "MMDoubleStreamBlock", #HunYuanVideo
124
- "MMSingleStreamBlock", #HunYuanVideo
127
+ "MMDoubleStreamBlock", # HunYuanVideo
128
+ "MMSingleStreamBlock", # HunYuanVideo
129
+ "WanAttentionBlock", # Wan
125
130
  ],
126
131
  "unet_target_name": [],
127
132
  "text_encoder_target_module": [],
@@ -105,12 +105,12 @@ def weight_gen(
105
105
  w2 = torch.empty(shape[0][1], shape[1][1])
106
106
 
107
107
  if use_w2:
108
- torch.nn.init.constant_(w2, 1)
108
+ torch.nn.init.constant_(w2, 0)
109
109
  else:
110
110
  if tucker:
111
111
  torch.nn.init.kaiming_uniform_(t2, a=math.sqrt(5))
112
112
  torch.nn.init.kaiming_uniform_(w2a, a=math.sqrt(5))
113
- torch.nn.init.constant_(w2b, 1)
113
+ torch.nn.init.constant_(w2b, 0)
114
114
 
115
115
  if use_w1:
116
116
  torch.nn.init.kaiming_uniform_(w1, a=math.sqrt(5))
@@ -57,16 +57,28 @@ def create_network(
57
57
  constraint = float(kwargs.get("constraint", None) or 0)
58
58
  rescaled = str_bool(kwargs.get("rescaled", False))
59
59
  weight_decompose = str_bool(kwargs.get("dora_wd", False))
60
- wd_on_output = str_bool(kwargs.get("wd_on_output", False))
60
+ wd_on_output = str_bool(kwargs.get("wd_on_output", True))
61
61
  full_matrix = str_bool(kwargs.get("full_matrix", False))
62
- bypass_mode = str_bool(kwargs.get("bypass_mode", None))
62
+ bypass_mode = str_bool(kwargs.get("bypass_mode", False))
63
63
  rs_lora = str_bool(kwargs.get("rs_lora", False))
64
64
  unbalanced_factorization = str_bool(kwargs.get("unbalanced_factorization", False))
65
65
  train_t5xxl = str_bool(kwargs.get("train_t5xxl", False))
66
- #lora_plus
67
- loraplus_lr_ratio = float(kwargs.get("loraplus_lr_ratio", None)) if kwargs.get("loraplus_lr_ratio", None) is not None else None
68
- loraplus_unet_lr_ratio = float(kwargs.get("loraplus_unet_lr_ratio", None)) if kwargs.get("loraplus_unet_lr_ratio", None) is not None else None
69
- loraplus_text_encoder_lr_ratio = float(kwargs.get("loraplus_text_encoder_lr_ratio", None)) if kwargs.get("loraplus_text_encoder_lr_ratio", None) is not None else None
66
+ # lora_plus
67
+ loraplus_lr_ratio = (
68
+ float(kwargs.get("loraplus_lr_ratio", None))
69
+ if kwargs.get("loraplus_lr_ratio", None) is not None
70
+ else None
71
+ )
72
+ loraplus_unet_lr_ratio = (
73
+ float(kwargs.get("loraplus_unet_lr_ratio", None))
74
+ if kwargs.get("loraplus_unet_lr_ratio", None) is not None
75
+ else None
76
+ )
77
+ loraplus_text_encoder_lr_ratio = (
78
+ float(kwargs.get("loraplus_text_encoder_lr_ratio", None))
79
+ if kwargs.get("loraplus_text_encoder_lr_ratio", None) is not None
80
+ else None
81
+ )
70
82
 
71
83
  if unbalanced_factorization:
72
84
  logger.info("Unbalanced factorization for LoKr is enabled")
@@ -121,8 +133,14 @@ def create_network(
121
133
  unbalanced_factorization=unbalanced_factorization,
122
134
  train_t5xxl=train_t5xxl,
123
135
  )
124
- if loraplus_lr_ratio is not None or loraplus_unet_lr_ratio is not None or loraplus_text_encoder_lr_ratio is not None:
125
- network.set_loraplus_lr_ratio(loraplus_lr_ratio, loraplus_unet_lr_ratio, loraplus_text_encoder_lr_ratio)
136
+ if (
137
+ loraplus_lr_ratio is not None
138
+ or loraplus_unet_lr_ratio is not None
139
+ or loraplus_text_encoder_lr_ratio is not None
140
+ ):
141
+ network.set_loraplus_lr_ratio(
142
+ loraplus_lr_ratio, loraplus_unet_lr_ratio, loraplus_text_encoder_lr_ratio
143
+ )
126
144
 
127
145
  return network
128
146
 
@@ -232,8 +250,9 @@ class LycorisNetworkKohya(LycorisNetwork):
232
250
  "DoubleStreamBlock",
233
251
  "SingleStreamBlock",
234
252
  "SingleDiTBlock",
235
- "MMDoubleStreamBlock", #HunYuanVideo
236
- "MMSingleStreamBlock", #HunYuanVideo
253
+ "MMDoubleStreamBlock", # HunYuanVideo
254
+ "MMSingleStreamBlock", # HunYuanVideo
255
+ "WanAttentionBlock", # Wan
237
256
  ]
238
257
  UNET_TARGET_REPLACE_NAME = [
239
258
  "conv_in",
@@ -301,7 +320,7 @@ class LycorisNetworkKohya(LycorisNetwork):
301
320
  self.multiplier = multiplier
302
321
  self.lora_dim = lora_dim
303
322
  self.train_t5xxl = train_t5xxl
304
-
323
+
305
324
  # 初始化LoRA+相关属性
306
325
  self.loraplus_lr_ratio = None
307
326
  self.loraplus_unet_lr_ratio = None
@@ -621,15 +640,23 @@ class LycorisNetworkKohya(LycorisNetwork):
621
640
 
622
641
  return key_scaled, sum(norms) / len(norms), max(norms)
623
642
 
624
- def set_loraplus_lr_ratio(self, loraplus_lr_ratio, loraplus_unet_lr_ratio, loraplus_text_encoder_lr_ratio):
643
+ def set_loraplus_lr_ratio(
644
+ self, loraplus_lr_ratio, loraplus_unet_lr_ratio, loraplus_text_encoder_lr_ratio
645
+ ):
625
646
  self.loraplus_lr_ratio = loraplus_lr_ratio
626
647
  self.loraplus_unet_lr_ratio = loraplus_unet_lr_ratio
627
648
  self.loraplus_text_encoder_lr_ratio = loraplus_text_encoder_lr_ratio
628
649
 
629
- logger.info(f"LoRA+ UNet LR Ratio: {self.loraplus_unet_lr_ratio or self.loraplus_lr_ratio}")
630
- logger.info(f"LoRA+ Text Encoder LR Ratio: {self.loraplus_text_encoder_lr_ratio or self.loraplus_lr_ratio}")
650
+ logger.info(
651
+ f"LoRA+ UNet LR Ratio: {self.loraplus_unet_lr_ratio or self.loraplus_lr_ratio}"
652
+ )
653
+ logger.info(
654
+ f"LoRA+ Text Encoder LR Ratio: {self.loraplus_text_encoder_lr_ratio or self.loraplus_lr_ratio}"
655
+ )
631
656
 
632
- def prepare_optimizer_params(self, text_encoder_lr=None, unet_lr: float = 1e-4, learning_rate=None):
657
+ def prepare_optimizer_params(
658
+ self, text_encoder_lr=None, unet_lr: float = 1e-4, learning_rate=None
659
+ ):
633
660
  self.requires_grad_(True)
634
661
 
635
662
  all_params = []
@@ -658,7 +685,10 @@ class LycorisNetworkKohya(LycorisNetwork):
658
685
  else:
659
686
  param_data["lr"] = lr
660
687
 
661
- if param_data.get("lr", None) == 0 or param_data.get("lr", None) is None:
688
+ if (
689
+ param_data.get("lr", None) == 0
690
+ or param_data.get("lr", None) is None
691
+ ):
662
692
  logger.info("NO LR skipping!")
663
693
  continue
664
694
 
@@ -674,7 +704,9 @@ class LycorisNetworkKohya(LycorisNetwork):
674
704
  self.loraplus_text_encoder_lr_ratio or self.loraplus_lr_ratio,
675
705
  )
676
706
  all_params.extend(params)
677
- lr_descriptions.extend(["textencoder" + (" " + d if d else "") for d in descriptions])
707
+ lr_descriptions.extend(
708
+ ["textencoder" + (" " + d if d else "") for d in descriptions]
709
+ )
678
710
 
679
711
  if self.unet_loras:
680
712
  params, descriptions = assemble_params(
@@ -683,7 +715,9 @@ class LycorisNetworkKohya(LycorisNetwork):
683
715
  self.loraplus_unet_lr_ratio or self.loraplus_lr_ratio,
684
716
  )
685
717
  all_params.extend(params)
686
- lr_descriptions.extend(["unet" + (" " + d if d else "") for d in descriptions])
718
+ lr_descriptions.extend(
719
+ ["unet" + (" " + d if d else "") for d in descriptions]
720
+ )
687
721
 
688
722
  return all_params, lr_descriptions
689
723
 
@@ -691,7 +725,7 @@ class LycorisNetworkKohya(LycorisNetwork):
691
725
  # not supported
692
726
  pass
693
727
 
694
- def prepare_grad_etc(self, unet):
728
+ def prepare_grad_etc(self, *args):
695
729
  self.requires_grad_(True)
696
730
 
697
731
  def on_epoch_start(self, unet):
@@ -290,6 +290,38 @@ class LycorisBaseModule(ModuleCustomSD):
290
290
  self.org_module[0].bias = nn.Parameter(bias)
291
291
  self.to(self_device, self_dtype)
292
292
 
293
+ def onfly_merge(self, multiplier=1.0):
294
+ if self.not_supported:
295
+ return
296
+ self_device = next(self.parameters()).device
297
+ self_dtype = next(self.parameters()).dtype
298
+ self.to(self.org_weight)
299
+ self.cached_org_weight = self.org_weight.data.cpu()
300
+ self.cached_org_bias = None
301
+ weight, bias = self.get_merged_weight(
302
+ multiplier, self.org_weight.shape, self.org_weight.device
303
+ )
304
+ self.org_weight = weight
305
+ if bias is not None:
306
+ bias = bias.to(self.org_weight)
307
+ if self.org_module[0].bias is not None:
308
+ self.org_module[0].bias.data.copy_(bias)
309
+ self.cached_org_bias = self.org_module[0].bias.data.cpu()
310
+ else:
311
+ self.org_module[0].bias = nn.Parameter(bias)
312
+ if self.org_module[0].bias is not None:
313
+ self.org_module[0].bias = self.org_module[0].bias.to(self.org_weight)
314
+ self.to(self_device, self_dtype)
315
+
316
+ def onfly_restore(self):
317
+ if self.not_supported:
318
+ return
319
+ self.org_weight = self.cached_org_weight.to(self.org_weight)
320
+ if self.cached_org_bias is not None:
321
+ self.org_module[0].bias.data.copy_(self.cached_org_bias.to(self.org_weight))
322
+ del self.cached_org_weight
323
+ del self.cached_org_bias
324
+
293
325
  def get_diff_weight(self, multiplier=1.0, shape=None, device=None):
294
326
  raise NotImplementedError
295
327
 
@@ -49,7 +49,7 @@ class LoConModule(LycorisBaseModule):
49
49
  use_scalar=False,
50
50
  rank_dropout_scale=False,
51
51
  weight_decompose=False,
52
- wd_on_out=False,
52
+ wd_on_out=True,
53
53
  bypass_mode=None,
54
54
  rs_lora=False,
55
55
  **kwargs,
@@ -41,7 +41,7 @@ class LohaModule(LycorisBaseModule):
41
41
  use_scalar=False,
42
42
  rank_dropout_scale=False,
43
43
  weight_decompose=False,
44
- wd_on_out=False,
44
+ wd_on_out=True,
45
45
  bypass_mode=None,
46
46
  rs_lora=False,
47
47
  **kwargs,
@@ -58,7 +58,7 @@ class LokrModule(LycorisBaseModule):
58
58
  factor: int = -1, # factorization factor
59
59
  rank_dropout_scale=False,
60
60
  weight_decompose=False,
61
- wd_on_out=False,
61
+ wd_on_out=True,
62
62
  full_matrix=False,
63
63
  bypass_mode=None,
64
64
  rs_lora=False,
@@ -89,9 +89,9 @@ def create_lycoris(module, multiplier=1.0, linear_dim=4, linear_alpha=1, **kwarg
89
89
  constraint = float(kwargs.get("constraint", 0) or 0)
90
90
  rescaled = str_bool(kwargs.get("rescaled", False))
91
91
  weight_decompose = str_bool(kwargs.get("dora_wd", False))
92
- wd_on_output = str_bool(kwargs.get("wd_on_output", False))
92
+ wd_on_output = str_bool(kwargs.get("wd_on_output", True))
93
93
  full_matrix = str_bool(kwargs.get("full_matrix", False))
94
- bypass_mode = str_bool(kwargs.get("bypass_mode", None))
94
+ bypass_mode = str_bool(kwargs.get("bypass_mode", False))
95
95
  unbalanced_factorization = str_bool(kwargs.get("unbalanced_factorization", False))
96
96
 
97
97
  if unbalanced_factorization:
@@ -568,6 +568,14 @@ class LycorisNetwork(torch.nn.Module):
568
568
  for lora in self.loras:
569
569
  lora.merge_to(weight)
570
570
 
571
+ def onfly_merge(self, weight=1.0):
572
+ for lora in self.loras:
573
+ lora.onfly_merge(weight)
574
+
575
+ def onfly_restore(self):
576
+ for lora in self.loras:
577
+ lora.onfly_restore()
578
+
571
579
  def apply_max_norm_regularization(self, max_norm_value, device):
572
580
  key_scaled = 0
573
581
  norms = []
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: lycoris_lora
3
- Version: 3.2.0.dev1
3
+ Version: 3.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
@@ -23,3 +23,11 @@ Requires-Dist: torch
23
23
  Requires-Dist: einops
24
24
  Requires-Dist: toml
25
25
  Requires-Dist: tqdm
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: home-page
30
+ Dynamic: license-file
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
@@ -38,7 +38,9 @@ lycoris_lora.egg-info/not-zip-safe
38
38
  lycoris_lora.egg-info/requires.txt
39
39
  lycoris_lora.egg-info/top_level.txt
40
40
  test/__init__.py
41
+ test/compile.py
41
42
  test/functional.py
42
43
  test/kohya.py
43
44
  test/module.py
45
+ test/restore.py
44
46
  test/wrapper.py
@@ -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.2.0.dev1",
7
+ version="3.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",
@@ -0,0 +1,69 @@
1
+ import sys
2
+
3
+ sys.setrecursionlimit(10000000)
4
+
5
+ import torch
6
+ import torch.nn as nn
7
+ import torch.nn.functional as F
8
+
9
+ from torchao.quantization.quant_api import int8_weight_only, quantize_
10
+
11
+ from lycoris import create_lycoris
12
+
13
+
14
+ class TestNet(nn.Module):
15
+ def __init__(self):
16
+ super(TestNet, self).__init__()
17
+ self.fc1 = nn.Linear(8, 1024)
18
+ self.fc2 = nn.Linear(1024, 8)
19
+
20
+ def forward(self, x):
21
+ x = self.fc1(x)
22
+ x = F.relu(x)
23
+ x = self.fc2(x)
24
+ return x
25
+
26
+
27
+ def test_lycoris_compile():
28
+ net = TestNet().cuda()
29
+
30
+ test_x = torch.randn(1, 8).cuda()
31
+ out = net(test_x)
32
+ print("\nOriginal\n", out)
33
+
34
+ quantize_(net, int8_weight_only())
35
+ out = net(test_x)
36
+ print("\nQuantized\n", out)
37
+ compiled_net = torch.compile(net)
38
+ out = compiled_net(test_x)
39
+ print("\nQuantized compiled\n", out)
40
+
41
+ compiled_net._orig_mod.cpu()
42
+ compiled_net._orig_mod.cuda()
43
+
44
+ compiled_net.cpu()
45
+ compiled_net.cuda()
46
+
47
+ lycoris = create_lycoris(
48
+ net, algo="lokr", factor=2, bypass_mode=True, full_matrix=True
49
+ )
50
+ lycoris.apply_to()
51
+ lycoris.cuda()
52
+ out = net(test_x)
53
+ print("\nBypass Lokr Applied\n", out)
54
+
55
+ compiled_net = torch.compile(net)
56
+ compiled_out = compiled_net(test_x)
57
+ print("\nLyCORIS+torchao quantize_ compiled\n", compiled_out)
58
+ torch.sum(compiled_out).backward()
59
+
60
+ diff = torch.sum(torch.abs(out - compiled_out))
61
+ print("\nDiff: ", diff)
62
+ net.cpu()
63
+ lycoris.cpu()
64
+
65
+ assert torch.allclose(out, compiled_out, atol=1e-6)
66
+
67
+
68
+ if __name__ == "__main__":
69
+ test_lycoris_compile()
@@ -0,0 +1,56 @@
1
+ import sys
2
+
3
+ sys.setrecursionlimit(10000000)
4
+
5
+ import torch
6
+ import torch.nn as nn
7
+ import torch.nn.functional as F
8
+
9
+ from lycoris import create_lycoris
10
+
11
+
12
+ class TestNet(nn.Module):
13
+ def __init__(self):
14
+ super(TestNet, self).__init__()
15
+ self.fc1 = nn.Linear(8, 1024)
16
+ self.fc2 = nn.Linear(1024, 8)
17
+
18
+ def forward(self, x):
19
+ x = self.fc1(x)
20
+ x = F.relu(x)
21
+ x = self.fc2(x)
22
+ return x
23
+
24
+
25
+ def test_lycoris_restore():
26
+ net = TestNet().cuda()
27
+ compiled_net = torch.compile(net)
28
+
29
+ test_x = torch.randn(1, 8).cuda()
30
+ out = compiled_net(test_x)
31
+ print("\nOriginal\n", out)
32
+
33
+ lycoris = create_lycoris(
34
+ net, algo="lokr", factor=2, bypass_mode=True, full_matrix=True
35
+ )
36
+ lycoris.apply_to()
37
+ lycoris.cuda()
38
+ for parameter in lycoris.parameters():
39
+ parameter.data = torch.randn_like(parameter) * 0.1
40
+ net = torch.compile(net)
41
+ out = net(test_x)
42
+ print("\nBypass Lokr Applied\n", out)
43
+
44
+ lycoris.restore()
45
+ # lycoris.set_multiplier(0.0)
46
+ out = net(test_x)
47
+ print("\nRestored\n", out)
48
+
49
+ lycoris.apply_to()
50
+ # lycoris.set_multiplier(1.0)
51
+ out = net(test_x)
52
+ print("\nBypass Lokr Applied\n", out)
53
+
54
+
55
+ if __name__ == "__main__":
56
+ test_lycoris_restore()