lycoris-lora 3.0.1.dev1__tar.gz → 3.0.1.dev2__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 (47) hide show
  1. {lycoris_lora-3.0.1.dev1/lycoris_lora.egg-info → lycoris_lora-3.0.1.dev2}/PKG-INFO +1 -1
  2. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/README.md +4 -4
  3. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/functional/loha.py +1 -1
  4. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/base.py +2 -2
  5. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/full.py +20 -19
  6. lycoris_lora-3.0.1.dev2/lycoris/utils/bnb.py +77 -0
  7. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/wrapper.py +1 -1
  8. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2/lycoris_lora.egg-info}/PKG-INFO +1 -1
  9. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/setup.py +1 -1
  10. lycoris_lora-3.0.1.dev1/lycoris/utils/bnb.py +0 -29
  11. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/LICENSE.md +0 -0
  12. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/__init__.py +0 -0
  13. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/config.py +0 -0
  14. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/functional/__init__.py +0 -0
  15. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/functional/boft.py +0 -0
  16. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/functional/diag_oft.py +0 -0
  17. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/functional/general.py +0 -0
  18. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/functional/locon.py +0 -0
  19. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/functional/lokr.py +0 -0
  20. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/kohya.py +0 -0
  21. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/logging.py +0 -0
  22. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/__init__.py +0 -0
  23. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/boft.py +0 -0
  24. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/diag_oft.py +0 -0
  25. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/dylora.py +0 -0
  26. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/glora.py +0 -0
  27. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/ia3.py +0 -0
  28. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/locon.py +0 -0
  29. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/loha.py +0 -0
  30. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/lokr.py +0 -0
  31. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/modules/norms.py +0 -0
  32. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/utils/__init__.py +0 -0
  33. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/utils/general.py +0 -0
  34. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/utils/logger.py +0 -0
  35. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/utils/preset.py +0 -0
  36. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris/utils/xformers_utils.py +0 -0
  37. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris_lora.egg-info/SOURCES.txt +0 -0
  38. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris_lora.egg-info/dependency_links.txt +0 -0
  39. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris_lora.egg-info/not-zip-safe +0 -0
  40. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris_lora.egg-info/requires.txt +0 -0
  41. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/lycoris_lora.egg-info/top_level.txt +0 -0
  42. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/setup.cfg +0 -0
  43. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/test/__init__.py +0 -0
  44. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/test/functional.py +0 -0
  45. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/test/kohya.py +0 -0
  46. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/test/module.py +0 -0
  47. {lycoris_lora-3.0.1.dev1 → lycoris_lora-3.0.1.dev2}/test/wrapper.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.1.dev1
3
+ Version: 3.0.1.dev2
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
@@ -27,7 +27,7 @@ Please check [List of Implemented Algorithms](docs/Algo-List.md) and [Guidelines
27
27
 
28
28
  A simple comparison of some of these methods are provided below (to be taken with a grain of salt)
29
29
 
30
- | | Full | LoRA | LoHa | LoKr low factor | LoKr high factor$^+$ |
30
+ | | Full | LoRA | LoHa | LoKr low factor | LoKr high factor $^+$ |
31
31
  | --------------------- | ---- | ---- | ---- | --------------- | ---------------------- |
32
32
  | Fidelity | ★ | ● | ▲ | ◉ | ▲ |
33
33
  | Flexibility $^*$ | ★ | ● | ◉ | ▲ | ● $^†$ |
@@ -39,9 +39,9 @@ A simple comparison of some of these methods are provided below (to be taken wit
39
39
  ★ > ◉ > ● > ▲
40
40
  [> means better and smaller size is better]
41
41
 
42
- $^+$ Usually we take `factor <= 0.5 * sqrt(dim)` as low factor and `factor >= sqrt(dim` as high factor. For example, factor<=8 for SD1.x/SD2.x/SDXL can be seen as low factor, and, factor>=16 can be seen as high factor. `<br>`
43
- $^*$ Flexibility means anything related to generating images not similar to those in the training set, and combination of multiple concepts, whether they are trained together or not `<br>`
44
- $^†$ It may become more difficult to switch base model or combine multiple concepts in this situation `<br>`
42
+ $^+$ Usually we take `factor <= 0.5 * sqrt(dim)` as low factor and `factor >= sqrt(dim` as high factor. For example, factor<=8 for SD1.x/SD2.x/SDXL can be seen as low factor, and, factor>=16 can be seen as high factor. <br>
43
+ $^*$ Flexibility means anything related to generating images not similar to those in the training set, and combination of multiple concepts, whether they are trained together or not <br>
44
+ $^†$ It may become more difficult to switch base model or combine multiple concepts in this situation <br>
45
45
 
46
46
  **The actual performance may vary depending on the datasets, tasks, and hyperparameters used. It is recommended to experiment with different settings to achieve optimal results.**
47
47
 
@@ -141,7 +141,7 @@ def diff_weight(w1d, w1u, w2d, w2u, t1=None, t2=None, gamma=1.0):
141
141
  w1d = w1d.reshape(w1d.size(0), -1)
142
142
  w1u = w1u.reshape(-1, w1u.size(1))
143
143
  w2d = w2d.reshape(w2d.size(0), -1)
144
- w2u = w1u.reshape(-1, w2u.size(1))
144
+ w2u = w2u.reshape(-1, w2u.size(1))
145
145
  result = make_weight(w1d, w1u, w2d, w2u, gamma)
146
146
 
147
147
  result = result.reshape(O, I, *k)
@@ -159,11 +159,11 @@ class LycorisBaseModule(ModuleCustomSD):
159
159
 
160
160
  self.register_buffer("dtype_tensor", torch.tensor(0.0), persistent=False)
161
161
 
162
- self.is_bnb = False
162
+ self.is_quant = False
163
163
  if isinstance(org_module, QuantLinears):
164
164
  if not bypass_mode:
165
165
  log_bypass()
166
- self.is_bnb = True
166
+ self.is_quant = True
167
167
  bypass_mode = True
168
168
  self.bypass_mode = bypass_mode
169
169
  self.dropout = dropout
@@ -44,7 +44,7 @@ class FullModule(LycorisBaseModule):
44
44
  if self.module_type not in self.support_module:
45
45
  raise ValueError(f"{self.module_type} is not supported in Full algo.")
46
46
 
47
- if self.is_bnb:
47
+ if self.is_quant:
48
48
  raise ValueError(
49
49
  "Quant Linear is not supported and meaningless in Full algo."
50
50
  )
@@ -57,6 +57,12 @@ class FullModule(LycorisBaseModule):
57
57
  self.bias = nn.Parameter(torch.zeros_like(org_module.bias))
58
58
  else:
59
59
  self.bias = None
60
+ self.is_diff = True
61
+ self._org_weight = [self.org_module[0].weight.data.cpu().clone()]
62
+ if self.org_module[0].bias is not None:
63
+ self.org_bias = [self.org_module[0].bias.data.cpu().clone()]
64
+ else:
65
+ self.org_bias = None
60
66
 
61
67
  @classmethod
62
68
  def make_module_from_state_dict(cls, lora_name, orig_module, diff, diff_b):
@@ -71,6 +77,7 @@ class FullModule(LycorisBaseModule):
71
77
  module.bias.copy_(diff_b)
72
78
  else:
73
79
  module.bias = nn.Parameter(diff_b)
80
+ module.is_diff = True
74
81
  return module
75
82
 
76
83
  @property
@@ -93,21 +100,7 @@ class FullModule(LycorisBaseModule):
93
100
  delattr(self.org_module[0], "bias")
94
101
  else:
95
102
  self.org_bias = None
96
-
97
- def merge_to(self, multiplier=1.0):
98
- need_restore = False
99
- if not hasattr(self, "_org_weight"):
100
- need_restore = True
101
- self.apply_to()
102
- result = super().merge_to(multiplier)
103
- if need_restore:
104
- self.weight = nn.Parameter(torch.zeros_like(self.org_module[0].weight))
105
- if self.org_module[0].bias is not None:
106
- self.bias = nn.Parameter(torch.zeros_like(self.org_module[0].bias))
107
- else:
108
- self.bias = None
109
- self.org_module[0].forward = self.org_forward
110
- return result
103
+ self.is_diff = False
111
104
 
112
105
  def restore(self):
113
106
  self.org_module[0].forward = self.org_forward
@@ -143,16 +136,24 @@ class FullModule(LycorisBaseModule):
143
136
  if self.rank_dropout and self.training
144
137
  else 1
145
138
  )
146
- if drop != 1 or scale != 1:
139
+ if drop != 1 or scale != 1 or self.is_diff:
147
140
  diff_w, diff_b = self.get_diff_weight(scale, device=device)
148
- weight = self.org_module[0].weight + diff_w * drop
149
- bias = self.org_module[0].bias + diff_b * drop
141
+ weight = self._org_weight + diff_w * drop
142
+ if self.org_bias is not None:
143
+ bias = self.org_bias + diff_b * drop
144
+ else:
145
+ bias = None
150
146
  else:
151
147
  weight = self.weight
152
148
  bias = self.bias
153
149
  return weight, bias
154
150
 
155
151
  def get_diff_weight(self, multiplier=1, shape=None, device=None):
152
+ if self.is_diff:
153
+ diff_b = None
154
+ if self.bias is not None:
155
+ diff_b = self.bias * multiplier
156
+ return self.weight * multiplier, diff_b
156
157
  org_weight = self.org_module[0].weight.to(device, dtype=self.weight.dtype)
157
158
  diff = self.weight.to(device) - org_weight
158
159
  diff_b = None
@@ -0,0 +1,77 @@
1
+ from functools import cache
2
+
3
+ SUPPORT_QUANT = False
4
+ try:
5
+ from bitsandbytes.nn import LinearNF4, Linear8bitLt, LinearFP4
6
+
7
+ SUPPORT_QUANT = True
8
+ except Exception:
9
+ import torch.nn as nn
10
+
11
+ class LinearNF4(nn.Linear):
12
+ pass
13
+
14
+ class Linear8bitLt(nn.Linear):
15
+ pass
16
+
17
+ class LinearFP4(nn.Linear):
18
+ pass
19
+
20
+
21
+ try:
22
+ from quanto.nn import QLinear, QConv2d, QLayerNorm
23
+
24
+ SUPPORT_QUANT = True
25
+ except Exception:
26
+ import torch.nn as nn
27
+
28
+ class QLinear(nn.Linear):
29
+ pass
30
+
31
+ class QConv2d(nn.Conv2d):
32
+ pass
33
+
34
+ class QLayerNorm(nn.LayerNorm):
35
+ pass
36
+
37
+
38
+ try:
39
+ from optimum.quanto.nn import (
40
+ QLinear as QLinearOpt,
41
+ QConv2d as QConv2dOpt,
42
+ QLayerNorm as QLayerNormOpt,
43
+ )
44
+
45
+ SUPPORT_QUANT = True
46
+ except Exception:
47
+ import torch.nn as nn
48
+
49
+ class QLinearOpt(nn.Linear):
50
+ pass
51
+
52
+ class QConv2dOpt(nn.Conv2d):
53
+ pass
54
+
55
+ class QLayerNormOpt(nn.LayerNorm):
56
+ pass
57
+
58
+
59
+ from ..logging import logger
60
+
61
+
62
+ QuantLinears = (
63
+ Linear8bitLt,
64
+ LinearFP4,
65
+ LinearNF4,
66
+ QLinear,
67
+ QConv2d,
68
+ QLayerNorm,
69
+ QLinearOpt,
70
+ QConv2dOpt,
71
+ QLayerNormOpt,
72
+ )
73
+
74
+
75
+ @cache
76
+ def log_bypass():
77
+ return logger.warning("Using bnb/quanto/optimum-quanto with LyCORIS will enable force-bypass mode.")
@@ -44,7 +44,7 @@ deprecated_arg_dict = {
44
44
  }
45
45
 
46
46
 
47
- def create_lycoris(module, multiplier, linear_dim, linear_alpha, **kwargs):
47
+ def create_lycoris(module, multiplier=1.0, linear_dim=4, linear_alpha=1, **kwargs):
48
48
  for key, value in kwargs.items():
49
49
  if key in deprecated_arg_dict:
50
50
  logger.warning(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.1.dev1
3
+ Version: 3.0.1.dev2
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.1.dev1",
7
+ version="3.0.1.dev2",
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",
@@ -1,29 +0,0 @@
1
- from functools import cache
2
-
3
- try:
4
- from bitsandbytes.nn import LinearNF4, Linear8bitLt, LinearFP4
5
-
6
- SUPPORT_BNB = True
7
- except Exception:
8
- SUPPORT_BNB = False
9
- import torch.nn as nn
10
-
11
- class LinearNF4(nn.Linear):
12
- pass
13
-
14
- class Linear8bitLt(nn.Linear):
15
- pass
16
-
17
- class LinearFP4(nn.Linear):
18
- pass
19
-
20
-
21
- from ..logging import logger
22
-
23
-
24
- QuantLinears = (Linear8bitLt, LinearFP4, LinearNF4)
25
-
26
-
27
- @cache
28
- def log_bypass():
29
- return logger.warning("Using bnb with LyCORIS will enable force-bypass mode.")