Optimal Flow Matching: Learning Straight Trajectories in Just One Step

Nikita Kornilov, Petr Mokrov, Alexander Gasnikov, Alexander Korotin

TL;DR

Optimal Flow Matching (OFM) is a new generative modeling approach that learns straight, Optimal Transport (OT) trajectories in a single training step. By parameterizing vector fields as gradients of convex functions using Input Convex Neural Networks (ICNNs), OFM avoids the error accumulation of iterative methods and the biases of minibatch heuristics, enabling faster and more accurate inference.

What Problem Does This Paper Address?

Generative models based on Flow Matching (FM) move a simple source distribution (like noise) to a complex target distribution (like images) along a vector field. Ideally, these paths should be straight lines—this corresponds to the "Optimal Transport" displacement, which minimizes the "effort" of moving mass. Straight paths are highly desirable because they allow for extremely fast inference; you can jump from start to finish in a single step without needing to solve a complex Ordinary Differential Equation (ODE).

However, standard FM often produces curved paths. Existing solutions have significant drawbacks:

  1. Rectified Flow (RF): Straightens paths iteratively, but each iteration accumulates numerical errors and requires expensive ODE integration during training.
  2. OT-Conditional Flow Matching (OT-CFM): Uses minibatch OT as a heuristic, which is biased and doesn't guarantee truly straight trajectories in practice.

Methods

The authors introduce Optimal Flow Matching (OFM). The core innovation is restricting the search space of vector fields to only those that must produce straight paths by design.

The Secret Sauce: Convexity

Instead of learning a general vector field $u_t(x)$, OFM parameterizes the vector field as the gradient of a convex function $\Psi$. Specifically, they use Input Convex Neural Networks (ICNNs) to represent $\Psi$.

Mathematically, they show that for quadratic transport costs, the optimal vector field $u^*$ defines linear trajectories: $$z_t = (1 - t)z_0 + t\nabla\Psi^*(z_0)$$ where $\Psi^*$ is the Brenier potential.

Our Optimal Flow Matching (OFM) obtains exactly straight trajectories in just a single FM loss minimization.

Training without ODEs

To train the model, they derive a novel loss function that is theoretically equivalent to the dual Optimal Transport loss. A key challenge is that the vector field formula depends on the initial point $z_0$, but during training, we only have the interpolated point $x_t$. To solve this, they perform a flow map inversion: finding the $z_0$ that leads to $x_t$ is framed as a strongly convex optimization sub-problem, which can be solved efficiently using standard optimizers like LBFGS.

An Optimal Vector Field with straight paths is parametrized by a gradient of a convex function.

Datasets

The authors evaluated OFM across three distinct regimes:

  1. Illustrative 2D Scenario: Moving a standard Gaussian to a Mixture of 8 Gaussians.
  2. High-dimensional OT Benchmarks: A standard suite of continuous distributions (dimensions $D=2$ to $256$) where the ground-truth OT map is known.
  3. Unpaired Image-to-Image Translation: Translating between "Adult" and "Child" faces using the FFHQ dataset. This was performed in the 512-dimensional latent space of a pre-trained ALAE autoencoder.

Key Insights and Ideas

  • Theoretical Bridge: The paper proves that minimizing the OFM loss is mathematically equivalent to minimizing the dual OT loss. This provides a rigorous foundation that previous heuristic methods lacked.
  • Plan Independence: Standard Flow Matching is sensitive to how you pair source and target points (the "transport plan"). OFM is theoretically agnostic to this choice; whether you use random pairing or minibatch OT, it converges to the same optimal straight-path solution.
  • One-Step Convergence: Unlike Rectified Flow, which requires multiple rounds of training and sampling to straighten paths, OFM achieves OT-optimality in a single training run.
  • Simulation-Free Inference: Because the learned trajectories are straight, the model can generate samples in one step during inference, bypassing the need for ODE solvers.

Key Results

  • Benchmark Performance: On high-dimensional OT tasks, OFM significantly outperformed other FM-based methods. For example, in 128 dimensions, OFM achieved an $L^2$-UVP (Unexplained Variance Percentage) of 1.5% - 1.9%, while OT-CFM scored 12.1% and Rectified Flow scored over 80%.
  • Image Translation: In the Adult $\to$ Child face translation task, OFM achieved a Frechet Inception Distance (FID) of 11.0, outperforming OT-CFM (12.9) and c-Rectified Flow (13.5).
  • Empirical Stability: 2D experiments confirmed that OFM finds the same straight-line solution regardless of whether the initial training pairs were independent, minibatch-optimized, or even "anti-optimized" (misleading pairs).
OFM finds the same solution for all initial plans π in the 2D setup.

Limitations and Future Work

  • Computational Cost of Inversion: While OFM is "one-step" in terms of training iterations, each training step requires solving an inner optimization problem (flow map inversion) and inverting a Hessian matrix, which is computationally expensive.
  • ICNN Expressivity: Input Convex Neural Networks are harder to train and potentially less expressive than standard architectures. The authors note that more expressive ICNN architectures are a promising area for future research.
  • Quadratic Cost Restriction: The current theory is specifically tailored for the quadratic transport cost ($W_2$ distance). Extending this to general cost functions remains an open challenge.

Summary updated

Abstract

Over the several recent years, there has been a boom in development of Flow Matching (FM) methods for generative modeling. One intriguing property pursued by the community is the ability to learn flows with straight trajectories which realize the Optimal Transport (OT) displacements. Straightness is crucial for the fast integration (inference) of the learned flow's paths. Unfortunately, most existing flow straightening methods are based on non-trivial iterative FM procedures which accumulate the error during training or exploit heuristics based on minibatch OT. To address these issues, we develop and theoretically justify the novel \textbf{Optimal Flow Matching} (OFM) approach which allows recovering the straight OT displacement for the quadratic transport in just one FM step. The main idea of our approach is the employment of vector field for FM which are parameterized by convex functions.
BibTeX
@inproceedings{kornilov2024optimal,
  author = {Nikita Kornilov and Petr Mokrov and Alexander Gasnikov and Alexander Korotin},
  title = {{Optimal Flow Matching: Learning Straight Trajectories in Just One Step}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=kqmucDKVcU},
}
Figure