Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
6c5f83b1
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
12 个月 前同步成功
通知
1771
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
6c5f83b1
编写于
7月 13, 2023
作者:
A
AUTOMATIC1111
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add support for SDXL loras with te1/te2 modules
上级
ff73841c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
12 deletion
+33
-12
extensions-builtin/Lora/lora.py
extensions-builtin/Lora/lora.py
+31
-10
modules/sd_models.py
modules/sd_models.py
+2
-1
modules/sd_models_xl.py
modules/sd_models_xl.py
+0
-1
未找到文件。
extensions-builtin/Lora/lora.py
浏览文件 @
6c5f83b1
...
@@ -68,6 +68,14 @@ def convert_diffusers_name_to_compvis(key, is_sd2):
...
@@ -68,6 +68,14 @@ def convert_diffusers_name_to_compvis(key, is_sd2):
return
f
"transformer_text_model_encoder_layers_
{
m
[
0
]
}
_
{
m
[
1
]
}
"
return
f
"transformer_text_model_encoder_layers_
{
m
[
0
]
}
_
{
m
[
1
]
}
"
if
match
(
m
,
r
"lora_te2_text_model_encoder_layers_(\d+)_(.+)"
):
if
'mlp_fc1'
in
m
[
1
]:
return
f
"1_model_transformer_resblocks_
{
m
[
0
]
}
_
{
m
[
1
].
replace
(
'mlp_fc1'
,
'mlp_c_fc'
)
}
"
elif
'mlp_fc2'
in
m
[
1
]:
return
f
"1_model_transformer_resblocks_
{
m
[
0
]
}
_
{
m
[
1
].
replace
(
'mlp_fc2'
,
'mlp_c_proj'
)
}
"
else
:
return
f
"1_model_transformer_resblocks_
{
m
[
0
]
}
_
{
m
[
1
].
replace
(
'self_attn'
,
'attn'
)
}
"
return
key
return
key
...
@@ -142,10 +150,20 @@ class LoraUpDownModule:
...
@@ -142,10 +150,20 @@ class LoraUpDownModule:
def
assign_lora_names_to_compvis_modules
(
sd_model
):
def
assign_lora_names_to_compvis_modules
(
sd_model
):
lora_layer_mapping
=
{}
lora_layer_mapping
=
{}
for
name
,
module
in
shared
.
sd_model
.
cond_stage_model
.
wrapped
.
named_modules
():
if
shared
.
sd_model
.
is_sdxl
:
lora_name
=
name
.
replace
(
"."
,
"_"
)
for
i
,
embedder
in
enumerate
(
shared
.
sd_model
.
conditioner
.
embedders
):
lora_layer_mapping
[
lora_name
]
=
module
if
not
hasattr
(
embedder
,
'wrapped'
):
module
.
lora_layer_name
=
lora_name
continue
for
name
,
module
in
embedder
.
wrapped
.
named_modules
():
lora_name
=
f
'
{
i
}
_
{
name
.
replace
(
"."
,
"_"
)
}
'
lora_layer_mapping
[
lora_name
]
=
module
module
.
lora_layer_name
=
lora_name
else
:
for
name
,
module
in
shared
.
sd_model
.
cond_stage_model
.
wrapped
.
named_modules
():
lora_name
=
name
.
replace
(
"."
,
"_"
)
lora_layer_mapping
[
lora_name
]
=
module
module
.
lora_layer_name
=
lora_name
for
name
,
module
in
shared
.
sd_model
.
model
.
named_modules
():
for
name
,
module
in
shared
.
sd_model
.
model
.
named_modules
():
lora_name
=
name
.
replace
(
"."
,
"_"
)
lora_name
=
name
.
replace
(
"."
,
"_"
)
...
@@ -168,10 +186,10 @@ def load_lora(name, lora_on_disk):
...
@@ -168,10 +186,10 @@ def load_lora(name, lora_on_disk):
keys_failed_to_match
=
{}
keys_failed_to_match
=
{}
is_sd2
=
'model_transformer_resblocks'
in
shared
.
sd_model
.
lora_layer_mapping
is_sd2
=
'model_transformer_resblocks'
in
shared
.
sd_model
.
lora_layer_mapping
for
key_diffusers
,
weight
in
sd
.
items
():
for
key_lora
,
weight
in
sd
.
items
():
key_diffusers_without_lora_parts
,
lora_key
=
key_diffusers
.
split
(
"."
,
1
)
key_lora_without_lora_parts
,
lora_key
=
key_lora
.
split
(
"."
,
1
)
key
=
convert_diffusers_name_to_compvis
(
key_diffusers_without_lora_parts
,
is_sd2
)
key
=
convert_diffusers_name_to_compvis
(
key_lora_without_lora_parts
,
is_sd2
)
sd_module
=
shared
.
sd_model
.
lora_layer_mapping
.
get
(
key
,
None
)
sd_module
=
shared
.
sd_model
.
lora_layer_mapping
.
get
(
key
,
None
)
if
sd_module
is
None
:
if
sd_module
is
None
:
...
@@ -180,12 +198,15 @@ def load_lora(name, lora_on_disk):
...
@@ -180,12 +198,15 @@ def load_lora(name, lora_on_disk):
sd_module
=
shared
.
sd_model
.
lora_layer_mapping
.
get
(
m
.
group
(
1
),
None
)
sd_module
=
shared
.
sd_model
.
lora_layer_mapping
.
get
(
m
.
group
(
1
),
None
)
# SDXL loras seem to already have correct compvis keys, so only need to replace "lora_unet" with "diffusion_model"
# SDXL loras seem to already have correct compvis keys, so only need to replace "lora_unet" with "diffusion_model"
if
sd_module
is
None
and
"lora_unet"
in
key_diffusers_without_lora_parts
:
if
sd_module
is
None
and
"lora_unet"
in
key_lora_without_lora_parts
:
key
=
key_diffusers_without_lora_parts
.
replace
(
"lora_unet"
,
"diffusion_model"
)
key
=
key_lora_without_lora_parts
.
replace
(
"lora_unet"
,
"diffusion_model"
)
sd_module
=
shared
.
sd_model
.
lora_layer_mapping
.
get
(
key
,
None
)
elif
sd_module
is
None
and
"lora_te1_text_model"
in
key_lora_without_lora_parts
:
key
=
key_lora_without_lora_parts
.
replace
(
"lora_te1_text_model"
,
"0_transformer_text_model"
)
sd_module
=
shared
.
sd_model
.
lora_layer_mapping
.
get
(
key
,
None
)
sd_module
=
shared
.
sd_model
.
lora_layer_mapping
.
get
(
key
,
None
)
if
sd_module
is
None
:
if
sd_module
is
None
:
keys_failed_to_match
[
key_
diffusers
]
=
key
keys_failed_to_match
[
key_
lora
]
=
key
continue
continue
lora_module
=
lora
.
modules
.
get
(
key
,
None
)
lora_module
=
lora
.
modules
.
get
(
key
,
None
)
...
...
modules/sd_models.py
浏览文件 @
6c5f83b1
...
@@ -289,7 +289,8 @@ def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer
...
@@ -289,7 +289,8 @@ def load_model_weights(model, checkpoint_info: CheckpointInfo, state_dict, timer
if
state_dict
is
None
:
if
state_dict
is
None
:
state_dict
=
get_checkpoint_state_dict
(
checkpoint_info
,
timer
)
state_dict
=
get_checkpoint_state_dict
(
checkpoint_info
,
timer
)
if
hasattr
(
model
,
'conditioner'
):
model
.
is_sdxl
=
hasattr
(
model
,
'conditioner'
)
if
model
.
is_sdxl
:
sd_models_xl
.
extend_sdxl
(
model
)
sd_models_xl
.
extend_sdxl
(
model
)
model
.
load_state_dict
(
state_dict
,
strict
=
False
)
model
.
load_state_dict
(
state_dict
,
strict
=
False
)
...
...
modules/sd_models_xl.py
浏览文件 @
6c5f83b1
...
@@ -48,7 +48,6 @@ def extend_sdxl(model):
...
@@ -48,7 +48,6 @@ def extend_sdxl(model):
discretization
=
sgm
.
modules
.
diffusionmodules
.
discretizer
.
LegacyDDPMDiscretization
()
discretization
=
sgm
.
modules
.
diffusionmodules
.
discretizer
.
LegacyDDPMDiscretization
()
model
.
alphas_cumprod
=
torch
.
asarray
(
discretization
.
alphas_cumprod
,
device
=
devices
.
device
,
dtype
=
dtype
)
model
.
alphas_cumprod
=
torch
.
asarray
(
discretization
.
alphas_cumprod
,
device
=
devices
.
device
,
dtype
=
dtype
)
model
.
is_sdxl
=
True
sgm
.
models
.
diffusion
.
DiffusionEngine
.
get_learned_conditioning
=
get_learned_conditioning
sgm
.
models
.
diffusion
.
DiffusionEngine
.
get_learned_conditioning
=
get_learned_conditioning
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录