lycoris-lora 3.0.0.dev16__tar.gz → 3.0.1.dev1__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.0.dev16/lycoris_lora.egg-info → lycoris_lora-3.0.1.dev1}/PKG-INFO +2 -2
  2. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/README.md +6 -3
  3. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/__init__.py +1 -1
  4. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/functional/general.py +2 -0
  5. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/base.py +2 -2
  6. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/dylora.py +2 -2
  7. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/full.py +15 -0
  8. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/glora.py +1 -1
  9. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/locon.py +22 -16
  10. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/loha.py +20 -15
  11. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/lokr.py +20 -15
  12. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/utils/bnb.py +1 -1
  13. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/utils/xformers_utils.py +2 -2
  14. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1/lycoris_lora.egg-info}/PKG-INFO +2 -2
  15. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris_lora.egg-info/SOURCES.txt +1 -0
  16. lycoris_lora-3.0.1.dev1/setup.py +29 -0
  17. lycoris_lora-3.0.1.dev1/test/kohya.py +133 -0
  18. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/test/module.py +3 -0
  19. lycoris_lora-3.0.0.dev16/setup.py +0 -29
  20. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/LICENSE.md +0 -0
  21. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/config.py +0 -0
  22. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/functional/__init__.py +0 -0
  23. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/functional/boft.py +0 -0
  24. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/functional/diag_oft.py +0 -0
  25. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/functional/locon.py +0 -0
  26. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/functional/loha.py +0 -0
  27. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/functional/lokr.py +0 -0
  28. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/kohya.py +0 -0
  29. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/logging.py +0 -0
  30. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/__init__.py +0 -0
  31. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/boft.py +0 -0
  32. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/diag_oft.py +0 -0
  33. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/ia3.py +0 -0
  34. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/modules/norms.py +0 -0
  35. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/utils/__init__.py +0 -0
  36. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/utils/general.py +0 -0
  37. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/utils/logger.py +0 -0
  38. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/utils/preset.py +0 -0
  39. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris/wrapper.py +0 -0
  40. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris_lora.egg-info/dependency_links.txt +0 -0
  41. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris_lora.egg-info/not-zip-safe +0 -0
  42. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris_lora.egg-info/requires.txt +0 -0
  43. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/lycoris_lora.egg-info/top_level.txt +0 -0
  44. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/setup.cfg +0 -0
  45. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/test/__init__.py +0 -0
  46. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/test/functional.py +0 -0
  47. {lycoris_lora-3.0.0.dev16 → lycoris_lora-3.0.1.dev1}/test/wrapper.py +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.0.dev16
3
+ Version: 3.0.1.dev1
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
7
7
  Author-email: apolloyeh0123@gmail.com
8
- Classifier: Development Status :: 4 - Beta
8
+ Classifier: Development Status :: 5 - Production/Stable
9
9
  Classifier: Environment :: GPU :: NVIDIA CUDA :: 11.8
10
10
  Classifier: Environment :: GPU :: NVIDIA CUDA :: 12
11
11
  Classifier: Environment :: GPU :: NVIDIA CUDA :: 12 :: 12.1
@@ -1,6 +1,9 @@
1
-
2
1
  ![pypi](https://img.shields.io/pypi/v/lycoris-lora.svg)
3
2
  ![versions](https://img.shields.io/pypi/pyversions/lycoris-lora.svg)
3
+ ![PyPI - License](https://img.shields.io/pypi/l/lycoris-lora)
4
+ ![downloads](https://img.shields.io/pypi/dm/lycoris-lora)
5
+ ![commits](https://img.shields.io/github/commit-activity/m/KohakuBlueleaf/LyCORIS/dev)
6
+ ![Discord](https://img.shields.io/discord/1082218577395986452)
4
7
 
5
8
  # LyCORIS - Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion. (ICLR'24)
6
9
 
@@ -27,7 +30,7 @@ A simple comparison of some of these methods are provided below (to be taken wit
27
30
  | | Full | LoRA | LoHa | LoKr low factor | LoKr high factor$^+$ |
28
31
  | --------------------- | ---- | ---- | ---- | --------------- | ---------------------- |
29
32
  | Fidelity | ★ | ● | ▲ | ◉ | ▲ |
30
- | Flexibility$^*$ | ★ | ● | ◉ | ▲ | ●$^†$ |
33
+ | Flexibility $^*$ | ★ | ● | ◉ | ▲ | ● $^†$ |
31
34
  | Diversity | ▲ | ◉ | ★ | ● | ★ |
32
35
  | Size | ▲ | ● | ● | ● | ★ |
33
36
  | Training Speed Linear | ★ | ● | ● | ★ | ★ |
@@ -256,7 +259,7 @@ See [docs/Conversion-scripts.md](docs/Conversion-scripts.md) for more informatio
256
259
 
257
260
  For full log, please see [Change.md](Change.md)
258
261
 
259
- ### 2024/06/xx update to 3.0.0 - Brand New Functional API, Parametrize API and Module API
262
+ ### 2024/06/29 update to 3.0.0 - Brand New Functional API, Parametrize API and Module API
260
263
 
261
264
  #### The reasons of 3.0.0
262
265
 
@@ -1,6 +1,6 @@
1
1
  try:
2
2
  from . import kohya
3
- except:
3
+ except Exception:
4
4
  pass
5
5
  from . import (
6
6
  modules,
@@ -76,6 +76,8 @@ def power2factorization(dimension: int, factor: int = -1) -> tuple[int, int]:
76
76
  if sum(int(i) for i in f"{dimension//m:b}") == 1:
77
77
  n = dimension // m
78
78
 
79
+ if n == 0:
80
+ return None, n
79
81
  return dimension // n, n
80
82
 
81
83
 
@@ -178,9 +178,9 @@ class LycorisBaseModule(ModuleCustomSD):
178
178
  # g(x) = WX + drop(ΔWX) for any algo except LoCon(lora), bypass
179
179
  # g(x) = (W + Brank_drop(A))X for LoCon(lora), rebuid
180
180
  # g(x) = (W + rank_drop(ΔW))X for any algo except LoCon(lora), rebuild
181
- self.drop = nn.Identity() if dropout == 0.0 else nn.Dropout(dropout)
181
+ self.drop = nn.Identity() if dropout == 0 else nn.Dropout(dropout)
182
182
  self.rank_drop = (
183
- nn.Identity() if rank_dropout == 0.0 else nn.Dropout(rank_dropout)
183
+ nn.Identity() if rank_dropout == 0 else nn.Dropout(rank_dropout)
184
184
  )
185
185
 
186
186
  self.multiplier = multiplier
@@ -114,7 +114,7 @@ class DyLoraModule(LycorisBaseModule):
114
114
  if rank is None:
115
115
  down, up, scale = self.get_random_rank_weight()
116
116
  else:
117
- down, up, scale = self.get_random_rank_weight()
117
+ down, up, scale = self.get_weight(rank)
118
118
  w = up @ (down * (scale * multiplier))
119
119
  if device is not None:
120
120
  w = w.to(device)
@@ -132,7 +132,7 @@ class DyLoraModule(LycorisBaseModule):
132
132
  if rank is None:
133
133
  down, up, gamma = self.get_random_rank_weight()
134
134
  else:
135
- down, up, gamma = self.get_random_rank_weight()
135
+ down, up, scale = self.get_weight(rank)
136
136
  down = down.view(self.lora_dim, -1, *self.shape[2:])
137
137
  up = up.view(-1, self.lora_dim, *(1 for _ in self.shape[2:]))
138
138
  scale = scale * gamma
@@ -94,6 +94,21 @@ class FullModule(LycorisBaseModule):
94
94
  else:
95
95
  self.org_bias = None
96
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
111
+
97
112
  def restore(self):
98
113
  self.org_module[0].forward = self.org_forward
99
114
  self.org_module[0].weight = nn.Parameter(self._org_weight[0])
@@ -76,7 +76,7 @@ class GLoRAModule(LycorisBaseModule):
76
76
  stride = org_module.stride
77
77
  padding = org_module.padding
78
78
  out_dim = org_module.out_channels
79
- self.tucker = use_tucker and all(i == 1 for i in k_size)
79
+ use_tucker = use_tucker and all(i == 1 for i in k_size)
80
80
  self.down_op = self.op
81
81
  self.up_op = self.op
82
82
 
@@ -7,7 +7,7 @@ import torch.nn.functional as F
7
7
 
8
8
  from .base import LycorisBaseModule
9
9
  from ..functional.general import rebuild_tucker
10
- from ..logging import logger
10
+ from ..logging import logger, warning_once
11
11
  from ..utils.bnb import LinearNF4
12
12
 
13
13
 
@@ -79,7 +79,7 @@ class LoConModule(LycorisBaseModule):
79
79
  stride = org_module.stride
80
80
  padding = org_module.padding
81
81
  out_dim = org_module.out_channels
82
- self.tucker = use_tucker and any(i != 1 for i in k_size)
82
+ use_tucker = use_tucker and any(i != 1 for i in k_size)
83
83
  self.down_op = self.op
84
84
  self.up_op = self.op
85
85
  if use_tucker and any(i != 1 for i in k_size):
@@ -135,7 +135,7 @@ class LoConModule(LycorisBaseModule):
135
135
 
136
136
  self.scale = alpha / r_factor
137
137
 
138
- self.register_buffer("alpha", torch.tensor(alpha)) # 定数として扱える
138
+ self.register_buffer("alpha", torch.tensor(alpha * (lora_dim / r_factor)))
139
139
 
140
140
  if use_scalar:
141
141
  self.scalar = nn.Parameter(torch.tensor(0.0))
@@ -218,15 +218,15 @@ class LoConModule(LycorisBaseModule):
218
218
  return diff, None
219
219
 
220
220
  def get_merged_weight(self, multiplier=1, shape=None, device=None):
221
- merged = (
222
- self.org_module[0].weight.data
223
- + self.get_diff_weight(multiplier=multiplier, shape=shape, device=device)[0]
224
- )
221
+ diff = self.get_diff_weight(multiplier=1, shape=shape, device=device)[0]
222
+ weight = self.org_weight
225
223
  if self.wd:
226
- merged = self.apply_weight_decompose(merged)
224
+ merged = self.apply_weight_decompose(weight + diff, multiplier)
225
+ else:
226
+ merged = weight + diff * multiplier
227
227
  return merged, None
228
228
 
229
- def apply_weight_decompose(self, weight):
229
+ def apply_weight_decompose(self, weight, multiplier=1):
230
230
  weight = weight.to(self.dora_scale.dtype)
231
231
  weight_norm = (
232
232
  weight.transpose(0, 1)
@@ -236,7 +236,11 @@ class LoConModule(LycorisBaseModule):
236
236
  .transpose(0, 1)
237
237
  ) + torch.finfo(weight.dtype).eps
238
238
 
239
- return weight * (self.dora_scale.to(weight.device) / weight_norm)
239
+ scale = self.dora_scale.to(weight.device) / weight_norm
240
+ if multiplier != 1:
241
+ scale = multiplier * (scale - 1) + 1
242
+
243
+ return weight * scale
240
244
 
241
245
  def custom_state_dict(self):
242
246
  destination = {}
@@ -289,16 +293,18 @@ class LoConModule(LycorisBaseModule):
289
293
  if self.module_dropout and self.training:
290
294
  if torch.rand(1) < self.module_dropout:
291
295
  return self.org_forward(x)
292
- scale = self.scale * self.multiplier
296
+ scale = self.scale
293
297
 
294
298
  dtype = self.dtype
295
299
  if not self.bypass_mode:
296
- weight = (
297
- self.org_module[0].weight.data.to(dtype)
298
- + self.make_weight(x.device).to(dtype) * scale
299
- )
300
+ diff_weight = self.make_weight(x.device).to(dtype) * scale
301
+ weight = self.org_module[0].weight.data.to(dtype)
300
302
  if self.wd:
301
- weight = self.apply_weight_decompose(weight)
303
+ weight = self.apply_weight_decompose(
304
+ weight + diff_weight, self.multiplier
305
+ )
306
+ else:
307
+ weight = weight + diff_weight * self.multiplier
302
308
  bias = (
303
309
  None
304
310
  if self.org_module[0].bias is None
@@ -125,7 +125,7 @@ class LohaModule(LycorisBaseModule):
125
125
 
126
126
  self.scale = alpha / r_factor
127
127
 
128
- self.register_buffer("alpha", torch.tensor(alpha)) # 定数として扱える
128
+ self.register_buffer("alpha", torch.tensor(alpha * (lora_dim / r_factor)))
129
129
 
130
130
  if use_scalar:
131
131
  self.scalar = nn.Parameter(torch.tensor(0.0))
@@ -220,15 +220,15 @@ class LohaModule(LycorisBaseModule):
220
220
  return diff, None
221
221
 
222
222
  def get_merged_weight(self, multiplier=1, shape=None, device=None):
223
- merged = (
224
- self.org_module[0].weight.data
225
- + self.get_diff_weight(multiplier=multiplier, shape=shape, device=device)[0]
226
- )
223
+ diff = self.get_diff_weight(multiplier=1, shape=shape, device=device)[0]
224
+ weight = self.org_weight
227
225
  if self.wd:
228
- merged = self.apply_weight_decompose(merged)
226
+ merged = self.apply_weight_decompose(weight + diff, multiplier)
227
+ else:
228
+ merged = weight + diff * multiplier
229
229
  return merged, None
230
230
 
231
- def apply_weight_decompose(self, weight):
231
+ def apply_weight_decompose(self, weight, multiplier=1):
232
232
  weight = weight.to(self.dora_scale.dtype)
233
233
  weight_norm = (
234
234
  weight.transpose(0, 1)
@@ -238,7 +238,11 @@ class LohaModule(LycorisBaseModule):
238
238
  .transpose(0, 1)
239
239
  ) + torch.finfo(weight.dtype).eps
240
240
 
241
- return weight * (self.dora_scale / weight_norm)
241
+ scale = self.dora_scale.to(weight.device) / weight_norm
242
+ if multiplier != 1:
243
+ scale = multiplier * (scale - 1) + 1
244
+
245
+ return weight * scale
242
246
 
243
247
  def custom_state_dict(self):
244
248
  destination = {}
@@ -289,16 +293,17 @@ class LohaModule(LycorisBaseModule):
289
293
  if self.bypass_mode:
290
294
  return self.bypass_forward(x, scale=self.multiplier)
291
295
  else:
292
- weight = (
293
- self.org_module[0].weight.data.to(self.dtype)
294
- + self.get_weight(self.shape) * self.scalar * self.multiplier
295
- )
296
+ diff_weight = self.get_weight(self.shape).to(self.dtype) * self.scalar
297
+ weight = self.org_module[0].weight.data.to(self.dtype)
298
+ if self.wd:
299
+ weight = self.apply_weight_decompose(
300
+ weight + diff_weight, self.multiplier
301
+ )
302
+ else:
303
+ weight = weight + diff_weight * self.multiplier
296
304
  bias = (
297
305
  None
298
306
  if self.org_module[0].bias is None
299
307
  else self.org_module[0].bias.data
300
308
  )
301
-
302
- if self.wd:
303
- weight = self.apply_weight_decompose(weight)
304
309
  return self.op(x, weight, bias, **self.kw_dict)
@@ -208,7 +208,7 @@ class LokrModule(LycorisBaseModule):
208
208
 
209
209
  self.scale = alpha / r_factor
210
210
 
211
- self.register_buffer("alpha", torch.tensor(alpha)) # 定数として扱える
211
+ self.register_buffer("alpha", torch.tensor(alpha * (lora_dim / r_factor)))
212
212
 
213
213
  if use_scalar:
214
214
  self.scalar = nn.Parameter(torch.tensor(0.0))
@@ -358,15 +358,15 @@ class LokrModule(LycorisBaseModule):
358
358
  return diff, None
359
359
 
360
360
  def get_merged_weight(self, multiplier=1, shape=None, device=None):
361
- merged = (
362
- self.org_module[0].weight.data
363
- + self.get_diff_weight(multiplier=multiplier, shape=shape, device=device)[0]
364
- )
361
+ diff = self.get_diff_weight(multiplier=1, shape=shape, device=device)[0]
362
+ weight = self.org_weight
365
363
  if self.wd:
366
- merged = self.apply_weight_decompose(merged)
364
+ merged = self.apply_weight_decompose(weight + diff, multiplier)
365
+ else:
366
+ merged = weight + diff * multiplier
367
367
  return merged, None
368
368
 
369
- def apply_weight_decompose(self, weight):
369
+ def apply_weight_decompose(self, weight, multiplier=1):
370
370
  weight = weight.to(self.dora_scale.dtype)
371
371
  weight_norm = (
372
372
  weight.transpose(0, 1)
@@ -376,7 +376,11 @@ class LokrModule(LycorisBaseModule):
376
376
  .transpose(0, 1)
377
377
  ) + torch.finfo(weight.dtype).eps
378
378
 
379
- return weight * (self.dora_scale / weight_norm)
379
+ scale = self.dora_scale.to(weight.device) / weight_norm
380
+ if multiplier != 1:
381
+ scale = multiplier * (scale - 1) + 1
382
+
383
+ return weight * scale
380
384
 
381
385
  def custom_state_dict(self):
382
386
  destination = {}
@@ -506,18 +510,19 @@ class LokrModule(LycorisBaseModule):
506
510
  if self.bypass_mode:
507
511
  return self.bypass_forward(x, self.multiplier)
508
512
  else:
509
- weight = (
510
- self.org_module[0].weight.data.to(self.dtype)
511
- + self.get_weight(self.shape) * self.scalar * self.multiplier
512
- )
513
+ diff_weight = self.get_weight(self.shape).to(self.dtype) * self.scalar
514
+ weight = self.org_module[0].weight.data.to(self.dtype)
515
+ if self.wd:
516
+ weight = self.apply_weight_decompose(
517
+ weight + diff_weight, self.multiplier
518
+ )
519
+ else:
520
+ weight = weight + diff_weight * self.multiplier
513
521
  bias = (
514
522
  None
515
523
  if self.org_module[0].bias is None
516
524
  else self.org_module[0].bias.data
517
525
  )
518
-
519
- if self.wd:
520
- weight = self.apply_weight_decompose(weight)
521
526
  return self.op(x, weight, bias, **self.kw_dict)
522
527
 
523
528
 
@@ -4,7 +4,7 @@ try:
4
4
  from bitsandbytes.nn import LinearNF4, Linear8bitLt, LinearFP4
5
5
 
6
6
  SUPPORT_BNB = True
7
- except:
7
+ except Exception:
8
8
  SUPPORT_BNB = False
9
9
  import torch.nn as nn
10
10
 
@@ -1,13 +1,13 @@
1
1
  memory_efficient_attention = None
2
2
  try:
3
3
  import xformers
4
- except:
4
+ except Exception:
5
5
  pass
6
6
 
7
7
  try:
8
8
  from xformers.ops import memory_efficient_attention
9
9
 
10
10
  XFORMERS_AVAIL = True
11
- except:
11
+ except Exception:
12
12
  memory_efficient_attention = None
13
13
  XFORMERS_AVAIL = False
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.0.dev16
3
+ Version: 3.0.1.dev1
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
7
7
  Author-email: apolloyeh0123@gmail.com
8
- Classifier: Development Status :: 4 - Beta
8
+ Classifier: Development Status :: 5 - Production/Stable
9
9
  Classifier: Environment :: GPU :: NVIDIA CUDA :: 11.8
10
10
  Classifier: Environment :: GPU :: NVIDIA CUDA :: 12
11
11
  Classifier: Environment :: GPU :: NVIDIA CUDA :: 12 :: 12.1
@@ -39,5 +39,6 @@ lycoris_lora.egg-info/requires.txt
39
39
  lycoris_lora.egg-info/top_level.txt
40
40
  test/__init__.py
41
41
  test/functional.py
42
+ test/kohya.py
42
43
  test/module.py
43
44
  test/wrapper.py
@@ -0,0 +1,29 @@
1
+ from setuptools import setup, find_packages
2
+
3
+
4
+ setup(
5
+ name="lycoris_lora",
6
+ packages=find_packages(),
7
+ version="3.0.1.dev1",
8
+ url="https://github.com/KohakuBlueleaf/LyCORIS",
9
+ description="Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion",
10
+ author="Shih-Ying Yeh(KohakuBlueLeaf), Yu-Guan Hsieh, Zhidong Gao",
11
+ author_email="apolloyeh0123@gmail.com",
12
+ zip_safe=False,
13
+ install_requires=["torch", "einops", "toml", "tqdm"],
14
+ python_requires=">=3.10",
15
+ classifiers=[
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Environment :: GPU :: NVIDIA CUDA :: 11.8",
18
+ "Environment :: GPU :: NVIDIA CUDA :: 12",
19
+ "Environment :: GPU :: NVIDIA CUDA :: 12 :: 12.1",
20
+ "Intended Audience :: Developers",
21
+ "Intended Audience :: End Users/Desktop",
22
+ "License :: OSI Approved :: Apache Software License",
23
+ "Programming Language :: Python",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Operating System :: OS Independent",
28
+ ],
29
+ )
@@ -0,0 +1,133 @@
1
+ import unittest
2
+ from itertools import product
3
+ from parameterized import parameterized
4
+
5
+ import torch
6
+
7
+ from lycoris.kohya import (
8
+ LycorisNetworkKohya,
9
+ create_network,
10
+ create_network_from_weights,
11
+ )
12
+ from lycoris.utils import merge, extract_diff
13
+
14
+ from library.model_util import (
15
+ load_models_from_stable_diffusion_checkpoint as load_sd,
16
+ load_file,
17
+ )
18
+ from library.sdxl_model_util import (
19
+ load_models_from_sdxl_checkpoint as load_sdxl,
20
+ )
21
+
22
+
23
+ algos: list[str] = [
24
+ "lora",
25
+ "loha",
26
+ "lokr",
27
+ "full",
28
+ "diag-oft",
29
+ "boft",
30
+ "glora",
31
+ "ia3",
32
+ ]
33
+ if torch.cuda.is_available():
34
+ device_and_dtype = [
35
+ (torch.device("cuda"), torch.float16),
36
+ ]
37
+ else:
38
+ device_and_dtype = [
39
+ (torch.device("cpu"), torch.float32),
40
+ ]
41
+ weight_decompose = [
42
+ False,
43
+ True,
44
+ ]
45
+ use_tucker = [
46
+ False,
47
+ True,
48
+ ]
49
+ use_scalar = [
50
+ False,
51
+ True,
52
+ ]
53
+
54
+ wrapper_param_list = list(
55
+ product(
56
+ algos,
57
+ device_and_dtype,
58
+ weight_decompose,
59
+ use_tucker,
60
+ use_scalar,
61
+ )
62
+ )
63
+ extract_param_list = list(
64
+ product(
65
+ device_and_dtype,
66
+ )
67
+ )
68
+
69
+ device, dtype = device_and_dtype[0]
70
+ sd_te1, sd_te2, vae, sdxl_unet, *_ = load_sdxl(
71
+ None, "./models/kohaku-xl-beta7.safetensors", "cpu", dtype
72
+ )
73
+
74
+
75
+ class LycorisKohyaWrapperTests(unittest.TestCase):
76
+ @parameterized.expand(wrapper_param_list)
77
+ def test_wrapper(self, algo, device_dtype, wd, tucker, scalar):
78
+ device, dtype = device_dtype
79
+ print(
80
+ f"{algo: <18}",
81
+ f"device={str(device): <5}",
82
+ f"dtype={str(dtype): <15}",
83
+ f"wd={str(wd): <6}",
84
+ f"tucker={str(tucker): <6}",
85
+ f"scalar={str(scalar): <6}",
86
+ sep="|| ",
87
+ )
88
+ network = create_network(
89
+ 1,
90
+ 16,
91
+ 16,
92
+ vae,
93
+ [sd_te1, sd_te2],
94
+ sdxl_unet,
95
+ algo=algo,
96
+ conv_dim=16,
97
+ conv_alpha=16.0,
98
+ dropout=0.0,
99
+ rank_dropout=0.0,
100
+ weight_decompose=wd,
101
+ use_tucker=tucker,
102
+ use_scalar=scalar,
103
+ train_norm=True,
104
+ )
105
+ network.apply_to([sd_te1, sd_te2], sdxl_unet, True, True)
106
+ network.restore()
107
+ create_network_from_weights(
108
+ 1, "", vae, [sd_te1, sd_te2], sdxl_unet, weights_sd=network.state_dict()
109
+ )
110
+ torch.cuda.empty_cache()
111
+
112
+ @parameterized.expand(extract_param_list)
113
+ def test_extract(self, device_dtype):
114
+ device, dtype = device_dtype
115
+ print(
116
+ "Extract",
117
+ f"device={str(device): <5}",
118
+ f"dtype={str(dtype): <15}",
119
+ sep="|| ",
120
+ )
121
+ extract_diff(
122
+ [sd_te1, sd_te2],
123
+ [sd_te1, sd_te2],
124
+ sdxl_unet,
125
+ sdxl_unet,
126
+ mode="fixed",
127
+ linear_mode_param=4,
128
+ conv_mode_param=4,
129
+ extract_device=device,
130
+ use_bias=True,
131
+ sparsity=0.98,
132
+ small_conv=True,
133
+ )
@@ -102,6 +102,9 @@ class LycorisModuleTests(unittest.TestCase):
102
102
  net.restore()
103
103
  net.merge_to()
104
104
 
105
+ # attr access test
106
+ net.org_weight
107
+
105
108
  @parameterized.expand(patch_forward_param_list)
106
109
  def test_lycoris_modules_bypass_mode(
107
110
  self, module, base, device_dtype, wd, tucker, scalar
@@ -1,29 +0,0 @@
1
- from setuptools import setup, find_packages
2
-
3
-
4
- setup(
5
- name="lycoris_lora",
6
- packages=find_packages(),
7
- version="3.0.0.dev16",
8
- url="https://github.com/KohakuBlueleaf/LyCORIS",
9
- description="Lora beYond Conventional methods, Other Rank adaptation Implementations for Stable diffusion",
10
- author="Shih-Ying Yeh(KohakuBlueLeaf), Yu-Guan Hsieh, Zhidong Gao",
11
- author_email="apolloyeh0123@gmail.com",
12
- zip_safe=False,
13
- install_requires=["torch", "einops", "toml", "tqdm"],
14
- python_requires=">=3.10",
15
- classifiers=[
16
- 'Development Status :: 4 - Beta',
17
- 'Environment :: GPU :: NVIDIA CUDA :: 11.8',
18
- 'Environment :: GPU :: NVIDIA CUDA :: 12',
19
- 'Environment :: GPU :: NVIDIA CUDA :: 12 :: 12.1',
20
- 'Intended Audience :: Developers',
21
- 'Intended Audience :: End Users/Desktop',
22
- 'License :: OSI Approved :: Apache Software License',
23
- 'Programming Language :: Python',
24
- 'Programming Language :: Python :: 3.10',
25
- 'Programming Language :: Python :: 3.11',
26
- 'Programming Language :: Python :: 3.12',
27
- 'Operating System :: OS Independent',
28
- ],
29
- )