TL;DR
Flow matching trains a model to generate data by learning a velocity field that carries noise, step by step, to data. The training target is built from simple paths that connect one noise sample to one data sample, so the training loss is a plain regression with no differential equation to solve. At sampling time you start from noise and follow the learned field with a numerical ODE solver.
Where you'll see it: in recent image and video generators that replace diffusion's curved sampling paths with learned flows, and in any generative model that must sample quickly from a continuous-time field.
Intuition
A river that carries noise to data
Picture every point in space as a leaf on a river. Each leaf is pushed by the current, and the current depends on where the leaf is and when it is. If you know the current everywhere, you can drop leaves at random in the start region and watch them drift into the target region. A vector field is that current: for each position and time it gives a velocity .
Generative modelling then becomes a question about the river. Start with a region of pure noise at . Choose a current so that, after time , the leaves are distributed like real images. Sampling is just letting the leaves drift.
The hard part is designing the current. Diffusion models learn it indirectly, by predicting the noise that was added and converting that prediction into a score. Flow matching skips the detour and regresses the velocity directly. The question is how to get training targets for that velocity without knowing the whole current in advance. The answer is to build the current out of many small, simple pieces, one per training example.
Why "simulation-free" matters
Earlier continuous-time generative models, called continuous normalizing flows (CNFs), were trained by simulating the ODE for every training example and comparing the result with the data. Each gradient step needed a full ODE solve, which is slow and memory-hungry. Flow matching avoids this. Each training example gives one time , one point on a simple path, and one known velocity. The model only has to match that velocity at that point. No solver runs during training.
The math
Setup
A probability path is a family of densities indexed by time . It starts at a simple density , for example the standard Gaussian , and ends at a density that should be close to the data distribution .
A vector field generates the path if the flow it defines moves into at every time. Concretely, a point follows the ordinary differential equation
and is the flow. Here is where the point started at sits at time . Pushing through must give . This is the ODE that sampling will solve.
A neural network with parameters is trained to act as this field. The ideal training objective is the flow matching loss
where is the target field that generates . Two obstacles block this in practice. We rarely know in closed form, and the marginal target is an integral over all data points, so it cannot be evaluated either.
Conditional paths
The fix is to define a path for each data point. Fix a data sample and define a conditional path with and with concentrated near . The marginal path is the mixture over data:
Each conditional path has its own conditional field . The marginal field is the average of these, weighted by how much each data point contributes at :
The paper proves that this average really does generate the marginal path (its Theorem 1). It is the marginal analogue of the continuity equation, the statement that probability mass is conserved as it flows.
The trick: the conditional loss has the same gradient
The conditional flow matching loss uses only the per-sample targets:
Expand both squared norms. The and terms do not depend on . The cross term is the one that matters:
which is exactly the cross term of . So the two losses differ only by a constant that does not depend on . Their gradients are identical (Theorem 2 of the paper). Minimising the easy per-sample loss therefore trains the same network you would have trained with the intractable one. This is the same idea that makes Score Matching tractable, and the paper draws the comparison explicitly.
Gaussian conditional paths
A simple and general choice is a Gaussian path. Let be the mean and the standard deviation at time :
The paper shows that a conditional field exists for any such path. The sample-level flow is , and the conditional field is its time derivative, evaluated at the point where it sits.
Two choices matter most.
- Diffusion paths. Choosing the means and standard deviations from a noise schedule gives back the paths used by diffusion models. The conditional field is then curved.
- Optimal transport (OT) paths. Choosing both quantities to change linearly in time gives
For this choice the flow is , and the target velocity is
Along each sample's trajectory the target velocity is the constant . Particles move in straight lines at constant speed. The paper shows that this flow is the optimal transport displacement between the two Gaussians, which is why it is called the OT path.
The training loop in practice
For the OT path the loss simplifies to
Each step: draw a data point , a noise point , a time , form , and regress at that point onto the constant target. Nothing is integrated.
Worked examples
Take for hand computation (the paper uses a small positive value so that is a proper density). Let the noise sample be and the data sample be .
- The flow is .
- Its time derivative is for every . So the target velocity is , constant.
- Positions at four times: gives ; gives ; gives ; gives .
- Sampling with a perfect model and two Euler steps of size (see Euler Method): start at . The first step gives . The second gives . The solver lands exactly on the data point.
Interpretation: when the target is straight, one step of size moves the point exactly times the velocity, so even a coarse solver is accurate. Curved diffusion paths need more steps for the same accuracy.
Take two pairs, with : paired with .
- Draw . The point on the path is .
- The target velocity is .
- Suppose the current network outputs at that point and time.
- The error is . Its squared norm is .
- The gradient of this loss with respect to pushes the network to output a velocity closer to at the point when . No ODE was solved to obtain the target.
Interpretation: a minibatch just averages this quantity over many random pairs and times . Each pair teaches the network about one straight segment, and the network's job is to average over the segments that pass through each point.
With and a fixed data point , the conditional path is Gaussian with mean and standard deviation . The density plotted below is the conditional density at three times.
- t = 0
- t = 0.5
- t = 0.8
At the mean is and the standard deviation is , so the peak height is . At the mean is and the standard deviation is , giving a peak of . The mean moves linearly in and the width shrinks linearly, which is the straight-path property in density form.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Using a diffusion path with few sampling steps | Curved trajectories need many small steps, so quality drops at low step counts | OT paths, whose straight trajectories tolerate coarse solvers |
| Setting exactly to 0 in code | The last-time density is degenerate and divisions by become unstable near | A small positive , and clipping away from 1 during training |
| Training with a poorly chosen time distribution | Regions of time that are rarely sampled during training may be poorly fitted, which hurts sampling in those regions | Sample uniformly, as the paper does, and check the loss across time bins before trying non-uniform schemes |
| Expecting exact likelihoods cheaply | Computing likelihoods requires integrating the divergence of the field along trajectories, which is costly | Use it for sampling; use the continuous-time likelihood only when needed |
| Sampling with an adaptive solver for speed | The number of function evaluations varies per sample, which complicates batching | Fixed-step solvers, as the paper does for its low-cost comparisons |
Flow matching is a clean framework, not a guarantee of better samples. The paper reports that, with fixed-step (midpoint) solvers on its ImageNet 32 models, OT paths reach a given numerical error with roughly 60 percent of the function evaluations diffusion paths need, and that they outperform diffusion baselines on likelihood and sample quality in its experiments. Those results depend on architecture, data and training budget, so treat them as evidence for the approach rather than a universal ranking.
Alternatives include diffusion models (which learn the same kind of field through noise prediction), Neural Ordinary Differential Equation training with full simulation (which is slower but was the earlier route to continuous flows), and stochastic differential equation samplers (which add noise during sampling).
History
Continuous normalizing flows were introduced by Chen, Rubanova, Bettencourt and Duvenaud in 2018, in the paper that also introduced neural ODEs. They showed that a network can define a continuous transformation whose log-density change is tractable, but training them needed an ODE solve per gradient step. Grathwohl and colleagues (2018) trained such models by maximum likelihood, and the cost of solving the ODE during training remained the main obstacle.
Diffusion models, popularised by Ho, Jain and Abbeel in 2020, took off because their training was stable and simulation-free, through denoising. Score-based views by Song and colleagues in 2020 and 2021 connected them to continuous-time stochastic differential equations.
Flow matching was proposed by Lipman, Chen, Ben-Hamu, Nickel and Le in late 2022, with the paper published at the 2023 ICLR conference. It combined the continuous-time framework of CNFs with the simulation-free training of diffusion models. Around the same time, Liu and colleagues (rectified flow) and Albergo and Vanden-Eijnden (stochastic interpolants) proposed closely related methods. The idea of straight, optimal-transport paths relies on a much older result: McCann's 1997 displacement interpolation, which the paper builds on. The approach caught on because it trains faster than diffusion with comparable or better quality, and because the same objective works for any choice of path.
Check yourself
QuestionRecall: what does a vector field generate, and what equation determines where a point ends up?Show answer
A vector field gives a velocity at each position and time. It generates a probability path if following it moves samples from the start distribution so that their distribution at each time equals . A single point follows the ODE with , and is where it ends.
QuestionComputation: with , , , what is the flow , and what is the target velocity?Show answer
The flow is . At this is . The target velocity is , the same at every time. The midpoint of the straight path is , and the constant speed is per unit time.
QuestionWhy: the conditional loss uses only one data point per target, yet it trains the same network as the marginal loss. Why?Show answer
Expanding the squared error shows that the only -dependent cross term is . The marginal field is defined as the average of the conditional fields weighted by the posterior over . Substituting that average into the cross term turns it into the expectation of over and . The remaining terms do not depend on . So the gradients of the two losses are equal, and the per-sample loss has the same minimiser.
QuestionApplied: you train a flow matching model with diffusion paths, but generation quality is poor with 10 sampling steps and good with 100. What change would you test first, and why?Show answer
Switch to OT conditional paths and keep everything else fixed. Diffusion paths give curved trajectories that a coarse fixed-step solver approximates poorly, so 10 steps leave large discretisation error. OT paths are straight, so the same solver with 10 steps should track the field much more closely. Changing the architecture or the training length would be a weaker first test, because the sampling error comes from the path geometry, not from the network's capacity.
Sources
- Lipman, Chen, Ben-Hamu, Nickel, Le, Flow Matching for Generative Modeling, 2022: https://arxiv.org/abs/2210.02747
- Chen, Rubanova, Bettencourt, Duvenaud, Neural Ordinary Differential Equations, 2018: https://arxiv.org/abs/1806.07366
- Ho, Jain, Abbeel, Denoising Diffusion Probabilistic Models, 2020: https://arxiv.org/abs/2006.11239
- Optimal transport, Wikipedia: https://en.wikipedia.org/wiki/Optimal_transport