From 67ab327a311917ab8bf91af979d643dc741b5b65 Mon Sep 17 00:00:00 2001 From: tazlin Date: Thu, 22 Feb 2024 22:18:42 -0500 Subject: [PATCH] feat: free resources less often --- examples/run_memory_test.py | 3 +-- hordelib/comfy_horde.py | 25 +++++++------------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/examples/run_memory_test.py b/examples/run_memory_test.py index ee6ec2e9..b5fe800f 100644 --- a/examples/run_memory_test.py +++ b/examples/run_memory_test.py @@ -14,7 +14,6 @@ hordelib.initialise(setup_logging=False) -from hordelib.comfy_horde import cleanup from hordelib.horde import HordeLib from hordelib.settings import UserSettings from hordelib.shared_model_manager import SharedModelManager @@ -155,7 +154,7 @@ def main(): model_index += 1 how_far -= 1 # That would have pushed something to disk, force a memory cleanup - cleanup() + # cleanup() report_ram() logger.warning("Loaded all models") diff --git a/hordelib/comfy_horde.py b/hordelib/comfy_horde.py index 70fb8955..b9926f71 100644 --- a/hordelib/comfy_horde.py +++ b/hordelib/comfy_horde.py @@ -222,8 +222,8 @@ def recursive_output_delete_if_changed_hijack(prompt: dict, old_prompt, outputs, return _comfy_recursive_output_delete_if_changed(prompt, old_prompt, outputs, current_item) -def cleanup(): - _comfy_soft_empty_cache() +# def cleanup(): +# _comfy_soft_empty_cache() def unload_all_models_vram(): @@ -271,17 +271,6 @@ def get_torch_free_vram_mb(): return round(_comfy_get_free_memory() / (1024 * 1024)) -def garbage_collect(): - logger.debug("Comfy_Horde garbage_collect called") - gc.collect() - if not torch.cuda.is_available(): - logger.debug("CUDA not available, skipping cuda empty cache") - return - if torch.version.cuda: - torch.cuda.empty_cache() - torch.cuda.ipc_collect() - - class Comfy_Horde: """Handles horde-specific behavior against ComfyUI.""" @@ -718,11 +707,11 @@ def _run_pipeline(self, pipeline: dict, params: dict) -> list[dict] | None: stdio.replay() - # Check if there are any resource to clean up - cleanup() - if time.time() - self._gc_timer > Comfy_Horde.GC_TIME: - self._gc_timer = time.time() - garbage_collect() + # # Check if there are any resource to clean up + # cleanup() + # if time.time() - self._gc_timer > Comfy_Horde.GC_TIME: + # self._gc_timer = time.time() + # garbage_collect() return self.images