Nodes/komojini-comfyui-nodes/KSampler (cacheable)
ComfyUI Node

KSampler (cacheable)

Same KSampler, minus the wasted GPU time — the cacheable sampler

By komojini·Created 3 years ago·Updated 2 years ago· 77
KSampler (cacheable)
  • model
  • positive
  • negative
  • latent_image
  • LATENT
seed0
steps20
cfg8.0
sampler_name
scheduler
denoise1.00

KSampler (cacheable) is a plain, boring drop-in replacement for the core KSampler - same inputs, same LATENT output - except it remembers what it just sampled. Run the same sampling pass twice with identical inputs and the second run hands you the cached latent instead of chewing through the model again. That's the entire trick, and it's more useful than it sounds.

This node comes from komojini-comfyui-nodes, a 2024-era pack built around generating video "step by step": you build a big workflow, run only the part you changed, and keep the expensive bits from re-running. The cacheable sampler is that philosophy applied to the sampler itself. When you're iterating on a prompt or a denoise value in an img2img/video pipeline, the steps that didn't change don't need to happen twice.

How it works. The class subclasses ComfyUI's own KSampler and wraps its sample() in an functools.lru_cache with a max size of 4. Every input - model, seed, steps, cfg, sampler, scheduler, positive, negative, latent, denoise - gets flattened into a hashable key, so an identical set of inputs is an automatic cache hit. The cache holds the four most recent results and evicts oldest-first, so it's bounded memory, not an infinite hoard. Change anything real (a new seed, a different latent, a freshly-loaded checkpoint) and it's a miss - which is the correct behavior, because that's when you want it to sample again.

The inputs you'll actually touch. steps (default 20) and cfg (default 8) do what they always do; denoise (default 1.0) is the one to lower when you're doing img2img or a second pass and want to keep the source structure. seed (default 0) and the sampler_name/scheduler dropdowns are the usual 34-sampler, 9-scheduler lists. Wire model, positive, negative, and latent_image in, and take the single LATENT output wherever you'd have taken the core KSampler's.

Install. It's part of the komojini pack, so one install covers all its nodes:

ComfyUI Manager → Custom Nodes → search "komojini-comfyui-nodes" → Install → restart

or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/komojini/komojini-comfyui-nodes

The pack's requirements.txt pins pytube==15.0.0 and pulls opencv-python, numpy, pillow, psutil and gputil. No model files to download - it uses whatever checkpoint you already load.

Where people get burned. The cache is process-lifetime and only four entries deep, so if you're juggling several workflows in one session you can evict the result you were hoping to reuse - that's the LRU tradeoff, not a bug. And remember this is a Feb-2024 pack. It predates ComfyUI's 2025 Nodes 2.0 frontend rewrite, which has already broken better-maintained packs like rgthree; if the node fails to appear or errors on a current ComfyUI, the era is the cause, not your setup. For a caching sampler with a smaller surface, the standalone KSampler (cacheable) in other maintained packs is the safer long-term bet - but if you're already running this pack's FlowBuilder workflow, this node is the one its author intended you to use.

Categorysampling

Inputs (10)

NameTypeDefaultDescription
modelMODELThe model used for denoising the input latent.
seedINT00–18446744073709550000The random seed used for creating the noise.
stepsINT201–10000The number of steps used in the denoising process.
cfgFLOAT8.00–100The Classifier-Free Guidance scale balances creativity and adherence to the prompt. Higher values result in images more closely matching the prompt however too high values will negatively impact quality.
sampler_nameCOMBOThe algorithm used when sampling, this can affect the quality, speed, and style of the generated output.
schedulerCOMBOThe scheduler controls how noise is gradually removed to form the image.
positiveCONDITIONINGThe conditioning describing the attributes you want to include in the image.
negativeCONDITIONINGThe conditioning describing the attributes you want to exclude from the image.
latent_imageLATENTThe latent image to denoise.
denoiseFLOAT1.000–1The amount of denoising applied, lower values will maintain the structure of the initial image allowing for image to image sampling.

Outputs (1)

NameTypeDescription
LATENTLATENTThe denoised latent.