Nodes/XB_ToolBox/XB-BOX - 🧹 显存清理
ComfyUI Node

XB-BOX - 🧹 显存清理

The manual 'clear VRAM' button you can drop anywhere in a graph

By wjluoxiao·Created 5 months ago·Updated 6 days ago· 302
XB-BOX - 🧹 显存清理
  • anything
  • pass-through
mode双次缓存清理

Somewhere between "finish the prompt" and "start the sampler," your VRAM is full of yesterday's garbage - PyTorch cache fragments, dead tensors, a model that was unloaded but not released. XB_ROCmMemCleaner is a node whose only job is to run a memory sweep at the point in the graph where you place it, then pass its input through untouched. It's the manual, on-demand version of the cleanup that the pack's "原版优化" samplers do automatically.

It belongs in the "pre-generation clearing" slot the pack's pitch calls essential: put it right before your sampler or VAE decode, and every run starts from a clean slate. On AMD/ROCm especially, where the caching allocator leaves more fragmentation behind than CUDA does, this kind of explicit hygiene is how people stop the random OOMs that make no sense.

How it works

The node reads your GPU stats before and after, then runs the sweep:

  • 单次缓存清理 (single cache clear) - soft_empty_cache() + empty_cache().
  • 双次缓存清理 (double cache clear) - the same, twice, with a gc.collect() in between. This is the default, and it's the "nuclear-lite" the author recommends - first pass flushes the obvious garbage, second pass catches what got released in between.
  • 卸载显存模型 (unload GPU models) - pushes resident models back to system RAM on top of the cache clears.

It prints a before/after summary to your console, including the GPU name, VRAM size, and how much was freed in GB. That freed-memory number is genuinely useful - it's your proof the sweep did something, and it's a great diagnostic for "how much garbage was actually in here."

Inputs & output

  • mode - the three levels above.
  • anything (optional, any type) - wire any node's output here to make the cleaner execute at the right moment.
  • pass-through (*) - whatever you wired in comes out the other side, byte-for-byte.

The pass-through is what makes placement free: you don't sacrifice a wire to insert the cleaner. Hang it off any output in the graph at the point where you want the sweep to happen; the value flows through unharmed.

Where it fits

Three classic placements:

  1. Before a heavy sampler - after the VAE encode and conditioning, when the graph is about to demand the most.
  2. Before tiled VAE decode - the decode is where OOMs actually land; a clean slate here is the difference between a run and a crash.
  3. As a manual trigger - wire it to a node you can re-run alone; every re-run sweeps memory.

Don't put it on every node - the sweep costs real time (double cache clear + gc on a loaded graph is not free). One or two well-placed cleaners beat five scattered ones.

Install & notes

cd ComfyUI/custom_nodes
git clone https://github.com/WJLUOXIAO/XB_ToolBox.git
# or: ComfyUI Manager → "XB_ToolBox"

No deps. One honest caveat: 卸载显存模型 unloads all resident models, which means the model you're about to sample with gets pushed to RAM and then has to reload - that's the "trading time for space" trade, and it's slower than the cache-only modes. Use it when you're truly at the wall. And the memory-reporting relies on GPU stats being readable; if the freed numbers print as zero, the sensors aren't being read on your setup - the sweep itself still ran.

CategoryXB_ToolBox/ROCm

Inputs (2)

NameTypeDefaultDescription
modeCOMBO双次缓存清理3 options: 单次缓存清理, 双次缓存清理, 卸载显存模型
anythingopt*

Outputs (1)

NameTypeDescription
pass-through*