Chapter 4 used optimal transport as a practical tool — mini-batch OT to reduce trajectory crossings, the OT coupling to straighten paths, the reflow procedure to approximate optimal maps. But at no point did we define what optimal transport actually is, or prove why the OT coupling has the properties we claimed. This was a deliberate omission: the flow matching framework can be stated, understood, and used without OT theory, and the historical development did not require it. But understanding why straight paths are optimal, what the Wasserstein metric measures, and how the Benamou-Brenier formula connects transport to the continuity equation — this is the mathematical foundation on which the entire field implicitly rests. The debt is now repaid.
The story begins in 1781, when Gaspard Monge asked how to move a pile of sand into a hole at minimum cost. It was reformulated in 1942 by Leonid Kantorovich, who relaxed the problem in a way that always admits a solution and, incidentally, founded linear programming. It was given its modern geometric form by Yann Brenier in 1991, who showed that the optimal map for quadratic cost is the gradient of a convex function. And in 2000, Jean-David Benamou and Brenier reformulated the problem in terms of fluid mechanics — the continuity equation and kinetic energy — in a form that turns out to be identical to the flow matching objective of Chapter 4. The connection was not an accident. It was always there, waiting to be recognized.
5.1 The Monge Problem
The original formulation is deceptively simple. Given two probability distributions and on — think of as the distribution of sand and as the shape of the hole — find a map that pushes onto while minimizing the total transport cost:
where is the cost of moving a unit of mass from to , and is the pushforward constraint: for every measurable set , , meaning that all mass arriving at under accounts for exactly .
The pushforward constraint is precisely the condition from Chapter 1 — a normalizing flow computes a map such that . The Monge problem asks: among all such maps, which one is cheapest?
The most natural cost is the quadratic cost , measuring the squared Euclidean distance each particle travels. With this choice, the Monge problem seeks the transport map that minimizes the total squared displacement.
[!remark] 5.1 The Monge problem does not always have a solution. If is a point mass at the origin and , then no deterministic map can push to — a single point cannot be split in two. This failure motivated Kantorovich’s relaxation, which allows mass to be split.
5.2 The Kantorovich Relaxation
Kantorovich’s insight was to replace the deterministic map with a coupling (or transport plan) — a joint probability distribution on whose marginals are and :
[!definition] 5.1 — Kantorovich Problem The Kantorovich optimal transport problem with cost is:
where is the set of all couplings — probability measures on with first marginal and second marginal .
A coupling generalizes a map: if is a transport map, then is the coupling that puts all the mass from onto . But a general coupling can split mass — the conditional can be a distribution over multiple destinations, not a point mass. This relaxation always admits a solution, even when the Monge problem does not.
The Kantorovich problem is a linear program: the objective is linear in , and the marginal constraints , are linear. This structure — which Kantorovich developed into the theory of linear programming — guarantees existence of a minimizer and, through duality, provides a powerful characterization of the solution.
[!theorem] 5.1 — Kantorovich Duality The Kantorovich problem with cost satisfies:
where the supremum is over all pairs of integrable functions satisfying the constraint for all . At optimality, is the -transform of .
The dual functions and are called Kantorovich potentials. They have a direct interpretation: is the “price” of mass at location , and is the “price” at location , such that the total price paid equals the total transport cost. The constraint says that the prices are consistent with the cost — it is never cheaper to buy mass at both endpoints than to transport it.
5.3 Brenier’s Theorem and the Monge Map
For the quadratic cost , Brenier’s theorem gives a definitive characterization of the optimal transport map when it exists.
[!theorem] 5.2 — Brenier’s Theorem Let and be probability measures on with finite second moments, and suppose is absolutely continuous with respect to the Lebesgue measure. Then there exists a unique optimal transport map for the quadratic cost, and it is the gradient of a convex function:
where is convex. The convex function is the Kantorovich potential.
The requirement that be absolutely continuous (no point masses) is precisely the condition under which the Monge problem has a solution for quadratic cost. The result is remarkable: the optimal way to rearrange mass is always a gradient map — a “potential flow” in the language of fluid mechanics — and the potential is convex, meaning the map is monotone. There is no rotation, no folding, no crossing of trajectories. The optimal transport map simply pushes each particle downhill along the convex potential.
[!remark] 5.2 Brenier’s theorem explains, at a fundamental level, why OT-conditioned flows in Chapter 4 produce non-crossing trajectories. The optimal coupling assigns each noise sample to a data sample via the gradient of a convex function. The straight-line interpolation then produces non-crossing paths, because monotone maps preserve the ordering of particles. Independent random coupling, by contrast, is far from the gradient of any convex function, and the resulting trajectories cross freely.
5.4 Wasserstein Distances
The optimal transport cost defines a family of distances on the space of probability measures.
[!definition] 5.2 — Wasserstein Distance The -Wasserstein distance between probability measures and with finite -th moments is:
is a genuine metric on the space of probability measures with finite -th moments: it is symmetric, satisfies the triangle inequality, and if and only if . The case is the most important for our purposes — the -Wasserstein distance inherits a Riemannian structure from the underlying Euclidean space.
Otto (2001) showed that can be formally endowed with the structure of an infinite-dimensional Riemannian manifold. The tangent space at a measure consists of velocity fields satisfying the continuity equation , and the inner product is:
This is the inner product weighted by the density — exactly the kinetic energy that appears in the flow matching objective. Geodesics in this Riemannian structure are optimal transport paths, and the geodesic distance is . The space of probability measures is not just a metric space; it is a curved space with a rich geometry of its own.
5.5 The Benamou-Brenier Formula: Dynamic Optimal Transport
The connection between optimal transport and the continuity equation is made explicit by the Benamou-Brenier formula (2000), which recasts the static OT problem as a dynamic one.
[!theorem] 5.3 — Benamou-Brenier Formula The squared -Wasserstein distance between and equals:
where the infimum is over all smooth paths of densities and velocity fields satisfying:
- The continuity equation: ,
- The boundary conditions: , .
Read this theorem carefully: it says that the squared Wasserstein distance is the minimum kinetic energy needed to transport to through a time-dependent flow governed by the continuity equation. The infimum is over both the density path and the velocity field — subject to the continuity equation linking the two.
This is the flow matching problem of Chapter 4. The continuity equation constraint is equation (4.1). The kinetic energy is the expected squared norm of the velocity field, integrated over time — the objective that the minimum-norm velocity field minimizes. The Benamou-Brenier theorem says: among all flows transporting to , the one with minimum kinetic energy is the optimal transport geodesic, and its kinetic energy is .
[!remark] 5.3 The Benamou-Brenier formula reveals that the flow matching framework has been computing optimal transport all along — or rather, approximating it. The flow matching objective (4.1) trains a velocity field to satisfy the continuity equation; the conditional flow matching objective (4.3) does so efficiently using conditional paths. The minimum-norm velocity field that the objective converges to is the Benamou-Brenier minimizer — the velocity field of the optimal transport geodesic. Flow matching, properly understood, is a simulation-free method for approximating the Wasserstein geodesic between the noise distribution and the data distribution.
5.6 Displacement Interpolation
The minimizer of the Benamou-Brenier formula has a beautiful geometric structure discovered by McCann (1997).
[!definition] 5.3 — McCann’s Displacement Interpolation Given and with optimal transport map (Brenier’s theorem), the displacement interpolation is the curve of measures:
Each particle at moves along the straight line from to at constant speed.
Displacement interpolation is the geodesic in — the shortest path between and in Wasserstein space. Unlike the mixture interpolation , which simply fades between the two distributions, displacement interpolation physically moves the mass. The difference is dramatic: mixture interpolation of two separated Gaussians produces a bimodal intermediate distribution, while displacement interpolation produces a single Gaussian that slides from one to the other.
This is exactly the rectified flow interpolant from Section 4.6, but with the OT map replacing the random coupling. The rectified flow reflow procedure iteratively approximates the OT map, and with each iteration the interpolation becomes closer to displacement interpolation — the constant-speed geodesic in Wasserstein space.
McCann showed that many important functionals are convex along displacement interpolations — the entropy , the internal energy , the interaction energy — a property known as displacement convexity. This convexity is the geometric reason that the OT path is well-behaved: the objective landscape along the geodesic has no spurious local minima.
5.7 From Theory to Computation: Mini-Batch OT
The exact computation of the OT map between two continuous distributions is, in general, an infinite-dimensional optimization problem. For discrete distributions (empirical measures from samples), it reduces to a finite linear program — but the computational cost scales cubically in the number of samples.
The discrete problem. Given source points and target points , each with equal mass , the discrete OT problem with quadratic cost is:
where is the set of permutations. This is the linear assignment problem: find the bijection between source and target points that minimizes total squared distance. The Hungarian algorithm solves it in time; for large , the auction algorithm of Bertsekas gives practical performance.
Mini-batch OT for flow matching. At each training step, draw a mini-batch of noise samples and data samples. Solve the discrete OT problem (5.2) to obtain the optimal permutation . Pair each noise sample with the data sample and train using the conditional flow matching objective with these paired samples. The cost per step is dominated by the assignment algorithm: for batch size , which is acceptable for and negligible compared to the neural network forward/backward pass for .
Entropic regularization and Sinkhorn. An alternative is to replace the linear program with its entropy-regularized version:
where is the entropy of the coupling and is a regularization parameter. The solution has the form where is the Gibbs kernel, and the vectors and are found by alternating normalization — the Sinkhorn algorithm. This converges in time per iteration and produces a smooth coupling that approximates the exact OT solution as . We will develop the Sinkhorn algorithm and its connection to Schrödinger bridges in the next chapter.
5.8 The Geometry of Curved and Straight Paths
The practical importance of optimal transport for generative modeling reduces to a single geometric fact: OT paths are straight, and straight paths require fewer solver steps.
To make this precise, consider the linear interpolant under some coupling with marginals and . The conditional velocity is — constant in time and directed along the straight line from to . But the marginal velocity field is the conditional expectation over all pairs that pass through at time , and this expectation can vary with , producing a curved marginal field even though the conditional paths are straight.
The curvature of the marginal field is directly determined by the amount of crossing among the conditional paths. If two trajectories and cross — meaning their straight-line interpolants and coincide at some — then the marginal velocity at that point is an average of the two different directions, and this average changes as varies (the trajectories diverge after the crossing).
[!proposition] 5.4 — OT Coupling Minimizes Marginal Curvature Among all couplings with the linear interpolant , the optimal transport coupling minimizes the expected temporal variation of the marginal velocity field:
In the limit of a continuous base distribution, the OT coupling produces a marginal velocity field with zero temporal variation — the marginal trajectories are themselves straight lines.
The implication for generation is direct. Euler integration with step size has global error . For a perfectly straight marginal velocity field (zero curvature), a single Euler step is exact — one NFE suffices. For a curved field (independent coupling), many Euler steps are needed to track the curvature. The NFE-quality tradeoff is thus controlled by how close the training coupling is to the OT coupling.
This is the geometric reason that flow matching with OT conditioning generates good samples in 10–50 steps, while DDPM (which uses the VP-SDE interpolant with independent coupling) requires 1000. The straight-line interpolant under OT coupling is a discrete approximation to the displacement interpolation — the Wasserstein geodesic — and geodesics are the smoothest possible paths between two points.
5.9 Historical Notes
The Monge problem was posed in Monge (1781) (“Mémoire sur la théorie des déblais et des remblais”), motivated by military engineering — moving earth to build fortifications at minimum effort. Kantorovich (1942) reformulated the problem as a linear program in “On the translocation of masses,” work that contributed to his Nobel Prize in Economics (1975). Brenier (1991) proved the existence and uniqueness of the optimal map for quadratic cost as the gradient of a convex function, connecting optimal transport to convex analysis.
McCann (1997) introduced displacement interpolation and displacement convexity, giving the space of probability measures a Riemannian-like structure. Benamou and Brenier (2000) established the dynamic formulation (Theorem 5.3), connecting optimal transport to fluid mechanics and the continuity equation. Otto (2001) formalized the Riemannian structure of and showed that many PDEs (heat equation, porous medium equation) are gradient flows in this geometry.
The modern theory is systematized in Villani (2003) (“Topics in Optimal Transportation”) and Villani (2008) (“Optimal Transport: Old and New”), which remain the standard references. Cuturi (2013) (“Sinkhorn Distances: Lightspeed Computation of Optimal Transport”) brought computational OT to machine learning through entropic regularization and the Sinkhorn algorithm. Peyré and Cuturi (2019) (“Computational Optimal Transport”) is the standard reference for algorithmic aspects.
The connection to generative modeling was anticipated by Tabak and Vanden-Eijnden (2010) and Tabak and Turner (2013), who proposed transport-based density estimation using the continuity equation. The direct application to flow matching was developed by Pooladian, Ben-Hamu, Domingo-Enrich, Amos, Lipman, and Chen (2023) (“Multisample Flow Matching”), who demonstrated the practical benefits of mini-batch OT conditioning, and by Liu (2022) (“Rectified Flow”), who connected the reflow procedure to iterative OT approximation. The theoretical analysis of path straightness and its relation to NFE efficiency appears in Liu (2022) and Albergo, Boffi, and Vanden-Eijnden (2023) (“Stochastic Interpolants: A Unifying Framework for Flows and Diffusions”), who connected flow matching to the kinetic energy formulation of Benamou-Brenier.