lycoris-lora 3.0.0.dev10__tar.gz → 3.0.0.dev11__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 (39) hide show
  1. {lycoris_lora-3.0.0.dev10/lycoris_lora.egg-info → lycoris_lora-3.0.0.dev11}/PKG-INFO +1 -1
  2. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/config.py +5 -1
  3. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/logging.py +16 -0
  4. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/base.py +8 -0
  5. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/norms.py +55 -15
  6. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11/lycoris_lora.egg-info}/PKG-INFO +1 -1
  7. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/setup.py +1 -1
  8. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/LICENSE.md +0 -0
  9. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/README.md +0 -0
  10. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/__init__.py +0 -0
  11. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/functional/__init__.py +0 -0
  12. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/functional/general.py +0 -0
  13. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/functional/locon.py +0 -0
  14. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/functional/loha.py +0 -0
  15. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/functional/lokr.py +0 -0
  16. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/kohya.py +0 -0
  17. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/__init__.py +0 -0
  18. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/boft.py +0 -0
  19. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/diag_oft.py +0 -0
  20. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/dylora.py +0 -0
  21. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/full.py +0 -0
  22. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/glora.py +0 -0
  23. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/ia3.py +0 -0
  24. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/locon.py +0 -0
  25. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/loha.py +0 -0
  26. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/modules/lokr.py +0 -0
  27. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/utils/__init__.py +0 -0
  28. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/utils/bnb.py +0 -0
  29. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/utils/general.py +0 -0
  30. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/utils/logger.py +0 -0
  31. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/utils/preset.py +0 -0
  32. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/utils/xformers_utils.py +0 -0
  33. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris/wrapper.py +0 -0
  34. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris_lora.egg-info/SOURCES.txt +0 -0
  35. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris_lora.egg-info/dependency_links.txt +0 -0
  36. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris_lora.egg-info/not-zip-safe +0 -0
  37. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris_lora.egg-info/requires.txt +0 -0
  38. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/lycoris_lora.egg-info/top_level.txt +0 -0
  39. {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev11}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.0.dev10
3
+ Version: 3.0.0.dev11
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
@@ -63,7 +63,11 @@ PRESET = {
63
63
  "SelfAttention",
64
64
  ],
65
65
  "unet_target_name": [],
66
- "text_encoder_target_module": ["CLIPAttention", "BertAttention", "MT5LayerSelfAttention"],
66
+ "text_encoder_target_module": [
67
+ "CLIPAttention",
68
+ "BertAttention",
69
+ "MT5LayerSelfAttention",
70
+ ],
67
71
  "text_encoder_target_name": [],
68
72
  },
69
73
  "unet-only": {
@@ -1,6 +1,7 @@
1
1
  import sys
2
2
  import copy
3
3
  import logging
4
+ from functools import cache
4
5
 
5
6
 
6
7
  class ColoredFormatter(logging.Formatter):
@@ -34,3 +35,18 @@ if not logger.handlers:
34
35
  )
35
36
  )
36
37
  logger.addHandler(handler)
38
+
39
+
40
+ @cache
41
+ def info_once(msg):
42
+ logger.info(msg)
43
+
44
+
45
+ @cache
46
+ def warning_once(msg):
47
+ logger.warning(msg)
48
+
49
+
50
+ @cache
51
+ def error_once(msg):
52
+ logger.error(msg)
@@ -80,6 +80,7 @@ class LycorisBaseModule(ModuleCustomSD):
80
80
  """if alpha == 0 or None, alpha is rank (no scaling)."""
81
81
  super().__init__()
82
82
  self.lora_name = lora_name
83
+ self.not_supported = False
83
84
 
84
85
  self.module = type(org_module)
85
86
  if isinstance(org_module, nn.Linear):
@@ -150,6 +151,7 @@ class LycorisBaseModule(ModuleCustomSD):
150
151
  self.dim = org_module.num_channels
151
152
  self.kw_dict = {"num_groups": org_module.num_groups, "eps": org_module.eps}
152
153
  else:
154
+ self.not_supported = True
153
155
  self.module_type = "unknown"
154
156
 
155
157
  self.register_buffer("dtype_tensor", torch.tensor(0.0), persistent=False)
@@ -236,13 +238,19 @@ class LycorisBaseModule(ModuleCustomSD):
236
238
  self.org_module[0].weight.data.copy_(value)
237
239
 
238
240
  def apply_to(self, **kwargs):
241
+ if self.not_supported:
242
+ return
239
243
  self.org_forward = self.org_module[0].forward
240
244
  self.org_module[0].forward = self.forward
241
245
 
242
246
  def restore(self):
247
+ if self.not_supported:
248
+ return
243
249
  self.org_module[0].forward = self.org_forward
244
250
 
245
251
  def merge_to(self, multiplier=1.0):
252
+ if self.not_supported:
253
+ return
246
254
  weight, bias = self.get_merged_weight(
247
255
  multiplier, self.org_weight.shape, self.org_weight.device
248
256
  )
@@ -2,6 +2,7 @@ import torch
2
2
  import torch.nn as nn
3
3
 
4
4
  from .base import LycorisBaseModule
5
+ from ..logging import warning_once
5
6
 
6
7
 
7
8
  class NormModule(LycorisBaseModule):
@@ -30,15 +31,31 @@ class NormModule(LycorisBaseModule):
30
31
  rank_dropout_scale=rank_dropout_scale,
31
32
  **kwargs,
32
33
  )
33
- if self.module_type not in self.support_module:
34
- raise ValueError(f"{self.module_type} is not supported in Norm algo.")
34
+ if self.module_type == "unknown":
35
+ if not hasattr(org_module, "weight") or not hasattr(org_module, "_norm"):
36
+ warning_once(f"{type(org_module)} is not supported in Norm algo.")
37
+ return
38
+ else:
39
+ self.dim = org_module.weight.numel()
40
+ self.not_supported = False
41
+ elif self.module_type not in self.support_module:
42
+ warning_once(f"{self.module_type} is not supported in Norm algo.")
43
+ return
35
44
 
36
45
  self.w_norm = nn.Parameter(torch.zeros(self.dim))
37
- self.b_norm = nn.Parameter(torch.zeros(self.dim))
46
+ if hasattr(org_module, "bias"):
47
+ self.b_norm = nn.Parameter(torch.zeros(self.dim))
48
+ if hasattr(org_module, "_norm"):
49
+ self.org_norm = org_module._norm
50
+ else:
51
+ self.org_norm = None
38
52
 
39
53
  def make_weight(self, scale=1, device=None):
40
54
  org_weight = self.org_module[0].weight.to(device, dtype=self.w_norm.dtype)
41
- org_bias = self.org_module[0].bias.to(device, dtype=self.b_norm.dtype)
55
+ if hasattr(self.org_module[0], "bias"):
56
+ org_bias = self.org_module[0].bias.to(device, dtype=self.b_norm.dtype)
57
+ else:
58
+ org_bias = None
42
59
  if self.rank_dropout and self.training:
43
60
  drop = (torch.rand(self.dim, device=device) < self.rank_dropout).to(
44
61
  self.w_norm.device
@@ -53,35 +70,58 @@ class NormModule(LycorisBaseModule):
53
70
  else 1
54
71
  )
55
72
  weight = self.w_norm.to(device) * drop * scale
56
- bias = self.b_norm.to(device) * drop * scale
57
- return org_weight + weight, org_bias + bias
73
+ if org_bias is not None:
74
+ bias = self.b_norm.to(device) * drop * scale
75
+ return org_weight + weight, org_bias + bias if org_bias is not None else None
58
76
 
59
77
  def get_diff_weight(self, multiplier=1, shape=None, device=None):
78
+ if self.not_supported:
79
+ return 0, 0
60
80
  w = self.w_norm * multiplier
61
- b = self.b_norm * multiplier
62
81
  if device is not None:
63
82
  w = w.to(device)
64
- b = b.to(device)
65
83
  if shape is not None:
66
84
  w = w.view(shape)
67
- b = b.view(shape)
85
+ if self.b_norm is not None:
86
+ b = self.b_norm * multiplier
87
+ if device is not None:
88
+ b = b.to(device)
89
+ if shape is not None:
90
+ b = b.view(shape)
91
+ else:
92
+ b = None
68
93
  return w, b
69
94
 
70
95
  def get_merged_weight(self, multiplier=1, shape=None, device=None):
71
- org_w = self.org_module[0].weight.to(device, dtype=self.w_norm.dtype)
72
- org_b = self.org_module[0].bias.to(device, dtype=self.b_norm.dtype)
96
+ if self.not_supported:
97
+ return None, None
73
98
  diff_w, diff_b = self.get_diff_weight(multiplier, shape, device)
99
+ org_w = self.org_module[0].weight.to(device, dtype=self.w_norm.dtype)
74
100
  weight = org_w + diff_w
75
- bias = org_b + diff_b
101
+ if diff_b is not None:
102
+ org_b = self.org_module[0].bias.to(device, dtype=self.b_norm.dtype)
103
+ bias = org_b + diff_b
104
+ else:
105
+ bias = None
76
106
  return weight, bias
77
107
 
78
108
  def forward(self, x):
79
- if self.module_dropout and self.training:
80
- if torch.rand(1) < self.module_dropout:
81
- return self.org_forward(x)
109
+ if self.not_supported or (
110
+ self.module_dropout
111
+ and self.training
112
+ and torch.rand(1) < self.module_dropout
113
+ ):
114
+ return self.org_forward(x)
82
115
  scale = self.multiplier
83
116
 
84
117
  w, b = self.make_weight(scale, x.device)
118
+ if self.org_norm is not None:
119
+ normed = self.org_norm(x)
120
+ scaled = normed * w
121
+ if b is not None:
122
+ scaled += b
123
+ return scaled
124
+
85
125
  kw_dict = self.kw_dict | {"weight": w, "bias": b}
86
126
  return self.op(x, **kw_dict)
87
127
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lycoris_lora
3
- Version: 3.0.0.dev10
3
+ Version: 3.0.0.dev11
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.dev10",
7
+ version="3.0.0.dev11",
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",