Flow Matching
1. Flow Matching (FM) and Conditional Flow Matching (CFM)
| Symbol | Description | Type/Dimension |
| Base distribution (typically simple, e.g., Gaussian) | Probability density | |
| Target data distribution | Probability density | |
| Probability path at time , connecting and | Probability density | |
| Conditional probability path given conditioning variable | Conditional density | |
| Conditioning variable for constructing conditional flows | Random variable | |
| Velocity field at time (marginal) | ||
| Conditional velocity field given condition | ||
| Neural network velocity field with parameters | ||
| Conditional flow map from initial point to time | ||
| Time variable, typically | ||
| Spatial position variable | ||
| Position at initial time | ||
| Position at final time | ||
| Neural network parameters | Parameter space | |
| Conditional Flow Matching loss function | ||
| Flow Matching loss function (intractable) |
1.1. Flow Matching Overview
Flow Matching is a framework for training continuous normalizing flows by learning velocity fields that transform a simple base distribution into a target data distribution. The key insight is to parameterize the transformation through a time-dependent velocity field that defines an ordinary differential equation.
Given a probability path that interpolates between (base distribution) and (data distribution), the velocity field must satisfy the continuity equation:
However, directly learning from this equation is challenging because:
- We don't know the true for intermediate times
- The continuity equation provides insufficient supervision
- There are infinitely many velocity fields satisfying the boundary conditions
CFM solves these issues by introducing conditional probability paths that enable tractable training.
1.2. Conditional Flow Matching (CFM)
The goal of CFM is to find a velocity field . However, there exists an infinite number of velocity fields that can satisfy the continuity equation for a given probability path. In order to get supervision for all , one must fully specify a probability path and its corresponding velocity field.
1.2.1. How to fully specify a probability path and velocity field ?
The key challenge is that solving the continuity equation for given has infinitely many solutions. CFM's core idea is to avoid this difficulty by constructively defining both the probability path and velocity field through:
- Choose a conditioning variable
- Design conditional probability paths with known flow maps
- Obtain the velocity field analytically via
We want to ensure two conditions are met:
- The induced global probability transforms into .
- The associated velocity field has an analytic form obtained from the flow construction.
1.2.2. Linear Interpolation
1.2.2.1. Conditioning on Base and Target Points
The conditional variable is defined as
1.2.2.2. Flow Construction and Velocity Field
We construct a deterministic linear flow between and :
This induces the probability path:
The velocity field is obtained by differentiating the flow map:
We can verify that this velocity field satisfies the continuity equation.
1.2.3. Conical Gaussian Paths
1.2.3.1. Alternative Conditioning Choice
We can make other choices for the conditional variable:
1.2.3.2. Flow Construction
We construct a flow that starts from a standard Gaussian and converges to the target point:
This induces the conditional probability path:
The corresponding velocity field is:
where we use the fact that by inverting the flow map.
1.2.4. General construction of conditional probability paths
The general CFM construction follows these steps:
- First, choose a conditioning variable (independent of )
- Second, design flow maps that connect the source and target distributions
- Third, obtain conditional probability paths as the push-forward of the source under the flow
- Fourth, derive velocity fields analytically
The conditional probability paths must satisfy the boundary conditions:
This construction ensures that:
- We avoid solving the ill-posed continuity equation
- The velocity field has an analytical, tractable form
- The global probability path correctly interpolates between and
1.2.5. From Conditional to Unconditional Velocity
Theorem: Let be any random variable independent of . Choose conditional probability paths , and let be the velocity field associated to these paths. Then the marginal velocity field associated to the probability path has a closed-form formula:
This is intractable in general, so we use a neural network to estimate. The training objective is to minimize the tractable Conditional Flow Matching (CFM) loss:
We can use the above loss because it's equivalent to directly regressing against the intractable unknown vector field 1:
2. Rectified Flow
Rectified Flow is a specific and powerful instantiation of the Flow Matching framework. It simplifies the construction of the probability path and velocity field by focusing on creating the straightest possible trajectories between points from the source and target distributions. This approach not only provides a clear and simple training objective but also leads to highly efficient generative models.
The core idea is to "rectify" the coupling between the base distribution and the target distribution . Instead of arbitrary or complex conditional paths, Rectified Flow learns an Ordinary Differential Equation (ODE) that transports mass along straight lines.
2.1. 1-Rectified Flow: The Direct Path
The initial Rectified Flow, often called the 1-rectified flow, is constructed in a manner very similar to the linear interpolation method in CFM.
2.1.1. Construction
We start by creating the simplest possible coupling between the base and target distributions: an independent coupling. We draw a pair of samples, and , and define a straight-line path between them.
The flow map is a direct linear interpolation:
This is the same as the "Linear Interpolation" above. The key difference in Rectified Flow is the focus on this specific construction and its iterative refinement.
The velocity field for this path is constant with respect to time for a given pair :
2.1.2. The "Rectified" Velocity Field
While individual paths are straight, the marginal velocity field at a point is the average velocity of all straight-line paths that pass through at time . This averaging process is what "rectifies" the flow. The resulting marginal velocity field is generally non-linear and complex, and it defines a deterministic flow that transforms to .
The training objective for a neural network is a straightforward regression problem, identical to the CFM loss but with this specific choice of conditional velocity:
This loss aims to learn the expected velocity where .
The resulting trained model can then be used to generate samples by solving the ODE from to , starting with a sample .
2.2. 2-Rectified Flow (and beyond): The "Reflow" Procedure

A key innovation of Rectified Flow is the reflow procedure. While the 1-rectified flow is a significant step, its trajectories are only perfectly straight if the model perfectly learns the conditional expectation. In practice, the generated paths from the 1-rectified flow model will have some curvature.
The reflow procedure aims to iteratively straighten these paths.
2.2.1. The Reflow Algorithm
-
Train the 1-Rectified Flow: First, train a velocity field using the direct straight-line paths between and as described above.
-
Generate a New Paired Dataset: Use the trained model to generate a new set of paired samples.
- Sample .
- Solve the ODE from to to obtain the corresponding endpoint .
- This creates a new dataset of pairs that represent a deterministic coupling induced by the 1-rectified flow.
-
Train the 2-Rectified Flow: Train a new velocity field using the same loss function, but on the new data pairs .
This process can be repeated to create 3-rectified flows and so on, with each iteration producing increasingly straight trajectories.
-
Proof that :
We need to show that minimizing the CFM loss is equivalent to minimizing the intractable loss up to a constant. We prove this by showing the gradients are equal.
Let be the squared L2 distance. Then:
Taking gradients: