XB-BOX - 采样器(原版优化)
KSampler, with a memory-cleanup button welded to the front
- model
- positive
- negative
- latent
- LATENT
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 portsampler(the legacy alias remaps it to the officialsampler_nameinternally). - 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 pluscleanup_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.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| seed | INT | 00–18446744073709550000 | — |
| steps | INT | 201–10000 | — |
| cfg | FLOAT | 8.00–100 | — |
| sampler | COMBO | 44 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +38 | |
| scheduler | COMBO | 9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3 | |
| positive | CONDITIONING | — | |
| negative | CONDITIONING | — | |
| latent | LATENT | — | |
| denoise | FLOAT | 1.000–1 | — |
| cleanup | COMBO | 不做任何清理 | 4 options: 不做任何清理, 单次缓存清理, 卸载显存模型, 卸载全量模型 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |