Merge pull request #15350 from baseco/memory-bug-fix

minor bug fix of sd model memory management
This commit is contained in:
AUTOMATIC1111 2024-03-30 07:37:10 +03:00 committed by GitHub
commit 8bebfde701
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -787,6 +787,13 @@ def reuse_model_from_already_loaded(sd_model, checkpoint_info, timer):
Additionally deletes loaded models that are over the limit set in settings (sd_checkpoints_limit).
"""
if sd_model is not None and sd_model.sd_checkpoint_info.filename == checkpoint_info.filename:
return sd_model
if shared.opts.sd_checkpoints_keep_in_cpu:
send_model_to_cpu(sd_model)
timer.record("send model to cpu")
already_loaded = None
for i in reversed(range(len(model_data.loaded_sd_models))):
loaded_model = model_data.loaded_sd_models[i]
@ -800,10 +807,6 @@ def reuse_model_from_already_loaded(sd_model, checkpoint_info, timer):
send_model_to_trash(loaded_model)
timer.record("send model to trash")
if shared.opts.sd_checkpoints_keep_in_cpu:
send_model_to_cpu(sd_model)
timer.record("send model to cpu")
if already_loaded is not None:
send_model_to_device(already_loaded)
timer.record("send model to device")