lycoris-lora 3.0.0.dev1__tar.gz → 3.0.0.dev3__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.dev1/lycoris_lora.egg-info → lycoris_lora-3.0.0.dev3}/PKG-INFO +1 -4
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/__init__.py +4 -1
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/functional/general.py +2 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/base.py +38 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/boft.py +41 -31
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/diag_oft.py +41 -25
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/full.py +30 -15
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/glora.py +40 -25
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/locon.py +44 -28
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/loha.py +44 -29
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/lokr.py +49 -27
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3/lycoris_lora.egg-info}/PKG-INFO +1 -4
- lycoris_lora-3.0.0.dev3/lycoris_lora.egg-info/requires.txt +3 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/setup.py +1 -4
- lycoris_lora-3.0.0.dev1/lycoris_lora.egg-info/requires.txt +0 -6
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/LICENSE.md +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/README.md +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/config.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/functional/__init__.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/functional/locon.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/functional/loha.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/kohya.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/logging.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/__init__.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/dylora.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/ia3.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/modules/norms.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/utils/__init__.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/utils/bnb.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/utils/logger.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/utils/preset.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/utils/xformers_utils.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris/wrapper.py +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris_lora.egg-info/SOURCES.txt +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris_lora.egg-info/dependency_links.txt +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris_lora.egg-info/not-zip-safe +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/lycoris_lora.egg-info/top_level.txt +0 -0
- {lycoris_lora-3.0.0.dev1 → lycoris_lora-3.0.0.dev3}/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.dev3
|
|
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
|
|
@@ -8,8 +8,5 @@ Author-email: apolloyeh0123@gmail.com
|
|
|
8
8
|
Requires-Python: >=3.10
|
|
9
9
|
License-File: LICENSE.md
|
|
10
10
|
Requires-Dist: torch
|
|
11
|
-
Requires-Dist: safetensors
|
|
12
|
-
Requires-Dist: diffusers
|
|
13
|
-
Requires-Dist: transformers
|
|
14
11
|
Requires-Dist: einops
|
|
15
12
|
Requires-Dist: toml
|
|
@@ -3,6 +3,7 @@ from collections import OrderedDict
|
|
|
3
3
|
import torch
|
|
4
4
|
import torch.nn as nn
|
|
5
5
|
import torch.nn.functional as F
|
|
6
|
+
import torch.nn.utils.parametrize as parametrize
|
|
6
7
|
|
|
7
8
|
from ..utils.bnb import QuantLinears, log_bypass
|
|
8
9
|
|
|
@@ -181,6 +182,38 @@ class LycorisBaseModule(ModuleCustomSD):
|
|
|
181
182
|
self.org_forward = org_module.forward
|
|
182
183
|
self.org_module = [org_module]
|
|
183
184
|
|
|
185
|
+
@classmethod
|
|
186
|
+
def parametrize(cls, org_module, attr, *args, **kwargs):
|
|
187
|
+
target_param = getattr(org_module, attr)
|
|
188
|
+
kwargs["bypass_mode"] = False
|
|
189
|
+
if target_param.dim() == 2:
|
|
190
|
+
proxy_module = nn.Linear(
|
|
191
|
+
target_param.shape[0], target_param.shape[1], bias=False
|
|
192
|
+
)
|
|
193
|
+
proxy_module.weight = target_param
|
|
194
|
+
elif target_param.dim() > 2:
|
|
195
|
+
module_type = [
|
|
196
|
+
None,
|
|
197
|
+
None,
|
|
198
|
+
None,
|
|
199
|
+
nn.Conv1d,
|
|
200
|
+
nn.Conv2d,
|
|
201
|
+
nn.Conv3d,
|
|
202
|
+
None,
|
|
203
|
+
None,
|
|
204
|
+
][target_param.dim()]
|
|
205
|
+
proxy_module = module_type(
|
|
206
|
+
target_param.shape[0],
|
|
207
|
+
target_param.shape[1],
|
|
208
|
+
*target_param.shape[2:],
|
|
209
|
+
)
|
|
210
|
+
proxy_module.weight = target_param
|
|
211
|
+
module_obj = cls("", proxy_module, *args, **kwargs)
|
|
212
|
+
module_obj.forward = module_obj.parametrize_forward
|
|
213
|
+
module_obj.to(target_param.device)
|
|
214
|
+
parametrize.register_parametrization(org_module, attr, module_obj)
|
|
215
|
+
return module_obj
|
|
216
|
+
|
|
184
217
|
@property
|
|
185
218
|
def dtype(self):
|
|
186
219
|
return self.dtype_tensor.dtype
|
|
@@ -231,5 +264,10 @@ class LycorisBaseModule(ModuleCustomSD):
|
|
|
231
264
|
def bypass_forward(self, x, scale=1):
|
|
232
265
|
raise NotImplementedError
|
|
233
266
|
|
|
267
|
+
def parametrize_forward(self, x: torch.Tensor, *args, **kwargs):
|
|
268
|
+
return self.get_merged_weight(
|
|
269
|
+
multiplier=self.multiplier, shape=x.shape, device=x.device
|
|
270
|
+
)[0].to(x.dtype)
|
|
271
|
+
|
|
234
272
|
def forward(self, *args, **kwargs):
|
|
235
273
|
raise NotImplementedError
|
|
@@ -136,7 +136,7 @@ class ButterflyOFTModule(LycorisBaseModule):
|
|
|
136
136
|
diff = self.make_weight(scale=multiplier, device=device, diff=True)
|
|
137
137
|
if shape is not None:
|
|
138
138
|
diff = diff.view(shape)
|
|
139
|
-
return diff
|
|
139
|
+
return diff, None
|
|
140
140
|
|
|
141
141
|
def get_merged_weight(self, multiplier=1, shape=None, device=None):
|
|
142
142
|
diff = self.make_weight(scale=multiplier, device=device)
|
|
@@ -200,33 +200,43 @@ class ButterflyOFTModule(LycorisBaseModule):
|
|
|
200
200
|
|
|
201
201
|
|
|
202
202
|
if __name__ == "__main__":
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
"test", base_4bit, 1, 4, 1, weight_decompose=False
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
203
|
+
device = torch.device("cuda")
|
|
204
|
+
module = ButterflyOFTModule
|
|
205
|
+
with torch.autocast("cuda" if torch.cuda.is_available() else "cpu"):
|
|
206
|
+
base = nn.Linear(128, 128).to(device).half()
|
|
207
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True).to(device)
|
|
208
|
+
print(net)
|
|
209
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
210
|
+
test_output = net(test_input)
|
|
211
|
+
torch.sum(test_output).backward()
|
|
212
|
+
print(test_output.shape)
|
|
213
|
+
|
|
214
|
+
base_4bit = LinearNF4(128, 128, device="cuda")
|
|
215
|
+
base_4bit.load_state_dict(base.state_dict())
|
|
216
|
+
base_4bit.to(device)
|
|
217
|
+
qnet = module("test", base_4bit, 1, 4, 1, weight_decompose=False).to(device)
|
|
218
|
+
print(qnet)
|
|
219
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
220
|
+
test_output = qnet(test_input)
|
|
221
|
+
torch.sum(test_output).backward()
|
|
222
|
+
print(test_output.shape)
|
|
223
|
+
|
|
224
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
225
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True).to(
|
|
226
|
+
device
|
|
227
|
+
)
|
|
228
|
+
print(net)
|
|
229
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
230
|
+
test_output = net(test_input)
|
|
231
|
+
torch.sum(test_output).backward()
|
|
232
|
+
print(test_output.shape)
|
|
233
|
+
|
|
234
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
235
|
+
net = module.parametrize(
|
|
236
|
+
base, "weight", 1, 4, 1, weight_decompose=True, use_tucker=True
|
|
237
|
+
).to(device)
|
|
238
|
+
print(base)
|
|
239
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
240
|
+
test_output = base(test_input)
|
|
241
|
+
torch.sum(test_output).backward()
|
|
242
|
+
print(test_output.shape)
|
|
@@ -119,7 +119,7 @@ class DiagOFTModule(LycorisBaseModule):
|
|
|
119
119
|
diff = self.make_weight(scale=multiplier, device=device, diff=True)
|
|
120
120
|
if shape is not None:
|
|
121
121
|
diff = diff.view(shape)
|
|
122
|
-
return diff
|
|
122
|
+
return diff, None
|
|
123
123
|
|
|
124
124
|
def get_merged_weight(self, multiplier=1, shape=None, device=None):
|
|
125
125
|
diff = self.make_weight(scale=multiplier, device=device)
|
|
@@ -185,27 +185,43 @@ class DiagOFTModule(LycorisBaseModule):
|
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
if __name__ == "__main__":
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
188
|
+
device = torch.device("cuda")
|
|
189
|
+
module = DiagOFTModule
|
|
190
|
+
with torch.autocast("cuda" if torch.cuda.is_available() else "cpu"):
|
|
191
|
+
base = nn.Linear(128, 128).to(device).half()
|
|
192
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True).to(device)
|
|
193
|
+
print(net)
|
|
194
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
195
|
+
test_output = net(test_input)
|
|
196
|
+
torch.sum(test_output).backward()
|
|
197
|
+
print(test_output.shape)
|
|
198
|
+
|
|
199
|
+
base_4bit = LinearNF4(128, 128, device="cuda")
|
|
200
|
+
base_4bit.load_state_dict(base.state_dict())
|
|
201
|
+
base_4bit.to(device)
|
|
202
|
+
qnet = module("test", base_4bit, 1, 4, 1, weight_decompose=False).to(device)
|
|
203
|
+
print(qnet)
|
|
204
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
205
|
+
test_output = qnet(test_input)
|
|
206
|
+
torch.sum(test_output).backward()
|
|
207
|
+
print(test_output.shape)
|
|
208
|
+
|
|
209
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
210
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True).to(
|
|
211
|
+
device
|
|
212
|
+
)
|
|
213
|
+
print(net)
|
|
214
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
215
|
+
test_output = net(test_input)
|
|
216
|
+
torch.sum(test_output).backward()
|
|
217
|
+
print(test_output.shape)
|
|
218
|
+
|
|
219
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
220
|
+
net = module.parametrize(
|
|
221
|
+
base, "weight", 1, 4, 1, weight_decompose=True, use_tucker=True
|
|
222
|
+
).to(device)
|
|
223
|
+
print(base)
|
|
224
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
225
|
+
test_output = base(test_input)
|
|
226
|
+
torch.sum(test_output).backward()
|
|
227
|
+
print(test_output.shape)
|
|
@@ -158,18 +158,33 @@ class FullModule(LycorisBaseModule):
|
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
if __name__ == "__main__":
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
device = torch.device("cuda")
|
|
162
|
+
module = FullModule
|
|
163
|
+
with torch.autocast("cuda" if torch.cuda.is_available() else "cpu"):
|
|
164
|
+
base = nn.Linear(128, 128).to(device).half()
|
|
165
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True).to(device)
|
|
166
|
+
print(net)
|
|
167
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
168
|
+
test_output = net(test_input)
|
|
169
|
+
torch.sum(test_output).backward()
|
|
170
|
+
print(test_output.shape)
|
|
171
|
+
|
|
172
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
173
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True).to(
|
|
174
|
+
device
|
|
175
|
+
)
|
|
176
|
+
print(net)
|
|
177
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
178
|
+
test_output = net(test_input)
|
|
179
|
+
torch.sum(test_output).backward()
|
|
180
|
+
print(test_output.shape)
|
|
181
|
+
|
|
182
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
183
|
+
net = module.parametrize(
|
|
184
|
+
base, "weight", 1, 4, 1, weight_decompose=True, use_tucker=True
|
|
185
|
+
).to(device)
|
|
186
|
+
print(base)
|
|
187
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
188
|
+
test_output = base(test_input)
|
|
189
|
+
torch.sum(test_output).backward()
|
|
190
|
+
print(test_output.shape)
|
|
@@ -169,28 +169,43 @@ class GLoRAModule(LycorisBaseModule):
|
|
|
169
169
|
|
|
170
170
|
|
|
171
171
|
if __name__ == "__main__":
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
172
|
+
device = torch.device("cuda")
|
|
173
|
+
module = GLoRAModule
|
|
174
|
+
with torch.autocast("cuda" if torch.cuda.is_available() else "cpu"):
|
|
175
|
+
base = nn.Linear(128, 128).to(device).half()
|
|
176
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True).to(device)
|
|
177
|
+
print(net)
|
|
178
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
179
|
+
test_output = net(test_input)
|
|
180
|
+
torch.sum(test_output).backward()
|
|
181
|
+
print(test_output.shape)
|
|
182
|
+
|
|
183
|
+
base_4bit = LinearNF4(128, 128, device="cuda")
|
|
184
|
+
base_4bit.load_state_dict(base.state_dict())
|
|
185
|
+
base_4bit.to(device)
|
|
186
|
+
qnet = module("test", base_4bit, 1, 4, 1, weight_decompose=False).to(device)
|
|
187
|
+
print(qnet)
|
|
188
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
189
|
+
test_output = qnet(test_input)
|
|
190
|
+
torch.sum(test_output).backward()
|
|
191
|
+
print(test_output.shape)
|
|
192
|
+
|
|
193
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
194
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True).to(
|
|
195
|
+
device
|
|
196
|
+
)
|
|
197
|
+
print(net)
|
|
198
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
199
|
+
test_output = net(test_input)
|
|
200
|
+
torch.sum(test_output).backward()
|
|
201
|
+
print(test_output.shape)
|
|
202
|
+
|
|
203
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
204
|
+
net = module.parametrize(
|
|
205
|
+
base, "weight", 1, 4, 1, weight_decompose=True, use_tucker=True
|
|
206
|
+
).to(device)
|
|
207
|
+
print(base)
|
|
208
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
209
|
+
test_output = base(test_input)
|
|
210
|
+
torch.sum(test_output).backward()
|
|
211
|
+
print(test_output.shape)
|
|
@@ -183,11 +183,12 @@ class LoConModule(LycorisBaseModule):
|
|
|
183
183
|
diff = diff.view(shape)
|
|
184
184
|
if device is not None:
|
|
185
185
|
diff = diff.to(device)
|
|
186
|
-
return diff
|
|
186
|
+
return diff, None
|
|
187
187
|
|
|
188
188
|
def get_merged_weight(self, multiplier=1, shape=None, device=None):
|
|
189
|
-
merged =
|
|
190
|
-
|
|
189
|
+
merged = (
|
|
190
|
+
self.org_module[0].weight.data
|
|
191
|
+
+ self.get_diff_weight(multiplier=multiplier, shape=shape, device=device)[0]
|
|
191
192
|
)
|
|
192
193
|
if self.wd:
|
|
193
194
|
merged = self.apply_weight_decompose(merged)
|
|
@@ -277,28 +278,43 @@ class LoConModule(LycorisBaseModule):
|
|
|
277
278
|
|
|
278
279
|
|
|
279
280
|
if __name__ == "__main__":
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
281
|
+
device = torch.device("cuda")
|
|
282
|
+
module = LoConModule
|
|
283
|
+
with torch.autocast("cuda" if torch.cuda.is_available() else "cpu"):
|
|
284
|
+
base = nn.Linear(128, 128).to(device).half()
|
|
285
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True).to(device)
|
|
286
|
+
print(net)
|
|
287
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
288
|
+
test_output = net(test_input)
|
|
289
|
+
torch.sum(test_output).backward()
|
|
290
|
+
print(test_output.shape)
|
|
291
|
+
|
|
292
|
+
base_4bit = LinearNF4(128, 128, device="cuda")
|
|
293
|
+
base_4bit.load_state_dict(base.state_dict())
|
|
294
|
+
base_4bit.to(device)
|
|
295
|
+
qnet = module("test", base_4bit, 1, 4, 1, weight_decompose=False).to(device)
|
|
296
|
+
print(qnet)
|
|
297
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
298
|
+
test_output = qnet(test_input)
|
|
299
|
+
torch.sum(test_output).backward()
|
|
300
|
+
print(test_output.shape)
|
|
301
|
+
|
|
302
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
303
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True).to(
|
|
304
|
+
device
|
|
305
|
+
)
|
|
306
|
+
print(net)
|
|
307
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
308
|
+
test_output = net(test_input)
|
|
309
|
+
torch.sum(test_output).backward()
|
|
310
|
+
print(test_output.shape)
|
|
311
|
+
|
|
312
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
313
|
+
net = module.parametrize(
|
|
314
|
+
base, "weight", 1, 4, 1, weight_decompose=True, use_tucker=True
|
|
315
|
+
)
|
|
316
|
+
print(base)
|
|
317
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
318
|
+
test_output = base(test_input)
|
|
319
|
+
torch.sum(test_output).backward()
|
|
320
|
+
print(test_output.shape)
|
|
@@ -181,15 +181,16 @@ class LohaModule(LycorisBaseModule):
|
|
|
181
181
|
diff = self.get_weight(shape) * scale
|
|
182
182
|
if device is not None:
|
|
183
183
|
diff = diff.to(device)
|
|
184
|
-
return diff
|
|
184
|
+
return diff, None
|
|
185
185
|
|
|
186
186
|
def get_merged_weight(self, multiplier=1, shape=None, device=None):
|
|
187
|
-
merged =
|
|
188
|
-
|
|
187
|
+
merged = (
|
|
188
|
+
self.org_module[0].weight.data
|
|
189
|
+
+ self.get_diff_weight(multiplier=multiplier, shape=shape, device=device)[0]
|
|
189
190
|
)
|
|
190
191
|
if self.wd:
|
|
191
192
|
merged = self.apply_weight_decompose(merged)
|
|
192
|
-
return merged
|
|
193
|
+
return merged, None
|
|
193
194
|
|
|
194
195
|
def apply_weight_decompose(self, weight):
|
|
195
196
|
weight = weight.to(self.dora_scale.dtype)
|
|
@@ -269,28 +270,42 @@ class LohaModule(LycorisBaseModule):
|
|
|
269
270
|
|
|
270
271
|
if __name__ == "__main__":
|
|
271
272
|
device = torch.device("cuda")
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
273
|
+
module = LohaModule
|
|
274
|
+
with torch.autocast("cuda" if torch.cuda.is_available() else "cpu"):
|
|
275
|
+
base = nn.Linear(128, 128).to(device).half()
|
|
276
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True).to(device)
|
|
277
|
+
print(net)
|
|
278
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
279
|
+
test_output = net(test_input)
|
|
280
|
+
torch.sum(test_output).backward()
|
|
281
|
+
print(test_output.shape)
|
|
282
|
+
|
|
283
|
+
base_4bit = LinearNF4(128, 128, device="cuda")
|
|
284
|
+
base_4bit.load_state_dict(base.state_dict())
|
|
285
|
+
base_4bit.to(device)
|
|
286
|
+
qnet = module("test", base_4bit, 1, 4, 1, weight_decompose=False).to(device)
|
|
287
|
+
print(qnet)
|
|
288
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
289
|
+
test_output = qnet(test_input)
|
|
290
|
+
torch.sum(test_output).backward()
|
|
291
|
+
print(test_output.shape)
|
|
292
|
+
|
|
293
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
294
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True).to(
|
|
295
|
+
device
|
|
296
|
+
)
|
|
297
|
+
print(net)
|
|
298
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
299
|
+
test_output = net(test_input)
|
|
300
|
+
torch.sum(test_output).backward()
|
|
301
|
+
print(test_output.shape)
|
|
302
|
+
|
|
303
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
304
|
+
net = module.parametrize(
|
|
305
|
+
base, "weight", 1, 4, 1, weight_decompose=True, use_tucker=True
|
|
306
|
+
)
|
|
307
|
+
print(base)
|
|
308
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
309
|
+
test_output = base(test_input)
|
|
310
|
+
torch.sum(test_output).backward()
|
|
311
|
+
print(test_output.shape)
|
|
@@ -262,15 +262,21 @@ class LokrModule(LycorisBaseModule):
|
|
|
262
262
|
weight *= drop
|
|
263
263
|
return weight
|
|
264
264
|
|
|
265
|
-
def
|
|
265
|
+
def get_diff_weight(self, multiplier=1, shape=None, device=None):
|
|
266
266
|
scale = self.scale * multiplier
|
|
267
267
|
diff = self.get_weight(shape) * scale
|
|
268
268
|
if device is not None:
|
|
269
269
|
diff = diff.to(device)
|
|
270
|
-
|
|
270
|
+
return diff, None
|
|
271
|
+
|
|
272
|
+
def get_merged_weight(self, multiplier=1, shape=None, device=None):
|
|
273
|
+
merged = (
|
|
274
|
+
self.org_module[0].weight.data
|
|
275
|
+
+ self.get_diff_weight(multiplier=multiplier, shape=shape, device=device)[0]
|
|
276
|
+
)
|
|
271
277
|
if self.wd:
|
|
272
278
|
merged = self.apply_weight_decompose(merged)
|
|
273
|
-
return merged
|
|
279
|
+
return merged, None
|
|
274
280
|
|
|
275
281
|
def apply_weight_decompose(self, weight):
|
|
276
282
|
weight = weight.to(self.dora_scale.dtype)
|
|
@@ -394,27 +400,43 @@ class LokrModule(LycorisBaseModule):
|
|
|
394
400
|
|
|
395
401
|
|
|
396
402
|
if __name__ == "__main__":
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
403
|
+
device = torch.device("cuda")
|
|
404
|
+
module = LokrModule
|
|
405
|
+
with torch.autocast("cuda" if torch.cuda.is_available() else "cpu"):
|
|
406
|
+
base = nn.Linear(128, 128).to(device).half()
|
|
407
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True).to(device)
|
|
408
|
+
print(net)
|
|
409
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
410
|
+
test_output = net(test_input)
|
|
411
|
+
torch.sum(test_output).backward()
|
|
412
|
+
print(test_output.shape)
|
|
413
|
+
|
|
414
|
+
base_4bit = LinearNF4(128, 128, device="cuda")
|
|
415
|
+
base_4bit.load_state_dict(base.state_dict())
|
|
416
|
+
base_4bit.to(device)
|
|
417
|
+
qnet = module("test", base_4bit, 1, 4, 1, weight_decompose=False).to(device)
|
|
418
|
+
print(qnet)
|
|
419
|
+
test_input = torch.randn(1, 128).to(device).half()
|
|
420
|
+
test_output = qnet(test_input)
|
|
421
|
+
torch.sum(test_output).backward()
|
|
422
|
+
print(test_output.shape)
|
|
423
|
+
|
|
424
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
425
|
+
net = module("test", base, 1, 4, 1, weight_decompose=True, use_tucker=True).to(
|
|
426
|
+
device
|
|
427
|
+
)
|
|
428
|
+
print(net)
|
|
429
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
430
|
+
test_output = net(test_input)
|
|
431
|
+
torch.sum(test_output).backward()
|
|
432
|
+
print(test_output.shape)
|
|
433
|
+
|
|
434
|
+
base = nn.Conv2d(128, 128, 3, 1, 1).to(device).half()
|
|
435
|
+
net = module.parametrize(
|
|
436
|
+
base, "weight", 1, 4, 1, weight_decompose=True, use_tucker=True
|
|
437
|
+
)
|
|
438
|
+
print(base)
|
|
439
|
+
test_input = torch.randn(1, 128, 16, 16).to(device).half()
|
|
440
|
+
test_output = base(test_input)
|
|
441
|
+
torch.sum(test_output).backward()
|
|
442
|
+
print(test_output.shape)
|
|
@@ -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.dev3
|
|
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
|
|
@@ -8,8 +8,5 @@ Author-email: apolloyeh0123@gmail.com
|
|
|
8
8
|
Requires-Python: >=3.10
|
|
9
9
|
License-File: LICENSE.md
|
|
10
10
|
Requires-Dist: torch
|
|
11
|
-
Requires-Dist: safetensors
|
|
12
|
-
Requires-Dist: diffusers
|
|
13
|
-
Requires-Dist: transformers
|
|
14
11
|
Requires-Dist: einops
|
|
15
12
|
Requires-Dist: toml
|
|
@@ -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.dev3",
|
|
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",
|
|
@@ -12,9 +12,6 @@ setup(
|
|
|
12
12
|
zip_safe=False,
|
|
13
13
|
install_requires=[
|
|
14
14
|
"torch",
|
|
15
|
-
"safetensors",
|
|
16
|
-
"diffusers",
|
|
17
|
-
"transformers",
|
|
18
15
|
"einops",
|
|
19
16
|
"toml",
|
|
20
17
|
],
|
|
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.dev1 → lycoris_lora-3.0.0.dev3}/lycoris_lora.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|