Probability paths
Let be a simple source density on , usually the standard Gaussian , and let be the data density. Time runs from noise at to data at . A probability path is a family of densities , one for each , that starts at and ends at . Many paths connect the same two densities, and you choose one. A common choice draws and independently and moves along the straight line between them, The density of defines . You can sample from this path at any without knowing in closed form. The training loss in the last section of this page relies on that.The continuity equation
A path says where the mass is at each time. It does not say how the mass gets there. A velocity field gives that motion: mass at position and time moves with velocity . Probability mass is conserved, so the field and the path must satisfy the continuity equation The product is the flux of mass. Where more flux leaves a point than enters it, the density there falls. The dynamic transport section derives this equation by counting the mass in an interval. When a pair satisfies it, the field moves the path . In 1D the continuity equation determines the field from the path. In it does not. You can add to any field with , and the path stays the same. Many fields therefore move the same path, and flow matching picks one of them. For the straight-line path above it picks the conditional mean of the pair velocities, described in the last section of this page.Particles and the flow
The field also moves individual samples. A particle at follows the ordinary differential equation For each starting point the ODE has one trajectory , under mild smoothness conditions on . The map is the flow of the field. When satisfies the continuity equation with , pushing through the flow gives the path back: This is the sampling view of the same object. Draw from , carry it along the field, and is a sample from . At it is a sample from . Only the starting points are Gaussian. All the randomness comes from the initial draw, and the ODE fixes the rest of each trajectory. The flow is a transport map from to . It is in general not the optimal transport map of the transport maps and couplings section. In 1D two trajectories of the ODE cannot cross, so is increasing. An increasing map between two densities on the line is unique, so is the optimal map. In there is no such ordering argument.Generation as trajectory integration
Once a network approximates the field, you sample by integrating the ODE numerically. The simplest method is Euler integration with step size : This is the same loop used for the storm example. At each step you evaluate the field at the current position and move a short distance in that direction. Start from and continue until . The distribution of the result approximates . Higher-order solvers (Heun, RK4, adaptive Dormand-Prince) integrate the same field with fewer steps and lower truncation error. You can choose the solver independently of the field.Views of a velocity field
A velocity field has three common representations:- The vector field view draws the arrow at each point and time . Quiver plots show this view.
- The streamline view fixes and traces the integral curves of .
- The particle view releases a cloud of particles at and follows them as the field carries them. Trajectory plots show this view.
The learned velocity field
For a training sample on the straight-line path you know the velocity of its own pair. You do not know the field . Many pairs pass through the same point at the same time with different velocities. Flow matching uses their average, Flow matching gets this average from least squares regression. For random variables and , the function that minimizes is the conditional mean . Take the input to be with uniform on , and the target to be . The loss then has the field as its minimizer. You can compute every target in it from a sampled pair. Lipman et al. introduced this objective, and the references below cover it in detail. The loss does not reach zero. Write . Then with . The first term does not depend on . It is the variance of the pair velocities around their conditional mean, and it is the smallest value the loss can take. A coupling with less spread in at each point, such as optimal pairs, lowers this floor, because fewer different velocities pass through the same . The network regresses a vector-valued function of position and time. The 1D mixture section trains such a network, compares it with the exact field, and repeats the construction with couplings other than independent pairs.Score matching on the same path
The score-based section trains a network on the same kind of path with a different regression target. Write a Gaussian path in general form as with , , and . The straight line above is the case , . The score-based section runs time the other way, with the data at , and calls the noise sample . Only the labels differ. Both methods sample a pair, build and regress a target computed from that pair. Flow matching regresses the time derivative of , which is , or on the straight line. Its minimizer is the velocity . Denoising score matching regresses , and its minimizer is the score .References
- Paper: Lipman et al. (2024). Flow Matching Guide and Code. This self-contained review covers the mathematical foundations, design choices, and extensions. It includes a PyTorch reference implementation. Sections 2-3 cover velocity fields and the continuity equation.
- Foundational paper: Lipman et al. (2023). Flow Matching for Generative Modeling.
- Code:
facebookresearch/flow_matching, the companion library with examples for image and text generation.
PyTorch reference
Found an error on this page? Report an issue.

