Skip to content

Commit

Permalink
feat: free resources less often
Browse files Browse the repository at this point in the history
  • Loading branch information
tazlin committed Feb 23, 2024
1 parent 990f419 commit 67ab327
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
3 changes: 1 addition & 2 deletions examples/run_memory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
25 changes: 7 additions & 18 deletions hordelib/comfy_horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 67ab327

Please sign in to comment.