Nodes/comfyui-zimage-sdnq/ZImage SDNQ Clear Caches
ComfyUI Node

ZImage SDNQ Clear Caches

The VRAM reset button for Z-Image SDNQ, disguised as a node

By GeneralShan·Created 8 months ago·Updated 6 months ago· 1
ZImage SDNQ Clear Caches
  • image
  • pipeline
  • control_pipeline
  • image
clear_torch_cachetrue
clear_pipeline_cachefalse
clear_control_pipeline_cachefalse

This is the pack's memory-management node, and once you understand why it exists, you'll stop being annoyed that it exists. comfyui-zimage-sdnq keeps loaded pipelines alive in a session cache so you can re-queue without re-loading the whole model - that's a genuinely good thing for iteration speed. But a cached pipeline holds VRAM, and on a 12GB card with an SDNQ-quantized Z-Image plus a ControlNet loaded, VRAM is exactly what you run out of. ZImageSDNQClearCaches is the manual release valve: it drops the cached pipelines and flushes torch's memory pool, right in the middle of your graph.

What it actually does

Three independent switches:

  • clear_torch_cache (default true) - runs gc.collect() then soft_empty_cache(), or the direct empty_cache() equivalents if that's not available. This is the "I'm at 11.9GB and one more step will OOM" button. It releases torch's cached-but-unused blocks back to the system.
  • clear_pipeline_cache (default false) - drops the loaded base Z-Image pipeline from the session cache entirely. The next time a loader runs, it rebuilds from scratch. This is for when the pipeline itself has gone stale, or you're about to do something big and want the memory back now.
  • clear_control_pipeline_cache (default false) - same thing, for the control pipeline (the one loaded by ZImageSDNQControlPipelineLoader).

The optional pipeline and control_pipeline inputs exist so you can wire the node into the pipeline graph and prove the dependency - but the node ignores their contents entirely and passes through the required image input untouched. That quirk is worth spelling out, because it's the one thing people find confusing: this node requires an image input and emits the same image back out, doing nothing to it. The image is a pass-through so the node has a legal place in your graph. The work happens on caches, not pixels.

When you'd actually use it

Honestly? Most people don't need it most of the time. The cache is the feature, not the problem. You reach for this node in two situations:

  1. Running a heavy control workflow after a base workflow - remember the pack keeps only one base and one control pipeline cached. If you keep swapping between text-to-image and a Canny control graph in one session, the stale pipeline sits in VRAM doing nothing. A ClearCaches node at the start of the heavy graph is an easy way to force a clean slate.
  2. OOMs mid-queue on 8–12GB cards - SDNQ is supposed to let you run Z-Image on 4GB cards, and it mostly does, but a burst of num_images or a big control batch can still spike. Sticking this node before the sampler and leaving only clear_torch_cache on is a cheap insurance policy.

Install and caveats

Installs with the pack: ComfyUI Manager (search "Z-Image SDNQ") or git clone https://github.com/GeneralShan/comfyui-zimage-sdnq into custom_nodes, then restart. No extra dependencies.

The one real warning: if you enable clear_pipeline_cache or clear_control_pipeline_cache, you're throwing away the whole loaded model, and the next queue will spend 30–60 seconds reloading it. That's the point when you want it, and a footgun when you've left it on. For a daily-driver workflow, leave the pipeline switches off and only let clear_torch_cache run - it's fast, safe, and usually all you need.

CategoryZImage SDNQ/Utilities

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
clear_torch_cacheBOOLEANtrue
clear_pipeline_cacheBOOLEANfalse
clear_control_pipeline_cacheBOOLEANfalse
pipelineoptZIMAGE_PIPELINE
control_pipelineoptZIMAGE_CONTROL_PIPELINE

Outputs (1)

NameTypeDescription
imageIMAGE