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
renzhc
diffusers_dcu
Commits
e6df8eda
Unverified
Commit
e6df8eda
authored
May 28, 2024
by
Sayak Paul
Committed by
GitHub
May 28, 2024
Browse files
[LoRA] attempt at fixing onetrainer lora. (#8242)
* attempt at fixing onetrainer lora. * fix
parent
80cfaeba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
1 deletion
+9
-1
src/diffusers/loaders/lora_conversion_utils.py
src/diffusers/loaders/lora_conversion_utils.py
+7
-1
src/diffusers/utils/state_dict_utils.py
src/diffusers/utils/state_dict_utils.py
+2
-0
No files found.
src/diffusers/loaders/lora_conversion_utils.py
View file @
e6df8eda
...
...
@@ -226,6 +226,8 @@ def _convert_kohya_lora_to_diffusers(state_dict, unet_name="unet", text_encoder_
diffusers_name
=
diffusers_name
.
replace
(
"k.proj.lora"
,
"to_k_lora"
)
diffusers_name
=
diffusers_name
.
replace
(
"v.proj.lora"
,
"to_v_lora"
)
diffusers_name
=
diffusers_name
.
replace
(
"out.proj.lora"
,
"to_out_lora"
)
diffusers_name
=
diffusers_name
.
replace
(
"text.projection"
,
"text_projection"
)
if
"self_attn"
in
diffusers_name
:
if
lora_name
.
startswith
((
"lora_te_"
,
"lora_te1_"
)):
te_state_dict
[
diffusers_name
]
=
state_dict
.
pop
(
key
)
...
...
@@ -243,6 +245,10 @@ def _convert_kohya_lora_to_diffusers(state_dict, unet_name="unet", text_encoder_
else
:
te2_state_dict
[
diffusers_name
]
=
state_dict
.
pop
(
key
)
te2_state_dict
[
diffusers_name
.
replace
(
".down."
,
".up."
)]
=
state_dict
.
pop
(
lora_name_up
)
# OneTrainer specificity
elif
"text_projection"
in
diffusers_name
and
lora_name
.
startswith
(
"lora_te2_"
):
te2_state_dict
[
diffusers_name
]
=
state_dict
.
pop
(
key
)
te2_state_dict
[
diffusers_name
.
replace
(
".down."
,
".up."
)]
=
state_dict
.
pop
(
lora_name_up
)
if
(
is_te_dora_lora
or
is_te2_dora_lora
)
and
lora_name
.
startswith
((
"lora_te_"
,
"lora_te1_"
,
"lora_te2_"
)):
dora_scale_key_to_replace_te
=
(
...
...
@@ -270,7 +276,7 @@ def _convert_kohya_lora_to_diffusers(state_dict, unet_name="unet", text_encoder_
network_alphas
.
update
({
new_name
:
alpha
})
if
len
(
state_dict
)
>
0
:
raise
ValueError
(
f
"The following keys have not been correctly
be
renamed:
\n\n
{
', '
.
join
(
state_dict
.
keys
())
}
"
)
raise
ValueError
(
f
"The following keys have not been correctly renamed:
\n\n
{
', '
.
join
(
state_dict
.
keys
())
}
"
)
logger
.
info
(
"Kohya-style checkpoint detected."
)
unet_state_dict
=
{
f
"
{
unet_name
}
.
{
module_name
}
"
:
params
for
module_name
,
params
in
unet_state_dict
.
items
()}
...
...
src/diffusers/utils/state_dict_utils.py
View file @
e6df8eda
...
...
@@ -62,6 +62,8 @@ DIFFUSERS_TO_PEFT = {
".out_proj.lora_linear_layer.down"
:
".out_proj.lora_A"
,
".lora_linear_layer.up"
:
".lora_B"
,
".lora_linear_layer.down"
:
".lora_A"
,
"text_projection.lora.down.weight"
:
"text_projection.lora_A.weight"
,
"text_projection.lora.up.weight"
:
"text_projection.lora_B.weight"
,
}
DIFFUSERS_OLD_TO_PEFT
=
{
...
...
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