Commit 8bebfde7 authored by AUTOMATIC1111's avatar AUTOMATIC1111 Committed by GitHub

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

minor bug fix of sd model memory management
parents 98096195 f62217b6
...@@ -787,6 +787,13 @@ def reuse_model_from_already_loaded(sd_model, checkpoint_info, timer): ...@@ -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). 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 already_loaded = None
for i in reversed(range(len(model_data.loaded_sd_models))): for i in reversed(range(len(model_data.loaded_sd_models))):
loaded_model = model_data.loaded_sd_models[i] loaded_model = model_data.loaded_sd_models[i]
...@@ -800,10 +807,6 @@ def reuse_model_from_already_loaded(sd_model, checkpoint_info, timer): ...@@ -800,10 +807,6 @@ def reuse_model_from_already_loaded(sd_model, checkpoint_info, timer):
send_model_to_trash(loaded_model) send_model_to_trash(loaded_model)
timer.record("send model to trash") 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: if already_loaded is not None:
send_model_to_device(already_loaded) send_model_to_device(already_loaded)
timer.record("send model to device") timer.record("send model to device")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment