Diffusion and flow: learn a path from noise
An interactive field guide
A generative model can produce an image through many small corrections. The training target determines what each correction means.
Before this article: Probability and tensors · Autoencoders
What was already possible
Section titled “What was already possible”An AE maps one input to one compact code, then decodes it. A probabilistic generator must also describe uncertainty: many images can satisfy the same class or text. Denoising models learn local predictions at different noise levels rather than mapping a single code directly to final pixels.
What changes, and why
Section titled “What changes, and why”DDPM adds Gaussian noise through a forward process and learns reverse transitions. Flow matching instead regresses a velocity field along chosen probability paths. They are related families, but their targets and solvers are not interchangeable. Here we use a straight interpolation as a fully computable flow example.
Read from left to right. Select a module to connect its role, tensor shape, and calculation. Snippets are teaching pseudocode. Sources provide the paper method or audited implementation.
Construct a noisy pair
The target is known because training has the clean image.
xt = (1-t)*x + t*noise
target = noise - xLearn a vector field
Condition c can be a class, text, or a reconstruction code.
prediction = model(xt, t, condition)
loss = mean((prediction-target)**2)Integrate backwards
Use decreasing times for this convention.
state = noise
for t, t_next in schedule:
state += (t_next-t)*model(state,t,condition)Work through the mechanism
Section titled “Work through the mechanism”Set clean value x=2 and noise ε=−1. Our convention is t=0 for data and t=1 for noise. Then xₜ=(1−t)x+tε=2−3t and target velocity ε−x=−3. To generate, move time backwards: x at the next time equals the current x plus a negative time step multiplied by predicted velocity.
At t=0.5, xₜ=0.5. With five remaining Euler steps, Δt=−0.1, so the next value is 0.8. The demo knows the true constant velocity. A trained network sees noisy input and conditions, not the clean endpoint; its estimate can be wrong. More steps therefore have no quality benefit in this exact straight-line example.
Change a parameter, inspect the computed values, then compare this small example with the model described above.
Analytical teaching model · controls change the example, not a trained research model.
The straight path has known velocity. A learned model must estimate velocity; this demo does not measure its error.
| Quantity | Value |
|---|---|
| t | 0.500 |
| x_t = (1 − t) × 2 + t × (−1) | 0.500 |
| v = ε − x | -3 |
| Δt = −t / steps | -0.100 |
| One reverse update | 0.800 |
Training is not sampling
Section titled “Training is not sampling”Training samples x, ε and t, constructs xₜ, and regresses the known target with squared error. It need not run the complete sampling trajectory for each training example. Sampling starts from noise and repeatedly calls the learned network. Count these calls as number of function evaluations, or NFE. A stochastic diffusion sampler and a deterministic ODE solver require different update rules.
What this does not establish
Section titled “What this does not establish”A model may predict noise, clean data, velocity, or a score. Conversion needs the matching schedule and time convention. Copying a velocity target from one implementation and an update sign from another can reverse the process. In a reconstruction decoder, the compact image code is an extra condition; in unconditional generation there is no observed input image.
Open the derivation
Differentiate the constructed straight path with respect to t while holding the sampled endpoints fixed. This gives the supervised velocity target. A learned field averages the conditional targets compatible with its input and conditions.
Euler approximates an integral over a short interval by the current velocity times the interval. With decreasing time, Δt is negative. For the constant-velocity example, the approximation is exact; in a learned nonlinear field it generally is not.
Check your understanding
Section titled “Check your understanding”Why can training use one sampled time while generation uses many steps?
The target velocity is known for a constructed training pair at any sampled time. At generation, the unknown data endpoint must be reached by integrating the learned field.
Sources and next steps
Section titled “Sources and next steps”Diagrams and snippets are teaching reconstructions. Paper reports, implementation observations, and analytical examples are distinguished. No research model runs in this page.