Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
e407d1af
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1748
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
e407d1af
编写于
1月 23, 2023
作者:
A
AUTOMATIC
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add support for loras trained on kohya's scripts 0.4.0 (alphas)
上级
e8c3d03f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
11 addition
and
7 deletion
+11
-7
extensions-builtin/Lora/lora.py
extensions-builtin/Lora/lora.py
+11
-7
未找到文件。
extensions-builtin/Lora/lora.py
浏览文件 @
e407d1af
...
...
@@ -92,6 +92,15 @@ def load_lora(name, filename):
keys_failed_to_match
.
append
(
key_diffusers
)
continue
lora_module
=
lora
.
modules
.
get
(
key
,
None
)
if
lora_module
is
None
:
lora_module
=
LoraUpDownModule
()
lora
.
modules
[
key
]
=
lora_module
if
lora_key
==
"alpha"
:
lora_module
.
alpha
=
weight
.
item
()
continue
if
type
(
sd_module
)
==
torch
.
nn
.
Linear
:
module
=
torch
.
nn
.
Linear
(
weight
.
shape
[
1
],
weight
.
shape
[
0
],
bias
=
False
)
elif
type
(
sd_module
)
==
torch
.
nn
.
Conv2d
:
...
...
@@ -104,17 +113,12 @@ def load_lora(name, filename):
module
.
to
(
device
=
devices
.
device
,
dtype
=
devices
.
dtype
)
lora_module
=
lora
.
modules
.
get
(
key
,
None
)
if
lora_module
is
None
:
lora_module
=
LoraUpDownModule
()
lora
.
modules
[
key
]
=
lora_module
if
lora_key
==
"lora_up.weight"
:
lora_module
.
up
=
module
elif
lora_key
==
"lora_down.weight"
:
lora_module
.
down
=
module
else
:
assert
False
,
f
'Bad Lora layer name:
{
key_diffusers
}
- must end in lora_up.weight
or lora_down.weight
'
assert
False
,
f
'Bad Lora layer name:
{
key_diffusers
}
- must end in lora_up.weight
, lora_down.weight or alpha
'
if
len
(
keys_failed_to_match
)
>
0
:
print
(
f
"Failed to match keys when loading Lora
{
filename
}
:
{
keys_failed_to_match
}
"
)
...
...
@@ -161,7 +165,7 @@ def lora_forward(module, input, res):
for
lora
in
loaded_loras
:
module
=
lora
.
modules
.
get
(
lora_layer_name
,
None
)
if
module
is
not
None
:
res
=
res
+
module
.
up
(
module
.
down
(
input
))
*
lora
.
multiplier
res
=
res
+
module
.
up
(
module
.
down
(
input
))
*
lora
.
multiplier
*
module
.
alpha
/
module
.
up
.
weight
.
shape
[
1
]
return
res
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录