From 30eb92c3cbe0e0dfa442d452b5f1187c654e572e Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Thu, 24 Aug 2023 19:39:18 -0400 Subject: [PATCH] Code cleanups. --- comfy/model_management.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/comfy/model_management.py b/comfy/model_management.py index f1873a34..0e86df41 100644 --- a/comfy/model_management.py +++ b/comfy/model_management.py @@ -302,16 +302,15 @@ def unload_model_clones(model): def free_memory(memory_required, device, keep_loaded=[]): unloaded_model = False for i in range(len(current_loaded_models) -1, -1, -1): - if DISABLE_SMART_MEMORY: - current_free_mem = 0 - else: - current_free_mem = get_free_memory(device) - if current_free_mem > memory_required: - break + if not DISABLE_SMART_MEMORY: + if get_free_memory(device) > memory_required: + break shift_model = current_loaded_models[i] if shift_model.device == device: if shift_model not in keep_loaded: - current_loaded_models.pop(i).model_unload() + m = current_loaded_models.pop(i) + m.model_unload() + del m unloaded_model = True if unloaded_model: