From ebdeadfcfbd7d65bd1a34dcd380aac4859aedced Mon Sep 17 00:00:00 2001 From: Raapys <2cool4credibility@gmail.com> Date: Mon, 12 Aug 2024 15:42:24 +0200 Subject: [PATCH] Initial --- README.md | 7 +++++++ __init__.py | 2 ++ nodes.py | 30 ++++++++++++++++++++++++++++++ pyproject.toml | 15 +++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 README.md create mode 100644 __init__.py create mode 100644 nodes.py create mode 100644 pyproject.toml diff --git a/README.md b/README.md new file mode 100644 index 0000000..db59078 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# ComfyUI LatentGC_Aggressive + +Contains a single node for ComfyUI (https://github.com/comfyanonymous/ComfyUI) that on being hit empties cache, runs GC and unloads models from VRAM. Useful to put between different stages of the workflow in low VRAM scenarios. Suggested use is before/after sampler, before VFI, etc. The performance impact of unloading models from VRAM and, in some cases, forcing an immediate re-load for the next node use, appears negligible on this system. + +Thanks to: +https://github.com/ntdviet/comfyui-ext +https://github.com/yolain/ComfyUI-Easy-Use \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..85cf340 --- /dev/null +++ b/__init__.py @@ -0,0 +1,2 @@ +from .nodes import NODE_CLASS_MAPPINGS +__all__ = ["NODE_CLASS_MAPPINGS"] \ No newline at end of file diff --git a/nodes.py b/nodes.py new file mode 100644 index 0000000..9bd5875 --- /dev/null +++ b/nodes.py @@ -0,0 +1,30 @@ +import torch +import comfy.model_management as mm +import gc + +class LatentGC_Aggressive: + def __init__(self): + pass + + @classmethod + + def INPUT_TYPES(s): + return { + "required": { + "samples": ("LATENT",), + } + } + RETURN_TYPES = ("LATENT",) + FUNCTION = "tunnelLatents" + CATEGORY = "latent" + + def tunnelLatents(self, samples): + s = samples.copy() + gc.collect() + mm.unload_all_models() + mm.soft_empty_cache() + return (s,) + +NODE_CLASS_MAPPINGS = { + "LatentGC": LatentGC_Aggressive, +} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8165b97 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[project] +name = "comfyui-latentgc_aggressive" +description = "This extension provides a node that aggressively empties the VRAM inbetween workflow stages, for low VRAM environments." +version = "1.0.0" +license = "LICENSE" +dependencies = [] + +[project.urls] +Repository = "https://github.com/ltdrdata/ComfyUI-Impact-Pack" +# Used by Comfy Registry https://comfyregistry.org + +[tool.comfy] +PublisherId = "" +DisplayName = "ComfyUI-LatentGC_Aggressive" +Icon = "" \ No newline at end of file