Simple Algorithm
Deep Learning · Emergence · 30 min

Continuous Flows & Flow Matching

Neural ODE flows, and training them without simulation by regressing velocity fields.

A continuous normalizing flow can use any network, because an ODE is invertible for free; the price is that maximum-likelihood training must solve that ODE at every step. Flow matching removes the price with a regression whose targets are known in closed form, and a short continuity-equation argument shows why it lands on the right field. Then come the subtleties: straight training paths give curved sampling paths, reflow straightens them, and flow matching and diffusion turn out to be one family written in different coordinates.

What you’ll learn

  • Derive the instantaneous change of variables from Jacobi's formula, and explain the cost of maximum-likelihood training of a CNF and the variance of Hutchinson's trace estimator.
  • Prove that the posterior-weighted average of conditional velocity fields generates the marginal probability path, and that the conditional flow-matching loss has the same gradient as the intractable marginal loss.
  • Derive the conditional velocity of a Gaussian path, explain why straight conditional paths give curved marginal trajectories, and state what rectified flow and reflow provably achieve.
  • Convert between velocity, noise, data and score prediction for Gaussian paths, identify v-prediction as flow matching on the variance-preserving path, and explain the role of the timestep distribution.

Continuous normalizing flows and what they cost

A continuous normalizing flow (CNF; Chen, Rubanova, Bettencourt & Duvenaud, 2018) defines its map by an ODE. Here, as in flow matching, time runs from noise at t=0t=0 to data at t=1t=1:

dxtdt=vθ(xt,t),x0∼p0=N(0,I).\frac{d\mathbf x_t}{dt}=\mathbf v_{\boldsymbol\theta}(\mathbf x_t,t),\qquad\mathbf x_0\sim p_0=\mathcal N(\mathbf 0,I).

If the velocity field vθ\mathbf v_{\boldsymbol\theta} is Lipschitz in x\mathbf x (uniformly in tt) and continuous in tt, the flow map ψt:x0↦xt\psi_t:\mathbf x_0\mapsto\mathbf x_t exists, is unique and is invertible (integrate backward), whatever the architecture. What replaces the log-determinant of a discrete flow?

DerivationProof via Jacobi's formula
  1. dJtdt=At Jt,J0=I\frac{dJ_t}{dt}=A_t\,J_t,\qquad J_0=I

    Differentiate the ODE with respect to its starting point. The Jacobian of the flow map, Jt=∂xt/∂x0J_t=\partial\mathbf x_t/\partial\mathbf x_0, obeys the linear variational equation, with At=∂vθ∂x(xt,t)A_t=\frac{\partial\mathbf v_{\boldsymbol\theta}}{\partial\mathbf x}(\mathbf x_t,t):

  2. ddtlog⁡det⁡Jt=tr⁡(Jt−1dJtdt)=tr⁡(Jt−1AtJt)=tr⁡At\frac{d}{dt}\log\det J_t=\operatorname{tr}\Big(J_t^{-1}\frac{dJ_t}{dt}\Big)=\operatorname{tr}\big(J_t^{-1}A_tJ_t\big)=\operatorname{tr}A_t

    Jacobi's formula differentiates a log-determinant. det⁡Jt\det J_t starts at 11 and never vanishes, so it stays positive, and the similarity Jt−1AtJtJ_t^{-1}A_tJ_t leaves the trace unchanged:

  3. ddtlog⁡pt(xt)=−tr⁡At\frac{d}{dt}\log p_t(\mathbf x_t)=-\operatorname{tr}A_t

    The change-of-variables formula for ψt\psi_t gives log⁡pt(xt)=log⁡p0(x0)−log⁡det⁡Jt\log p_t(\mathbf x_t)=\log p_0(\mathbf x_0)-\log\det J_t; differentiate in tt. ■\blacksquare The discrete flow's sum of log-determinants has become an integral of a trace, and the field needs no special structure.

What it costs. The exact trace needs the diagonal of a d×dd\times d Jacobian, about dd passes of automatic differentiation. FFJORD (Grathwohl, Chen, Bettencourt, Sutskever & Duvenaud, 2019) used the Hutchinson estimator tr⁡A=E[ϵ⊤Aϵ]\operatorname{tr}A=\E[\boldsymbol\epsilon^\top A\boldsymbol\epsilon], unbiased for any noise with E[ϵϵ⊤]=I\E[\boldsymbol\epsilon\boldsymbol\epsilon^\top]=I and needing a single vector–Jacobian product ϵ⊤A\boldsymbol\epsilon^\top A. Its variance depends on the noise. With A^=12(A+A⊤)\hat A=\tfrac12(A+A^\top),

Var⁡Gaussian(ϵ⊤Aϵ)=2∥A^∥F2,Var⁡Rademacher(ϵ⊤Aϵ)=2(∥A^∥F2−∑iA^ii2),\Var_{\text{Gaussian}}\big(\boldsymbol\epsilon^\top A\boldsymbol\epsilon\big)=2\norm{\hat A}_F^2,\qquad\Var_{\text{Rademacher}}\big(\boldsymbol\epsilon^\top A\boldsymbol\epsilon\big)=2\Big(\norm{\hat A}_F^2-\sum_i\hat A_{ii}^2\Big),

so random signs never do worse than Gaussian noise. Even so, every maximum-likelihood step must solve the ODE forward with an adaptive solver, carrying the trace along, and backward again with the adjoint method for the gradients. The number of function evaluations is set by how hard the learned dynamics are to integrate, and FFJORD found that it grew during training. Simulation inside the training loop made CNFs hard to scale to large images.

Check your understanding

At some point the Jacobian AA of the field happens to be diagonal. What is the variance of Hutchinson's estimate ϵ⊤Aϵ\boldsymbol\epsilon^\top A\boldsymbol\epsilon with Rademacher noise (ϵi=±1\epsilon_i=\pm1 with equal probability)?

  1. 2∑iAii22\sum_iA_{ii}^2, the same as with Gaussian noise
  2. ∑iAii2\sum_iA_{ii}^2
  3. It depends on the dimension dd but not on AA
  4. 00: the estimate equals the trace exactly
Show the answer

D. 00: the estimate equals the trace exactly

For diagonal AA, ϵ⊤Aϵ=∑iAiiϵi2=∑iAii\boldsymbol\epsilon^\top A\boldsymbol\epsilon=\sum_iA_{ii}\epsilon_i^2=\sum_iA_{ii}, since ϵi2=1\epsilon_i^2=1. The formula agrees: ∥A^∥F2−∑iA^ii2=0\norm{\hat A}_F^2-\sum_i\hat A_{ii}^2=0. Rademacher noise errs only through the off-diagonal entries, Gaussian noise through all of them.

Flow matching: a regression with the right answer

Flow matching (Lipman, Chen, Ben-Hamu, Nickel & Le, 2023) never integrates during training. It fixes a probability path ptp_t from p0=N(0,I)p_0=\mathcal N(\mathbf 0,I) to (approximately) the data distribution qq and regresses vθ\mathbf v_{\boldsymbol\theta} onto a field ut\mathbf u_t that generates it: the pair satisfies the continuity equation ∂tpt+∇⋅(ptut)=0\partial_tp_t+\nabla\cdot(p_t\mathbf u_t)=0, so mass moves with the field and is neither created nor destroyed. For real data neither ptp_t nor ut\mathbf u_t has a closed form, so both are assembled from per-sample pieces: a conditional path pt(x∣x1)p_t(\mathbf x\mid\mathbf x_1) that starts at the noise and ends concentrated at one data point x1\mathbf x_1, and a conditional field ut(x∣x1)\mathbf u_t(\mathbf x\mid\mathbf x_1) that generates it.

pt(x)=∫pt(x∣x1) q(x1) dx1,ut(x)=∫ut(x∣x1) pt(x∣x1) q(x1)pt(x) dx1=E[ut(x∣x1) ∣ xt=x]p_t(\mathbf x)=\int p_t(\mathbf x\mid\mathbf x_1)\,q(\mathbf x_1)\,d\mathbf x_1,\qquad\mathbf u_t(\mathbf x)=\int\mathbf u_t(\mathbf x\mid\mathbf x_1)\,\frac{p_t(\mathbf x\mid\mathbf x_1)\,q(\mathbf x_1)}{p_t(\mathbf x)}\,d\mathbf x_1=\E\big[\mathbf u_t(\mathbf x\mid\mathbf x_1)\,\big|\,\mathbf x_t=\mathbf x\big]
The marginal path mixes the conditional paths over the data. The marginal field averages the conditional fields at x\mathbf x, weighted by the posterior probability that a path passing through x\mathbf x at time tt is headed for x1\mathbf x_1.
DerivationProof
  1. ∂tpt(x)=∫∂tpt(x∣x1) q(x1) dx1=−∫∇⋅(pt(x∣x1) ut(x∣x1)) q(x1) dx1\partial_tp_t(\mathbf x)=\int\partial_tp_t(\mathbf x\mid\mathbf x_1)\,q(\mathbf x_1)\,d\mathbf x_1=-\int\nabla\cdot\big(p_t(\mathbf x\mid\mathbf x_1)\,\mathbf u_t(\mathbf x\mid\mathbf x_1)\big)\,q(\mathbf x_1)\,d\mathbf x_1

    Differentiate the mixture under the integral (assuming enough regularity to do so) and use the continuity equation of each conditional path:

  2. ∂tpt(x)=−∇⋅(∫pt(x∣x1) ut(x∣x1) q(x1) dx1)=−∇⋅(pt(x) ut(x))\partial_tp_t(\mathbf x)=-\nabla\cdot\Big(\int p_t(\mathbf x\mid\mathbf x_1)\,\mathbf u_t(\mathbf x\mid\mathbf x_1)\,q(\mathbf x_1)\,d\mathbf x_1\Big)=-\nabla\cdot\big(p_t(\mathbf x)\,\mathbf u_t(\mathbf x)\big)

    Pull the divergence out of the integral. What remains inside is pt(x) ut(x)p_t(\mathbf x)\,\mathbf u_t(\mathbf x), by the definition of the marginal field:

  3. The continuity equation is linear in the pair (p, pu)(p,\,p\mathbf u), so a mixture of solutions is a solution. ■\blacksquare When ut\mathbf u_t is regular enough for this equation to have a unique solution, the ODE x˙t=ut(xt)\dot{\mathbf x}_t=\mathbf u_t(\mathbf x_t) started from p0p_0 has marginal ptp_t at every time, and in particular reaches the data distribution at t=1t=1.

The paths used in practice are Gaussian, pt(x∣x1)=N(μt(x1),σt2I)p_t(\mathbf x\mid\mathbf x_1)=\mathcal N\big(\boldsymbol\mu_t(\mathbf x_1),\sigma_t^2I\big) with μ0=0\boldsymbol\mu_0=\mathbf 0, σ0=1\sigma_0=1 and σ1\sigma_1 small, generated by the affine flow of the noise ψt(x0)=σtx0+μt(x1)\psi_t(\mathbf x_0)=\sigma_t\mathbf x_0+\boldsymbol\mu_t(\mathbf x_1).

DerivationThe conditional velocity of a Gaussian path (Lipman et al., 2023, Theorem 3)
  1. ddtψt(x0)=σ˙tx0+μ˙t(x1)⟹ut(x∣x1)=σ˙tσt(x−μt(x1))+μ˙t(x1)\frac{d}{dt}\psi_t(\mathbf x_0)=\dot\sigma_t\mathbf x_0+\dot{\boldsymbol\mu}_t(\mathbf x_1)\quad\Longrightarrow\quad\mathbf u_t(\mathbf x\mid\mathbf x_1)=\frac{\dot\sigma_t}{\sigma_t}\big(\mathbf x-\boldsymbol\mu_t(\mathbf x_1)\big)+\dot{\boldsymbol\mu}_t(\mathbf x_1)

    Differentiate the flow in time, then express the noise through the current position, x0=(x−μt)/σt\mathbf x_0=(\mathbf x-\boldsymbol\mu_t)/\sigma_t:

  2. LCFM=Et,x0,x1∥vθ(αtx1+σtx0, t)−(α˙tx1+σ˙tx0)∥2\loss_{\text{CFM}}=\E_{t,\mathbf x_0,\mathbf x_1}\big\lVert\mathbf v_{\boldsymbol\theta}(\alpha_t\mathbf x_1+\sigma_t\mathbf x_0,\,t)-(\dot\alpha_t\mathbf x_1+\dot\sigma_t\mathbf x_0)\big\rVert^2

    With μt=αtx1\boldsymbol\mu_t=\alpha_t\mathbf x_1, so that xt=αtx1+σtx0\mathbf x_t=\alpha_t\mathbf x_1+\sigma_t\mathbf x_0, the regression target at a sampled pair is just the velocity of the interpolation:

  3. xt=tx1+(1−t)x0,target  x1−x0\mathbf x_t=t\mathbf x_1+(1-t)\mathbf x_0,\qquad\text{target }\ \mathbf x_1-\mathbf x_0

    Lipman et al.'s optimal-transport path takes μt=tx1\boldsymbol\mu_t=t\mathbf x_1 and σt=1−(1−σmin⁡)t\sigma_t=1-(1-\sigma_{\min})t, for which each conditional flow is the optimal-transport map between N(0,I)\mathcal N(\mathbf 0,I) and N(x1,σmin⁡2I)\mathcal N(\mathbf x_1,\sigma_{\min}^2I): every point moves in a straight line at constant speed. As σmin⁡→0\sigma_{\min}\to0 it becomes the interpolation of rectified flow:

Straight lines in, curved paths out

Each conditional path of the straight-line interpolation is a straight line, but the marginal field is not straight-line motion. ut(x)=E[x1−x0∣xt=x]\mathbf u_t(\mathbf x)=\E[\mathbf x_1-\mathbf x_0\mid\mathbf x_t=\mathbf x] averages the directions of all the lines that pass through x\mathbf x at time tt. Where lines heading for different data points cross, the average points somewhere in between, and since trajectories of an ODE cannot cross, the flow reroutes particles along curves. Lipman et al. say so themselves: the conditional flow is optimal transport, but that "by no means" makes the marginal field an optimal-transport solution.

Predict before you look

In this example, take a single Euler step of size 11 from t=0t=0 with the exact field, x1≈x0+u0(x0)x_1\approx x_0+u_0(x_0). Where does the noise point x0=0.5x_0=0.5 land?

Show the answer

0

u0(x)=E[x1]−x=−xu_0(x)=\E[x_1]-x=-x, so x0+u0(x0)=0x_0+u_0(x_0)=0 for every starting point: one step piles all of the noise onto the data mean, which is not even a data point. Euler's step follows only the initial direction of a curved trajectory.

DerivationProof of (ii)
  1. E c(Z1−Z0)=E c(∫01vX(Zt,t) dt)≤E∫01c(vX(Zt,t)) dt\E\,c(Z_1-Z_0)=\E\,c\Big(\int_0^1v^X(Z_t,t)\,dt\Big)\le\E\int_0^1c\big(v^X(Z_t,t)\big)\,dt

    Write the displacement as the integral of the velocity along the path and apply Jensen's inequality over time:

  2. =E∫01c(E[X1−X0∣Xt]) dt≤E∫01c(X1−X0) dt=E c(X1−X0)■=\E\int_0^1c\big(\E[X_1-X_0\mid X_t]\big)\,dt\le\E\int_0^1c(X_1-X_0)\,dt=\E\,c(X_1-X_0)\qquad\blacksquare

    By (i), ZtZ_t may be replaced by XtX_t, which has the same distribution. Then apply Jensen's inequality to the conditional expectation that defines vXv^X:

Reflow in the example. The first rectified flow of the two-point example maps every x0>0x_0>0 to +1+1 and every x0<0x_0<0 to −1-1: in one dimension, trajectories that cannot cross preserve order. Reflow trains a new field on the pairs (x0,sign⁡x0)(x_0,\operatorname{sign}x_0). Their straight lines never cross, so the new field is constant along each one, the paths are exactly straight, and a single Euler step is exact. In higher dimensions straightness is only approached, each reflow must simulate the previous flow to produce its pairs, and errors in the learned field accumulate; Liu et al. found one reflow already nearly straight and advised against many. Distilling the result into a one-step generator is part of Few-Step Generation.

Other couplings and paths. Reflow straightens by replacing the independent coupling with a deterministic one. Alternatively, noise and data can be paired within each minibatch by solving a small optimal-transport assignment, which lowers the variance of the regression targets and straightens the learned flow (Pooladian et al., 2023; Tong et al., 2024). With the exact optimal-transport plan as the coupling, the marginal flow would solve the dynamic optimal-transport problem (Tong et al., 2024, under regularity assumptions); a minibatch plan only approximates that plan. Stochastic interpolants generalize the construction. Albergo & Vanden-Eijnden (2023) connected any two distributions by an interpolant xt=I(t,x0,x1)\mathbf x_t=I(t,\mathbf x_0,\mathbf x_1) whose velocity is the minimizer of a quadratic regression, and Albergo, Boffi & Vanden-Eijnden (2023) added a latent noise, xt=I(t,x0,x1)+γ(t)z\mathbf x_t=I(t,\mathbf x_0,\mathbf x_1)+\gamma(t)\mathbf z: the velocity and the score are then each the minimizer of a quadratic regression, and the same marginals can be sampled by the ODE or by SDEs with an adjustable amount of noise.

One family: flow matching and diffusion

The Gaussian paths xt=αtx1+σtx0\mathbf x_t=\alpha_t\mathbf x_1+\sigma_t\mathbf x_0 include diffusion. A variance-preserving diffusion keeps αt2+σt2=1\alpha_t^2+\sigma_t^2=1 and runs from data to noise; read backward in time it is a Gaussian path like any other, for instance αt=sin⁡πt2\alpha_t=\sin\frac{\pi t}2, σt=cos⁡πt2\sigma_t=\cos\frac{\pi t}2, the cosine schedule (the widget's VP path). Its marginal field is exactly the drift of the probability-flow ODE that Diffusion Models writes in terms of the score. A network for either can be trained to predict four different things, and at the optimum each determines the others:

DerivationFour parameterizations of one field
  1. x=αtx^1+σtϵ^,ut(x)=α˙tx^1+σ˙tϵ^\mathbf x=\alpha_t\hat{\mathbf x}_1+\sigma_t\hat{\boldsymbol\epsilon},\qquad\mathbf u_t(\mathbf x)=\dot\alpha_t\hat{\mathbf x}_1+\dot\sigma_t\hat{\boldsymbol\epsilon}

    Take conditional expectations given xt=x\mathbf x_t=\mathbf x of the interpolation and of its velocity, with the data prediction x^1(x,t)=E[x1∣xt=x]\hat{\mathbf x}_1(\mathbf x,t)=\E[\mathbf x_1\mid\mathbf x_t=\mathbf x] and the noise prediction ϵ^(x,t)=E[x0∣xt=x]\hat{\boldsymbol\epsilon}(\mathbf x,t)=\E[\mathbf x_0\mid\mathbf x_t=\mathbf x]:

  2. ut(x)=α˙tαt x+σt2(α˙tαt−σ˙tσt)∇xlog⁡pt(x)\mathbf u_t(\mathbf x)=\frac{\dot\alpha_t}{\alpha_t}\,\mathbf x+\sigma_t^2\Big(\frac{\dot\alpha_t}{\alpha_t}-\frac{\dot\sigma_t}{\sigma_t}\Big)\nabla_{\mathbf x}\log p_t(\mathbf x)

    Because the noise is Gaussian, the noise prediction is a scaled score, ϵ^=−σt∇xlog⁡pt(x)\hat{\boldsymbol\epsilon}=-\sigma_t\nabla_{\mathbf x}\log p_t(\mathbf x) (Tweedie's formula; Diffusion Models proves it for noise prediction). Eliminate x^1\hat{\mathbf x}_1 and ϵ^\hat{\boldsymbol\epsilon}:

  3. ut(x)=xt+1−tt∇xlog⁡pt(x),∥v^−(x1−x0)∥2=1t2∥ϵ^−x0∥2  for  v^=xt−ϵ^t\mathbf u_t(\mathbf x)=\frac{\mathbf x}{t}+\frac{1-t}{t}\nabla_{\mathbf x}\log p_t(\mathbf x),\qquad\big\lVert\hat{\mathbf v}-(\mathbf x_1-\mathbf x_0)\big\rVert^2=\frac{1}{t^2}\big\lVert\hat{\boldsymbol\epsilon}-\mathbf x_0\big\rVert^2\ \text{ for }\ \hat{\mathbf v}=\frac{\mathbf x_t-\hat{\boldsymbol\epsilon}}{t}

    For the straight path, αt=t\alpha_t=t and σt=1−t\sigma_t=1-t. The same algebra applies to a network's outputs, so a velocity error is a reweighted noise error:

Check your understanding

A network trained by flow matching on the straight path outputs v^\hat{\mathbf v} at (xt,t)(\mathbf x_t,t). Which noise prediction does it imply?

  1. xt+(1−t) v^\mathbf x_t+(1-t)\,\hat{\mathbf v}
  2. xt−t v^\mathbf x_t-t\,\hat{\mathbf v}
  3. −v^/t-\hat{\mathbf v}/t
  4. (xt−v^)/(1−t)(\mathbf x_t-\hat{\mathbf v})/(1-t)
Show the answer

B. xt−t v^\mathbf x_t-t\,\hat{\mathbf v}

Substitute v^=x^1−ϵ^\hat{\mathbf v}=\hat{\mathbf x}_1-\hat{\boldsymbol\epsilon} into xt=tx^1+(1−t)ϵ^\mathbf x_t=t\hat{\mathbf x}_1+(1-t)\hat{\boldsymbol\epsilon}: xt=ϵ^+tv^\mathbf x_t=\hat{\boldsymbol\epsilon}+t\hat{\mathbf v}. The noise estimate is the current point minus the distance traveled since t=0t=0.

v-prediction is flow matching. Salimans & Ho (2022) proposed predicting v≡αϵ−σx\mathbf v\equiv\alpha\boldsymbol\epsilon-\sigma\mathbf x for a variance-preserving diffusion z=αx+σϵ\mathbf z=\alpha\mathbf x+\sigma\boldsymbol\epsilon (their notation: x\mathbf x data, ϵ\boldsymbol\epsilon noise), defining it as a velocity: with α=cos⁡ϕ\alpha=\cos\phi and σ=sin⁡ϕ\sigma=\sin\phi, v=dz/dϕ\mathbf v=d\mathbf z/d\phi. In flow time, ϕ=π2(1−t)\phi=\frac\pi2(1-t) turns z\mathbf z into the VP path above, and the chain rule gives

α˙tx1+σ˙tx0=−π2 v.\dot\alpha_t\mathbf x_1+\dot\sigma_t\mathbf x_0=-\frac\pi2\,\mathbf v.

So v-prediction is flow matching on the variance-preserving path, up to a constant factor and the direction of time. Salimans & Ho introduced it because noise prediction breaks down at zero signal, where the input is pure noise and predicting that noise says nothing about the data; the velocity target stays informative at every noise level.

Where to spend the training. Drawing training times from a density π(t)\pi(t) instead of uniformly is the same as weighting the loss by π(t)\pi(t), so the timestep distribution is part of the objective. Esser et al. (2024) compared 61 formulations for latent text-to-image models: noise and velocity prediction under several schedules, EDM, and rectified flow with several timestep samplers. Rectified flow with logit-normal times, t=1/(1+e−u)t=1/(1+e^{-u}) with u∼N(0,1)u\sim\mathcal N(0,1), which concentrates training on intermediate times, ranked best overall, while rectified flow with uniform times did not beat the established noise-prediction baseline. Their explanation: the velocity target is hardest to predict in the middle, while near either end the optimal prediction is just a mean. Rectified-flow formulations also lost less quality when the number of sampling steps was cut, and the authors scaled such models, with a transformer that processes text and image tokens jointly, to high-resolution text-to-image generation.

Key takeaways

  • A CNF x˙t=vθ(xt,t)\dot{\mathbf x}_t=\mathbf v_{\boldsymbol\theta}(\mathbf x_t,t) is invertible for any Lipschitz field, and Jacobi's formula gives ddtlog⁡pt(xt)=−tr⁡∂xvθ\frac{d}{dt}\log p_t(\mathbf x_t)=-\operatorname{tr}\partial_{\mathbf x}\mathbf v_{\boldsymbol\theta}; maximum-likelihood training needs ODE solves and trace estimates at every step.
  • Flow matching mixes per-sample conditional paths. The posterior-weighted average of their fields generates the marginal path, by linearity of the continuity equation, and regressing on the conditional fields has the same gradient as regressing on the marginal one.
  • For a Gaussian path the conditional velocity is σ˙tσt(x−μt)+μ˙t\frac{\dot\sigma_t}{\sigma_t}(\mathbf x-\boldsymbol\mu_t)+\dot{\boldsymbol\mu}_t, and the straight path's target is x1−x0\mathbf x_1-\mathbf x_0; yet marginal trajectories bend, and one Euler step from noise lands on the data mean.
  • Rectified flow preserves marginals and lowers every convex transport cost, and reflow straightens paths at rate O(1/K)\order{1/K}; minibatch optimal-transport couplings and stochastic interpolants are other ways to choose the pairing and the path.
  • Velocity, noise, data and score predictions are interchangeable for Gaussian paths; v-prediction is flow matching on the variance-preserving path, and the timestep distribution is a loss weighting (logit-normal times did best in the comparison of Esser et al., 2024).

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Along a trajectory of a continuous normalizing flow x˙t=v(xt,t)\dot{\mathbf x}_t=\mathbf v(\mathbf x_t,t), how does the log-density of the moving point change?

  1. ddtlog⁡pt(xt)=−log⁡∣det⁡∂v∂x∣\frac{d}{dt}\log p_t(\mathbf x_t)=-\log\abs{\det\frac{\partial\mathbf v}{\partial\mathbf x}}
  2. ddtlog⁡pt(xt)=−∥v(xt,t)∥2\frac{d}{dt}\log p_t(\mathbf x_t)=-\norm{\mathbf v(\mathbf x_t,t)}^2
  3. ddtlog⁡pt(xt)=+tr⁡∂v∂x\frac{d}{dt}\log p_t(\mathbf x_t)=+\operatorname{tr}\frac{\partial\mathbf v}{\partial\mathbf x}
  4. ddtlog⁡pt(xt)=−tr⁡∂v∂x\frac{d}{dt}\log p_t(\mathbf x_t)=-\operatorname{tr}\frac{\partial\mathbf v}{\partial\mathbf x}
Show the answer

D. ddtlog⁡pt(xt)=−tr⁡∂v∂x\frac{d}{dt}\log p_t(\mathbf x_t)=-\operatorname{tr}\frac{\partial\mathbf v}{\partial\mathbf x}

Jacobi's formula gives ddtlog⁡det⁡Jt=tr⁡∂v∂x\frac{d}{dt}\log\det J_t=\operatorname{tr}\frac{\partial\mathbf v}{\partial\mathbf x} for the Jacobian of the flow map, and the density falls as volume grows: a field that spreads points apart, with positive divergence, lowers the density along the way.

Question 2

Rectified flow is trained on straight lines from noise to data. Why do samples from the trained model follow curved paths, even with an exact ODE solver?

  1. Because neural networks cannot represent straight-line motion
  2. Because the regression target is the average direction of all the lines passing through a point; where lines toward different data cross, that average turns, and trajectories bend rather than cross
  3. Because the solver's discretization adds curvature
  4. They do not: an exact solver retraces the training lines
Show the answer

B. Because the regression target is the average direction of all the lines passing through a point; where lines toward different data cross, that average turns, and trajectories bend rather than cross

The minimizer is E[x1−x0∣xt=x]\E[\mathbf x_1-\mathbf x_0\mid\mathbf x_t=\mathbf x], a posterior average of line directions. Early on that average points toward the data mean; later it points toward the data point the particle is committing to. Only when the lines of the coupling never cross, as after a perfect reflow, are the trajectories straight.

Question 3

After one reflow step, with an exact velocity field and a well-posed ODE, which statement is guaranteed?

  1. The new coupling is the optimal-transport coupling for squared distance
  2. A single Euler step now produces exact samples, in any dimension
  3. The training loss of the new flow is zero
  4. The new flow has the same marginals at every time, and its noise–data pairs have no larger expected convex transport cost than before
Show the answer

D. The new flow has the same marginals at every time, and its noise–data pairs have no larger expected convex transport cost than before

Rectification preserves the marginals of the interpolation and lowers every convex transport cost (Liu et al., 2023), and iterating it drives the straightness to zero at rate O(1/K)\order{1/K}. It does not reach the optimal coupling in general (one dimension is the exception), and paths are only approximately straight after one reflow.

Question 4

How is v-prediction (Salimans & Ho, 2022) related to flow matching?

  1. v\mathbf v is the velocity of the variance-preserving path in an angle parameterization, so v-prediction is flow matching on that path up to a constant factor and the direction of time
  2. v\mathbf v is the score of the noised data
  3. v-prediction is noise prediction with a different loss weighting, unrelated to any flow
  4. v\mathbf v is the straight-line velocity x1−x0\mathbf x_1-\mathbf x_0 of rectified flow
Show the answer

A. v\mathbf v is the velocity of the variance-preserving path in an angle parameterization, so v-prediction is flow matching on that path up to a constant factor and the direction of time

With zϕ=cos⁡ϕ x+sin⁡ϕ ϵ\mathbf z_\phi=\cos\phi\,\mathbf x+\sin\phi\,\boldsymbol\epsilon, v=dzϕ/dϕ\mathbf v=d\mathbf z_\phi/d\phi. Setting ϕ=π2(1−t)\phi=\frac\pi2(1-t) gives the VP path sin⁡πt2x1+cos⁡πt2x0\sin\frac{\pi t}2\mathbf x_1+\cos\frac{\pi t}2\mathbf x_0, whose flow-matching target is −π2v-\frac\pi2\mathbf v.

Further reading

  • R. T. Q. Chen, Y. Rubanova, J. Bettencourt & D. Duvenaud, "Neural ordinary differential equations," NeurIPS (2018).
  • W. Grathwohl, R. T. Q. Chen, J. Bettencourt, I. Sutskever & D. Duvenaud, "FFJORD: Free-form continuous dynamics for scalable reversible generative models," ICLR (2019).
  • Y. Lipman, R. T. Q. Chen, H. Ben-Hamu, M. Nickel & M. Le, "Flow matching for generative modeling," ICLR (2023).
  • X. Liu, C. Gong & Q. Liu, "Flow straight and fast: Learning to generate and transfer data with rectified flow," ICLR (2023).
  • Y. Lipman, M. Havasi, P. Holderrieth, N. Shaul, M. Le, B. Karrer, R. T. Q. Chen, D. Lopez-Paz, H. Ben-Hamu & I. Gat, "Flow matching guide and code," arXiv:2412.06264 (2024).