Generative Vision

Flow Matching

A simulation-free way to train continuous normalizing flows by regressing a network onto the velocity of a chosen path between noise and data; conditional flow matching and why it equals the marginal objective, straight-line (rectified flow) paths, minibatch optimal-transport couplings, reflow, the link to diffusion models, and its use in Stable Diffusion 3.

advanced

Flow matching trains a generative model as an ordinary differential equation (ODE). The model is a time-dependent velocity field: started from Gaussian noise and integrated over a unit time interval, it carries the noise to an image. Such a model is a continuous normalizing flow (CNF), the continuous-time member of the normalizing flow family, but flow matching trains it without solving the ODE during training. It fixes a path in advance that moves each noise sample to a data sample, and regresses the network onto the velocity of that path, a plain least-squares loss in the manner of diffusion model training. The later papers used here credit the idea to three ICLR 2023 papers: Flow Matching (Lipman, Chen, Ben-Hamu, Nickel & Le), rectified flow (Liu, Gong & Liu) and stochastic interpolants (Albergo & Vanden-Eijnden). Only their abstracts could be read for this article, so the method is described here from the two later papers that set it out in full, Multisample Flow Matching (Pooladian et al., 2023) and Stable Diffusion 3 (Esser et al., 2024), and from official code. With straight-line paths the method is often called rectified flow; Stable Diffusion 3 is trained this way.

Purpose

A CNF defines its samples by dx/dt=vθ(x,t)dx/dt = v_\theta(x, t). Fitting it by maximum likelihood means solving this ODE, and differentiating through the solver, at every training step. Esser et al. (2024, §2) describe this as computationally expensive, especially for large networks. Flow matching removes the solver from training: given any path of distributions ptp_t from noise to data and a velocity field utu_t that generates it, the network is fitted to utu_t by regression at random times. The cost per step is one network evaluation, as for a diffusion model.

The second aim is fast sampling. The path is a design choice, and it fixes the ODE the network learns. A path whose trajectories are straight can be integrated accurately in a few large steps; Esser et al. (§1) note that a straight path could in principle be simulated in a single step and is less prone to error accumulation, while the curved trajectories of common diffusion ODEs need many solver steps (Appendix A).

When to Use It

Flow matching fits the same uses as diffusion models: image, video and other generation from noise, conditioned on text or other inputs. It is a training objective and a choice of path, not an architecture, so the same U-Net or transformer serves both. It is worth considering when:

  • Few-step sampling matters. The straight-path formulation degraded less than diffusion formulations when the number of sampling steps was cut in Esser et al.’s study (§5.1.1, Fig. 3), and couplings or reflow can straighten the flow further (below).
  • A deterministic map is needed. In our reading, the ODE gives a one-to-one map between noise and samples, which can be run backward, as for DDIM in diffusion sampling.
  • Two arbitrary distributions must be connected. The construction does not need a Gaussian source; Pooladian et al. (§6.3) use it to approximate optimal transport maps between two Gaussian mixtures.

It does not by itself give single-step generation from a curved flow: one-step models are obtained by distillation or by straightening the flow with reflow, and consistency models offer another route.

How It Works

The notation follows Pooladian et al.: noise x0∼q0=N(0,I)x_0 \sim q_0 = \mathcal{N}(0, I) at t=0t = 0, data x1∼q1x_1 \sim q_1 at t=1t = 1, and a flow ψt\psi_t defined by ddtψt(x0)=ut(ψt(x0))\tfrac{d}{dt}\psi_t(x_0) = u_t(\psi_t(x_0)), ψ0(x0)=x0\psi_0(x_0) = x_0. A field utu_t generates a probability path ptp_t if pushing q0q_0 through ψt\psi_t gives ptp_t. Stable Diffusion 3 and the latent diffusion article use the reverse time direction, data at t=0t = 0 and noise at t=1t = 1; formulas quoted from Stable Diffusion 3 below keep its direction and say so.

The flow matching objective

If a pair (pt,ut)(p_t, u_t) with p0=q0p_0 = q_0 and p1=q1p_1 = q_1 were known, the network could be trained with the flow matching (FM) loss

LFM(θ)=Et, x∼pt∥vθ(x,t)−ut(x)∥2,\mathcal{L}_{\text{FM}}(\theta) = \mathbb{E}_{t,\, x \sim p_t} \big\lVert v_\theta(x, t) - u_t(x) \big\rVert^2,

with tt uniform on [0,1][0, 1] (Pooladian et al., Eq. 3; Esser et al., Eq. 7). Neither ptp_t nor utu_t is known for real data, which is why this loss is intractable as written.

Conditional paths and the marginal field

Lipman et al.’s construction, as Pooladian et al. (§2.2) set it out, starts from paths conditioned on one data point. A conditional path pt(x∣x1)p_t(x \mid x_1) begins at the noise distribution and ends at a point mass on x1x_1; it is generated by a conditional field ut(x∣x1)u_t(x \mid x_1) that is easy to write down. Averaging over the data gives the marginal path and the marginal field

pt(x)=∫pt(x∣x1) q1(x1) dx1,ut(x)=∫ut(x∣x1) pt(x∣x1) q1(x1)pt(x) dx1p_t(x) = \int p_t(x \mid x_1)\, q_1(x_1)\, dx_1, \qquad u_t(x) = \int u_t(x \mid x_1)\, \frac{p_t(x \mid x_1)\, q_1(x_1)}{p_t(x)}\, dx_1

(Eqs. 4–5). The marginal field generates the marginal path. Esser et al. (Appendix B.1) give the proof through the continuity equation, ∂tpt+∇⋅(ptut)=0\partial_t p_t + \nabla \cdot (p_t u_t) = 0, which holds for each conditional pair and is linear, so it survives the average. The marginal field is therefore a velocity field whose flow carries the noise distribution exactly to the data distribution, and the second expression says that it is a posterior average: the conditional velocities of all data points that could have produced xx at time tt, weighted by how likely each one is.

Conditional flow matching

The conditional flow matching (CFM) loss regresses the network onto the conditional field instead:

LCFM(θ)=Et, x1∼q1, x∼pt(x∣x1)∥vθ(x,t)−ut(x∣x1)∥2.\mathcal{L}_{\text{CFM}}(\theta) = \mathbb{E}_{t,\, x_1 \sim q_1,\, x \sim p_t(x \mid x_1)} \big\lVert v_\theta(x, t) - u_t(x \mid x_1) \big\rVert^2 .

It has the same gradient with respect to θ\theta as LFM\mathcal{L}_{\text{FM}} (Lipman et al.’s Theorem 2, as Pooladian et al. state it). Esser et al. (Appendix B.1, Eqs. 27–33) expand both squares: the ∥vθ∥2\lVert v_\theta \rVert^2 terms agree, and the cross terms agree because the marginal field is the posterior average of the conditional ones, so

LFM(θ)=LCFM(θ)+c,\mathcal{L}_{\text{FM}}(\theta) = \mathcal{L}_{\text{CFM}}(\theta) + c,

with cc independent of θ\theta. In our reading the identity is the familiar fact that least squares estimates a conditional mean: the minimizer of LCFM\mathcal{L}_{\text{CFM}} is E[ut(x∣x1)∣xt=x]=ut(x)\mathbb{E}[u_t(x \mid x_1) \mid x_t = x] = u_t(x), and the loss left at the optimum is the variance of the conditional target around it. The same argument turns denoising into score matching in diffusion models.

Straight paths

The most used conditional path moves each point at constant speed along a straight line. Pooladian et al. (§2.2.1) call it the conditional optimal transport (CondOT) path, because for a standard Gaussian source it is the optimal transport displacement interpolant between the noise and the point x1x_1:

xt=ψt(x0∣x1)=(1−t) x0+t x1,ut(x∣x1)=x1−x1−t=x1−x0x_t = \psi_t(x_0 \mid x_1) = (1 - t)\, x_0 + t\, x_1, \qquad u_t(x \mid x_1) = \frac{x_1 - x}{1 - t} = x_1 - x_0

(Eqs. 8–10). Training is then a few lines: draw noise x0x_0, an image x1x_1 and a time tt; form xtx_t; regress vθ(xt,t)v_\theta(x_t, t) onto x1−x0x_1 - x_0. Pooladian et al. note that Liu et al. and Albergo and Vanden-Eijnden studied the same straight paths, where the conditional flow is called a stochastic interpolant, and Esser et al. use rectified flow (RF) for the forward process zt=(1−t) x0+t ϵz_t = (1 - t)\, x_0 + t\, \epsilon in their own direction of time (§3, Eq. 13).

Each conditional path is straight, but the marginal flow is not: many pairs (x0,x1)(x_0, x_1) pass through the same point xx at time tt with different directions, and the marginal field averages them. Pooladian et al. stress that a straight conditional path does not make the marginal path anywhere close to the optimal transport path between noise and data (§1). The example below shows how curved the marginal flow of a mixture of shapes is.

Straightness. Pooladian et al. (§3, Eqs. 18–19) measure it by

S=Et, x0[∥ut(ψt(x0))∥2−∥ψ1(x0)−x0∥2]=Et, x0∥ut(ψt(x0))−Et′[ut′(ψt′(x0))]∥2,S = \mathbb{E}_{t,\, x_0} \Big[ \big\lVert u_t(\psi_t(x_0)) \big\rVert^2 - \big\lVert \psi_1(x_0) - x_0 \big\rVert^2 \Big] = \mathbb{E}_{t,\, x_0} \big\lVert u_t(\psi_t(x_0)) - \mathbb{E}_{t'}[u_{t'}(\psi_{t'}(x_0))] \big\rVert^2 ,

the variance of the velocity along each trajectory, which is zero only for straight lines travelled at constant speed. The second term in the first form is the transport cost of the map x0↦ψ1(x0)x_0 \mapsto \psi_1(x_0).

Gaussian paths and the relation to diffusion

Lipman et al. showed, in Pooladian et al.’s account (§2.2.1), that the conditional construction works for any Gaussian conditional path pt(x∣x1)=N(x∣μt(x1),σt(x1)2I)p_t(x \mid x_1) = \mathcal{N}(x \mid \mu_t(x_1), \sigma_t(x_1)^2 I), a family that includes the paths of most earlier diffusion models; the straight path is one member. Esser et al. (§2) write the forward process as zt=atx0+btϵz_t = a_t x_0 + b_t \epsilon in their direction of time and show that CFM with any such path is a noise-prediction loss with a time-dependent weight. With λt=log⁡(at2/bt2)\lambda_t = \log(a_t^2 / b_t^2), the log signal-to-noise ratio, the conditional target is

ut(zt∣ϵ)=at′at zt−bt2 λt′ ϵu_t(z_t \mid \epsilon) = \frac{a_t'}{a_t}\, z_t - \frac{b_t}{2}\, \lambda_t'\, \epsilon

(Eq. 10), so a velocity network defines a noise predictor ϵΘ=−2λt′bt(vΘ−at′atz)\epsilon_\Theta = -\tfrac{2}{\lambda_t' b_t}\big(v_\Theta - \tfrac{a_t'}{a_t} z\big) and LCFM\mathcal{L}_{\text{CFM}} becomes a weighted ∥ϵΘ−ϵ∥2\lVert \epsilon_\Theta - \epsilon \rVert^2 (Eqs. 11–12). In the unified form of Kingma and Gao that Esser et al. adopt, Lw=−12 Et,ϵ wtλt′∥ϵΘ(zt,t)−ϵ∥2\mathcal{L}_w = -\tfrac{1}{2}\, \mathbb{E}_{t, \epsilon}\, w_t \lambda_t' \lVert \epsilon_\Theta(z_t, t) - \epsilon \rVert^2, rectified flow has weight wtRF=t/(1−t)w_t^{\text{RF}} = t/(1 - t), the cosine schedule with ϵ\epsilon-prediction sech⁡(λt/2)\operatorname{sech}(\lambda_t / 2) and with v-prediction e−λt/2e^{-\lambda_t / 2} (§3). A time-dependent weighting does not change the optimum of the objective, but it can change the optimization (§2), so for a given path the formulations differ in how training effort is spread over noise levels. The three parameterizations of the diffusion model article carry over: on the straight path, in Esser et al.’s direction of time, x^0=zt−t v\hat x_0 = z_t - t\, v and ϵ^=zt+(1−t) v\hat\epsilon = z_t + (1 - t)\, v (our algebra), and the sd3.5 reference code computes its denoised estimate as model_input - model_output * sigma, the first of these.

How to Apply It

Training. One step of CFM with straight paths:

  1. Draw a batch of images x1x_1 (or their latents), noise x0∼N(0,I)x_0 \sim \mathcal{N}(0, I), and times tt.
  2. Form xt=(1−t) x0+t x1x_t = (1 - t)\, x_0 + t\, x_1.
  3. Minimize ∥vθ(xt,t,c)−(x1−x0)∥2\lVert v_\theta(x_t, t, c) - (x_1 - x_0) \rVert^2, with any condition cc, such as a text embedding, given to the network.

The official flow_matching library of Meta expresses the path as Xt=αtX1+σtX0X_t = \alpha_t X_1 + \sigma_t X_0, with schedulers that supply αt\alpha_t, σt\sigma_t and their derivatives; the straight path is its CondOTScheduler (αt=t\alpha_t = t, σt=1−t\sigma_t = 1 - t), and others include polynomial, variance-preserving and cosine schedules. Its affine path also converts between velocity, data and noise predictions, so one trained network can be read in any of the three forms (path/affine.py, path/scheduler/scheduler.py, commit 11568d3).

Sampling. Integrate dx/dt=vθ(x,t)dx/dt = v_\theta(x, t) from noise at t=0t = 0 to t=1t = 1. The library’s ODESolver calls torchdiffeq and defaults to Euler’s method, with midpoint, heun3 and the adaptive dopri5 among the alternatives (solver/ode_solver.py). Esser et al. sampled all models of their formulation study with Euler steps (Appendix B.3). The solver choices of diffusion sampling apply unchanged, since, in our reading, a flow-matching model trained on a Gaussian path with independent pairs is a probability-flow ODE with a particular schedule; Esser et al. sampled with classifier-free guidance scales of 1.0, 2.5 and 5.0 (Appendix B.3).

Timestep sampling. Uniform tt trains every noise level equally, but Esser et al. argue that the velocity target is hardest to predict in the middle of the path, since near either end the optimal prediction is close to the mean of one of the two distributions (§3.1). Sampling tt from a density π(t)\pi(t) instead of uniformly is equivalent to the weight wtπ=t1−t π(t)w_t^\pi = \tfrac{t}{1 - t}\, \pi(t) (Eq. 18, in their direction of time). They tried a logit-normal density, t=sigmoid⁡(u)t = \operatorname{sigmoid}(u) with u∼N(m,s2)u \sim \mathcal{N}(m, s^2), a heavy-tailed “mode” density that stays positive at the ends, and a mapping that matches the log-SNR of the cosine schedule (§3.1).

Resolution shift. Higher resolutions need more noise to destroy the same image, because many noisy pixels together still reveal a constant image. Esser et al. match the uncertainty of a constant image between resolutions of nn and mm pixels; with α=m/n\alpha = \sqrt{m/n} and noise at t=1t = 1 as in their paper, the timestep at the new resolution is tm=α tn/(1+(α−1) tn)t_m = \alpha\, t_n / \big(1 + (\alpha - 1)\, t_n\big), which lowers the log-SNR by 2log⁡α2 \log \alpha (Appendix C.2, Eqs. 34–35). In a human preference study at 1024×10241024 \times 1024 they found a strong preference for shifts above 1.5 and used α=3.0\alpha = 3.0 for both training and sampling. The sd3.5 reference code applies the same map to its sampling schedule, shift * t / (1 + (shift - 1) * t) (sd3_impls.py, commit 8565799). Its settings table gives a shift of 3.0 for the SD 3.5 models and 1.0 for SD 3 Medium, although a comment in the same file says that the publicly released models use 3.0 (sd3_infer.py, as of November 2026).

Example: the exact velocity field of a mixture of shapes

The example computes the marginal field in closed form, so that the properties above can be measured without any learning error. The data are the Gaussian mixture of Diffusion Sampling’s example: four 16×1616 \times 16 shapes (disk, square, plus sign, diagonal bar) with pixel values ±1\pm 1, weights 0.4, 0.3, 0.2 and 0.1, and pixel noise of standard deviation τ=0.1\tau = 0.1. Under the straight path with independent noise and data, a component kk with mean μk\mu_k puts xtx_t at N(tμk,st2I)\mathcal{N}(t \mu_k, s_t^2 I) with st2=(1−t)2+t2τ2s_t^2 = (1 - t)^2 + t^2 \tau^2, and Gaussian conditioning (our derivation) gives

ut(x)=mt(x)+tτ2−(1−t)st2 (x−t mt(x)),mt(x)=∑krk(x,t) μk,u_t(x) = m_t(x) + \frac{t \tau^2 - (1 - t)}{s_t^2}\, \big(x - t\, m_t(x)\big), \qquad m_t(x) = \sum_k r_k(x, t)\, \mu_k ,

where rkr_k is the posterior probability of component kk given xt=xx_t = x. At t=0t = 0 this is E[x1]−x\mathbb{E}[x_1] - x, so a single Euler step sends every noise image to the same place, the mean of the four shapes.

The script checks four things. First, that utu_t is the conditional mean of the target x1−x0x_1 - x_0: the residual of the target should have zero mean and be uncorrelated with ut(xt)u_t(x_t) and with xtx_t. Second, the identity LCFM(θ)=LFM(θ)+LCFM(u)\mathcal{L}_{\text{CFM}}(\theta) = \mathcal{L}_{\text{FM}}(\theta) + \mathcal{L}_{\text{CFM}}(u) for a small multilayer perceptron trained with the CFM loss for 3,000 steps. The identity holds for any network, so this one is not trained to a good fit and only its losses are used. Third, that the exact flow, integrated with 200 Runge–Kutta (RK4) steps, reproduces the data, and its transport cost and straightness per pixel (Pooladian et al., Eq. 18, with the time integral taken by the trapezoid rule on the RK4 grid). Fourth, the median root-mean-square (RMS) distance per pixel between Euler’s method with 1 to 16 steps and the RK4 endpoint, from the same 1,000 noise images. Diffusion Sampling’s example compares samplers on the same data; this one measures how far the marginal flow is from straight.

The script needs NumPy and PyTorch (output from PyTorch 2.14.1 and NumPy 2.5.4, four CPU threads); it ran in 16 to 36 seconds on a laptop CPU in our runs, most of it training the network.

import sys
import numpy as np
import torch
import torch.nn as nn

seed = int(sys.argv[1]) if len(sys.argv) > 1 else 0
torch.set_num_threads(4)
torch.manual_seed(seed)
rng = np.random.default_rng(seed)

# Data of the Diffusion Sampling article: four 16x16 shapes in [-1, 1], x1 = mu_k + 0.1 * noise.
yy, xx = np.mgrid[:16, :16]
shapes = [(yy - 7.5) ** 2 + (xx - 7.5) ** 2 < 5.5 ** 2,          # disk
          (abs(yy - 7.5) < 5) & (abs(xx - 7.5) < 5),               # square
          (abs(yy - 7.5) < 2) | (abs(xx - 7.5) < 2),               # plus
          abs(yy - xx) < 2.5]                                      # diagonal bar
mu = np.array([np.where(m, 1.0, -1.0).ravel() for m in shapes])   # (4, 256)
w = np.array([0.4, 0.3, 0.2, 0.1])
tau2, D = 0.1 ** 2, 256

def sample_data(n):
    return mu[rng.choice(4, n, p=w)] + 0.1 * rng.standard_normal((n, D))

def independent(n):                                    # independent coupling of noise and data
    return rng.standard_normal((n, D)), sample_data(n)

# Convention: x_t = (1 - t) x0 + t x1, noise x0 ~ N(0, I) at t = 0, data x1 at t = 1.
def u_exact(x, t):
    """Marginal velocity E[x1 - x0 | x_t = x] for the independent coupling (closed form)."""
    t = np.broadcast_to(np.asarray(t, float).reshape(-1), (len(x),))[:, None]
    s2 = (1 - t) ** 2 + t ** 2 * tau2                 # variance of x_t within a component
    d2 = (x ** 2).sum(1, keepdims=True) - 2 * t * (x @ mu.T) + t ** 2 * (mu ** 2).sum(1)
    lg = np.log(w) - d2 / (2 * s2)
    r = np.exp(lg - lg.max(1, keepdims=True))
    r /= r.sum(1, keepdims=True)                       # posterior over components
    m = r @ mu
    return m + (t * tau2 - (1 - t)) / s2 * (x - t * m)

# ---------- u* is the conditional mean: the residual is orthogonal to functions of x_t ----------
x0, x1 = independent(20000)
t = rng.random(20000)
xt = (1 - t[:, None]) * x0 + t[:, None] * x1
u = u_exact(xt, t)
r = (x1 - x0) - u
print(f"seed {seed}. residual of u*: mean {r.mean():.1e}, E[r.u]/E[u.u] "
      f"{(r * u).sum(1).mean() / (u * u).sum(1).mean():.1e}, E[r.x]/E[x.x] "
      f"{(r * xt).sum(1).mean() / (xt * xt).sum(1).mean():.1e}")

# ---------- a small network trained with the conditional loss ----------
class Net(nn.Module):
    def __init__(s, h=512):
        super().__init__()
        s.f = nn.Sequential(nn.Linear(D + 33, h), nn.SiLU(), nn.Linear(h, h), nn.SiLU(),
                            nn.Linear(h, h), nn.SiLU(), nn.Linear(h, D))
    def forward(s, x, t):
        k = torch.arange(1, 17, dtype=x.dtype) * np.pi * t[:, None]
        return s.f(torch.cat([x, t[:, None], torch.sin(k), torch.cos(k)], 1))

net = Net()
opt = torch.optim.Adam(net.parameters(), lr=1e-3)
for _ in range(3000):                                  # CFM: regress v(x_t, t) on x1 - x0
    a0, a1 = independent(256)
    ta = rng.random(256)
    xa = (1 - ta[:, None]) * a0 + ta[:, None] * a1
    xa, ta, tgt = (torch.tensor(q, dtype=torch.float32) for q in (xa, ta, a1 - a0))
    loss = ((net(xa, ta) - tgt) ** 2).mean()
    opt.zero_grad(); loss.backward(); opt.step()
with torch.no_grad():
    v = net(torch.tensor(xt, dtype=torch.float32), torch.tensor(t, dtype=torch.float32)).double().numpy()
L_cfm_net, L_cfm_u = ((v - (x1 - x0)) ** 2).mean(), ((u - (x1 - x0)) ** 2).mean()
L_fm = ((v - u) ** 2).mean()
print(f"CFM loss of the network {L_cfm_net:.4f} = FM loss {L_fm:.4f} "
      f"+ CFM loss of the exact field {L_cfm_u:.4f} (sum {L_fm + L_cfm_u:.4f})")

# ---------- the exact flow: endpoint, straightness and few-step Euler ----------
def rk4(v, x, steps=200):
    """Fine solve of dx/dt = v(x, t) on [0, 1]; also returns the trapezoid integral of |v|^2 dt."""
    ts, e2 = np.linspace(0, 1, steps + 1), 0.0
    for a, b in zip(ts[:-1], ts[1:]):
        h = b - a
        k1 = v(x, a); k2 = v(x + h / 2 * k1, a + h / 2)
        k3 = v(x + h / 2 * k2, a + h / 2); k4 = v(x + h * k3, b)
        e2 = e2 + h * (0.5 if a == 0 else 1.0) * (k1 ** 2).sum(1)
        x = x + h / 6 * (k1 + 2 * k2 + 2 * k3 + k4)
    return x, e2 + h * 0.5 * (v(x, 1.0) ** 2).sum(1)

def euler(v, x, n):
    for i in range(n):
        x = x + v(x, i / n) / n
    return x

def rms(a, b):
    return np.sqrt(((a - b) ** 2).mean(1))

z = rng.standard_normal((1000, D))                     # 1,000 test noises
end, energy = rk4(u_exact, z)
disp = end - z
S = (energy - (disp ** 2).sum(1)).mean() / D           # straightness (Pooladian et al., Eq. 18)
d2 = ((end[:, None, :] - mu[None]) ** 2).mean(-1)
k = d2.argmin(1)
print(f"\nexact flow, 200 RK4 steps: shares {np.bincount(k, minlength=4) / len(k)}, "
      f"median RMS to nearest shape {np.median(np.sqrt(d2.min(1))):.4f}")
print(f"transport cost per pixel {(disp ** 2).sum(1).mean() / D:.3f}, straightness per pixel {S:.4f}")
print(f"one Euler step: max |x - mean image| = {np.abs(euler(u_exact, z, 1) - w @ mu).max():.1e}")
print("Euler steps                  " + "".join(f"{n:8d}" for n in [1, 2, 4, 8, 16]))
print("median RMS to the RK4 endpoint" + "".join(f"{np.median(rms(euler(u_exact, z, n), end)):8.4f}"
                                                 for n in [1, 2, 4, 8, 16]))

Output:

seed 0. residual of u*: mean -6.8e-05, E[r.u]/E[u.u] 2.2e-04, E[r.x]/E[x.x] 3.5e-04
CFM loss of the network 0.3567 = FM loss 0.1510 + CFM loss of the exact field 0.2058 (sum 0.3567)

exact flow, 200 RK4 steps: shares [0.397 0.313 0.189 0.101], median RMS to nearest shape 0.1003
transport cost per pixel 1.737, straightness per pixel 0.0715
one Euler step: max |x - mean image| = 6.0e-15
Euler steps                         1       2       4       8      16
median RMS to the RK4 endpoint  0.3897  0.2137  0.0742  0.0470  0.0254

The residual checks are zero to sampling error, which confirms that the closed form is the conditional mean of the CFM target. The second line is the CFM–FM equivalence: the network’s CFM loss splits into its distance from the exact field plus a floor, the CFM loss of the exact field itself, which no network can go below. The floor is the variance of x1−x0x_1 - x_0 around its conditional mean; it is larger here than the network’s own error, so a CFM training curve that flattens says little about how close the network is to the field it should learn.

Integrated finely, the exact field carries the noise to the four shapes in close to their weights, with the data’s own pixel noise of 0.1 left around each. The flow is far from straight. One Euler step lands every one of the 1,000 noises on the mean image, to rounding error, because at t=0t = 0 the field points from each xx to E[x1]\mathbb{E}[x_1]; the shape is decided later, when the posterior rkr_k has committed to one component. From four steps on, doubling the number of steps divides the error by 1.6 to 1.9, approaching the halving expected of Euler’s first-order method, so, in our reading, the error is governed by how much the velocity changes along each trajectory, which the straightness also measures. Two steps are erratic: the script run with seeds 1 to 4 gave two-step medians of 0.1833, 0.1412, 0.2748 and 0.1475, while over seeds 0 to 4 the 4-, 8- and 16-step medians stayed within 0.0734–0.0742, 0.0467–0.0470 and 0.0253–0.0254, the straightness within 0.0694–0.0715 per pixel and the transport cost within 1.730–1.738. In our reading, the second step starts at t=0.5t = 0.5 from the midpoint between a noise image and the mean image, so its result depends on which shape the posterior rkr_k favours at that point, which need not be the shape the exact flow reaches; the output does not show how the per-image errors are distributed.

The example has no learned flows. Its plan also trained networks with a minibatch optimal-transport coupling and with reflow, but they were left out after a pilot in which the trained networks did not reach accuracy criteria fixed in advance, and the network kept here is used only for the loss identity, which holds for any network. Neither coupling has a closed-form marginal field.

Variants

Rectified flow and reflow. With straight conditional paths, the learned flow defines a new, deterministic coupling between noise and data, x0↦ψ1(x0)x_0 \mapsto \psi_1(x_0). Reflow trains a new flow on pairs drawn from this coupling instead of independent pairs. Pooladian et al. (Appendix E) ran it as their rectified-flow baseline: from a trained flow-matching model they generated 50,000 noise–sample pairs and trained on them with the same algorithm and settings for 300 epochs, which they describe as equivalent to Liu et al.’s 2-rectified flow. In our reading, the paths of a deterministic coupling still cross when straightened, so one reflow straightens the flow without making it straight, and each round costs a full sampling pass over the training pairs. Esser et al. (Appendix A) cite a later application of reflow by Liu et al. to distil a pretrained latent diffusion text-to-image model.

Minibatch optimal-transport couplings. Pooladian et al. replace the independent pairing of noise and data by a coupling computed within each batch. From kk noise samples and kk images, a doubly stochastic matrix π(i,j)\pi(i, j) is built and pairs are drawn from it (§4); the joint distribution so defined has the correct marginals (Lemma 4.1), and the joint CFM loss with any such coupling yields a field that maps noise to data (Lemma 3.1). The independent coupling is π(i,j)=1/k\pi(i, j) = 1/k. BatchOT solves the exact assignment problem on squared Euclidean costs within the batch, giving a permutation in O(k3)O(k^3) (§4.2); BatchEOT uses Sinkhorn’s entropic approximation, which approaches BatchOT as the regularization goes to zero and the independent coupling as it grows (§4.3); and Stable and Heuristic couplings use the Gale–Shapley algorithm and a cost-aware variant of it (§4.4). As k→∞k \to \infty, BatchOT drives the joint CFM loss of the optimal field and its straightness to zero and its transport cost to the squared 2-Wasserstein distance (Theorem 4.2, an asymptotic result). The joint CFM loss also bounds the average variance of the gradient at fixed xx and tt (Lemma 3.2), which is the authors’ explanation for faster training. They ran the couplings within each GPU’s batch, 256 images for ImageNet 32×3232 \times 32 and 50 for 64×6464 \times 64, after coupling across all GPUs gave no noticeable gain (Appendix E). The TorchCFM library implements BatchOT as ExactOptimalTransportConditionalFlowMatcher; its sampler solves the plan with the POT library and then draws the batch’s pairs from the plan with replacement, rather than taking the permutation directly (optimal_transport.py, commit 7c65385). Tong et al.’s OT-CFM, which the library’s README describes as the same coupling, is a concurrent formulation of it (Pooladian et al., §5.1).

Stochastic interpolants. Esser et al. (Appendix A) group stochastic interpolants with rectified flows as flows that need no simulation of the ODE during training, and Pooladian et al. (§2.2.1) note that Albergo and Vanden-Eijnden studied the straight conditional path under that name. TorchCFM’s VariancePreservingConditionalFlowMatcher uses the trigonometric interpolant cos⁡(πt/2) x0+sin⁡(πt/2) x1\cos(\pi t / 2)\, x_0 + \sin(\pi t / 2)\, x_1, which its docstring attributes to Albergo et al.

Gaussian diffusion paths. Flow matching with a diffusion path trains a network with the same optimum as a diffusion model but through a velocity regression. Pooladian et al. (Table 6) list this “Flow Matching with Diffusion” path among their baselines.

Conditional generation. Conditions enter the network as in diffusion models. Esser et al. set each of their three text encoders’ outputs to zero with probability 46.4% so that the model is trained unconditionally in roughly 10% of steps, for classifier-free guidance (Appendix B.3); Appendix C.4 gives the rate as 46.3%.

Best Practices

  • Bias training toward intermediate times. In Esser et al.’s study of 61 formulations, trained on ImageNet with class-name captions and on CC12M and scored by CLIP score and by FID on CLIP features of COCO-2014 validation images, rectified flow with logit-normal timesteps (m,s)=(0,1)(m, s) = (0, 1) had the best average rank, 1.54, over 24 combinations of sampler setting, EMA weights and dataset; uniform rectified flow ranked 5.67 and the earlier latent-diffusion formulation (eps/linear) 2.88. Only rectified-flow variants with modified timestep sampling beat eps/linear (§5.1.1, Table 1).
  • Check a timestep density across step budgets. Logit-normal with (0.5,0.6)(0.5, 0.6) was the best variant with 50 sampling steps but averaged rank 8.5 with 5 steps (Table 1); several variants that excelled in one metric did badly in the other (Table 2).
  • Shift the schedule with resolution. At 1024×10241024 \times 1024, Esser et al. preferred shifts above 1.5 and used 3.0 (Appendix C.2).
  • Pair couplings with small batches. Pooladian et al. report only 0.8% more training time on ImageNet 32×3232 \times 32 and 4% on 64×6464 \times 64 for minibatch couplings (§6.2), with the coupling computed per GPU.
  • Compare samplers at equal network evaluations. Esser et al.’s Table 6 counts the loss in CLIP score at 5, 10 and 20 sampling steps against 50; FID comparisons in Pooladian et al. fix the number of function evaluations (NFE).

Pitfalls

  • Expecting straight conditional paths to give a straight flow. The marginal field averages crossing paths; the example’s one-step sample is the mean image for every noise.
  • Reading the training loss as accuracy. The CFM loss has a floor equal to the conditional variance of the target, which depends on the path and the coupling, not on the network. Pooladian et al. report final joint CFM values of 10.72 for the independent coupling and 0.24 for BatchOT on their 2D checkerboard (Fig. 2): loss values are comparable only within one coupling.
  • Mixing time conventions. Flow-matching papers and libraries put noise at t=0t = 0, Stable Diffusion 3 and its code at t=1t = 1, and the sign of the velocity flips with it (x1−x0x_1 - x_0 against ϵ−x0\epsilon - x_0).
  • Forgetting the schedule at sampling time. A model trained with shifted timesteps is sampled on the shifted schedule; the shift is a sampler setting in the sd3.5 code, so a wrong value is silently accepted.
  • Expecting optimal transport. Rectified flows “do not result in optimal transport solutions” (Esser et al., Appendix A); minibatch couplings approach the transport cost of optimal transport only as the batch grows (Pooladian et al., Theorem 4.2).

Evidence and Impact

Few-step sampling. On face-blurred ImageNet downsampled to 32×3232 \times 32, Pooladian et al. report FID with Euler steps (Table 2): at 4 NFE, 38.86 for BatchOT and 33.92 for the Stable coupling against 362.37 for DDPM and 340.17 for ScoreSDE; at 20 NFE, 7.71 and 8.66 against 63.08 and 58.02; with an adaptive solver, 4.68 and 5.79 against 5.72 and 6.84. To reach FID 10 on 32×3232 \times 32, flow matching with the CondOT path needed 20 Euler NFE and BatchOT 14; to reach FID 20 on 64×6464 \times 64, 29 and 12, while the diffusion baselines needed at least 40 (Table 1). The paper’s text summarizes this as 30% to 60% lower sampling cost for low FID at 4% more training time (§1). With an adaptive solver (Table 6), FIDs on 32×3232 \times 32 were 5.04 for CondOT, 4.68 for BatchOT and 5.55 for rectified flow, at 139, 146 and 111 NFE, and 13.93, 12.37 and 13.02 on 64×6464 \times 64, the CondOT and rectified-flow models being the authors’ reproductions; negative log-likelihood was 3.58 to 3.59 bits per dimension on 32×3232 \times 32 for all three, so the couplings did not trade likelihood for speed. The rectified-flow baseline was trained for much longer, starting from the CondOT model (Appendix E). Low-NFE samples from BatchOT were also closer to the same noise’s high-NFE sample, by a distance between Inception features that the authors call consistency (Table 3). Fréchet Inception Distance has its own article.

Text-to-image at scale. Esser et al. found that rectified-flow formulations degraded less than diffusion formulations as the number of Euler steps fell, and that for 25 and more steps only logit-normal rectified flow stayed competitive with eps/linear (§5.1.1, Fig. 3). Their MM-DiT models, up to 8 billion parameters and 5×10225 \times 10^{22} training FLOPs, trained as rectified flows on latents (§6); the Stable Diffusion and diffusion transformer articles cover the architecture and results. Larger models lost less CLIP score when sampled with fewer steps: relative to 50 steps, 4.30%, 3.59% and 2.71% at 5 steps for depths 15, 30 and 38, with path lengths ∑∥vθ dt∥\sum \lVert v_\theta\, dt \rVert of 191.13, 187.96 and 185.96 (Table 6), which the authors attribute to larger models fitting the straight-path objective better.

Other uses. Flow matching has spread beyond still images. Meta’s Movie Gen trains a 30-billion-parameter transformer with it to generate video, as the video generation article describes, and the robot policy π0 generates chunks of continuous actions by integrating a learned velocity field with 10 Euler steps, as the vision–language–action models article describes. Pooladian et al. (§6.3) also used minibatch couplings, computed under four cost functions that the learner was not given, to learn approximate optimal-transport maps between Gaussian mixtures in 2 to 64 dimensions.

Place among generative models. Flow matching links continuous normalizing flows and diffusion models: it trains a CNF with a diffusion-style regression and, with a Gaussian path, recovers a diffusion model with another loss weighting. What it adds in practice is freedom in the path and the coupling, and with them control over how straight, and so how cheap to sample, the learned ODE is.

Related

  • Diffusion Sampling Methods

    How a trained diffusion model is turned into images; ancestral sampling, DDIM with its deterministic and invertible update, Euler and Heun steps on the probability-flow ODE in the EDM parameterization, DPM-Solver's exponential integrators, predictor–corrector samplers, and the trade-off between network evaluations and sample quality.

  • Stable Diffusion

    The family of open-weight text-to-image models from CompVis, Runway and Stability AI, from the latent-diffusion U-Nets of versions 1.x, 2.x and SDXL to the rectified-flow transformers of Stable Diffusion 3 and 3.5; their training data, the distilled Turbo models, licences, the fine-tuning and control ecosystem, reported results, and known risks.

  • Latent Diffusion Model

    A diffusion model that runs in the compressed latent space of a pretrained autoencoder instead of in pixels; the two-stage design, the downsampling factor and its trade-off, the latent scaling factor, cross-attention and concatenation conditioning, the compute savings, and successors from SDXL to latent transformers and rectified flow.

  • Consistency Model

    A generative model that maps any point on a diffusion model's probability-flow ODE trajectory straight to the trajectory's origin, so it can sample in one network evaluation; the consistency function and its boundary condition, consistency distillation and consistency training, multistep sampling, zero-shot editing, the published results, and later variants such as improved consistency training and latent consistency models.

  • Score Matching

    A way to learn the gradient of the log-density of images, the score, without ever computing a normalizing constant; Hyvärinen's explicit and implicit objectives, denoising and sliced score matching, Langevin sampling, noise-conditional score networks and the score-SDE view behind diffusion models.

  • Diffusion Transformer

    A diffusion model whose denoiser is a plain transformer over patches of a latent image instead of a convolutional U-Net; patchify and patch size, the in-context, cross-attention, adaLN and adaLN-Zero blocks, scaling by forward-pass Gflops, U-ViT's long skips, Stable Diffusion 3's joint-attention MM-DiT, video transformers in outline, and published results.

References

  1. Lipman, Y., Chen, R. T. Q., Ben-Hamu, H., Nickel, M. & Le, M. (2023). Flow Matching for Generative Modeling. International Conference on Learning Representations (ICLR) (only the abstract read).
  2. Liu, X., Gong, C. & Liu, Q. (2023). Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow. International Conference on Learning Representations (ICLR) (only the abstract read).
  3. Albergo, M. & Vanden-Eijnden, E. (2023). Building Normalizing Flows with Stochastic Interpolants. International Conference on Learning Representations (ICLR) (only the abstract read).
  4. Pooladian, A.-A., Ben-Hamu, H., Domingo-Enrich, C., Amos, B., Lipman, Y. & Chen, R. T. Q. (2023). Multisample Flow Matching: Straightening Flows with Minibatch Couplings. Proceedings of the 40th International Conference on Machine Learning (ICML), PMLR 202, 28100–28127.
  5. Esser, P., Kulal, S., Blattmann, A., Entezari, R., Müller, J., Saini, H., Levi, Y., Lorenz, D., Sauer, A., Boesel, F., Podell, D., Dockhorn, T., English, Z. & Rombach, R. (2024). Scaling Rectified Flow Transformers for High-Resolution Image Synthesis. Proceedings of the 41st International Conference on Machine Learning (ICML), PMLR 235, 12606–12633.
  6. Meta Platforms. flow_matching: a PyTorch library for flow matching (official repository facebookresearch/flow_matching, CC BY-NC 4.0; README, path and solver modules at commit 11568d3 of 5 January 2026; accessed November 2026).
  7. Tong, A. et al. TorchCFM: a Conditional Flow Matching library (GitHub repository atong01/conditional-flow-matching, MIT licence; README and torchcfm modules at commit 7c65385 of 20 July 2026; accessed November 2026).
  8. Stability AI. sd3.5: inference reference implementation for Stable Diffusion 3 and 3.5 (GitHub repository Stability-AI/sd3.5, code under the MIT licence; sd3_impls.py and sd3_infer.py at commit 8565799 of 8 January 2025; accessed November 2026).