Flow Matching & Rectified Flows
Continuous normalizing flows for generation: the flow matching objective, optimal transport paths, rectified flows, connection to diffusion, and why SD3 and Flux use flow matching.
Prerequisites
Table of Contents
- Learning Objectives
- Notation
- Core Intuition
- Continuous Normalizing Flows
- The Flow Matching Objective
- Conditional Flow Matching
- Rectified Flows
- Connection to Diffusion Models
- Advantages Over Diffusion
- Common Pitfalls
- Summary
- Exercises
Learning Objectives
- Define continuous normalizing flows and the transport equation.
- Derive the flow matching training objective.
- Explain why conditional flow matching makes training tractable.
- Derive rectified flows as straight-line interpolations.
- Compare flow matching vs diffusion in terms of sample quality and speed.
Notation
- — flow (diffeomorphism) at time
- — learned velocity field
- — probability density at time (evolving)
- ,
Core Intuition
Instead of adding and removing noise (diffusion), flow matching learns a velocity field that transports samples from noise () to data () along smooth paths. The simplest paths are straight lines between noise and data points. This leads to a simpler objective than diffusion, faster sampling (straighter paths need fewer integration steps), and a unified framework.
Flow Matching vs Diffusion
Continuous Normalizing Flows
A flow is defined by an ODE:
The density evolves according to the continuity equation:
Goal: Find such that is transported to .
The Flow Matching Objective
Ideal objective: Match the true velocity field that generates the target flow:
Problem: We don't know or (they depend on the optimal transport plan).
Conditional Flow Matching
Solution (Lipman et al., 2023): Condition on individual data points. Define a simple conditional flow for each data point :
This is a straight line from noise to data .
Conditional velocity:
Training objective (equivalent to FM):
Simplicity: Sample noise , sample data , interpolate to get , predict the velocity (direction from noise to data). That's it.
Rectified Flows
Rectified flow (Liu et al., 2022): The straight-line interpolation defines a "rectified" flow.
Property: If the learned velocity field perfectly matches, then the ODE trajectories are straight lines — requiring only one Euler step for perfect generation.
Reflow procedure: Iteratively straighten trajectories:
- Train flow matching model.
- Generate pairs by integrating the learned ODE.
- Retrain on these pairs (now the coupling is better than random).
- Repeat: trajectories become straighter each iteration.
After 2–3 reflow iterations, 1–4 step generation becomes possible.
Connection to Diffusion Models
Diffusion as a special flow: The VP-SDE diffusion process defines a specific (curved) path:
This is NOT a straight line (nonlinear interpolation). The corresponding velocity involves the score function.
Flow matching uses straight lines (equation 4): simpler, straighter paths → fewer ODE steps needed.
Equivalence: Both can achieve the same final quality, but flow matching reaches it in fewer steps because trajectories are straighter (less curvature → less numerical error per step).
Advantages Over Diffusion
1. Simpler objective: Predict instead of noise . No noise schedule needed.
2. Fewer sampling steps: Straight-line flows need 10–20 Euler steps for high quality (vs 50+ for diffusion).
3. No variance schedule tuning: The interpolation is the only "schedule."
4. Unified framework: Natural extension to other source distributions (not just Gaussian noise), optimal transport couplings, and conditional generation.
Common Pitfalls
Pitfall 1. Assuming flow matching is always better. For very high-quality samples (FID < 2), well-tuned diffusion with many steps can still match or beat flow matching.
Pitfall 2. Using random coupling between and . Random pairing creates crossing trajectories that are hard to learn. Optimal transport coupling (mini-batch OT) significantly improves quality.
Pitfall 3. Ignoring the simulation-free property. Flow matching is trained without simulating the ODE — each training step only needs a random and the interpolated point.
Summary
- Flow matching learns a velocity field transporting noise to data along straight lines.
- Conditional flow matching makes training tractable by conditioning on individual data points.
- Objective: Predict the velocity at interpolated points.
- Rectified flows iteratively straighten trajectories for few-step generation.
- Simpler than diffusion: no noise schedule, fewer steps, unified framework.
- Used in: Stable Diffusion 3, Flux, modern image/video generation.
Exercises
Exercise 1. Verify that satisfies and .
Exercise 2. Derive the conditional velocity field for the VP-SDE interpolation .
Exercise 3. Prove that the marginal flow matching objective (equation 3) equals the conditional flow matching objective (equation 6) in expectation.
Exercise 4. Explain why straight-line flows need fewer Euler steps than curved diffusion paths.
Exercise 5. Design a reflow procedure for a trained model and estimate the quality after 1, 2, and 3 reflow iterations.