Multistep samplers and state caching
Preserve trajectory-specific solver history and distinguish exact reusable conditioning from approximate denoiser activation reuse.
On this page
The question for today
What you’ll understand
- Explain how a multistep method depends on previous field evaluations.
- Identify changes that invalidate a trajectory history or cached prediction.
- Separate capacity and hit-rate evidence from semantic cache validity.
A multistep sampler saves evaluations by using information from earlier positions on the same trajectory. That history is numerical state, not a generic cache indexed only by prompt or loop count. Reusing another request’s field values or continuing through an unsupported schedule change can corrupt the integration while producing perfectly shaped tensors. Serving needs explicit ownership and invalidation for each kind of reusable state.
History belongs to a particular equation and trajectory
A classical two-step Adams–Bashforth update illustrates the dependency: it combines the current field value with a previous one under a constant-step formula. Those evaluations must belong to the intended trajectory, coordinate spacing, and field. DPM-Solver multistep methods use their own structure-specific coefficients and parameterization; the classical formula is an explanatory comparison, not their implementation. Variable step ratios, startup, and endpoints need the appropriate method rather than blindly reusing constant-step weights.
Changing conditioning, guidance, model weights, adapters, prediction conversion, or schedule can change the field whose history was stored. Some changes can be handled by a derived restart or lower-order transition, but arbitrary reuse has no automatic order guarantee. A pause/resume checkpoint must preserve the actual sample, coordinate, solver history, configuration, and any required random state together. Sharing a mutable scheduler object across interleaved requests without isolating that state can mix histories even when the denoiser itself is safely shared.
Classify cached objects by their real dependencies
Static text-encoder embeddings can be reused when prompt tokens, encoder revision, adapters, relevant preprocessing, precision policy, and other conditioning inputs match. A denoiser output generally also depends on the current latent, noise coordinate, guidance context, and model state. Equal prompt and timestep do not imply equal latent states for two requests. Approximate feature or activation caching across steps deliberately omits some recomputation; it needs a stated error policy and quality evaluation rather than being described as exact memoization.
Diffusers v0.35.1’s DPMSolverMultistepScheduler stores previous model outputs, order-progress state, and a step index, and resets history when setting a new inference schedule. Those fields demonstrate why a request restart must use the intended initialization path. They are implementation details of the pinned version, not a promise that every scheduler is stateful in exactly the same way. Record the actual configuration and supported reset behavior, and use separate request state or a verified grouping mechanism for independent trajectories.
Test invalidation and lifetime before measuring hit rate
Build fixtures that interleave two requests, restart at a new grid, alter guidance midway, change an adapter, and cancel while cached buffers are still referenced. Compare a no-reuse reference at the same numerical settings. Track semantic validation failures alongside hit rate; a cache can achieve perfect hits by returning the wrong tensor. Memory ownership also matters: a retained history entry must not alias a scratch output overwritten by a later denoiser call. Release or recycle storage only after every scheduled user has completed.
The cache instrument measures capacity effects for its declared address stream. Reset, set both C=4 and s=4, predict four misses and thirteen hits after seventeen requests, then Step once. Separately Reset, set both C=2 and s=4, predict seventeen misses after seventeen requests, then Step once. One Step advances the initial sixteen-request stream by one. This fully associative LRU toy has no latent values, conditioning, solver history, or semantic invalidation. Its hit counts cannot establish that a real sampler cache’s keys or ownership rules are correct.
Work it through
A stale previous field changes the update
Use the illustrative constant-step update with x_n=1, h=0.1, current field F_n=−1, and valid previous field F_(n−1)=−0.8. Compare it with an unrelated cached previous value +0.8.
With valid history, the weighted field is 1.5×(−1)−0.5×(−0.8)=−1.1. The increment is −0.11, giving the next state 0.89.
With unrelated history +0.8, the weighted field becomes −1.5−0.4=−1.9. The increment is −0.19 and the next state is 0.81.
The stale entry creates an immediate difference of 0.08 despite matching scalar shape. This generic ODE example demonstrates history dependence, not a numerical error bound or a DPM-Solver coefficient rule.
A history cache is part of the numerical method. Correct identity and invalidation precede any valid performance claim.
The living notebook
Explore the model
Interactive lab · cache
Hits measure reuse, not the validity of a prediction
Reset, set both C=4 and s=4, predict four misses and thirteen hits at seventeen requests, then Step once. Separately Reset, set both C=2 and s=4, predict seventeen misses, then Step once. This modulo-16 LRU model has no denoiser state, history coefficients, cache-key validation, or approximate activation error.
- Hits / requests
- 0 / 16
- Hit rate
- 0%
- Address-stream period
- 16 addresses
A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forMeasure semantic equivalence and ownership separately from hit rate and capacity.
Pause & reason
Check your understanding
Your turn
Try it yourself
For the same illustrative two-step formula, take x_n=2, h=0.2, F_n=−0.5, and F_(n−1)=−0.4. Compute the update under valid constant-step history.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Combine field values before multiplying by h.
Compare with the solution
The weighted field is 1.5×(−0.5)−0.5×(−0.4)=−0.55. The increment is −0.11 and x_(n+1)=1.89. This requires valid history for the stated constant-step ODE method; changing schedule ratios or importing another request’s values requires a different justified treatment.
Keep the idea
Take it with you
- Treat multistep history as owned trajectory state.
- Key exact reuse by all relevant dependencies and label approximate reuse explicitly.
- Validate reset, invalidation, aliasing, and cancellation before interpreting cache hits.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.