Continuous-time diffusion and flow matching
Shrink DDPM's steps to zero and noising becomes an SDE. Its probability-flow ODE samples deterministically and gives exact likelihoods, the reverse-time SDE is DDPM's sampler, and flow matching learns a velocity field directly.
From steps to time
The topic Score matching showed that DDPM's noise predictor is a scaled score, , and that each reverse step moves along that score and adds fresh noise. It ended with a pointer: Song et al. (2021) join the two views in continuous time. This topic takes that limit, infinitely many infinitely small steps, and sees what it buys.
Why should a limit exist at all? DDPM cuts the noising into steps, but the network only ever sees how much noise has been added so far, not how it was cut. So describe the schedule as a rate on and split it into steps:
With this is DDPM's linear schedule, from about to .
The product then turns into an integral. For small , , so is a sum , a Riemann sum. As grows,
Halfway through the process, the discrete product with , and steps is , and , and it settles on a limit. At the end, and , close to DDPM's .
The payoff is practical. A network that depends only on the noise level can drive any discretization of the continuous process: the 1000 training steps, 50 steps, or an adaptive solver. First we need the equation of that process.
The noising SDE
Take one DDPM step with and :
Expand the square root, , and look at the change:
The drift is of order , the noise of order . The square root is forced. One unit of time holds independent kicks, and their variances add, so each kick must have variance proportional to for the total to stay finite and nonzero.
Sums of such kicks form a Wiener process : its increments are independent of the past. Writing for one increment, the limit of the DDPM chain is the variance-preserving (VP) SDE, a stochastic differential equation:
The general form is with a drift and a diffusion coefficient . Read it as the limit of Euler–Maruyama steps ; Itô calculus makes this rigorous. Each step adds noise of variance , so is the rate at which noise variance is pumped in.
The closed form survives the limit: , so we can still jump to any time. NCSN from Score matching has a limit too. It only adds noise, up to the level , with no shrinking. That is the variance-exploding (VE) SDE, .
How densities move
An SDE moves single points at random. A generative model cares about the whole cloud: how does the density of change in time? The answer is the Fokker–Planck equation:
where is the Laplacian, the sum of second derivatives. To derive it, average a smooth test function over one Euler–Maruyama step, expand to first order in and integrate by parts.
The two terms are two mechanisms. Transport, , carries mass along the velocity , like dye in a current. Diffusion, , moves mass from peaks to valleys and smooths , like dye spreading in still water.
Two special cases matter for the rest of the topic.
- No noise, . What remains, , is the continuity equation of the ODE . Every point moves deterministically, and the density follows the points.
- Drift along the score, . Then , the two terms cancel, and stays put. Transport pushes mass uphill exactly as fast as diffusion spreads it. You have already sampled with such an SDE; the check asks where.
The probability-flow ODE
The diffusion term can be disguised as transport. Since ,
and the Fokker–Planck equation becomes a continuity equation with no noise at all:
So the probability-flow ODE
moves the density exactly as the SDE does: the same at every . When the velocity is Lipschitz, trajectories are unique and the continuity equation has one solution from a given ; for a learned score that is an assumption about the network. The paths differ. The SDE jitters every point; the ODE carries it along the average flow.
For the VP SDE, put in the score from the noise predictor. The same trained network now drives an ODE, with no retraining:
A Gaussian example shows the paths. Take data . By the closed form, stays Gaussian. In one dimension ODE trajectories cannot cross, so the flow keeps the order of points, and a map that keeps order and turns into must keep every point's z-score. The point sits one standard deviation above the mean. At the mean is and the standard deviation almost , so . Running the ODE backwards from returns exactly .
What a deterministic sampler buys
Swapping the SDE for an ODE with the same marginals buys three things.
Encoding. The map from to is deterministic and invertible. Run the ODE forward to turn an image into its noise, and backwards to get the image back. The DDPM sampler cannot do this: it adds fresh noise at every step, so one leads to many images, and no image has a single noise of its own.
Exact likelihood. Along an ODE trajectory with velocity , the log-density changes by minus the divergence:
Here is the standard normal log-density. This is the change of variables from The change of variables in continuous time: the log-determinant of a flow becomes an integral of a trace, since the divergence is the trace of the Jacobian of . The exact trace costs backward passes, the wall that plain score matching hit, so Song et al. estimate it with random projections. The ELBO of DDPM: reverse process and objective only bounded the likelihood; the ODE computes it.
Any solver. The ODE can be integrated with higher-order methods and adaptive step sizes, often in far fewer than 1000 network calls. DDIM, the fast deterministic sampler that the topic Latent diffusion uses, is Euler's method for this ODE in rescaled coordinates.
Running the SDE backwards
The ODE drops the noise. Can we run backwards and keep it? Build the reverse process from two pieces. First, run the probability-flow ODE backwards in time: it carries to . Second, at every time add a Langevin pair, the drift with the noise . The Fokker–Planck block showed that this pair leaves unchanged, so it does not spoil the marginals. Run from down to and the two score drifts add up:
where and is a Wiener process running backwards. This is the reverse-time SDE. Anderson (1982) showed that the forward process, read backwards, solves it, so whole paths match in distribution, not just marginals. The score drift is twice the ODE's: one half undoes the forward spreading, the other half cancels the spreading caused by the reverse step's own noise.
DDPM's sampler is this SDE. One Euler–Maruyama step backwards for the VP SDE, with and , is
and the DDPM reverse mean from Score matching agrees with it up to terms of order .
The noise is not just decoration. Take the mixture from Score matching, use its exact score, and count samples in the left mode; the target is .
| reverse steps | SDE | ODE |
|---|---|---|
The ODE stalls because it starts from , while the true still has component means . A deterministic flow carries that small error at the start all the way to the end. The SDE's Langevin part keeps pulling samples toward and partly forgets the start. Predictor–corrector samplers do this on purpose: after each reverse step they run a few Langevin steps at the current noise level.
Flow matching
So far the path from data to noise was dictated by the SDE, and the ODE's velocity was assembled from , and a learned score. Flow matching (Lipman et al., 2023) turns this around: choose the path first, then learn its velocity directly.
Any velocity field whose ODE carries at to the data at is a generator. Pick a path of densities between the two, and let be the velocity whose continuity equation moves along it. The ideal loss is
but neither nor is known. The simplest path joins each image to its own noise draw by a straight line:
For one pair the velocity is constant, . The marginal velocity at a point averages it over all pairs whose lines pass through that point: .
This is the trick of denoising score matching again. Regress onto the per-pair target; squared error is minimized by the conditional mean, which is exactly . The conditional flow matching loss
differs from the ideal one by a constant that does not depend on , so it has the same gradients and the same minimizer. To sample, draw and integrate from down to , for example with Euler steps .
The link to diffusion is close. Given , knowing fixes , so the velocity, the noise and the score are all affine functions of one denoiser . A velocity network, a noise network and a score network are three parameterizations of the same object. The VP path of diffusion is just another Gaussian path, with coefficients and instead of and .
Curved paths and rectified flow
Every pair moves on a straight line. Why not sample in one Euler step? Because the marginal paths are not straight. Lines from different images cross: a point lies on many lines, and averages their directions. As a sample moves, the mix of lines through it changes, and its trajectory bends.
The extreme case is . There , which is independent of the image, so and . Here is the same mixture , sampled with its exact marginal velocity:
| Euler steps | share in left mode | std in left mode |
|---|---|---|
With two steps almost every sample lands in the left mode, squeezed to half its width. A hundred steps are accurate. The check asks what a single step does.
Rectified flow (Liu, Gong and Liu, 2023) straightens the paths. Lines cross because and were paired independently. Reflow runs the trained ODE from noise draws to generated images and retrains with the same loss on these coupled pairs . Their lines barely cross, so the new flow is much straighter. On CIFAR-10 with one Euler step, the paper reports FID 378 without reflow, 12.21 after one reflow and 8.15 after two; FID measures sample quality, lower is better, and the course defines it later. The price is a second training run on 4 million generated pairs, and slightly worse quality with an accurate solver.
The continuous picture is now complete: the VP SDE, its probability-flow ODE, the reverse-time SDE that DDPM discretizes, and flow matching that learns a velocity directly. Solvers and straighter paths cut sampling from 1000 steps to tens, sometimes one. But every step is still a full pass of a large network over every pixel: numbers for a colour image. The next topic, Latent diffusion, moves the whole machine into the small latent space of an autoencoder and samples it with DDIM, a discretization of the probability-flow ODE.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.