Skip to content

Commit bf7a699

Browse files
committed
Fix #4035 for real now
1 parent 36966e3 commit bf7a699

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

modules/sd_models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def load_model_weights(model, checkpoint_info):
165165
checkpoint_file = checkpoint_info.filename
166166
sd_model_hash = checkpoint_info.hash
167167

168+
if shared.opts.sd_checkpoint_cache > 0 and hasattr(model, "sd_checkpoint_info"):
169+
checkpoints_loaded[model.sd_checkpoint_info] = model.state_dict().copy()
170+
168171
if checkpoint_info not in checkpoints_loaded:
169172
print(f"Loading weights [{sd_model_hash}] from {checkpoint_file}")
170173

@@ -198,16 +201,14 @@ def load_model_weights(model, checkpoint_info):
198201
model.first_stage_model.load_state_dict(vae_dict)
199202

200203
model.first_stage_model.to(devices.dtype_vae)
201-
202-
if shared.opts.sd_checkpoint_cache > 0:
203-
checkpoints_loaded[checkpoint_info] = model.state_dict().copy()
204-
while len(checkpoints_loaded) > shared.opts.sd_checkpoint_cache + 1:
205-
checkpoints_loaded.popitem(last=False) # LRU
206204
else:
207205
print(f"Loading weights [{sd_model_hash}] from cache")
208-
checkpoints_loaded.move_to_end(checkpoint_info)
209206
model.load_state_dict(checkpoints_loaded[checkpoint_info])
210207

208+
if shared.opts.sd_checkpoint_cache > 0:
209+
while len(checkpoints_loaded) > shared.opts.sd_checkpoint_cache:
210+
checkpoints_loaded.popitem(last=False) # LRU
211+
211212
model.sd_model_hash = sd_model_hash
212213
model.sd_model_checkpoint = checkpoint_file
213214
model.sd_checkpoint_info = checkpoint_info

0 commit comments

Comments
 (0)