Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
614b7e73
Commit
614b7e73
authored
Dec 09, 2023
by
comfyanonymous
Browse files
Implement GLora.
parent
cb63e230
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
comfy/lora.py
comfy/lora.py
+11
-0
comfy/model_patcher.py
comfy/model_patcher.py
+10
-0
No files found.
comfy/lora.py
View file @
614b7e73
...
...
@@ -118,6 +118,17 @@ def load_lora(lora, to_load):
if
(
lokr_w1
is
not
None
)
or
(
lokr_w2
is
not
None
)
or
(
lokr_w1_a
is
not
None
)
or
(
lokr_w2_a
is
not
None
):
patch_dict
[
to_load
[
x
]]
=
(
"lokr"
,
(
lokr_w1
,
lokr_w2
,
alpha
,
lokr_w1_a
,
lokr_w1_b
,
lokr_w2_a
,
lokr_w2_b
,
lokr_t2
))
#glora
a1_name
=
"{}.a1.weight"
.
format
(
x
)
a2_name
=
"{}.a2.weight"
.
format
(
x
)
b1_name
=
"{}.b1.weight"
.
format
(
x
)
b2_name
=
"{}.b2.weight"
.
format
(
x
)
if
a1_name
in
lora
:
patch_dict
[
to_load
[
x
]]
=
(
"glora"
,
(
lora
[
a1_name
],
lora
[
a2_name
],
lora
[
b1_name
],
lora
[
b2_name
],
alpha
))
loaded_keys
.
add
(
a1_name
)
loaded_keys
.
add
(
a2_name
)
loaded_keys
.
add
(
b1_name
)
loaded_keys
.
add
(
b2_name
)
w_norm_name
=
"{}.w_norm"
.
format
(
x
)
b_norm_name
=
"{}.b_norm"
.
format
(
x
)
...
...
comfy/model_patcher.py
View file @
614b7e73
...
...
@@ -311,6 +311,16 @@ class ModelPatcher:
weight
+=
(
alpha
*
m1
*
m2
).
reshape
(
weight
.
shape
).
type
(
weight
.
dtype
)
except
Exception
as
e
:
print
(
"ERROR"
,
key
,
e
)
elif
patch_type
==
"glora"
:
if
v
[
4
]
is
not
None
:
alpha
*=
v
[
4
]
/
v
[
0
].
shape
[
0
]
a1
=
comfy
.
model_management
.
cast_to_device
(
v
[
0
].
flatten
(
start_dim
=
1
),
weight
.
device
,
torch
.
float32
)
a2
=
comfy
.
model_management
.
cast_to_device
(
v
[
1
].
flatten
(
start_dim
=
1
),
weight
.
device
,
torch
.
float32
)
b1
=
comfy
.
model_management
.
cast_to_device
(
v
[
2
].
flatten
(
start_dim
=
1
),
weight
.
device
,
torch
.
float32
)
b2
=
comfy
.
model_management
.
cast_to_device
(
v
[
3
].
flatten
(
start_dim
=
1
),
weight
.
device
,
torch
.
float32
)
weight
+=
((
torch
.
mm
(
b2
,
b1
)
+
torch
.
mm
(
torch
.
mm
(
weight
.
flatten
(
start_dim
=
1
),
a2
),
a1
))
*
alpha
).
reshape
(
weight
.
shape
).
type
(
weight
.
dtype
)
else
:
print
(
"patch type not recognized"
,
patch_type
,
key
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment