Nodes/XB_ToolBox/XB-BOX - 采样器(原版优化)
ComfyUI Node

XB-BOX - 采样器(原版优化)

KSampler, with a memory-cleanup button welded to the front

By wjluoxiao·Created 5 months ago·Updated 6 days ago· 302
XB-BOX - 采样器(原版优化)
  • model
  • positive
  • negative
  • latent
  • LATENT
seed0
steps20
cfg8.0
sampler
scheduler
denoise1.00
cleanup不做任何清理

This is ComfyUI's stock KSampler, faithfully wrapped, with exactly one addition: a cleanup dropdown that runs a memory-clearing pass before sampling starts. That's the whole trick, and it's more useful than it sounds.

The name says ROCm, and the pack's whole identity is AMD-native - but read the source and you'll see the real story. This node is a legacy alias (the "原版优化"/original-optimized series) that just calls nodes.KSampler().sample() with your parameters. It does not implement its own sampling algorithm. The only thing it adds is the cleanup scheduler: before the official sampler runs, it optionally empties PyTorch's cache, unloads models, or goes nuclear with gc.collect() and a full model purge. On AMD cards, where memory fragmentation and PyTorch's caching allocator misbehave worse than on CUDA, that "clean the slate before a big run" step is the difference between a generation and an OOM.

The inputs that matter

Everything you already know from KSampler, plus one:

  • model, positive, negative, latent - wire as usual.
  • seed, steps, cfg, denoise - identical semantics to stock KSampler.
  • sampler / scheduler - 44 samplers and 9 schedulers straight from comfy.samplers; all the usual suspects (euler, dpmpp_2m, etc.). The brief's schema calls the port sampler (the legacy alias remaps it to the official sampler_name internally).
  • cleanup - the reason this node exists. Four levels:
    • 不做任何清理 (no cleanup) - pure KSampler passthrough.
    • 单次缓存清理 (single cache clear) - soft_empty_cache() + torch.cuda.empty_cache(). Cheap, usually enough.
    • 卸载显存模型 (unload GPU models) - also pushes resident models back to RAM.
    • 卸载全量模型 (unload everything) - cache clears plus cleanup_models() + gc.collect() + ipc_collect(). The maximum-force option, and the slowest.

Output is LATENT, same as stock.

How it works under the hood

The wrapper is deliberately dumb, and that's a feature. It copies the official INPUT_TYPES, injects the cleanup widget, then when you run it: pops the cleanup level, calls _execute_cleanup(), and hands your kwargs straight to the official sampler. There's no custom math to go stale when ComfyUI updates - the official node does the work, this node just sweeps the floor first.

That design philosophy is worth knowing because the pack has older ROCm nodes that did real custom low-level patching. This "原版优化" series is the newer, saner direction: trust the official implementation, add the memory hygiene around it.

Install & usage

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

No deps. Practical advice: start with 不做任何清理 - if your graph runs fine, the dropdown is just extra waiting. When you hit an OOM or a generation that dies right after a big VAE encode, bump to 单次缓存清理, then 卸载显存模型. Reserve 卸载全量模型 for the "I just watched it OOM twice, please" moments - it's fast enough but every run pays for it.

When to use it vs. the stock node

Honest answer: if you're on NVIDIA with a well-behaved workflow, you don't need this - stock KSampler is the same sampler with no cleanup tax. On AMD, or in heavy video graphs where cache fragmentation is real, the per-run cleanup is a genuine reliability win. And because it's a drop-in (same inputs, same LATENT output), you can swap it in only where you need it.

CategoryXB_ToolBox/原版优化

Inputs (11)

NameTypeDefaultDescription
modelMODEL
seedINT00–18446744073709550000
stepsINT201–10000
cfgFLOAT8.00–100
samplerCOMBO44 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +38
schedulerCOMBO9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3
positiveCONDITIONING
negativeCONDITIONING
latentLATENT
denoiseFLOAT1.000–1
cleanupCOMBO不做任何清理4 options: 不做任何清理, 单次缓存清理, 卸载显存模型, 卸载全量模型

Outputs (1)

NameTypeDescription
LATENTLATENT