KSamplerAdvanced (cacheable)
KSamplerAdvanced (cacheable) — staged sampling that doesn't redo what it already did
- model
- positive
- negative
- latent_image
- LATENT
KSamplerAdvanced (cacheable) is the advanced sampler from the komojini pack with a memory: it caches its last few sampling runs, so identical inputs return the stored latent instead of resampling. It's the more powerful sibling of the pack's KSampler (cacheable), with the full KSamplerAdvanced input set - start_at_step/end_at_step control, add_noise toggling, and return_with_leftover_noise - plus the same four-slot LRU cache wrapping.
Why advanced, and why cache it? KSamplerAdvanced is the sampler you use when a generation happens in stages: img2img, hi-res passes, inpainting, or step-skipping workflows where one sampler hands a partial latent to the next. In a step-by-step pipeline - exactly the kind the pack's FlowBuilder encourages - you re-run the graph over and over while tweaking one stage. The other stages, with identical inputs, would normally resample pointlessly. This node makes those unchanged stages return their cached result instantly.
How it works. The class wraps ComfyUI's internal common_ksampler in an functools.lru_cache (max size 4). Every input - model, noise seed, steps, cfg, sampler, scheduler, positive, negative, latent, start/end step, noise and leftover-noise settings - is flattened into a hashable key, so a repeat call with the same inputs is a cache hit. Four most-recent results are kept; older ones evict. Change anything real and it's a miss, which is what you want.
The inputs that matter. Same shape as core KSamplerAdvanced:
start_at_step/end_at_step- which slice of the denoising schedule this pass handles.end_at_step10000 means "to the end"; a common trick is sampling 0→N in one pass and N→end in another.add_noise(enable/disable) - disable when a pass starts from an already-noisy latent (e.g. a second stage).noise_seed,steps,cfg,sampler_name,scheduler- the usual knobs.return_with_leftover_noise(disable/enable) - whether the output latent keeps residual noise for the next stage (the classic KSamplerAdvanced toggle for chaining passes).
Output is a single LATENT - the denoised latent from this pass, ready to feed the next stage or a VAE decode.
Where people get burned. The cache is four entries, process-lifetime, and keyed on the actual input objects. Swap in a new checkpoint and you get a fresh object → miss → resample (correct). But keep the same inputs and deliberately tweak a hidden upstream that doesn't flow into the sampler, and you may get a cached result you thought would reflect the change - the cache can't see what you changed if it isn't an input. Also: this is a Feb-2024 pack, so while the Python-side caching is simple and sturdy, don't expect any maintenance if ComfyUI's internals shift. If you need this pattern in a maintained pack, several modern packs offer cacheable/unchanged-skip samplers; this one is the original from the komojini era.
Install. One pack:
ComfyUI Manager → search "komojini-comfyui-nodes" → Install → restart
or cd ComfyUI/custom_nodes && git clone https://github.com/komojini/komojini-comfyui-nodes. No model downloads beyond your usual checkpoints.
Inputs (13)
| 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 | 34 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +28 | |
| scheduler | COMBO | 9 options: normal, karras, exponential, sgm_uniform, simple, ddim_uniform, +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 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |