diff options
author | Muhammad Rizqi Nur <rizqinur2010@gmail.com> | 2022-10-31 09:27:27 +0000 |
---|---|---|
committer | Muhammad Rizqi Nur <rizqinur2010@gmail.com> | 2022-10-31 09:27:27 +0000 |
commit | bf7a699845675eefdabb9cfa40c55398976274ae (patch) | |
tree | f26dc84660ccbc7b93d45c0a6dff0bf12c5d2bf4 /modules/sd_models.py | |
parent | 36966e3200943dbf890b5338cfa939df552d3c47 (diff) | |
download | stable-diffusion-webui-gfx803-bf7a699845675eefdabb9cfa40c55398976274ae.tar.gz stable-diffusion-webui-gfx803-bf7a699845675eefdabb9cfa40c55398976274ae.tar.bz2 stable-diffusion-webui-gfx803-bf7a699845675eefdabb9cfa40c55398976274ae.zip |
Fix #4035 for real now
Diffstat (limited to 'modules/sd_models.py')
-rw-r--r-- | modules/sd_models.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/modules/sd_models.py b/modules/sd_models.py index a29c8c1a..b2dd005a 100644 --- a/modules/sd_models.py +++ b/modules/sd_models.py @@ -165,6 +165,9 @@ def load_model_weights(model, checkpoint_info): checkpoint_file = checkpoint_info.filename
sd_model_hash = checkpoint_info.hash
+ if shared.opts.sd_checkpoint_cache > 0 and hasattr(model, "sd_checkpoint_info"):
+ checkpoints_loaded[model.sd_checkpoint_info] = model.state_dict().copy()
+
if checkpoint_info not in checkpoints_loaded:
print(f"Loading weights [{sd_model_hash}] from {checkpoint_file}")
@@ -198,16 +201,14 @@ def load_model_weights(model, checkpoint_info): model.first_stage_model.load_state_dict(vae_dict)
model.first_stage_model.to(devices.dtype_vae)
-
- if shared.opts.sd_checkpoint_cache > 0:
- checkpoints_loaded[checkpoint_info] = model.state_dict().copy()
- while len(checkpoints_loaded) > shared.opts.sd_checkpoint_cache + 1:
- checkpoints_loaded.popitem(last=False) # LRU
else:
print(f"Loading weights [{sd_model_hash}] from cache")
- checkpoints_loaded.move_to_end(checkpoint_info)
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
+
model.sd_model_hash = sd_model_hash
model.sd_model_checkpoint = checkpoint_file
model.sd_checkpoint_info = checkpoint_info
|