XB-BOX - 高级采样器(原版优化)
KSamplerAdvanced, with a pre-run VRAM cleanup bolted on
- model
- positive
- negative
- latent_image
- LATENT
Same story as its sibling XB_KSampler, one rung up the ladder: this is ComfyUI's stock KSamplerAdvanced, wrapped word-for-word, with a cleanup dropdown injected before the sampling pass. If you already reach for KSamplerAdvanced - because you're doing multi-stage sampling, inpainting with a start/end step window, or a refiner pass - this is that node with a low-VRAM convenience knob.
Why bother? On tight GPUs the moments between passes are where OOMs actually strike: a big VAE encode for inpainting just happened, PyTorch's cache is full of freed-but-still-reserved blobs, and the next sampler stage tries to allocate fresh and dies. This node lets you clear the cache (or unload models entirely) right before the stage runs, without adding a separate VRAM-cleaner node to the graph.
The added input
The cleanup dropdown is the only difference from stock, and it has the same four levels as the plain KSampler wrapper:
- 不做任何清理 (no cleanup) - stock behavior.
- 单次缓存清理 (single cache cleanup) - soft + hard
empty_cache(). Cheap, usually enough. - 卸载显存模型 (unload VRAM models) - adds
unload_all_models(), models go to RAM until the sampler needs them. - 卸载全量模型 (full cleanup) - everything plus
cleanup_models(),gc.collect(), IPC collect. Slowest, most aggressive.
The inputs you actually use
Everything else matches KSamplerAdvanced exactly, and the ones that matter for the classic multi-stage workflow are:
- start_at_step / end_at_step - the window of the denoise schedule this stage runs. First stage 0→20 full denoise, second stage 20→25 at lower denoise for refinement. Getting these right is the whole skill of staged sampling.
- add_noise -
enablefor the first stage,disablewhen you're continuing from an existing latent where noise is already there. - return_with_leftover_noise -
enableon the last stage when the next stage wants partially-noised latents (the img2img/refiner handoff);disablefor a clean output. - noise_seed - the seed for this stage's noise, separate from the shared seed on the model.
Output is a single LATENT, same as stock. Same sampler/scheduler theory applies - on flow-matching models, euler-family + conservative schedulers; Karras is a DDPM-era habit that doesn't translate.
Installing it
Part of XB_ToolBox - ComfyUI Manager search XB_ToolBox, or:
cd ComfyUI/custom_nodes
git clone https://github.com/WJLUOXIAO/XB_ToolBox.git
then restart. No extra pip dependencies for this one; it's pure ComfyUI core.
The trap to avoid
The cleanup runs before sampling, which means a full unload reloads your model right when you least want the wait - in the middle of a long multi-stage chain, every stage paying a model reload is a recipe for turning a 2-minute generation into 6. Set it to single cache cleanup by default and only escalate when you're actually seeing OOMs. And don't mistake this for a different sampler: if you came here hoping for better sampling quality, you'll find the stock algorithm behind the dropdown. Its value is memory hygiene, not image quality.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| add_noise | COMBO | 2 options: enable, disable | |
| noise_seed | INT | 00–18446744073709550000 | — |
| steps | INT | 201–10000 | — |
| cfg | FLOAT | 8.00–100 | — |
| sampler_name | 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_image | LATENT | — | |
| start_at_step | INT | 00–10000 | — |
| end_at_step | INT | 100000–10000 | — |
| return_with_leftover_noise | COMBO | 2 options: disable, enable | |
| cleanup | COMBO | 不做任何清理 | 4 options: 不做任何清理, 单次缓存清理, 卸载显存模型, 卸载全量模型 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |