Flow Matching for Generative Modeling

Train a network to point from noise toward data along straight lines, with no ODE solver inside the training loop. Then a sampler reaches the data in about 10 steps, where a curved diffusion path needs 100 or more.

Pick a path, then drag the number of solver steps down. Watch the curved path miss the data while the straight path still lands. Then we build, piece by piece, how to train those straight paths without ever simulating an ODE.

You need probability distributions and sampling, basic ODEs and a feel for score matching or diffusion. We build the rest from zero.

Yaron Lipman, Ricky T. Q. Chen, Heli Ben-Hamu, Maximilian Nickel and Matt Le, Meta AI, 2022.

Sample with few steps

5

A toy, not the paper’s experiment. The data are eight points on a ring of radius 3.5; the noise is a unit Gaussian. Both paths use their exact velocity field for this data (the average of the conditional fields, Chapter 4), integrated with Euler steps. The diffusion path is the usual linear-beta VP schedule; the straight path is xt = (1 − t) x0 + t x1. A dot counts as landed if it ends within 0.45 of a data point. The paper’s own numbers are in Chapter 7.

Chapter 0

Why Flow Matching?

See why straight noise-to-data paths are worth having, and why they were out of reach until training stopped needing an ODE solver

You want to turn noise into images. Diffusion models do this brilliantly, but they found an unintuitive trick: add noise gradually, then learn to reverse it. The resulting trajectories from noise to data are curved, wandering paths through high-dimensional space.

What if you could just learn straight lines from noise to data? Straight lines are faster to traverse (fewer ODE steps at inference), easier to learn (a simpler vector field) and more stable to train. But there is a catch. The elegant framework for this, Continuous Normalizing Flows, has been impractical, because training one requires simulating ODEs, which is extremely expensive.

The breakthrough: Flow Matching shows you can train CNFs without ever simulating an ODE during training. Instead of the intractable marginal vector field, you regress against conditional vector fields that have closed-form solutions. The resulting loss is as simple as score matching, but it works with ANY probability path, including the straight-line Optimal Transport paths that diffusion cannot reach.

The key advantages of Flow Matching over traditional diffusion training:

Compare curved and straight paths

The same six noise dots and six data dots, joined two ways. Diffusion models follow the curved dashed paths (warm). Flow Matching with OT follows the straight paths (teal). Press Resample to draw new pairs.

Illustrative: the pairs are random and the curved path is a smooth bow through the middle, standing in for a diffusion trajectory. The path lengths are measured live on this picture, in screen pixels.

The road

The page follows the paper’s own order: the flow, the obstacle, the trick that removes it, the loss, the best path, and what it unifies.

  1. Continuous Normalizing Flows: a vector field carries noise to data.
  2. The Training Problem: why matching the true field is out of reach.
  3. Conditional Paths: aim at one data point and the target becomes a formula.
  4. The Flow Matching Objective: the conditional loss has the same gradient.
  5. Optimal Transport Paths: straight lines, and why they win.
  6. Connection to Diffusion: score matching is a special case.
  7. Results & Applications: ImageNet numbers and the models built on top.
  8. Connections: the lineage, and what to read next.
What is the core computational bottleneck that Flow Matching eliminates from CNF training?

Chapter 1

Continuous Normalizing Flows

Move a cloud of noise to a cloud of data by following a vector field through time

A Continuous Normalizing Flow (CNF) defines a generative model by moving samples along a time-dependent vector field. Think of it as a river: at time t = 0 you drop particles into noise, and the flow carries them to data at t = 1.

The ODE Formulation

A CNF is defined by a vector field vt : Rd → Rd that generates a flow φt via the ODE:

dφt(x) / dt
How fast the particle that started at x is moving at time t.
vt(φt(x))
The vector field: an arrow at every place and time. The particle moves along whatever arrow it sits on.
φ0(x) = x
At t = 0 the flow map does nothing. Every particle starts where it was dropped.

Starting from φ0(x) = x (identity at t = 0), the flow map φt transforms samples from the source distribution p0 (noise) to the target distribution p1 (data). At each time t, there is an intermediate distribution pt = [φt]# p0, the pushforward of p0 through φt.

Pushforward intuition: If you have a bucket of particles distributed as p0 (standard Gaussian), and you flow each particle through the ODE for time t, the resulting cloud of particles forms the distribution pt. At t = 1, that cloud should match your data distribution q. The pushforward [φt]# p0 just means “apply φt to each sample and look at the resulting distribution.”

The Continuity Equation

The densities pt satisfy the continuity equation:

∂pt / ∂t
How the density at a fixed place changes over time.
div(pt vt)
The net probability flowing out of that place. Density in, minus density out, is the change. The two terms cancel.

This is a conservation law: probability mass is neither created nor destroyed, it just flows. The vector field vt generates the probability path pt. Given vt, you can compute pt by solving this PDE (or equivalently, by simulating the ODE and pushing samples forward).

Sampling from a CNF

To generate a sample, draw x0 ~ p0 = N(0, I), then solve the ODE forward from t = 0 to t = 1 using an ODE solver (Euler, RK45, etc.):

x1
The generated sample, at the end of the trip.
x0
The starting noise draw from N(0, I).
∫01 vθ dt
All the small pushes the learned field gives along the way. An ODE solver adds them up step by step.

With a learned vθ, this gives you a sample from the model’s approximation of q (the data distribution).

CNFs vs. Discrete Normalizing Flows: Discrete NFs (RealNVP, Glow) use a fixed number of invertible layers. CNFs use a continuous transformation parameterized by an ODE: infinitely flexible, with no architecture constraints on invertibility. The price is that you need an ODE solver at inference. But the flexibility is enormous, because any smooth vector field works.

Flow particles through time

Particles start as noise (t = 0) and flow to data (t = 1) along the vector field. Drag the time slider to see the intermediate clouds.

0.00

Illustrative: twelve seeded particles that move in straight lines from a noise sample to a data sample, to show the idea of a flow. A real CNF learns the field that does this for a whole data set.

What does the flow map φt do in a CNF?

Chapter 2

The Training Problem

Find out why a beautiful generative model hit a wall, and what the wall was made of

We have a beautiful generative model: learn vθ, integrate it to generate samples. But how do we train vθ? This is where CNFs ran into a wall for years.

The Naive Approach: Flow Matching (Intractable)

The most natural objective is to match our learned vector field to the true one that generates the data distribution:

LFM(θ)
The loss. It is small when the learned field matches the true one.
Et Ex ~ pt
Average over a random time t and over points x drawn from the path pt.
vθ(t, x)
What the network predicts at time t and place x.
ut(x)
The true field that generates the path. This is the one we do not have.

Here ut is the vector field that generates a probability path pt interpolating between p0 and the data distribution q.

Problem 1: We don’t know ut. It’s defined implicitly as whatever vector field generates pt via the continuity equation. There’s no closed-form expression for the marginal ut(x).

Problem 2: Even if we could compute ut, sampling from pt requires simulating the ODE forward from t = 0, which means running an ODE solver inside the training loop. This is the same issue that plagued original CNF training (FFJORD): backpropagating through an ODE solver is expensive, memory-intensive and numerically unstable.

The cost of simulation: FFJORD-style training requires: (1) a forward ODE solve to get pt samples, (2) a backward ODE solve (adjoint method) for gradients, (3) trace estimation for the log-likelihood term. Each training step costs O(NFE × d), where NFE is the number of function evaluations (50-200 typically). This makes CNFs 10-100x slower to train than diffusion models, which need only one forward pass per step.

Prior Solutions and Their Limitations

Flow Matching’s insight: we can get the simplicity of score matching (closed-form targets, no simulation) but for any probability path, not just diffusion paths.

Compare the cost of a training step

ODE-based training needs expensive forward and backward solves at every step. Flow Matching needs a single network evaluation. Choose a method to read its cost.

Illustrative: the heights are the page’s rough estimates, not measured numbers from the paper. They follow the text above: simulation-based CNF training costs 10 to 100 times more per step than a diffusion step, and DDPM and Flow Matching both use one forward pass.

Why can’t we directly minimize LFM = E||vθ(t,x) - ut(x)||2?

Chapter 3

Conditional Paths

Aim at one data point at a time, and turn an impossible target into a one-line formula

Here is the key insight that unlocks everything. Instead of thinking about the marginal probability path pt (which is intractable), we think about conditional probability paths pt(x | x1): the path from noise to a specific data point x1.

The Conditioning Trick

Define a conditional probability path pt(x | x1) that:

The simplest choice is a Gaussian conditional path:

pt(x | x1)
Where particles are at time t, if they are all heading for the one data point x1.
μt(x1)
The centre of the cloud. It moves from near 0 to x1.
σt(x1)2 I
The spread of the cloud. It shrinks from 1 to almost 0.

Here μt and σt are differentiable functions of t with boundary conditions μ0 ≈ 0, σ0 ≈ 1, μ1 = x1, σ1 ≈ 0.

The Conditional Vector Field

For any Gaussian conditional path, there exists a unique vector field ut(x | x1) that generates it (via the continuity equation). For Gaussian paths, it has a closed-form expression:

ut(x | x1)
The arrow that carries a particle along this one conditional path.
σt′ / σt
How fast the spread shrinks, relative to its size. It pulls the particle in toward the centre.
x − μt(x1)
How far the particle sits from the centre of its cloud.
μt′(x1)
How fast the centre itself moves. It carries the particle toward x1.

This is exact. No approximation. No simulation needed. Given a sample xt from pt(x | x1), we can compute the vector field analytically.

The Reparameterization

Sampling from pt(x | x1) is trivial via reparameterization:

xt
A point on the path at time t.
μt(x1)
The centre of the cloud.
σt(x1)
The spread: how far from the centre to go.
ε
One fresh draw of standard noise.

For the simplest choice (linear interpolation, a.k.a. Optimal Transport path):

μt(x1) = t · x1,   σt = 1 − t
xt = (1 − t) x0 + t x1,   x0 ~ N(0, I)

This is just linear interpolation between a noise sample and a data sample! And the conditional vector field becomes:

ut(xt | x1) = x1 − x0

The target is simply the displacement from noise to data. It is constant in time. A straight line.

The magic: We’ve turned an intractable marginal problem into a trivial conditional problem. The conditional vector field ut(xt | x1) = x1 − x0 is just “point from where you are toward the data.” No ODE, no simulation, no score function: just a vector.

Follow the conditional paths

Each data point x1 (warm) defines a conditional path from a noise sample x0. The conditional vector field is constant: x1 − x0. Drag the time and watch each dot ride its path with the same arrow.

0.40

Illustrative: five made-up data points and three seeded noise samples for each. The paths are xt = (1 − t) x0 + t x1, exactly as in the text, and the arrow is x1 − x0 drawn at the dot.

For the linear interpolation path xt = (1-t)x0 + t*x1, what is the conditional vector field ut(xt | x1)?

Chapter 4

The Flow Matching Objective

Prove that the easy conditional loss trains the same field as the impossible marginal one, then write the training step

We now have all the pieces. The conditional vector field ut(x | x1) is tractable. But we want to learn the marginal vector field ut(x) that generates the marginal pt. How does conditioning on x1 help?

From Marginal to Conditional

The crucial mathematical result (Theorem 2 in the paper): the marginal probability path can be recovered by marginalizing over the conditional paths:

pt(x) = ∫ pt(x | x1) q(x1) dx1

And the marginal vector field that generates this pt is:

ut(x) = ∫ ut(x | x1) · pt(x1 | x) q(x1) dx1 / pt(x)

This is still intractable (it involves an integral over all data points). But here is the punchline:

The Conditional Flow Matching Loss

Define the Conditional Flow Matching (CFM) loss:

LCFM(θ)
The conditional loss: the one we can actually compute.
Et Ex1 Ext
Pick a random time, a random data point, then a random point on the path to that data point.
vθ(t, xt)
The network’s prediction. It never sees x1.
ut(xt | x1)
The closed-form conditional target from Chapter 3.
Theorem (Lipman et al., 2022): LCFM and LFM have identical gradients with respect to θ. That is, ∇θ LCFM = ∇θ LFM. Minimizing the tractable conditional loss is equivalent to minimizing the intractable marginal loss.

The Proof Sketch

The proof uses a simple trick. Expand LFM:

LFM = Et Ex ~ pt [||vθ||2 − 2 ⟨vθ, ut(x)⟩]

The cross term ⟨vθ(t,x), ut(x)⟩ under Ex ~ pt can be rewritten by substituting the marginal expressions. After expanding pt(x) = ∫ pt(x|x1)q(x1)dx1 and ut(x) as its conditional mixture, the cross term becomes Ex1 ~ q Ex ~ pt(x|x1) ⟨vθ, ut(x|x1)⟩, which is exactly the cross term in LCFM. The squared norms also match up to constants independent of θ.

The Training Algorithm

With OT conditional paths, training is beautifully simple:

# Flow Matching training step (OT path)
def fm_step(model, x1, optimizer):
    # x1: batch of data samples [B, d]
    t = torch.rand(B, 1)           # sample time
    x0 = torch.randn_like(x1)      # sample noise
    xt = (1 - t) * x0 + t * x1     # interpolate
    target = x1 - x0               # conditional vector field
    pred = model(t, xt)             # predict vector field
    loss = (pred - target).pow(2).mean()
    loss.backward()
    optimizer.step()

That’s it. Four lines of math. No ODE solver. No score function. No noise schedule to tune.

Compare to diffusion training: DDPM training: sample t, compute noise schedule αt, σt, add noise xt = αtx0 + σtε, predict ε. Flow Matching: sample t, interpolate xt = (1-t)x0 + tx1, predict x1 - x0. The structure is almost identical! But FM works for any path, not just diffusion paths. And the OT path gives straighter trajectories.
Why can we use the Conditional FM loss (LCFM) instead of the intractable marginal FM loss (LFM)?

Chapter 5

Optimal Transport Paths

Choose the straight path, and see where it leaves the diffusion path behind

Flow Matching works with any Gaussian conditional path. But which path should you choose? This is where the Optimal Transport (OT) path shines, and where FM decisively separates from diffusion.

The OT Conditional Path

The OT path uses linear interpolation:

μt(x1) = t · x1
The centre slides from 0 to x1 at constant speed.
σt(x1)
The spread shrinks in a straight line from 1 to σmin, a tiny leftover width.

For practical purposes with σmin → 0:

xt = (1 − t) x0 + t x1

This is the displacement interpolation from Optimal Transport theory. The sample moves along a straight line from x0 to x1 at constant speed.

Why “Optimal Transport”?

In OT theory, the optimal way to transport mass from one distribution to another (minimizing total displacement) is via straight lines. The conditional OT path xt = (1-t)x0 + tx1 moves each particle along the shortest path between its noise sample and its data target. While this is only the true OT map when conditioning on a single x1, the conditional paths still produce straighter marginal flows than diffusion paths.

Diffusion Path (VP-SDE) for Comparison

The Variance Preserving path used by DDPM:

μt(x1) = αt x1,   σt = √(1 − αt2)

where αt = exp(−½ ∫0t β(s) ds) with some noise schedule β(t). This produces curved trajectories: the particle first drifts toward the origin (as noise is added), then curves toward x1 (as signal emerges).

Why Straight Lines Win

Empirical evidence: On ImageNet 64×64, OT-CFM achieves FID 3.5 with only 110 NFEs, while VP-CFM (diffusion path) needs 142 NFEs for FID 4.3. Same model, same architecture: the only difference is the path geometry. Straight paths are simply better.

Race straight against curved

Teal is OT (straight lines). Warm is diffusion VP (curved). Drag the time slider, or press Play, to animate. Notice how the OT paths cross directly while the diffusion paths bend through the middle first.

0.00
t = 0 (noise) → t = 1 (data)

Illustrative: eight seeded pairs. The teal dots follow the exact OT formula. The warm dots follow a smooth curve that starts by shrinking toward the middle, standing in for a VP diffusion trajectory; its shape is a sketch, not a measurement from the paper.

Why do Optimal Transport paths require fewer ODE steps at inference than diffusion paths?

Chapter 6

Connection to Diffusion

Show that score matching is Flow Matching on one particular path, and see what Flow Matching adds

Flow Matching doesn’t replace diffusion. It generalizes it. Score matching for diffusion models is a special case of Conditional Flow Matching when you choose the diffusion probability path.

Score Matching as a Special Case

Recall: in diffusion models, we have a noising process:

xt = αt x1 + σt ε,   ε ~ N(0, I)

The score function is ∇x log pt(x | x1) = −(xt − αt x1) / σt2 = −ε / σt.

Denoising score matching trains the network to predict ε from xt.

Now, the conditional vector field for the diffusion (VP) path is:

ut(x | x1) = (σt′ / σt)(x − αt x1) + αt′ x1

Substituting x = αt x1 + σt ε:

ut(x | x1)
The flow-matching target on the diffusion path.
σt′ ε
The noise the diffusion model predicts, scaled by how fast the noise level changes.
αt′ x1
The clean data, scaled by how fast the signal level changes.

This is a linear combination of ε and x1, exactly what diffusion models predict (up to reparameterization). Training a network to predict this vector field is equivalent to training it to predict ε or x1.

The unification: Denoising score matching (DSM), DDPM’s ε-prediction and x0-prediction are all special cases of Conditional Flow Matching with the VP-SDE probability path. The only difference is a time-dependent rescaling of the target. FM reveals that what diffusion models are really doing is learning a vector field. They just never frame it that way.

What FM Adds Beyond Diffusion

PropertyDiffusion (VP/VE)Flow Matching
Path geometryCurved (noise schedule-dependent)Any, including straight OT lines
Training targetε or x0 or scoreVector field (encompasses all above)
InferenceSDE/ODE solver (many steps)ODE solver (fewer steps with OT)
Path flexibilityLocked to diffusion processAny Gaussian path works
Noise scheduleCritical hyperparameterNot needed (for OT paths)

Relationship to Rectified Flows

Rectified Flows (Liu et al., 2022) independently proposed the same OT conditional path xt = (1-t)x0 + tx1 and the same training objective. The key difference: Rectified Flows additionally proposed reflow, which iteratively straightens trajectories by using the model’s own predictions as new training pairs. Flow Matching provides the theoretical foundation (the equivalence theorem), while Rectified Flows provide the practical refinement technique.

The landscape in 2024: Stable Diffusion 3, Flux, and most modern image generators use Flow Matching with OT paths. The field has largely moved from “diffusion” to “flow” formulations, precisely because of the advantages this paper identified: simpler training, faster inference, no noise schedule.
How is denoising score matching related to Flow Matching?

Chapter 7

Results & Applications

Read the ImageNet numbers, then see which models and robots now run on Flow Matching

Flow Matching isn’t just a theoretical curiosity. It achieves state-of-the-art results and has become the foundation for modern generative models.

ImageNet Results

On ImageNet 64×64 (unconditional), comparing different probability paths with the same architecture:

MethodPathNLL (bpd)FIDNFE
FM + VP pathDiffusion (VP)0.974.31142
FM + OT pathOptimal Transport0.933.50110
DDPM (original)Diffusion (VP)3.7011.01000
Score SDE (VP)Diffusion (VP)2.992.41*2000

*Score SDE uses 2000 NFEs and Predictor-Corrector sampling. OT-CFM uses only 110 NFEs with an adaptive ODE solver.

Key finding: OT-CFM simultaneously achieves better likelihood AND better sample quality (FID) than VP-CFM, while using fewer integration steps. This is remarkable: traditionally likelihood and sample quality are at odds (the “likelihood-FID tradeoff”). Straight paths help both.

Training Stability

The paper shows that FM with OT paths has significantly more stable training dynamics compared to VP paths:

Downstream Impact

Flow Matching has become the standard training paradigm for modern generative models:

Why FM won for robotics: Robot action generation needs fast inference (real-time control at 10-50 Hz). FM with OT paths needs only 5-10 denoising steps vs 50-100 for DDPM. This makes flow-based policies practical for real-time robot control, where diffusion policies were too slow.

Trade steps for quality

OT paths (teal) reach a lower FID with fewer steps than VP diffusion paths (warm). Lower is better. Drag the budget to read both curves at the same number of function evaluations.

110

From the paper’s ImageNet 64×64 table: FM + OT reaches FID 3.5 at 110 NFE, and FM + VP reaches 4.3 at 142 NFE. The other points, and the lines between them, are an illustrative sketch of the shape of the trade-off, not measured values.

What practical advantage does Flow Matching with OT paths provide for downstream applications like robotics?

Chapter 8

Connections

Place Flow Matching in its lineage, sample from it in six lines, and pick what to read next

Flow Matching sits at the intersection of several major ideas in generative modeling and beyond. In one paragraph: a CNF moves noise to data along a vector field; training it used to need an ODE solver; conditioning on one data point at a time makes the target a closed-form arrow, with the same gradients as the impossible marginal loss; and the straight OT path makes that arrow constant, so a sampler needs only a handful of steps.

The core as code

Chapter 4 gave the training step. Sampling is the other half: the same Euler loop the hero runs, with the number of steps as your quality knob.

# Flow Matching sampling: integrate the learned field with Euler steps
@torch.no_grad()
def sample(model, shape, steps=10):
    x = torch.randn(shape)                      # x0 ~ N(0, I)
    for k in range(steps):
        t = torch.full((shape[0], 1), k / steps)
        x = x + model(t, x) / steps             # x += v(t, x) * dt
    return x                                    # x1 ~ model of the data

Related Papers in This Collection

The Intellectual Lineage

2018
Neural ODEs (Chen et al.): continuous-depth networks
↓
2019
FFJORD: free-form CNFs with trace estimation (expensive)
↓
2020
Score SDE (Song et al.): unified SDE framework for diffusion
↓
2022
Flow Matching (this paper): simulation-free CNF training
↓
2022
Rectified Flows (Liu et al.): iterative straightening + reflow
↓
2024
SD3, Flux, MovieGen, pi0: FM as the default generative backbone

Key Takeaways

The big picture: Flow Matching showed that the “right” way to think about generative modeling is through vector fields and probability paths. Diffusion was always doing this implicitly. FM made it explicit, and in doing so, unlocked better paths (OT), faster inference and simpler training. It’s the theoretical foundation on which modern generative AI is built.

References

  1. Lipman, Y., Chen, R. T. Q., Ben-Hamu, H., Nickel, M., Le, M. “Flow Matching for Generative Modeling.” ICLR 2023. arXiv:2210.02747
  2. Liu, X., Gong, C., Liu, Q. “Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow.” ICLR 2023. arXiv:2209.03003
  3. Chen, R. T. Q., Rubanova, Y., Bettencourt, J., Duvenaud, D. “Neural Ordinary Differential Equations.” NeurIPS 2018. arXiv:1806.07366
  4. Song, Y., Sohl-Dickstein, J., Kingma, D. P., Kumar, A., Ermon, S., Poole, B. “Score-Based Generative Modeling through Stochastic Differential Equations.” ICLR 2021. arXiv:2011.13456
  5. Esser, P. et al. “Scaling Rectified Flow Transformers for High-Resolution Image Synthesis.” ICML 2024. arXiv:2403.03206

Ready to test yourself? Open Present to explain the idea out loud, or Teach to draw it on a whiteboard. Or go back to the hero and drag the steps down once more.

Flow Matching for Generative Modeling
Read the paper · Back to Veanors