DOGMA After Masks VRAM Cleanup
The stage barrier that evicts SAM before Klein moves in
- image
- mask_1
- mask_2
- mask_3
- mask_4
- mask_5
- mask_6
- image
- status
A semantic detailer stack is heavy in a specific and annoying way: it needs three model families that don't overlap in time. A VLM writes the plan, a grounded SAM makes the masks, and a big edit model does the local passes. On a 24GB card you can hold two of those, not three. DOGMAAfterMasksVRAMCleanup is the node that lets you say "masks are done, get the segmenter out of my VRAM" - explicitly, inside the graph, where you can see it.
What it is
Its docstring is the honest description: "Explicit stage barrier: all six SAM masks must exist before this runs. Then SAM/Qwen/upscaler models can be unloaded before Klein inpainting."
Inputs: image, mask_1 through mask_6, and a boolean unload_models (default true). Outputs: image and a status string. The six mask inputs are not data dependencies - the node doesn't touch them. They're a wiring trick: by requiring all six upstream mask branches as inputs, ComfyUI cannot execute this node until every segmentation branch has finished. That's how you force a stage boundary in a lazy graph where nothing else imposes one.
The image input-output pass-through is the same idea for the pixel path: the node sits in the middle of your image wire so its position in the graph is meaningful by construction.
What it actually does
With unload_models on, it calls ComfyUI's model manager to unload all models, then runs a garbage collection and a soft cache empty. Both Comfy calls are wrapped in try/except - the comment notes that older or newer Comfy builds may not expose the exact same API, and if they don't, the node degrades to a soft cache cleanup rather than raising. That's a small thing that matters: a VRAM barrier that can break a working graph is worse than no barrier.
The status output is the receipt: "SAM stage complete. Model/cache cleanup executed before Klein stage."
Where it goes
Planner → segmentation branches → this node → the crop/Klein/stitch side of the graph. Put it after the last mask producer and before the first crop node, feeding it your six sector masks and the image. Everything downstream will reload what it needs automatically; ComfyUI re-loads on demand, which is exactly why unloading is safe here.
Two caveats from the wider field: unloading costs a reload, and a reload is real wall time on a big edit model. If your card comfortably fits the whole stack - a 24GB+ card holding an fp8 Klein and a small VLM - turning the unload off and keeping this node purely as an ordering barrier is the faster path. And if you're fighting OOM, unloading is a fix for sequencing pressure, not for a model that simply doesn't fit. Concepts-side, the honest hierarchy is: quantize first (GGUF or fp8), then manage order, then throw hardware at it.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/axior/ComfyUI-DOGMA-Nodes
Or Manager → DOGMA Nodes, restart. No dependencies to install, no models bundled. The README on GitHub doesn't mention this node - like most of the semantic family, it's undocumented outside the source.
Common issues
It runs before the masks are ready. Only possible if you wired fewer than six mask inputs; the barrier is the wiring, and dropping inputs drops the guarantee. If you run fewer sectors, feed zeros into the unused slots (DOGMACategoryMaskGate is a clean way to produce them).
No visible speedup, slight slowdown. Expected on a card that already fits everything. Set unload_models false and use it as an ordering marker only.
Unloading mid-run and something reloads immediately anyway. That's ComfyUI being correct - a downstream node needs a model, so it comes back at the next stage. The barrier helps when the stages are genuinely sequential, not when two branches interleave.
Nothing in status. The status string is static text, not a report of what was freed. Use your console/GPU tooling if you want the actual numbers.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask_1 | MASK | — | |
| mask_2 | MASK | — | |
| mask_3 | MASK | — | |
| mask_4 | MASK | — | |
| mask_5 | MASK | — | |
| mask_6 | MASK | — | |
| unload_models | BOOLEAN | true | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| status | STRING | — |