diffusion-sampler -- integrating a learned field

Image generators show a "steps" number, and it is not a quality setting the model was trained with. The generator is following a path from random speckle to a finished picture, and the step count is simply how many stops you make along the way — fewer, longer jumps cut the corners of the path. What that costs is subtle: the result does not look broken, it lands slightly off, which in a real picture means fine texture that is not quite right rather than an obvious mistake. Past a point more stops buy nothing. A second choice hides in the same loop: sprinkling fresh randomness at each stop pulls a drifting result back on track, but it no longer heads for one fixed destination — add stops to the steady version and it settles onto a single answer, while this one keeps landing somewhere slightly different.

Interactive page: what a diffusion / flow-matching model does at inference time -- integrating a learned velocity field from a noise sample to a data sample -- and why the step count is a discretisation dial, not a quality setting. Anchor: generative sampling (diffusion / flow matching).

Scope. This page is the sampler only. The training objective and the noising schedule are the diffusion-noise page; conditioning and guidance scale are the guidance page.

What is on screen

A 2D toy distribution -- two moons, as an equal-weight mixture of narrow Gaussians -- with:

ElementWhat it is
faint green dotsthe data manifold (the mixture's modes)
violet arrowsthe velocity field u(x, t) at the current t, so the field visibly turns as the run proceeds
solid blue linesthe trajectory each particle actually walks, revealed step by step
hollow circleseach particle's start (its noise sample) -- drag one
dashed gold curvethe conditional path x_t = α(t)·x_end + σ(t)·x_start -- what the interpolant toggle straightens
right-hand panelsthe same seed and the same field integrated at 4 / 10 / 50 steps

Nothing is a neural network and nothing is faked. For a Gaussian mixture the probability-flow velocity is closed form, so every arrow, every particle update and every number in the readout is arithmetic the page just did.

The math it runs

With the interpolant x_t = α(t)·x_data + σ(t)·x_noise, t: 0 → 1:

diffusion path α = sin(½πt) σ = cos(½πt) curved, schedule-shaped
rectified flow α = t σ = 1 − t straight conditional path

E[x_data | x_t = x] = (1 − c·α)·M(x) + c·x c = α·var / τ², τ² = α²var + σ²
u(x, t) = α'·E1 + (σ'/σ)·(x − α·E1) the probability-flow velocity
∇ log p_t(x) = −(x − α·E1) / σ² the score

ODE step x ← x + u·h h = 1/N
SDE step x ← x + (u + ½g²·∇log p_t)·h + g·√h·z g = churn·σ

M(x) is the responsibility-weighted mean of the mixture modes -- a softmax over squared distances, which is why the field points at whichever moon you are nearest and blends between them where you are not.

The SDE drift carries the ½g²·score correction, so both samplers have the same marginals. The toggle therefore isolates exactly one variable: whether noise is re-injected along the way.

The trade the page is built to show

Three measured numbers, recomputed live:

MetricMeaning
offmean distance from an endpoint to the nearest data mode -- how far off the manifold the run landed. Its floor is the data's own mode width (0.06), not zero
Δrefmean distance from an endpoint to the same particle's endpoint under a 200-step deterministic reference
path/chordmean trajectory length ÷ start-to-end distance; 1.00 is a straight line

Read across the 4 / 10 / 50 ladder:

On "straighter ⇒ fewer steps"

The page separates two things the folk version of this claim conflates:

  1. The conditional path (a specific noise sample to a specific datum) is exactly a straight segment under the linear interpolant. That is the dashed ghost, and it is a definition, not a result.
  2. The marginal trajectory the sampler actually integrates is a different object. On this toy, switching to the linear interpolant does not straighten it -- the page prints path/chord for both so you can check rather than take it on faith. Genuine straightening of the marginal is what reflow buys.

And whether straightness is what does the work at all is disputed: <https://arxiv.org/abs/2410.07303> argues it is not.

Interactions

InteractionHow
step the integrationtransport play / pause / step / scrub; auto-plays and loops
re-integrate under your handdrag a hollow start marker -- that particle's whole trajectory, and its reference endpoint, recompute live
inspect the fieldhover an arrow for u, E[data|x], the score, and how far one step of h moves; hover a particle for its position and the full update arithmetic; hover a ladder panel for its metrics
change the pathinterpolant select: diffusion (curved) vs rectified flow (straight conditional path) -- same field formula, same integrator, same particles
change the samplerODE / SDE toggle + churn slider (g = churn·σ)
resize the problemstep count, particle count, seed

URL hooks

Every control is restorable from the query string, so one URL replays one exact run -- the randomness is seeded per (seed, particle, step).

?step=3 pause the transport at integration step 3
?steps=50&path=linear 50 steps on the rectified-flow interpolant
?sde=1&churn=1.2 stochastic sampler at a given noise level
?seed=7&P=16 which noise samples, and how many
?drag=0,1.4,-1.1 move particle 0's start (headless stand-in for a drag)
?hover=300,220 place the cursor (headless stand-in for a hover)
?guide=0 hide the dashed conditional paths

Sources