Flow matching: straight lines, curved flows
Continuous normalising flows trained without simulating them. The continuity equation and the instantaneous change of variables; why regressing on straight lines between random pairs learns the right flow; why flow matching and diffusion are one model; why the learned paths still curve, and how optimal-transport pairing and reflow straighten them. Every step derived, with the exact flow of a toy next to three trained networks.
Contents
- Notation
- 1. Continuous normalising flows
- 2. The flow matching idea
- 3. Generating, and why one step returns the average
- 4. Flow matching and diffusion are one model
- 5. Why the learned paths curve, and how to straighten them
- Straight paths make sampling exact
- Why averaging straight lines gives curves
- Fix 1: pair points so their lines do not cross
- Fix 2: reflow
- 6. How many steps does that save?
- 7. What is new, 2023 to 2026
- Questions
- References
Flow matching trains a generative model by a regression that fits on one line: pick a data point and a noise point, join them by a straight line, and teach a network the velocity along it. Below is the series’ toy, a ring of eight Gaussians. The first view shows the training lines; the others show the flow the network actually learns from them, and what happens when the pairs are chosen more cleverly:
What to try. The training lines cross each other everywhere, because data and noise are paired at random. The flow they define (exact on this toy) has paths that never cross and are clearly curved: the ratio of straight-line distance to path length is 0.66. Pair the points by optimal transport and the flow becomes almost straight (0.996); retrain on the flow’s own pairs, reflow, and it is straighter still (0.999). Straight paths are what make few-step generation possible: Section 6.
This is the third post of the series on deep generative models, after the map and diffusion models. It answers five questions:
- What is a continuous normalising flow, and why was training one by maximum likelihood slow? (Section 1.)
- Why does regressing on straight lines between random pairs learn the right flow? (Sections 2 and 3.)
- Why are flow matching and diffusion the same model? (Section 4.)
- Why are the learned paths curved, and how do optimal transport and reflow straighten them? (Section 5.)
- How many sampling steps does that save? (Section 6.)
Every result has a folded proof in numbered steps. As in the diffusion post, the toy’s marginal velocity has a closed form, so the exact answer sits next to three networks trained on the same data.
Notation
The series keeps data at and noise at . Lipman et al. (2023) use the opposite convention; formulas here are flipped accordingly.
| Symbol | Meaning |
|---|---|
| , | a data point and a noise point |
| a coupling: how pairs are drawn; independent unless stated | |
| the interpolant; linear path: , | |
| the velocity of one pair’s path; for the linear path | |
| the marginal velocity | |
| , | a network; the distribution of |
| divergence |
1. Continuous normalising flows
A continuous normalising flow (Chen et al., 2018) defines a generator by an ordinary differential equation, , run from noise at to data at . The density of the moving points changes as they go. Two facts describe how.
Theorem 1 (The continuity equation)
If points move by and is their density, then .
Proof
Step 1. Follow a test function. For smooth vanishing at infinity, by the chain rule.
Step 2. Write both sides as integrals. The left side is . The right side is , by integration by parts (the divergence theorem; boundary terms vanish).
Step 3. True for every , so the integrands agree.
Proposition 1 (The instantaneous change of variables (Chen et al., 2018))
Along a trajectory, .
Proof
Step 1. Chain rule for a function of : .
Step 2. Expand the continuity equation. . Dividing by : .
Step 3. Add. The terms cancel.
This is the continuous version of the change-of-variables formula in the map, Section 2. One small Euler step has Jacobian , and : the log-determinants of the discrete flow become an integral of the divergence. So a continuous flow has an exact likelihood,
and it can be trained by maximum likelihood. That is expensive. Every training step must solve the ODE for each data point and integrate the divergence along it. The divergence is the trace of a Jacobian, which costs backward passes, or a noisy random estimate (Grathwohl et al., 2019). Flow matching removes the simulation from training altogether.
2. The flow matching idea
Instead of learning by likelihood, choose a path of distributions from data to noise, and regress onto the velocity that produces it. The path is built from pairs. Draw from a coupling whose marginals are and , and move each pair along . For the linear path (, ), each pair moves in a straight line at constant velocity .
One point at time lies on many such lines, each with its own velocity. A single ODE needs one velocity per point, so take the average.
Theorem 2 (The marginal velocity generates the path (Lipman et al., 2023; Liu et al., 2023; Albergo and Vanden-Eijnden, 2023))
Let be the distribution of , and . Then satisfy the continuity equation. Hence the ODE , started from at and run to , ends at .
Proof
Step 1. Follow a test function along the pairs. , since each pair moves with velocity .
Step 2. Condition on . By the tower property, .
Step 3. As integrals. The left side is , and the right side is . For every , so .
Step 4. The ODE reproduces . The densities of the ODE’s points satisfy the same continuity equation with the same velocity and the same value at . Under standard regularity conditions its solution is unique, so they equal at every time, in particular .
The proof never used independence of the pair, only the two marginals. That freedom is what Section 5 exploits. The marginal velocity is unknown, because it averages over the data distribution. But it can be learned without ever computing it.
Theorem 3 (Conditional flow matching (Lipman et al., 2023))
For any model ,
with independent of , the expectations over , the pair and .
Proof
Step 1. Expand both squares. Both have the same term, and their last terms (, ) do not depend on .
Step 2. The cross terms are equal. , by the tower property.
So training is plain regression on known targets. With the linear path:
x0, eps = sample_data(B), torch.randn(B, d) # a pair per row
t = torch.rand(B, 1)
xt = (1 - t) * x0 + t * eps # a point on the straight line
loss = ((v_theta(xt, t) - (eps - x0)) ** 2).sum(1).mean() # regress on the line's velocity
No ODE is solved during training, and no divergence is computed. On the toy the marginal velocity is exact: , both conditional means following from the Gaussian-mixture posterior as in the diffusion post. A network trained with the five lines above reproduces its flow: the straightness of its paths is 0.659, against 0.658 for the exact flow.
3. Generating, and why one step returns the average
Generation integrates from to . In our convention time runs backwards, so Euler’s method with step is .
Proposition 2 (One step from noise lands on the mean)
For the linear path with an independent coupling, a single Euler step from gives , whatever is.
Proof
Step 1. At , , so .
Step 2. Independence. is independent of , so .
Step 3. Substitute. , so .
The same lesson as the diffusion post, in different clothes: from pure noise, the best single guess is the average of the data. The animation shows why, in one dimension:
4. Flow matching and diffusion are one model
Both learn a velocity (or score) field for a Gaussian path , and both sample by an ODE. In fact they are the same ODE.
Theorem 4 (The marginal velocity is the probability-flow drift)
For any Gaussian path with independent coupling,
which is the drift of the diffusion post’s probability-flow ODE, with and .
Proof
Step 1. Linearity of conditional expectation. .
Step 2. Tweedie’s formula (diffusion post, Section 4): and .
Step 3. Substitute and collect. .
Step 4. Compare. , the coefficient of the score in Step 3.
So a diffusion model’s probability-flow ODE is a flow-matching ODE for a variance-preserving path, and flow matching with the linear path is a diffusion model with the schedule , . What actually differs between the methods is three choices: the shape of the path, which target is regressed and how the loss weights each time, and the coupling.
For the linear path the conversions are especially simple. From and (in conditional expectation):
Check: , and similarly for .
5. Why the learned paths curve, and how to straighten them
Straight paths make sampling exact
Proposition 3 (Straight, constant-speed paths need one step)
If every trajectory of is a straight line traversed at constant velocity, then Euler’s method is exact for any step size, including a single step from to .
Proof
Step 1. Along a trajectory, , a constant vector.
Step 2. The exact solution is , which is exactly the Euler update with step .
Why averaging straight lines gives curves
Each training pair moves in a straight line. But the marginal velocity at is an average over all the lines through at time , and with random pairing many lines cross. Trajectories of an ODE cannot cross: two would then share a point at the same time and, by uniqueness of solutions, be the same trajectory. So where the training lines cross, the flow must bend to keep its paths apart. On the toy the exact flow’s paths have chord-to-length ratio 0.66; the animation of Section 3 shows the mechanism in one dimension.
Fix 1: pair points so their lines do not cross
The theorem of Section 2 allows any coupling with the right marginals. Choose one whose lines do not cross. Optimal transport with squared distance does exactly this.
Proposition 4 (Optimal-transport lines do not cross)
Let a coupling of finitely many data and noise points minimise the total squared distance over all pairings. Then no two of its straight-line paths, , meet at the same time , unless they coincide.
Proof
Step 1. Suppose two paths meet. For pairs and let . Write and .
Step 2. Express the swapped pairs through and . and , so . Likewise .
Step 3. Convexity of the squared norm. , and the same with and exchanged. Adding, the swapped pairing costs at most , the original cost, with equality only if .
Step 4. Conclude. If , swapping partners strictly lowers the cost, contradicting optimality. If , the two paths have the same velocity and meet, so they are the same line.
In practice the optimal pairing is computed within each minibatch, by solving the assignment problem between the batch’s data and noise points (Pooladian et al., 2023; Tong et al., 2024). Within a batch the lines then do not cross, and the marginal flow is nearly straight: 0.996 on the toy.
Fix 2: reflow
Rectified flow (Liu, Gong and Liu, 2023) straightens a trained flow by retraining it on its own pairs. Generate noise points, push each through the current flow, and pair it with where it lands. Then train a fresh flow-matching model on those pairs with straight lines. The new coupling is deterministic and already close to non-crossing, so the new flow is much straighter. Liu et al. prove that this reflow never increases any convex transport cost. Lee, Lin and Fanti (2024) found that a single round is enough to make trajectories nearly straight. In one dimension it is exact: the paths of a one-dimensional ODE cannot cross, so they keep their order, and lines joining ordered starts to ordered ends never cross (the end of the animation). On the toy, one round of reflow gives straightness 0.999. The price is an offline pass that simulates the first model, whose errors are then baked into the second.
6. How many steps does that save?
Here are samples after Euler steps, for the exact flow and the three networks (same architecture, 15,000 training steps each). Slide the number of steps and switch models:
On 4000 samples, the share that lands on a mode (every run covers all 8 modes, except the 1- and 2-step runs with random pairing):
| Euler steps | exact flow, random pairs | network, random pairs | network, OT pairs | network, reflow |
|---|---|---|---|---|
| 1 | 0% (the mean) | 0% (the mean) | 76% | 88% |
| 2 | 5% | 5% | 86% | 89% |
| 4 | 79% | 74% | 91% | 92% |
| 8 | 98% | 90% | 93% | 94% |
| 32 | 99% | 96% | 95% | 95% |
Three things to read off. With random pairing, one step returns the mean, as Section 3 proved, and about eight steps are needed. Straightening by optimal transport or reflow turns one step from useless into 76% and 88% on a mode. And with many steps all three networks plateau around 95%: that is the limit of the network’s capacity, not of the integrator. Straight flows get close in a step or two, but not all the way, because no finite network makes every path perfectly straight. Learning the whole jump directly, rather than straightening the path and hoping, is the idea of the last post.
7. What is new, 2023 to 2026
| year | work | what it changes |
|---|---|---|
| 2023 | Lipman et al. (flow matching); Liu et al. (rectified flow); Albergo and Vanden-Eijnden | simulation-free training of continuous flows by regression |
| 2023 | Pooladian et al.; Tong et al. (TMLR 2024) | minibatch optimal-transport couplings for straighter flows |
| 2024 | Esser et al. (Stable Diffusion 3) | rectified-flow transformers at scale for text-to-image |
| 2024 | Liu et al. (InstaFlow) | one-step text-to-image generation from reflow plus distillation |
| 2024 | Lee, Lin and Fanti | one round of reflow is enough; better time sampling and losses |
| 2024 | Chen and Lipman; Gat et al. | flow matching on manifolds, and for discrete data |
| 2024 | Lipman et al. (guide and code) | a self-contained reference and PyTorch library |
| 2025 | Albergo, Boffi and Vanden-Eijnden (JMLR) | stochastic interpolants: one framework for flows and diffusions |
| 2025 | Geng et al. (MeanFlow) and others | learn the average velocity over an interval for one-step generation: the next post |
Questions
Question 1
The training targets are straight lines. Why are the learned paths curved?
Answer
The network learns the marginal velocity, the average of the straight-line velocities of all pairs passing through a point at a given time. Where lines cross, their velocities differ and the average matches none of them. ODE trajectories cannot cross, so the flow bends to keep them apart. Only when the coupling’s lines do not cross is the average equal to each line’s own velocity.
Question 2
Why does optimal-transport pairing not change what distribution the model learns?
Answer
The theorem of Section 2 needs only the coupling’s marginals: data at , noise at . Any coupling with those marginals defines a path from to , and its marginal velocity transports one to the other. Optimal transport changes which flow gets there, and makes it straighter, not where it goes.
Question 3
A colleague says flow matching is better than diffusion. What is the precise comparison?
Answer
With Gaussian paths and independent pairs they are the same model: Section 4 shows the marginal velocity equals the probability-flow drift. The real differences are the path’s schedule (linear versus variance-preserving), the target and loss weighting (velocity versus noise prediction), and, optionally, the coupling. Linear paths with velocity prediction are simple and often somewhat straighter, which helps few-step sampling, but they are a point in the same design space, not a different principle.
Question 4
Why can a continuous flow be trained without ever solving its ODE, when maximum likelihood needs the ODE at every step?
Answer
Maximum likelihood needs the density of each data point, which requires integrating the divergence along the trajectory (Section 1). Flow matching instead fixes the path in advance through the interpolant, so the target velocity at a sampled point is known in closed form. The conditional flow matching theorem shows that regressing on it is equivalent to regressing on the unknown marginal velocity.
Question 5
Reflow is said to “bake in” the first model’s errors. What does that mean?
Answer
Reflow’s training pairs are (noise, where the first flow sends it). If the first flow puts some samples between modes, those pairs teach the second flow to do the same, along straighter paths. Reflow makes a model faster, not more accurate, which is why it is usually followed by careful evaluation, or combined with distillation.
References
- R. T. Q. Chen, Y. Rubanova, J. Bettencourt, D. Duvenaud. Neural ordinary differential equations. NeurIPS, 2018. arXiv:1806.07366
- W. Grathwohl, R. T. Q. Chen, J. Bettencourt, I. Sutskever, D. Duvenaud. FFJORD: free-form continuous dynamics for scalable reversible generative models. ICLR, 2019.
- Y. Lipman, R. T. Q. Chen, H. Ben-Hamu, M. Nickel, M. Le. Flow matching for generative modeling. ICLR, 2023. arXiv:2210.02747
- X. Liu, C. Gong, Q. Liu. Flow straight and fast: learning to generate and transfer data with rectified flow. ICLR, 2023. arXiv:2209.03003
- M. S. Albergo, E. Vanden-Eijnden. Building normalizing flows with stochastic interpolants. ICLR, 2023.
- M. S. Albergo, N. M. Boffi, E. Vanden-Eijnden. Stochastic interpolants: a unifying framework for flows and diffusions. JMLR, 2025. arXiv:2303.08797
- A.-A. Pooladian, H. Ben-Hamu, C. Domingo-Enrich, B. Amos, Y. Lipman, R. T. Q. Chen. Multisample flow matching: straightening flows with minibatch couplings. ICML, 2023.
- A. Tong, K. Fatras, N. Malkin, G. Huguet, Y. Zhang, J. Rector-Brooks, G. Wolf, Y. Bengio. Improving and generalizing flow-based generative models with minibatch optimal transport. TMLR, 2024.
- P. Esser et al. Scaling rectified flow transformers for high-resolution image synthesis. ICML, 2024.
- X. Liu, X. Zhang, J. Ma, J. Peng, Q. Liu. InstaFlow: one step is enough for high-quality diffusion-based text-to-image generation. ICLR, 2024.
- S. Lee, Z. Lin, G. Fanti. Improving the training of rectified flows. NeurIPS, 2024.
- R. T. Q. Chen, Y. Lipman. Flow matching on general geometries. ICLR, 2024.
- I. Gat, T. Remez, N. Shaul, F. Kreuk, R. T. Q. Chen, G. Synnaeve, Y. Adi, Y. Lipman. Discrete flow matching. NeurIPS, 2024.
- Y. Lipman, M. Havasi, P. Holderrieth, N. Shaul, M. Le, B. Karrer, R. T. Q. Chen, D. Lopez-Paz, H. Ben-Hamu, I. Gat. Flow matching guide and code. 2024. arXiv:2412.06264
- Z. Geng, M. Deng, X. Bai, J. Z. Kolter, K. He. Mean flows for one-step generative modeling. NeurIPS, 2025.
Was this useful?
Thanks, that helps me decide what to write next.