Diffusion and Flow Matching
Contents · 18 sections
- Author’s note
- Preliminaries and notation
- Generative modeling as probability transport
- Continuity equation
- Fokker–Planck equation
- Diffusion: prescribe a forward noising process
- Anderson’s reverse-time SDE
- Connection to DDPM
- Probability-flow ODE
- Connection to deterministic DDIM
- Flow matching: construct the transport directly
- Why the conditional mean satisfies the continuity equation
- MSE learns the conditional mean
- Randomness can come entirely from the initial sample
- Adding stochasticity while preserving the probability path
- Recovering diffusion from the stochastic flow
- Flow matching can learn the diffusion probability-flow velocity
- Recovering a score from a linear Gaussian flow
Author’s note
This is a general overview for the author’s own use.
Supplemental details and relevant basic / advanced topics (annealed langevin sampling, SMC, Feynman-Kac Correctors, etc) will be posted later. For readers interested in stochastic interpolants, this study guide (Ziseok Lee, 2026) provides a comprehensive overview.
Preliminaries and notation
The objective is straightforward: transport a simple source distribution into the target data distribution.
: source distribution, usually Gaussian.
: target data distribution.
: intermediate density during generation.
: deterministic velocity field.
: score of the intermediate density.
: standard Brownian motion.
Use for generation, running from noise to data. When discussing forward diffusion, use , running from data to noise, with .
Exact statements assume sufficient regularity, integrability, appropriate boundary behavior, and well-posed dynamics. Scores require positive differentiable densities. Singular endpoint distributions may require smoothing or a limiting interpretation.
Generative modeling as probability transport
A deterministic generative process starts from a random latent variable and evolves through an ODE:
The solution defines a flow map :
The desired endpoint condition is
The pushforward notation means that applying to source samples produces target-distributed samples.
The velocity field describes instantaneous motion; the flow map is obtained by integrating that field.
Diffusion and flow matching can both be studied through this transport perspective. We focus on their ODE and SDE formulations, leaving aside diffusion’s hierarchical latent-variable and variational-autoencoder interpretation. (Luo, 2022) That interpretation is valid, but the differential-equation perspective makes the relationship between the methods especially direct.
Continuity equation
If is a density and is its probability current, conservation of probability gives
For the deterministic dynamics
the current is
Therefore,
The density changes because probability moves between regions. Under suitable boundary conditions, its total integral remains one.
Fokker–Planck equation
Consider an Itô SDE with scalar, spatially constant noise amplitude:
Its density satisfies
This is the Fokker–Planck equation. It also has continuity-equation form:
Using
we obtain
The corresponding probability-transport velocity is therefore
The SDE drift and the probability-transport velocity have different roles. Brownian sample paths generally have no ordinary instantaneous velocity; the expression above describes the evolution of their distribution. (Song et al., 2021)
Diffusion: prescribe a forward noising process
Write the forward diffusion as
Let denote its density. The forward process adds noise; the reverse process generates data.
A canonical example is the variance-preserving, or VP, diffusion:
Its conditional distribution is
where
As becomes small, the distribution approaches a standard Gaussian. For a finite schedule, the terminal distribution is generally only approximately Gaussian.
Anderson’s reverse-time SDE
Switch to the increasing generation clock
Anderson’s reverse-time formula gives
Starting from the exact terminal distribution,
the reverse process satisfies
The score correction is essential: fresh Brownian noise continues to spread probability during reverse simulation. Merely negating the forward drift does not reverse that spreading. (Anderson, 1982)
This recovers the original distribution. A fresh reverse simulation does not generally recover the particular clean sample that produced a given noisy observation.
Connection to DDPM
DDPM uses discrete forward transitions
For small steps with
this process approaches the VP SDE.
DDPM’s learned reverse Gaussian transitions approximate the corresponding reverse dynamics. At finite step sizes, the true reverse conditional is generally not Gaussian. Exact continuous-time reversal therefore does not imply exact recovery by a finite-step DDPM sampler. (Ho et al., 2020)
Probability-flow ODE
The same diffusion marginals can be generated deterministically.
Reversing the forward Fokker–Planck equation gives
Since ,
This is the continuity equation for
Thus, in generation time:
Removing the stochastic noise also requires reducing the score coefficient from one to one-half.
With exact fields, correct initialization, and well-posed evolution, the SDE and ODE share every time marginal. Their trajectories, transition probabilities, and endpoint pairings generally differ.
Connection to deterministic DDIM
For the VP coefficients defined above, a deterministic DDIM step from to is
Expanding one step to first order yields
For the VP schedule,
With independent , the optimal noise predictor satisfies
Substitution gives
This is the VP probability-flow ODE, expressed in the noising clock and integrated toward decreasing for generation.
To clarify, deterministic DDIM has the corresponding probability-flow ODE as its continuous-time limit. Finite DDIM steps are numerical approximations, and arbitrary ODE discretizations need not equal DDIM updates. (Song, Meng, and Ermon, 2020)
Detailed training parameterizations, schedule choices, loss weights, and practical discrete samplers will be discussed in a separate post.
Flow matching: construct the transport directly
Instead of prescribing a forward diffusion, choose an interpolation between source and target samples.
Sample an endpoint pair
The coupling is a joint distribution with the required endpoint marginals. Independent sampling is one possible choice.
For a linear interpolation, define
Then
The endpoints are correct by construction:
Different sampled interpolations can pass through the same location at the same time with different velocities. Their aggregate probability current is represented by
This is a conditional average of interpolation velocities, weighted by the endpoint pairs compatible with the observed position and time. It is defined -almost everywhere.
For a general differentiable interpolation, the corresponding formula is
For more details, read Lipman et al., 2022.
Why the conditional mean satisfies the continuity equation
Let be any smooth, compactly supported test function.
Differentiate its expectation along the interpolation:
Apply the law of iterated expectations:
Because is determined by ,
Using the definition of ,
Integration by parts gives
Meanwhile,
Therefore,
Because this holds for every such test function,
in the weak sense.
With the required uniqueness properties, solving
therefore produces
The generated trajectories need not follow the sampled training lines or reproduce the original coupling . The guarantee concerns their time-dependent marginal distributions.
Straight training interpolations do not necessarily produce straight ODE trajectories or an optimal-transport map.
Also, a density path does not uniquely determine its velocity field. Adding any field satisfying
preserves the same continuity equation.
MSE learns the conditional mean
The transport argument comes first. We can now choose a learning objective that estimates its conditional-mean velocity.
For a neural field , use
where is independent of .
At a fixed time,
The second term is independent of . Thus, with sufficient capacity and ideal optimization, squared-error regression recovers
The reasoning is:
MSE is a convenient realization of conditional-mean estimation. It is not needed to establish the transport identity. A different objective must preserve the same population target; an arbitrary replacement loss need not do so.
Training requires sampling a time and endpoint pair, constructing and , and performing the regression update. No ODE simulation is needed to obtain those training examples.
The minimum loss can remain positive because the conditional velocities can have nonzero variance.
Randomness can come entirely from the initial sample
For a fixed latent , a well-posed ODE gives one output:
Across random initial samples,
This distribution can be highly multimodal despite every trajectory being deterministic.
For conditional generation with a condition ,
The same condition can produce many outputs by changing the latent sample. For a fixed condition and fixed full latent state, the output is deterministic.
A regular ODE does not literally split one initial state into several trajectories.
Adding stochasticity while preserving the probability path
Suppose generates , and its score
is available.
Choose a time-dependent scalar noise amplitude . Consider
Substituting into its Fokker–Planck equation gives
Using ,
Hence,
The score drift cancels the additional diffusion current. With the same initial distribution and well-posed evolution, the stochastic sampler retains the deterministic flow’s marginals.
Simply adding noise without the score correction generally changes those marginals. (Albergo, Boffi, and Vanden-Eijnden, 2023)
Recovering diffusion from the stochastic flow
Insert the generation-direction probability-flow velocity
Choose
The stochastic sampler’s drift becomes
Therefore,
which is Anderson’s reverse SDE.
Choosing instead recovers the probability-flow ODE.
Flow matching can learn the diffusion probability-flow velocity
Take independent samples
and choose the interpolation
This construction has the reversed diffusion marginals. On the interior where the coefficients are nonzero,
The conditional-mean velocity is
Because
we obtain
For the reversed VP schedule,
This is exactly the generation-direction VP probability-flow velocity.
Thus, selecting the diffusion interpolation lets flow matching learn the corresponding deterministic transport. Selecting another interpolation generally changes the intermediate distributions.
For a finite VP schedule, the initial marginal of this particular interpolation is the exact diffusion terminal distribution , which is generally only approximately standard Gaussian.
Recovering a score from a linear Gaussian flow
Obtaining the score is an additional requirement for stochastic sampling. Some paths provide an explicit conversion.
For the independent linear Gaussian interpolation
the conditional density is
Differentiating the marginal density and applying Bayes’ rule gives
Since ,
Also,
Taking conditional expectations,
Therefore,
This conversion relies on the independent Gaussian endpoint noise and the chosen linear interpolation. It does not apply unchanged to arbitrary couplings or paths.
With learned fields and numerical solvers, marginal equality is approximate. In particular, converting an imperfect using this formula does not automatically produce the exact score of the density generated by its ODE.
Exact preservation of a learned ODE’s distribution requires that distribution’s own score. The endpoint also requires separate limiting or numerical treatment.