Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
e666220e
Unverified
Commit
e666220e
authored
Nov 11, 2022
by
AUTOMATIC1111
Committed by
GitHub
Nov 11, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4514 from cluder/4448_fix_ckpt_cache
#4448 fix checkpoint cache usage
parents
6a2044f5
eebf4959
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
sd_models.py
modules/sd_models.py
+18
-11
No files found.
modules/sd_models.py
View file @
e666220e
...
@@ -163,13 +163,21 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
...
@@ -163,13 +163,21 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
checkpoint_file
=
checkpoint_info
.
filename
checkpoint_file
=
checkpoint_info
.
filename
sd_model_hash
=
checkpoint_info
.
hash
sd_model_hash
=
checkpoint_info
.
hash
if
shared
.
opts
.
sd_checkpoint_cache
>
0
and
hasattr
(
model
,
"sd_checkpoint_info"
):
cache_enabled
=
shared
.
opts
.
sd_checkpoint_cache
>
0
if
cache_enabled
:
sd_vae
.
restore_base_vae
(
model
)
sd_vae
.
restore_base_vae
(
model
)
checkpoints_loaded
[
model
.
sd_checkpoint_info
]
=
model
.
state_dict
()
.
copy
()
vae_file
=
sd_vae
.
resolve_vae
(
checkpoint_file
,
vae_file
=
vae_file
)
vae_file
=
sd_vae
.
resolve_vae
(
checkpoint_file
,
vae_file
=
vae_file
)
if
checkpoint_info
not
in
checkpoints_loaded
:
if
cache_enabled
and
checkpoint_info
in
checkpoints_loaded
:
# use checkpoint cache
vae_name
=
sd_vae
.
get_filename
(
vae_file
)
if
vae_file
else
None
vae_message
=
f
" with {vae_name} VAE"
if
vae_name
else
""
print
(
f
"Loading weights [{sd_model_hash}]{vae_message} from cache"
)
model
.
load_state_dict
(
checkpoints_loaded
[
checkpoint_info
])
else
:
# load from file
print
(
f
"Loading weights [{sd_model_hash}] from {checkpoint_file}"
)
print
(
f
"Loading weights [{sd_model_hash}] from {checkpoint_file}"
)
pl_sd
=
torch
.
load
(
checkpoint_file
,
map_location
=
shared
.
weight_load_location
)
pl_sd
=
torch
.
load
(
checkpoint_file
,
map_location
=
shared
.
weight_load_location
)
...
@@ -180,6 +188,10 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
...
@@ -180,6 +188,10 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
del
pl_sd
del
pl_sd
model
.
load_state_dict
(
sd
,
strict
=
False
)
model
.
load_state_dict
(
sd
,
strict
=
False
)
del
sd
del
sd
if
cache_enabled
:
# cache newly loaded model
checkpoints_loaded
[
checkpoint_info
]
=
model
.
state_dict
()
.
copy
()
if
shared
.
cmd_opts
.
opt_channelslast
:
if
shared
.
cmd_opts
.
opt_channelslast
:
model
.
to
(
memory_format
=
torch
.
channels_last
)
model
.
to
(
memory_format
=
torch
.
channels_last
)
...
@@ -199,14 +211,9 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
...
@@ -199,14 +211,9 @@ def load_model_weights(model, checkpoint_info, vae_file="auto"):
model
.
first_stage_model
.
to
(
devices
.
dtype_vae
)
model
.
first_stage_model
.
to
(
devices
.
dtype_vae
)
else
:
# clean up cache if limit is reached
vae_name
=
sd_vae
.
get_filename
(
vae_file
)
if
vae_file
else
None
if
cache_enabled
:
vae_message
=
f
" with {vae_name} VAE"
if
vae_name
else
""
while
len
(
checkpoints_loaded
)
>
shared
.
opts
.
sd_checkpoint_cache
+
1
:
# we need to count the current model
print
(
f
"Loading weights [{sd_model_hash}]{vae_message} from cache"
)
model
.
load_state_dict
(
checkpoints_loaded
[
checkpoint_info
])
if
shared
.
opts
.
sd_checkpoint_cache
>
0
:
while
len
(
checkpoints_loaded
)
>
shared
.
opts
.
sd_checkpoint_cache
:
checkpoints_loaded
.
popitem
(
last
=
False
)
# LRU
checkpoints_loaded
.
popitem
(
last
=
False
)
# LRU
model
.
sd_model_hash
=
sd_model_hash
model
.
sd_model_hash
=
sd_model_hash
...
...
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