caching.md

April 27, 2026 ยท View on GitHub

Caching

Caching methods accelerate diffusion inference by reusing intermediate computations when changes between steps are small.

Cache Modes

ModeTargetDescription
ucacheUNET modelsCondition-level caching with error tracking
easycacheDiT modelsCondition-level cache
dbcacheDiT modelsBlock-level L1 residual threshold
taylorseerDiT modelsTaylor series approximation
cache-ditDiT modelsCombined DBCache + TaylorSeer
spectrumUNET and DiT modelsChebyshev + Taylor output forecasting

UCache (UNET Models)

UCache caches the residual difference (output - input) and reuses it when input changes are below threshold.

sd-cli -m model.safetensors -p "a cat" --cache-mode ucache --cache-option "threshold=1.5"

Parameters

ParameterDescriptionDefault
thresholdError threshold for reuse decision1.0
startStart caching at this percent of steps0.15
endStop caching at this percent of steps0.95
decayError decay rate (0-1)1.0
relativeScale threshold by output norm (0/1)1
resetReset error after computing (0/1)1

Reset Parameter

The reset parameter controls error accumulation behavior:

  • reset=1 (default): Resets accumulated error after each computed step. More aggressive caching, works well with most samplers.
  • reset=0: Keeps error accumulated. More conservative, recommended for euler_a sampler.

EasyCache (DiT Models)

Condition-level caching for DiT models. Caches and reuses outputs when input changes are below threshold.

--cache-mode easycache --cache-option "threshold=0.3"

Parameters

ParameterDescriptionDefault
thresholdInput change threshold for reuse0.2
startStart caching at this percent of steps0.15
endStop caching at this percent of steps0.95

Cache-DIT (DiT Models)

For DiT models like FLUX and QWEN, use block-level caching modes.

DBCache

Caches blocks based on L1 residual difference threshold:

--cache-mode dbcache --cache-option "threshold=0.25,warmup=4"

TaylorSeer

Uses Taylor series approximation to predict block outputs:

--cache-mode taylorseer

Cache-DIT (Combined)

Combines DBCache and TaylorSeer:

--cache-mode cache-dit

Parameters

ParameterDescriptionDefault
FnFront blocks to always compute8
BnBack blocks to always compute0
thresholdL1 residual difference threshold0.08
warmupSteps before caching starts8

SCM Options

Steps Computation Mask controls which steps can be cached:

--scm-mask "1,1,1,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1"

Mask values: 1 = compute, 0 = can cache.

PolicyDescription
dynamicCheck threshold before caching
staticAlways cache on cacheable steps
--scm-policy dynamic

Spectrum (UNET and DiT Models)

Spectrum uses Chebyshev polynomial fitting blended with Taylor extrapolation to predict denoised outputs, skipping entire forward passes. Based on the paper Spectrum: Adaptive Spectral Feature Forecasting for Efficient Diffusion Sampling.

sd-cli -m model.safetensors -p "a cat" --cache-mode spectrum

Parameters

ParameterDescriptionDefault
wChebyshev vs Taylor blend weight (0=Taylor, 1=Chebyshev)0.40
mChebyshev polynomial degree3
lamRidge regression regularization1.0
windowInitial window size (compute every N steps)2
flexWindow growth per computed step after warmup0.50
warmupSteps to always compute before caching starts4
stopStop caching at this fraction of total steps0.9

Performance Tips

  • Start with default thresholds and adjust based on output quality
  • Lower threshold = better quality, less speedup
  • Higher threshold = more speedup, potential quality loss
  • More steps generally means more caching opportunities