lycoris-lora 3.0.0.dev10__tar.gz → 3.0.0.dev12__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.
- {lycoris_lora-3.0.0.dev10/lycoris_lora.egg-info → lycoris_lora-3.0.0.dev12}/PKG-INFO +1 -1
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/config.py +5 -1
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/logging.py +16 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/__init__.py +1 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/base.py +8 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/lokr.py +6 -2
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/norms.py +55 -15
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12/lycoris_lora.egg-info}/PKG-INFO +1 -1
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/setup.py +1 -1
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/LICENSE.md +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/README.md +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/__init__.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/functional/__init__.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/functional/general.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/functional/locon.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/functional/loha.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/functional/lokr.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/kohya.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/boft.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/diag_oft.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/dylora.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/full.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/glora.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/ia3.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/locon.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/modules/loha.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/utils/__init__.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/utils/bnb.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/utils/general.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/utils/logger.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/utils/preset.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/utils/xformers_utils.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris/wrapper.py +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris_lora.egg-info/SOURCES.txt +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris_lora.egg-info/dependency_links.txt +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris_lora.egg-info/not-zip-safe +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris_lora.egg-info/requires.txt +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris_lora.egg-info/top_level.txt +0 -0
- {lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: lycoris_lora
|
|
3
|
-
Version: 3.0.0.
|
|
3
|
+
Version: 3.0.0.dev12
|
|
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": [
|
|
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
|
)
|
|
@@ -137,7 +137,11 @@ class LokrModule(LycorisBaseModule):
|
|
|
137
137
|
(in_m, in_n),
|
|
138
138
|
) # ((a, b), (c, d)), out_dim = a*c, in_dim = b*d
|
|
139
139
|
# smaller part. weight scale
|
|
140
|
-
if
|
|
140
|
+
if (
|
|
141
|
+
decompose_both
|
|
142
|
+
and lora_dim < max(shape[0][0], shape[1][0]) / 2
|
|
143
|
+
and not self.full_matrix
|
|
144
|
+
):
|
|
141
145
|
self.lokr_w1_a = nn.Parameter(torch.empty(shape[0][0], lora_dim))
|
|
142
146
|
self.lokr_w1_b = nn.Parameter(torch.empty(lora_dim, shape[1][0]))
|
|
143
147
|
else:
|
|
@@ -145,7 +149,7 @@ class LokrModule(LycorisBaseModule):
|
|
|
145
149
|
self.lokr_w1 = nn.Parameter(
|
|
146
150
|
torch.empty(shape[0][0], shape[1][0])
|
|
147
151
|
) # a*c, 1-mode
|
|
148
|
-
if lora_dim < max(shape[0][1], shape[1][1]) / 2:
|
|
152
|
+
if lora_dim < max(shape[0][1], shape[1][1]) / 2 and not self.full_matrix:
|
|
149
153
|
# bigger part. weight and LoRA. [b, dim] x [dim, d]
|
|
150
154
|
self.lokr_w2_a = nn.Parameter(torch.empty(shape[0][1], lora_dim))
|
|
151
155
|
self.lokr_w2_b = nn.Parameter(torch.empty(lora_dim, shape[1][1]))
|
|
@@ -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
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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.
|
|
80
|
-
|
|
81
|
-
|
|
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.
|
|
3
|
+
Version: 3.0.0.dev12
|
|
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.
|
|
7
|
+
version="3.0.0.dev12",
|
|
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",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lycoris_lora-3.0.0.dev10 → lycoris_lora-3.0.0.dev12}/lycoris_lora.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|