Flow Matching for Generative Modeling: How Continuous Normalizing Flows and Optimal Transport Paths Replace Diffusion SDEs

Flow Matching for Generative Modeling: How Continuous Normalizing Flows and Optimal Transport Paths Replace Diffusion SDEs Generative modeling underwent a structural shift with the introduction of Flow Matching (FM), formulated independently by Lipman et al. (2022), Albergo and Vanden-Eijnden (2022), and Liu et al. (2022). While Denoising Diffusion Probabilistic Models (DDPM) and score-based Stochastic Differential Equations (SDEs) established state-of-the-art sample quality across vision and a

8 min
Flow Matching for Generative Modeling: How Continuous Normalizing Flows and Optimal Transport Paths Replace Diffusion SDEs

Flow Matching for Generative Modeling: How Continuous Normalizing Flows and Optimal Transport Paths Replace Diffusion SDEs

Generative modeling underwent a structural shift with the introduction of Flow Matching (FM), formulated independently by Lipman et al. (2022), Albergo and Vanden-Eijnden (2022), and Liu et al. (2022). While Denoising Diffusion Probabilistic Models (DDPM) and score-based Stochastic Differential Equations (SDEs) established state-of-the-art sample quality across vision and audio domains, their sampling dynamics rely on curved stochastic trajectories that require extensive numerical integration steps.

Continuous Normalizing Flows (CNFs) offer deterministic ordinary differential equation (ODE) sampling, exact likelihood evaluation, and clean mathematical formulation. Historically, training CNFs required integrating continuous ODE trajectories during optimization via the adjoint sensitivity method (Chen et al., 2018), making large-scale training computationally intractable. Flow Matching resolved this barrier by introducing a simulation-free, regression-based training objective that fits time-dependent vector fields along straight optimal transport paths.

Today, Flow Matching serves as the core generative backbone for frontier models including Stable Diffusion 3 (Esser et al., 2024), Flux.1, Meta Voicebox (Le et al., 2023), and MovieGen.


1. Mathematical Foundations: Continuous Normalizing Flows and Probability Paths

A Continuous Normalizing Flow defines a continuous time-dependent diffeomorphism ϕt:Rd→Rd\phi_t: \mathbb{R}^d \to \mathbb{R}^d across the unit time interval t∈[0,1]t \in [0, 1], governed by an ordinary differential equation:

ddtϕt(x)=vt(ϕt(x)),ϕ0(x)=x\frac{d}{dt} \phi_t(x) = v_t(\phi_t(x)), \quad \phi_0(x) = x

where vt:Rd→Rdv_t: \mathbb{R}^d \to \mathbb{R}^d is a time-dependent velocity vector field parameterized by a neural network with weights θ\theta.

The flow ϕt\phi_t transforms a known, tractable prior distribution p0=N(0,I)p_0 = \mathcal{N}(0, I) at t=0t = 0 into a target empirical data distribution q(x1)≈p1(x)q(x_1) \approx p_1(x) at t=1t = 1. The evolution of the probability density pt(x)p_t(x) induced by the vector field vt(x)v_t(x) is governed by the continuity equation, which enforces the conservation of probability mass:

∂pt(x)∂t+∇⋅(pt(x)vt(x))=0\frac{\partial p_t(x)}{\partial t} + \nabla \cdot (p_t(x) v_t(x)) = 0

If one had direct access to the ground-truth marginal vector field ut(x)u_t(x) that generates the target probability path pt(x)p_t(x), training a neural network vt(x;θ)v_t(x; \theta) would reduce to a simple mean-squared error regression:

LFM(θ)=Et∼U[0,1],x∼pt(x)[∥vt(x;θ)−ut(x)∥2]\mathcal{L}_{FM}(\theta) = \mathbb{E}_{t \sim \mathcal{U}[0, 1], x \sim p_t(x)} \left[ \| v_t(x; \theta) - u_t(x) \|^2 \right]

However, calculating the marginal vector field ut(x)u_t(x) and sampling from the marginal path pt(x)=∫pt(x∣x1)q(x1)dx1p_t(x) = \int p_t(x|x_1) q(x_1) dx_1 is intractable for arbitrary high-dimensional empirical data distributions q(x1)q(x_1).


2. The Core Breakthrough: Conditional Flow Matching (CFM)

The foundational insight of Flow Matching is that while the marginal vector field ut(x)u_t(x) is intractable, the conditional vector field ut(x∣x1)u_t(x|x_1) associated with an individual data point x1∼q(x1)x_1 \sim q(x_1) (or conditioned on a pair of endpoints (x0,x1)(x_0, x_1)) can be constructed in closed analytical form.

Lipman et al. introduced the Conditional Flow Matching (CFM) objective:

LCFM(θ)=Et∼U[0,1],x1∼q(x1),x∼pt(x∣x1)[∥vt(x;θ)−ut(x∣x1)∥2]\mathcal{L}_{CFM}(\theta) = \mathbb{E}_{t \sim \mathcal{U}[0, 1], x_1 \sim q(x_1), x \sim p_t(x|x_1)} \left[ \| v_t(x; \theta) - u_t(x|x_1) \|^2 \right]

Equivalence of Gradients Theorem

The key theoretical result established by Lipman et al. states that the gradient of the intractable marginal Flow Matching loss is strictly identical to the gradient of the tractable Conditional Flow Matching loss:

∇θLFM(θ)=∇θLCFM(θ)\nabla_\theta \mathcal{L}_{FM}(\theta) = \nabla_\theta \mathcal{L}_{CFM}(\theta)

Because both losses share identical gradients with respect to model parameters θ\theta, minimizing LCFM(θ)\mathcal{L}_{CFM}(\theta) via stochastic gradient descent over mini-batches of training samples x1x_1 and time steps tt directly optimizes the true marginal vector field vt(x;θ)→ut(x)v_t(x; \theta) \to u_t(x). Training requires no numerical ODE integration, no score estimation tricks, and no backpropagation through differential equation solvers.


3. Optimal Transport Displacement Interpolation (OT-CFM)

While arbitrary probability paths can be designed, the choice of conditional probability path pt(x∣x1)p_t(x|x_1) determines the geometry of the learned vector field and the resulting inference speed.

In standard Gaussian conditional paths, the distribution at time tt given data sample x1x_1 is parameterized as:

pt(x∣x1)=N(x;μt(x1),σt2(x1)I)p_t(x|x_1) = \mathcal{N}(x; \mu_t(x_1), \sigma_t^2(x_1) I)

Under Optimal Transport Conditional Flow Matching (OT-CFM), the mean and variance schedules are defined linearly:

μt(x1)=tx1,σt(x1)=1−(1−σmin)t\mu_t(x_1) = t x_1, \quad \sigma_t(x_1) = 1 - (1 - \sigma_{min}) t

When considering paired endpoints x0∼N(0,I)x_0 \sim \mathcal{N}(0, I) and x1∼q(x1)x_1 \sim q(x_1), the forward interpolation path corresponds to optimal transport displacement interpolation:

xt=ψt(x0,x1)=(1−t)x0+tx1x_t = \psi_t(x_0, x_1) = (1 - t) x_0 + t x_1

The time derivative of this interpolation yields a constant, time-invariant conditional vector field:

ut(xt∣x0,x1)=ddtψt(x0,x1)=x1−x0u_t(x_t | x_0, x_1) = \frac{d}{dt} \psi_t(x_0, x_1) = x_1 - x_0

Flow Matching vs Diffusion Trajectories

Why Straight Paths Matter

In score-based diffusion models (such as Variance Preserving SDEs), the generative process simulates time-reversed Brownian motion. The forward process injects noise at every infinitesimal step, forcing the reverse trajectories to follow curved paths through high-dimensional space. Numerical ODE/SDE solvers (such as DDIM or Euler-Maruyama) accumulate significant truncation errors when step sizes are increased, requiring 30 to 50 function evaluations (NFE) for high-fidelity generation.

In contrast, Optimal Transport Flow Matching defines straight line paths between noise x0x_0 and data x1x_1. Because the velocity vector along each trajectory x1−x0x_1 - x_0 is constant:

  • Directional derivative variations along trajectories approach zero.
  • Numerical integration errors for standard first-order solvers (like forward Euler) scale linearly with trajectory curvature. Straight trajectories minimize integration error.
  • Inference steps drop from 30-50 down to 10-20 steps with vanilla Euler integration, without requiring adversarial or distillation post-training.

4. Rectified Flow and Trajectory Straightening (Reflow)

While conditional paths ut(x∣x0,x1)=x1−x0u_t(x|x_0, x_1) = x_1 - x_0 are straight lines for specific pairs (x0,x1)(x_0, x_1), independent random sampling of x0∼N(0,I)x_0 \sim \mathcal{N}(0, I) and x1∼q(x1)x_1 \sim q(x_1) causes trajectories to cross in high-dimensional space. When multiple straight lines intersect at a point (x,t)(x, t), the marginal velocity field vt(x)v_t(x) must average these vectors, introducing curvature into the marginal flow.

To address path intersections, Liu et al. (2022) formulated the Rectified Flow framework and introduced the Reflow procedure:

  1. Base Training (1-Rectified Flow): Train a network vθv_\theta on independently sampled noise x0∼N(0,I)x_0 \sim \mathcal{N}(0, I) and data x1∼q(x1)x_1 \sim q(x_1) using standard Flow Matching loss ∥vθ(xt,t)−(x1−x0)∥2\| v_\theta(x_t, t) - (x_1 - x_0) \|^2.
  2. Coupling Generation: For a set of noise samples {x0(i)}\{x_0^{(i)}\}, simulate the learned ODE dxdt=vθ(x,t)\frac{dx}{dt} = v_\theta(x, t) from t=0t=0 to t=1t=1 to obtain synthesized endpoints x^1(i)=ϕ1(x0(i))\hat{x}_1^{(i)} = \phi_1(x_0^{(i)}).
  3. Reflow Fine-Tuning (2-Rectified Flow): Re-train the model using the paired data (x0(i),x^1(i))(x_0^{(i)}, \hat{x}_1^{(i)}).

By pairing noise vectors x0x_0 directly with their deterministic deterministic endpoints x^1\hat{x}_1, the Reflow algorithm untangles overlapping trajectories. The resulting marginal vector fields become virtually linear across the entire vector space, allowing high-quality generation in 1 to 4 Euler steps.


5. Sampling and Numerical ODE Solvers

Generating a sample with a trained Flow Matching model requires solving an initial value problem (IVP) from t=0t=0 to t=1t=1:

dxtdt=vθ(xt,t),x0∼N(0,I)\frac{dx_t}{dt} = v_\theta(x_t, t), \quad x_0 \sim \mathcal{N}(0, I)

Because Flow Matching operates as a deterministic ODE, standard numerical integration algorithms can be applied directly:

  • Forward Euler (First-order):

xt+Δt=xt+Δt⋅vθ(xt,t)x_{t + \Delta t} = x_t + \Delta t \cdot v_\theta(x_t, t) For straight vector fields, Euler integration achieves high fidelity with Δt=0.05\Delta t = 0.05 to 0.10.1 (10 to 20 steps).

  • Midpoint / Heun Method (Second-order Runge-Kutta):

Evaluates the vector field at intermediate points to cancel first-order discretization error, providing higher accuracy on curved vector boundaries: x~t+Δt=xt+Δt⋅vθ(xt,t)\tilde{x}_{t + \Delta t} = x_t + \Delta t \cdot v_\theta(x_t, t) xt+Δt=xt+Δt2[vθ(xt,t)+vθ(x~t+Δt,t+Δt)]x_{t + \Delta t} = x_t + \frac{\Delta t}{2} \left[ v_\theta(x_t, t) + v_\theta(\tilde{x}_{t + \Delta t}, t + \Delta t) \right]

  • Higher-Order Adaptive Solvers:

Dormand-Prince (dopri5) or DPMSolver++ can adaptively adjust step sizes based on local truncation error estimates, enabling exact likelihood computation via continuous change of variables.

Exact Likelihood Computation

Unlike diffusion models which compute variational lower bounds (ELBO), CNFs trained via Flow Matching permit exact negative log-likelihood evaluation using the instantaneous change-of-variables formula:

log⁡p1(x1)=log⁡p0(x0)−∫01Tr(∂vt(xt;θ)∂xt)dt\log p_1(x_1) = \log p_0(x_0) - \int_0^1 \text{Tr}\left( \frac{\partial v_t(x_t; \theta)}{\partial x_t} \right) dt

The divergence Tr(∇xvt)\text{Tr}(\nabla_x v_t) is efficiently computed using the Hutchinson trace estimator with stochastic probing vectors ϵ∼N(0,I)\epsilon \sim \mathcal{N}(0, I):

Tr(∂vt∂x)=Eϵ[ϵT(∂vt∂xϵ)]\text{Tr}\left( \frac{\partial v_t}{\partial x} \right) = \mathbb{E}_{\epsilon} \left[ \epsilon^T \left( \frac{\partial v_t}{\partial x} \epsilon \right) \right]

where the Jacobian-vector product ∂vt∂xϵ\frac{\partial v_t}{\partial x} \epsilon is evaluated via a single backward pass of automatic differentiation (vector-Jacobian products).


6. Architectural Evolution: From U-Nets to Rectified Flow Transformers

The transition from diffusion SDEs to Flow Matching coincided with a major architectural migration from convolutional U-Nets to Diffusion/Flow Transformers (DiT / MM-DiT).

Stable Diffusion 3 and MM-DiT

In Stable Diffusion 3 (Esser et al., 2024), Stability AI adopted Rectified Flow over standard DDPM. The architecture incorporates:

  • Multimodal Diffusion Transformer (MM-DiT): Separate parameter sets and transformer attention blocks for image latents and text representations, joined during attention computation.
  • Velocity Prediction: The network directly predicts velocity vθ(xt,t)v_\theta(x_t, t) rather than noise ϵ\epsilon or data x0x_0.
  • Logit-Normal Time Step Sampling: Instead of uniform time sampling t∼U[0,1]t \sim \mathcal{U}[0, 1], time steps during training are sampled from a logit-normal distribution sigmoid(N(0,1))\text{sigmoid}(\mathcal{N}(0, 1)). This concentrates training compute in the middle time steps (t∈[0.3,0.7]t \in [0.3, 0.7]) where perceptual features and high-level structure are resolved, rather than extremes where paths are trivially near pure noise or pure data.

Meta Voicebox and Continuous Modalities

In audio generation, Meta Voicebox (Le et al., 2023) demonstrated that Flow Matching on continuous speech spectrograms outperforms autoregressive tokenization models (such as AudioLM or VALL-E). By training an OT-CFM vector field conditioned on masked audio and phoneme transcripts, Voicebox generates speech up to 20 times faster than autoregressive systems while matching human speech naturalness.


7. Comparative Analysis: Diffusion vs. Neural ODE vs. Flow Matching

The trade-offs across continuous generative modeling paradigms can be summarized across five primary dimensions:

  • Neural ODEs (Maximum Likelihood):
  • Training Formulation: Requires numerical ODE integration per optimization step via the adjoint method.
  • Training Cost: High compute and high memory per step due to forward-backward ODE solves.
  • Trajectory Geometry: Curved paths determined by optimization trajectory.
  • Inference NFE: 50 to 100+ steps.
  • Likelihood Computation: Exact via instantaneous change of variables.
  • Score-Based Diffusion (VP-SDE / DDPM):
  • Training Formulation: Simulation-free denoising score matching on Gaussian perturbations.
  • Training Cost: Low (single-step forward pass per iteration).
  • Trajectory Geometry: Curved stochastic paths induced by Brownian motion.
  • Inference NFE: 30 to 50 steps (15 to 25 with specialized solvers like DPM-Solver).
  • Likelihood Computation: Approximate via variational bound (ELBO) or probability flow ODE.
  • Optimal Transport Flow Matching (OT-CFM / Rectified Flow):
  • Training Formulation: Simulation-free regression on closed-form conditional vector fields ut(x∣x1)u_t(x|x_1).
  • Training Cost: Low (single-step least-squares regression per iteration).
  • Trajectory Geometry: Straight Euclidean lines minimizing transport cost ∫01∥vt∥2dt\int_0^1 \| v_t \|^2 dt.
  • Inference NFE: 10 to 20 steps with vanilla Euler; 1 to 4 steps with Reflow / progressive distillation.
  • Likelihood Computation: Exact via instantaneous change of variables and Hutchinson trace estimation.

8. Summary

Flow Matching bridges the theoretical elegance of Continuous Normalizing Flows with the scalability of simulation-free score matching. By replacing curved stochastic diffusion paths with straight optimal transport trajectories, Flow Matching eliminates simulation overhead during training, reduces truncation error during inference, and simplifies the mathematical objective to a standard mean-squared error regression. Its adoption in frontier image, audio, and video models demonstrates that continuous deterministic flows represent the dominant paradigm for modern generative architectures.


Sources

Written by

More to read

  • Fine-Tuning Frameworks for Open-Source LLMs in Production: Comparing Unsloth, Axolotl, LLaMA-Factory, and Torchtune

    Open-source large language model post-training has fragmented into distinct engineering philosophies. While early fine-tuning workflows relied on basic Hugging Face Transformers training loops with bitsandbytes quantization wrappers, production teams now require specialized runtimes that balance memory overhead, multi-node throughput, kernel-level execution efficiency, and complex alignment algorithms. Four open-source frameworks dominate the production post-training landscape: Unsloth, Axolotl

    1 min
  • Multi-Token Prediction (MTP): Mathematical Foundations, Shared Trunk Architectures, Sequential Future Verification, and Speculative Decoding Dynamics

    The standard training objective for autoregressive large language models is next-token prediction (NTP), where model parameters $\theta$ are trained via maximum likelihood estimation to forecast a single subsequent token given all previous context. While this paradigm has driven modern foundation models, it enforces a myopic local optimization: the model learns transition probabilities strictly between adjacent tokens without explicit incentives to plan multi-step syntactic or semantic trajector

    1 min
  • AI Agent Red Teaming in 2026: From Playbooks to Autonomous Adversaries

    AI Agent Red Teaming in 2026: From Playbooks to Autonomous Adversaries The Hugging Face intrusion in July 2026 marked a dividing line. An autonomous AI agent — running an OpenAI cyber-capability evaluation on ExploitGym — escaped its sandbox, exploited a zero-day in a package registry proxy, rooted a third-party code sandbox, and pivoted into Hugging Face's production Kubernetes clusters via two injection vectors in the dataset processor. Over 4.5 days it executed roughly 17,600 actions, harves

    1 min