lycoris-lora 3.2.0.dev1__tar.gz → 3.2.0.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.
- {lycoris_lora-3.2.0.dev1/lycoris_lora.egg-info → lycoris_lora-3.2.0.dev2}/PKG-INFO +9 -2
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/config.py +14 -14
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/kohya.py +50 -17
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/base.py +32 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/wrapper.py +8 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2/lycoris_lora.egg-info}/PKG-INFO +9 -2
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris_lora.egg-info/SOURCES.txt +2 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/setup.py +1 -1
- lycoris_lora-3.2.0.dev2/test/compile.py +69 -0
- lycoris_lora-3.2.0.dev2/test/restore.py +56 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/LICENSE.md +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/README.md +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/__init__.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/functional/__init__.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/functional/boft.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/functional/diag_oft.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/functional/general.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/functional/locon.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/functional/loha.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/functional/lokr.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/logging.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/__init__.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/boft.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/diag_oft.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/dylora.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/full.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/glora.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/ia3.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/locon.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/loha.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/lokr.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/modules/norms.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/utils/__init__.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/utils/general.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/utils/logger.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/utils/preset.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/utils/quant.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris/utils/xformers_utils.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris_lora.egg-info/dependency_links.txt +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris_lora.egg-info/not-zip-safe +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris_lora.egg-info/requires.txt +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris_lora.egg-info/top_level.txt +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/setup.cfg +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/test/__init__.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/test/functional.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/test/kohya.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/test/module.py +0 -0
- {lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/test/wrapper.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: lycoris_lora
|
|
3
|
-
Version: 3.2.0.
|
|
3
|
+
Version: 3.2.0.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
|
|
@@ -23,3 +23,10 @@ Requires-Dist: torch
|
|
|
23
23
|
Requires-Dist: einops
|
|
24
24
|
Requires-Dist: toml
|
|
25
25
|
Requires-Dist: tqdm
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: home-page
|
|
30
|
+
Dynamic: requires-dist
|
|
31
|
+
Dynamic: requires-python
|
|
32
|
+
Dynamic: summary
|
|
@@ -6,12 +6,12 @@ PRESET = {
|
|
|
6
6
|
"ResnetBlock2D",
|
|
7
7
|
"Downsample2D",
|
|
8
8
|
"Upsample2D",
|
|
9
|
-
"HunYuanDiTBlock",
|
|
10
|
-
"DoubleStreamBlock",
|
|
11
|
-
"SingleStreamBlock",
|
|
12
|
-
"SingleDiTBlock",
|
|
13
|
-
"MMDoubleStreamBlock",
|
|
14
|
-
"MMSingleStreamBlock",
|
|
9
|
+
"HunYuanDiTBlock", # HunYuanDiT
|
|
10
|
+
"DoubleStreamBlock", # Flux
|
|
11
|
+
"SingleStreamBlock", # Flux
|
|
12
|
+
"SingleDiTBlock", # SD3.5
|
|
13
|
+
"MMDoubleStreamBlock", # HunYuanVideo
|
|
14
|
+
"MMSingleStreamBlock", # HunYuanVideo
|
|
15
15
|
],
|
|
16
16
|
"unet_target_name": [
|
|
17
17
|
"conv_in",
|
|
@@ -37,8 +37,8 @@ PRESET = {
|
|
|
37
37
|
"DoubleStreamBlock",
|
|
38
38
|
"SingleStreamBlock",
|
|
39
39
|
"SingleDiTBlock",
|
|
40
|
-
"MMDoubleStreamBlock",
|
|
41
|
-
"MMSingleStreamBlock",
|
|
40
|
+
"MMDoubleStreamBlock", # HunYuanVideo
|
|
41
|
+
"MMSingleStreamBlock", # HunYuanVideo
|
|
42
42
|
],
|
|
43
43
|
"unet_target_name": [
|
|
44
44
|
"time_embedding.linear_1",
|
|
@@ -61,8 +61,8 @@ PRESET = {
|
|
|
61
61
|
"DoubleStreamBlock",
|
|
62
62
|
"SingleStreamBlock",
|
|
63
63
|
"SingleDiTBlock",
|
|
64
|
-
"MMDoubleStreamBlock",
|
|
65
|
-
"MMSingleStreamBlock",
|
|
64
|
+
"MMDoubleStreamBlock", # HunYuanVideo
|
|
65
|
+
"MMSingleStreamBlock", # HunYuanVideo
|
|
66
66
|
],
|
|
67
67
|
"unet_target_name": [],
|
|
68
68
|
"text_encoder_target_module": [
|
|
@@ -100,8 +100,8 @@ PRESET = {
|
|
|
100
100
|
"DoubleStreamBlock",
|
|
101
101
|
"SingleStreamBlock",
|
|
102
102
|
"SingleDiTBlock",
|
|
103
|
-
"MMDoubleStreamBlock",
|
|
104
|
-
"MMSingleStreamBlock",
|
|
103
|
+
"MMDoubleStreamBlock", # HunYuanVideo
|
|
104
|
+
"MMSingleStreamBlock", # HunYuanVideo
|
|
105
105
|
],
|
|
106
106
|
"unet_target_name": [
|
|
107
107
|
"conv_in",
|
|
@@ -120,8 +120,8 @@ PRESET = {
|
|
|
120
120
|
"DoubleStreamBlock",
|
|
121
121
|
"SingleStreamBlock",
|
|
122
122
|
"SingleDiTBlock",
|
|
123
|
-
"MMDoubleStreamBlock",
|
|
124
|
-
"MMSingleStreamBlock",
|
|
123
|
+
"MMDoubleStreamBlock", # HunYuanVideo
|
|
124
|
+
"MMSingleStreamBlock", # HunYuanVideo
|
|
125
125
|
],
|
|
126
126
|
"unet_target_name": [],
|
|
127
127
|
"text_encoder_target_module": [],
|
|
@@ -63,10 +63,22 @@ def create_network(
|
|
|
63
63
|
rs_lora = str_bool(kwargs.get("rs_lora", False))
|
|
64
64
|
unbalanced_factorization = str_bool(kwargs.get("unbalanced_factorization", False))
|
|
65
65
|
train_t5xxl = str_bool(kwargs.get("train_t5xxl", False))
|
|
66
|
-
#lora_plus
|
|
67
|
-
loraplus_lr_ratio =
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
# lora_plus
|
|
67
|
+
loraplus_lr_ratio = (
|
|
68
|
+
float(kwargs.get("loraplus_lr_ratio", None))
|
|
69
|
+
if kwargs.get("loraplus_lr_ratio", None) is not None
|
|
70
|
+
else None
|
|
71
|
+
)
|
|
72
|
+
loraplus_unet_lr_ratio = (
|
|
73
|
+
float(kwargs.get("loraplus_unet_lr_ratio", None))
|
|
74
|
+
if kwargs.get("loraplus_unet_lr_ratio", None) is not None
|
|
75
|
+
else None
|
|
76
|
+
)
|
|
77
|
+
loraplus_text_encoder_lr_ratio = (
|
|
78
|
+
float(kwargs.get("loraplus_text_encoder_lr_ratio", None))
|
|
79
|
+
if kwargs.get("loraplus_text_encoder_lr_ratio", None) is not None
|
|
80
|
+
else None
|
|
81
|
+
)
|
|
70
82
|
|
|
71
83
|
if unbalanced_factorization:
|
|
72
84
|
logger.info("Unbalanced factorization for LoKr is enabled")
|
|
@@ -121,8 +133,14 @@ def create_network(
|
|
|
121
133
|
unbalanced_factorization=unbalanced_factorization,
|
|
122
134
|
train_t5xxl=train_t5xxl,
|
|
123
135
|
)
|
|
124
|
-
if
|
|
125
|
-
|
|
136
|
+
if (
|
|
137
|
+
loraplus_lr_ratio is not None
|
|
138
|
+
or loraplus_unet_lr_ratio is not None
|
|
139
|
+
or loraplus_text_encoder_lr_ratio is not None
|
|
140
|
+
):
|
|
141
|
+
network.set_loraplus_lr_ratio(
|
|
142
|
+
loraplus_lr_ratio, loraplus_unet_lr_ratio, loraplus_text_encoder_lr_ratio
|
|
143
|
+
)
|
|
126
144
|
|
|
127
145
|
return network
|
|
128
146
|
|
|
@@ -232,8 +250,8 @@ class LycorisNetworkKohya(LycorisNetwork):
|
|
|
232
250
|
"DoubleStreamBlock",
|
|
233
251
|
"SingleStreamBlock",
|
|
234
252
|
"SingleDiTBlock",
|
|
235
|
-
"MMDoubleStreamBlock",
|
|
236
|
-
"MMSingleStreamBlock",
|
|
253
|
+
"MMDoubleStreamBlock", # HunYuanVideo
|
|
254
|
+
"MMSingleStreamBlock", # HunYuanVideo
|
|
237
255
|
]
|
|
238
256
|
UNET_TARGET_REPLACE_NAME = [
|
|
239
257
|
"conv_in",
|
|
@@ -301,7 +319,7 @@ class LycorisNetworkKohya(LycorisNetwork):
|
|
|
301
319
|
self.multiplier = multiplier
|
|
302
320
|
self.lora_dim = lora_dim
|
|
303
321
|
self.train_t5xxl = train_t5xxl
|
|
304
|
-
|
|
322
|
+
|
|
305
323
|
# 初始化LoRA+相关属性
|
|
306
324
|
self.loraplus_lr_ratio = None
|
|
307
325
|
self.loraplus_unet_lr_ratio = None
|
|
@@ -621,15 +639,23 @@ class LycorisNetworkKohya(LycorisNetwork):
|
|
|
621
639
|
|
|
622
640
|
return key_scaled, sum(norms) / len(norms), max(norms)
|
|
623
641
|
|
|
624
|
-
def set_loraplus_lr_ratio(
|
|
642
|
+
def set_loraplus_lr_ratio(
|
|
643
|
+
self, loraplus_lr_ratio, loraplus_unet_lr_ratio, loraplus_text_encoder_lr_ratio
|
|
644
|
+
):
|
|
625
645
|
self.loraplus_lr_ratio = loraplus_lr_ratio
|
|
626
646
|
self.loraplus_unet_lr_ratio = loraplus_unet_lr_ratio
|
|
627
647
|
self.loraplus_text_encoder_lr_ratio = loraplus_text_encoder_lr_ratio
|
|
628
648
|
|
|
629
|
-
logger.info(
|
|
630
|
-
|
|
649
|
+
logger.info(
|
|
650
|
+
f"LoRA+ UNet LR Ratio: {self.loraplus_unet_lr_ratio or self.loraplus_lr_ratio}"
|
|
651
|
+
)
|
|
652
|
+
logger.info(
|
|
653
|
+
f"LoRA+ Text Encoder LR Ratio: {self.loraplus_text_encoder_lr_ratio or self.loraplus_lr_ratio}"
|
|
654
|
+
)
|
|
631
655
|
|
|
632
|
-
def prepare_optimizer_params(
|
|
656
|
+
def prepare_optimizer_params(
|
|
657
|
+
self, text_encoder_lr=None, unet_lr: float = 1e-4, learning_rate=None
|
|
658
|
+
):
|
|
633
659
|
self.requires_grad_(True)
|
|
634
660
|
|
|
635
661
|
all_params = []
|
|
@@ -658,7 +684,10 @@ class LycorisNetworkKohya(LycorisNetwork):
|
|
|
658
684
|
else:
|
|
659
685
|
param_data["lr"] = lr
|
|
660
686
|
|
|
661
|
-
if
|
|
687
|
+
if (
|
|
688
|
+
param_data.get("lr", None) == 0
|
|
689
|
+
or param_data.get("lr", None) is None
|
|
690
|
+
):
|
|
662
691
|
logger.info("NO LR skipping!")
|
|
663
692
|
continue
|
|
664
693
|
|
|
@@ -674,7 +703,9 @@ class LycorisNetworkKohya(LycorisNetwork):
|
|
|
674
703
|
self.loraplus_text_encoder_lr_ratio or self.loraplus_lr_ratio,
|
|
675
704
|
)
|
|
676
705
|
all_params.extend(params)
|
|
677
|
-
lr_descriptions.extend(
|
|
706
|
+
lr_descriptions.extend(
|
|
707
|
+
["textencoder" + (" " + d if d else "") for d in descriptions]
|
|
708
|
+
)
|
|
678
709
|
|
|
679
710
|
if self.unet_loras:
|
|
680
711
|
params, descriptions = assemble_params(
|
|
@@ -683,7 +714,9 @@ class LycorisNetworkKohya(LycorisNetwork):
|
|
|
683
714
|
self.loraplus_unet_lr_ratio or self.loraplus_lr_ratio,
|
|
684
715
|
)
|
|
685
716
|
all_params.extend(params)
|
|
686
|
-
lr_descriptions.extend(
|
|
717
|
+
lr_descriptions.extend(
|
|
718
|
+
["unet" + (" " + d if d else "") for d in descriptions]
|
|
719
|
+
)
|
|
687
720
|
|
|
688
721
|
return all_params, lr_descriptions
|
|
689
722
|
|
|
@@ -691,7 +724,7 @@ class LycorisNetworkKohya(LycorisNetwork):
|
|
|
691
724
|
# not supported
|
|
692
725
|
pass
|
|
693
726
|
|
|
694
|
-
def prepare_grad_etc(self,
|
|
727
|
+
def prepare_grad_etc(self, *args):
|
|
695
728
|
self.requires_grad_(True)
|
|
696
729
|
|
|
697
730
|
def on_epoch_start(self, unet):
|
|
@@ -290,6 +290,38 @@ class LycorisBaseModule(ModuleCustomSD):
|
|
|
290
290
|
self.org_module[0].bias = nn.Parameter(bias)
|
|
291
291
|
self.to(self_device, self_dtype)
|
|
292
292
|
|
|
293
|
+
def onfly_merge(self, multiplier=1.0):
|
|
294
|
+
if self.not_supported:
|
|
295
|
+
return
|
|
296
|
+
self_device = next(self.parameters()).device
|
|
297
|
+
self_dtype = next(self.parameters()).dtype
|
|
298
|
+
self.to(self.org_weight)
|
|
299
|
+
self.cached_org_weight = self.org_weight.data.cpu()
|
|
300
|
+
self.cached_org_bias = None
|
|
301
|
+
weight, bias = self.get_merged_weight(
|
|
302
|
+
multiplier, self.org_weight.shape, self.org_weight.device
|
|
303
|
+
)
|
|
304
|
+
self.org_weight = weight
|
|
305
|
+
if bias is not None:
|
|
306
|
+
bias = bias.to(self.org_weight)
|
|
307
|
+
if self.org_module[0].bias is not None:
|
|
308
|
+
self.org_module[0].bias.data.copy_(bias)
|
|
309
|
+
self.cached_org_bias = self.org_module[0].bias.data.cpu()
|
|
310
|
+
else:
|
|
311
|
+
self.org_module[0].bias = nn.Parameter(bias)
|
|
312
|
+
if self.org_module[0].bias is not None:
|
|
313
|
+
self.org_module[0].bias = self.org_module[0].bias.to(self.org_weight)
|
|
314
|
+
self.to(self_device, self_dtype)
|
|
315
|
+
|
|
316
|
+
def onfly_restore(self):
|
|
317
|
+
if self.not_supported:
|
|
318
|
+
return
|
|
319
|
+
self.org_weight = self.cached_org_weight.to(self.org_weight)
|
|
320
|
+
if self.cached_org_bias is not None:
|
|
321
|
+
self.org_module[0].bias.data.copy_(self.cached_org_bias.to(self.org_weight))
|
|
322
|
+
del self.cached_org_weight
|
|
323
|
+
del self.cached_org_bias
|
|
324
|
+
|
|
293
325
|
def get_diff_weight(self, multiplier=1.0, shape=None, device=None):
|
|
294
326
|
raise NotImplementedError
|
|
295
327
|
|
|
@@ -568,6 +568,14 @@ class LycorisNetwork(torch.nn.Module):
|
|
|
568
568
|
for lora in self.loras:
|
|
569
569
|
lora.merge_to(weight)
|
|
570
570
|
|
|
571
|
+
def onfly_merge(self, weight=1.0):
|
|
572
|
+
for lora in self.loras:
|
|
573
|
+
lora.onfly_merge(weight)
|
|
574
|
+
|
|
575
|
+
def onfly_restore(self):
|
|
576
|
+
for lora in self.loras:
|
|
577
|
+
lora.onfly_restore()
|
|
578
|
+
|
|
571
579
|
def apply_max_norm_regularization(self, max_norm_value, device):
|
|
572
580
|
key_scaled = 0
|
|
573
581
|
norms = []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: lycoris_lora
|
|
3
|
-
Version: 3.2.0.
|
|
3
|
+
Version: 3.2.0.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
|
|
@@ -23,3 +23,10 @@ Requires-Dist: torch
|
|
|
23
23
|
Requires-Dist: einops
|
|
24
24
|
Requires-Dist: toml
|
|
25
25
|
Requires-Dist: tqdm
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: home-page
|
|
30
|
+
Dynamic: requires-dist
|
|
31
|
+
Dynamic: requires-python
|
|
32
|
+
Dynamic: summary
|
|
@@ -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.2.0.
|
|
7
|
+
version="3.2.0.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",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
sys.setrecursionlimit(10000000)
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
import torch.nn as nn
|
|
7
|
+
import torch.nn.functional as F
|
|
8
|
+
|
|
9
|
+
from torchao.quantization.quant_api import int8_weight_only, quantize_
|
|
10
|
+
|
|
11
|
+
from lycoris import create_lycoris
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestNet(nn.Module):
|
|
15
|
+
def __init__(self):
|
|
16
|
+
super(TestNet, self).__init__()
|
|
17
|
+
self.fc1 = nn.Linear(8, 1024)
|
|
18
|
+
self.fc2 = nn.Linear(1024, 8)
|
|
19
|
+
|
|
20
|
+
def forward(self, x):
|
|
21
|
+
x = self.fc1(x)
|
|
22
|
+
x = F.relu(x)
|
|
23
|
+
x = self.fc2(x)
|
|
24
|
+
return x
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_lycoris_compile():
|
|
28
|
+
net = TestNet().cuda()
|
|
29
|
+
|
|
30
|
+
test_x = torch.randn(1, 8).cuda()
|
|
31
|
+
out = net(test_x)
|
|
32
|
+
print("\nOriginal\n", out)
|
|
33
|
+
|
|
34
|
+
quantize_(net, int8_weight_only())
|
|
35
|
+
out = net(test_x)
|
|
36
|
+
print("\nQuantized\n", out)
|
|
37
|
+
compiled_net = torch.compile(net)
|
|
38
|
+
out = compiled_net(test_x)
|
|
39
|
+
print("\nQuantized compiled\n", out)
|
|
40
|
+
|
|
41
|
+
compiled_net._orig_mod.cpu()
|
|
42
|
+
compiled_net._orig_mod.cuda()
|
|
43
|
+
|
|
44
|
+
compiled_net.cpu()
|
|
45
|
+
compiled_net.cuda()
|
|
46
|
+
|
|
47
|
+
lycoris = create_lycoris(
|
|
48
|
+
net, algo="lokr", factor=2, bypass_mode=True, full_matrix=True
|
|
49
|
+
)
|
|
50
|
+
lycoris.apply_to()
|
|
51
|
+
lycoris.cuda()
|
|
52
|
+
out = net(test_x)
|
|
53
|
+
print("\nBypass Lokr Applied\n", out)
|
|
54
|
+
|
|
55
|
+
compiled_net = torch.compile(net)
|
|
56
|
+
compiled_out = compiled_net(test_x)
|
|
57
|
+
print("\nLyCORIS+torchao quantize_ compiled\n", compiled_out)
|
|
58
|
+
torch.sum(compiled_out).backward()
|
|
59
|
+
|
|
60
|
+
diff = torch.sum(torch.abs(out - compiled_out))
|
|
61
|
+
print("\nDiff: ", diff)
|
|
62
|
+
net.cpu()
|
|
63
|
+
lycoris.cpu()
|
|
64
|
+
|
|
65
|
+
assert torch.allclose(out, compiled_out, atol=1e-6)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
test_lycoris_compile()
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
sys.setrecursionlimit(10000000)
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
import torch.nn as nn
|
|
7
|
+
import torch.nn.functional as F
|
|
8
|
+
|
|
9
|
+
from lycoris import create_lycoris
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestNet(nn.Module):
|
|
13
|
+
def __init__(self):
|
|
14
|
+
super(TestNet, self).__init__()
|
|
15
|
+
self.fc1 = nn.Linear(8, 1024)
|
|
16
|
+
self.fc2 = nn.Linear(1024, 8)
|
|
17
|
+
|
|
18
|
+
def forward(self, x):
|
|
19
|
+
x = self.fc1(x)
|
|
20
|
+
x = F.relu(x)
|
|
21
|
+
x = self.fc2(x)
|
|
22
|
+
return x
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_lycoris_restore():
|
|
26
|
+
net = TestNet().cuda()
|
|
27
|
+
compiled_net = torch.compile(net)
|
|
28
|
+
|
|
29
|
+
test_x = torch.randn(1, 8).cuda()
|
|
30
|
+
out = compiled_net(test_x)
|
|
31
|
+
print("\nOriginal\n", out)
|
|
32
|
+
|
|
33
|
+
lycoris = create_lycoris(
|
|
34
|
+
net, algo="lokr", factor=2, bypass_mode=True, full_matrix=True
|
|
35
|
+
)
|
|
36
|
+
lycoris.apply_to()
|
|
37
|
+
lycoris.cuda()
|
|
38
|
+
for parameter in lycoris.parameters():
|
|
39
|
+
parameter.data = torch.randn_like(parameter) * 0.1
|
|
40
|
+
net = torch.compile(net)
|
|
41
|
+
out = net(test_x)
|
|
42
|
+
print("\nBypass Lokr Applied\n", out)
|
|
43
|
+
|
|
44
|
+
lycoris.restore()
|
|
45
|
+
# lycoris.set_multiplier(0.0)
|
|
46
|
+
out = net(test_x)
|
|
47
|
+
print("\nRestored\n", out)
|
|
48
|
+
|
|
49
|
+
lycoris.apply_to()
|
|
50
|
+
# lycoris.set_multiplier(1.0)
|
|
51
|
+
out = net(test_x)
|
|
52
|
+
print("\nBypass Lokr Applied\n", out)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
test_lycoris_restore()
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lycoris_lora-3.2.0.dev1 → lycoris_lora-3.2.0.dev2}/lycoris_lora.egg-info/dependency_links.txt
RENAMED
|
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
|