Diffusion caching

last edited

Diffusion caching is a training-free way to speed up image and video generation by reusing intermediate features from one denoising step in the next. Adjacent steps of a diffusion model change little, so part of the network can be skipped at a small cost in fidelity.

deep features cachedshallow layers rerun every step

Origins

DeepCache appeared in December 2023. It caches deep U-Net features and recomputes only shallow layers. The paper reports 2.3x on Stable Diffusion with a 0.05 CLIP drop.

FORA and Learning-to-Cache brought the idea to transformers in mid-2024. FORA reuses attention and MLP outputs. Learning-to-Cache trains a small router that picks layers to skip.

How the reuse works

thresholdfull stepskipped steps reuse the cache

Early methods ran the full model every N steps and reused the cached result in between. Later methods pick steps from a cheap signal.

TeaCache tracks the change in timestep-modulated inputs and recomputes once it passes a threshold, with up to 4.41x claimed. MagCache uses a magnitude law for successive residuals and needs one calibration sample. First Block Cache runs only the first transformer block and compares its residual. TaylorSeer forecasts skipped features with a polynomial instead of copying old ones, reaching 4.99x on FLUX with little loss.

Tools and measured speedups

no cache26.36 sthreshold 0.0817.01 sthreshold 0.1213.78 swall time, same image, same steps

The Diffusers caching guide puts several methods behind one enable_cache call, with a default threshold of 0.05. On FLUX, ParaAttention cuts wall time from 26.36 s to 13.78 s. That run used threshold 0.12.

ComfyUI-TeaCache and ComfyUI-MagCache add nodes to ComfyUI. Gains stack with quantization.

Trade-offs and the LLM contrast

kv cache: one row per tokendiffusion cache: stale, then refreshed

Higher thresholds skip more steps and blur fine detail or motion. Thresholds are model specific, cached tensors cost memory, and few-step distilled models leave little to skip, as in Wan 2.2 Lightning.

A language model's KV cache is exact by contrast. Reused diffusion features are stale by design, so every skipped step trades a little fidelity for speed.

Sources