Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
3d8256e4
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
11 个月 前同步成功
通知
1759
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3d8256e4
编写于
12月 31, 2022
作者:
A
AUTOMATIC1111
提交者:
GitHub
12月 31, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6017 from hitomi/master
Add memory cache for VAE weights
上级
d81636a0
893933e0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
6 deletion
+26
-6
modules/sd_vae.py
modules/sd_vae.py
+25
-6
modules/shared.py
modules/shared.py
+1
-0
未找到文件。
modules/sd_vae.py
浏览文件 @
3d8256e4
import
torch
import
os
import
collections
from
collections
import
namedtuple
from
modules
import
shared
,
devices
,
script_callbacks
from
modules.paths
import
models_path
...
...
@@ -30,6 +31,7 @@ base_vae = None
loaded_vae_file
=
None
checkpoint_info
=
None
checkpoints_loaded
=
collections
.
OrderedDict
()
def
get_base_vae
(
model
):
if
base_vae
is
not
None
and
checkpoint_info
==
model
.
sd_checkpoint_info
and
model
:
...
...
@@ -149,13 +151,30 @@ def load_vae(model, vae_file=None):
global
first_load
,
vae_dict
,
vae_list
,
loaded_vae_file
# save_settings = False
cache_enabled
=
shared
.
opts
.
sd_vae_checkpoint_cache
>
0
if
vae_file
:
assert
os
.
path
.
isfile
(
vae_file
),
f
"VAE file doesn't exist:
{
vae_file
}
"
print
(
f
"Loading VAE weights from:
{
vae_file
}
"
)
store_base_vae
(
model
)
vae_ckpt
=
torch
.
load
(
vae_file
,
map_location
=
shared
.
weight_load_location
)
vae_dict_1
=
{
k
:
v
for
k
,
v
in
vae_ckpt
[
"state_dict"
].
items
()
if
k
[
0
:
4
]
!=
"loss"
and
k
not
in
vae_ignore_keys
}
_load_vae_dict
(
model
,
vae_dict_1
)
if
cache_enabled
and
vae_file
in
checkpoints_loaded
:
# use vae checkpoint cache
print
(
f
"Loading VAE weights [
{
get_filename
(
vae_file
)
}
] from cache"
)
store_base_vae
(
model
)
_load_vae_dict
(
model
,
checkpoints_loaded
[
vae_file
])
else
:
assert
os
.
path
.
isfile
(
vae_file
),
f
"VAE file doesn't exist:
{
vae_file
}
"
print
(
f
"Loading VAE weights from:
{
vae_file
}
"
)
store_base_vae
(
model
)
vae_ckpt
=
torch
.
load
(
vae_file
,
map_location
=
shared
.
weight_load_location
)
vae_dict_1
=
{
k
:
v
for
k
,
v
in
vae_ckpt
[
"state_dict"
].
items
()
if
k
[
0
:
4
]
!=
"loss"
and
k
not
in
vae_ignore_keys
}
_load_vae_dict
(
model
,
vae_dict_1
)
if
cache_enabled
:
# cache newly loaded vae
checkpoints_loaded
[
vae_file
]
=
vae_dict_1
.
copy
()
# clean up cache if limit is reached
if
cache_enabled
:
while
len
(
checkpoints_loaded
)
>
shared
.
opts
.
sd_vae_checkpoint_cache
+
1
:
# we need to count the current model
checkpoints_loaded
.
popitem
(
last
=
False
)
# LRU
# If vae used is not in dict, update it
# It will be removed on refresh though
...
...
modules/shared.py
浏览文件 @
3d8256e4
...
...
@@ -356,6 +356,7 @@ options_templates.update(options_section(('training', "Training"), {
options_templates
.
update
(
options_section
((
'sd'
,
"Stable Diffusion"
),
{
"sd_model_checkpoint"
:
OptionInfo
(
None
,
"Stable Diffusion checkpoint"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
list_checkpoint_tiles
()},
refresh
=
refresh_checkpoints
),
"sd_checkpoint_cache"
:
OptionInfo
(
0
,
"Checkpoints to cache in RAM"
,
gr
.
Slider
,
{
"minimum"
:
0
,
"maximum"
:
10
,
"step"
:
1
}),
"sd_vae_checkpoint_cache"
:
OptionInfo
(
0
,
"VAE Checkpoints to cache in RAM"
,
gr
.
Slider
,
{
"minimum"
:
0
,
"maximum"
:
10
,
"step"
:
1
}),
"sd_vae"
:
OptionInfo
(
"auto"
,
"SD VAE"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
sd_vae
.
vae_list
},
refresh
=
sd_vae
.
refresh_vae_list
),
"sd_vae_as_default"
:
OptionInfo
(
False
,
"Ignore selected VAE for stable diffusion checkpoints that have their own .vae.pt next to them"
),
"sd_hypernetwork"
:
OptionInfo
(
"None"
,
"Hypernetwork"
,
gr
.
Dropdown
,
lambda
:
{
"choices"
:
[
"None"
]
+
[
x
for
x
in
hypernetworks
.
keys
()]},
refresh
=
reload_hypernetworks
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录