Nodes/DOGMA Nodes/DOGMA Image VRAM Cleanup v14
ComfyUI Node

DOGMA Image VRAM Cleanup v14

DOGMA Image VRAM Cleanup v14

By axior·Created 4 months ago·Updated 3 days ago· 1
DOGMA Image VRAM Cleanup v14
  • image
  • image
  • status
unload_modelstrue

This is an image pass-through that calls three functions. It has no other behaviour. It earns its place in the pack because a DOGMA workflow can have four or five different models loaded over the course of a run, and ComfyUI's model cache does not know which one you're done with.

Wire it where the pipeline changes models and it buys you the VRAM to finish.

What it is

Multi-stage graphs load models they never release. That's usually fine - the cache is what makes re-running a workflow fast - and it's exactly wrong in a graph that loads a planner, then a SAM, then an edit model, then a VAE decoder, each one bigger than the last. Somebody has to say "I'm done with that one now."

The DOGMA pipeline has an unusually high model count per run: planner, segmenter, per-category passes, a re-render model, plus whatever the sampler loads. So the pack carries several of these barriers, and this is the general-purpose one, from the v14 era. The class docstring puts it plainly: "generic image pass-through with an explicit model/cache unload barrier."

How it works

It does the three things you'd otherwise do in a custom script. If unload_models is on it calls comfy.model_management.unload_all_models(), wrapped in a try/except so a version change in ComfyUI can't take your whole run down. Then gc.collect(). Then comfy.model_management.soft_empty_cache(), also guarded.

The exception handling is worth noting rather than glossing over: this node is written to be harmless if the ComfyUI internals it calls move, because they do move. It won't crash your graph; at worst it quietly does nothing.

unload_all_models() is the nuclear option - it clears the cache of everything, not just your VLM. In a graph where the next stage is going to load a fresh model anyway, that's exactly what you want. In a graph that will immediately need something it just unloaded, you've traded a slow run for a slower one.

Inputs and outputs

Two inputs. image (IMAGE) - the pass-through, typically the image leaving the stage you're finished with. unload_models (BOOLEAN, default on) - the switch that decides whether the models get dropped as well as the cache. Turn it off and you're left with just the gc.collect() and soft cache empty, which is the gentler option when you know the next node wants the same model.

Two outputs: image (IMAGE), unchanged, and status (STRING) - a fixed sentence confirming cleanup ran before the next heavy stage. It's a receipt, not a report; there's no memory figure in it. If you need one, a preview of the executed status plus your GPU monitor of choice is the combination.

Install

ComfyUI Manager → search DOGMA Nodes (publisher axior), install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/axior/ComfyUI-DOGMA-Nodes
# restart ComfyUI

No dependencies to install and no weights, which matters here - there is no chance that the fix for your OOM installs something that makes the OOM worse.

Common issues

Placement is everything, and the two places people get it wrong are the two obvious ones. Put it before the stage you want to have memory for, not after the one you're finishing - it's a barrier between stages, so it belongs at the boundary. And keep it off the list wire path: this node takes a single IMAGE, not a list of crops, so putting it in the middle of a per-crop branch either forces a batch conversion or just doesn't fit.

Then there's the honest limit: unload_all_models() frees the cache, and if something still holds a reference to a tensor the memory isn't coming back. The pack's other cleanup node, DOGMAAfterMasksVRAMCleanup (v10), is the sibling designed for the mask-heavy part of the graph where six mask batches plus an image are all resident; this one is the general-purpose variant. If your OOM survives both, the problem is that two models are genuinely concurrent, and the fix is dependency ordering - the kind DOGMAImageAfterText manufactures - not a cleanup call.

CategoryDOGMA/Semantic Detailer

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
unload_modelsBOOLEANtrue

Outputs (2)

NameTypeDescription
imageIMAGE
statusSTRING