Diffusion Policy & Flow Matching.
Both methods learn to turn Gaussian noise into an action chunk, conditioned on what the robot observes. Diffusion learns to undo a noising process step by step. Flow matching learns a velocity field along paths you choose. The two turn out to be the same model family seen from two sides.
Both panes start from the same noise and aim at the same target. The left pane follows the diffusion probability-flow ODE with a cosine schedule. The right pane follows the flow matching ODE with a linear path. Pick a target, press Play, and watch how far each particle bends on the way from noise to action.
Organization
The first part states the problem both methods solve. Track I covers diffusion: the forward noising process, training from the ELBO to the \(\varepsilon\)-loss, DDPM and DDIM sampling, the score and SDE view, and the Diffusion Policy system. Track II covers flow matching: the velocity-field idea, why the simple loss works, probability paths and couplings, training, ODE solvers, straight paths and few-step generation, and flow policies such as \(\pi_0\). Track III connects the two and compares them on sampling steps, code and robot policies. Each part ends with its derivations.
All derivations on the page:
Diffusion track
- The DDPM closed form, and what the \(\varepsilon\)-loss learns
- The DDPM posterior \(q(a^{k-1}\mid a^k,a)\) by completing the square
- From the likelihood to the variational bound
- From the KL terms to the \(\varepsilon\)-loss, \(\hat a\)-loss and SNR weighting
- The DDPM ancestral sampling step, the variance choice, and respacing
- The DDIM family: same marginals, any amount of noise
- The continuous limit, the reverse SDE and the probability-flow ODE
Flow matching track
- The straight-line path, its velocity and its conditional law
- The continuity equation, and a hand check on the straight-line path
- The conditional flow matching theorem
- The marginal field as a posterior average, and its closed form for Gaussian mixtures
- The conditional velocity of a Gaussian path, and why it generates the path
- Flow matching with any coupling, and why optimal-transport pairs do not cross
- Parameterizations on the linear path, and the effective time weighting
- Exact log-likelihood from the flow: the instantaneous change of variables and Hutchinson's trace
- Order of accuracy of ODE solvers: Euler, Heun, midpoint, RK4
- From velocity to score to a stochastic sampler
- Rectified flow: marginals, cost and straightness under reflow
- Average velocity, the MeanFlow identity and one-step generation
Head to head:
The problem both methods solve
Behavior cloning learns a policy from demonstrations. Given an observation \(o\), the demonstrator produced an action chunk \(a\): a short sequence of future actions, for example the next 16 end-effector displacements. The data define a conditional distribution \(p(a \mid o)\), and the goal is a model that outputs samples from it.
The difficulty is that \(p(a \mid o)\) is often multimodal. Picture a robot that must get past an obstacle to a goal. Some demonstrators go left, others go right, and both are correct. A single observation \(o\) is paired with two very different chunks.
What regression does
The standard way to train a deterministic policy \(f_\theta(o)\) is mean squared error. The minimizer of that loss is the conditional mean:
This holds for any distribution: the part of the error you cannot remove is the spread of \(a\) around its mean, and the best constant guess for a random variable is its mean. For a bimodal \(p(a \mid o)\) the mean sits between the modes. If half the demonstrations pass left of the obstacle and half pass right, the average path goes straight into it. Each demonstration was feasible. Their average is not. The figure shows this on a top-down toy task.
Press Play. The MSE policy drives into the obstacle because it outputs the average of the two modes. The Diffusion Policy and flow matching policies each commit to one side. Different samples go left or right, in roughly the proportion seen in the demonstrations, and every sample is a path that a demonstrator could have produced.
Sampling instead of averaging
A generative policy does not output a single answer. It draws \(a \sim p_\theta(a \mid o)\). Both methods in this page do that by the same recipe: draw Gaussian noise \(\varepsilon \sim \mathcal{N}(0, I)\) and transform it into an action chunk with a learned, observation-conditioned map. The noise decides which mode you land in. The network decides what each mode looks like.
Why a whole chunk
The sample is a whole chunk, not one action at a time. This matters for temporal consistency. If you sampled each action independently from its own marginal, step 1 could come from the left mode and step 2 from the right, and the executed path would zigzag across the obstacle. Sampling the chunk jointly means the network produces all its steps from one noise vector, so the entire chunk commits to one mode. The robot then executes the chunk, or part of it, and replans from the new observation.
MSE regression returns \(\mathbb{E}[a \mid o]\), the average of the modes, which can be an action nobody demonstrated. A generative policy returns a sample from \(p(a \mid o)\), so it picks one mode. Sampling a joint chunk makes that choice consistent over time.
Track I builds the diffusion route to such a sampler. Track II builds the flow matching route. Track III puts them side by side.
Diffusion Policy
The diffusion model behind Diffusion Policy: the forward noising chain, the ELBO and the \(\varepsilon\)-loss, DDPM and DDIM sampling, and the continuous score and SDE picture. The last part covers the policy built around the model: action chunks, a receding horizon, and the network.
Diffusion I: the forward noising process
Diffusion builds a path from data to noise that it knows exactly, then learns to walk that path backwards [1], [2]. The forward direction has no learning in it. Start from a clean action chunk \(a^0 = a\) and add a little Gaussian noise at each of \(K\) steps:
The numbers \(\beta_1, \dots, \beta_K\) are the noise schedule. The superscript \(k\) counts noising steps, so \(k = 0\) is data and \(k = K\) is almost pure noise. This is the opposite orientation from flow matching time, where \(t = 0\) is noise.
Why the scaling by the square root of \(\alpha_k\)
The step does not just add noise. It also shrinks the signal by \(\sqrt{\alpha_k}\), to keep the variance under control. As a sample, the step is \(a^k = \sqrt{\alpha_k}\, a^{k-1} + \sqrt{\beta_k}\, \varepsilon\) with \(\varepsilon \sim \mathcal{N}(0, I)\) independent of \(a^{k-1}\). Scaling by \(c\) scales a variance by \(c^2\), and variances of independent terms add. So if an entry of \(a^{k-1}\) has variance \(v\),
With \(v = 1\) this is exactly \(1\). Without the shrinkage it would be \(v + \beta_k\), growing by \(\beta_k\) every step to \(1 + \sum_k \beta_k\), a huge and badly scaled distribution. For any other starting \(v\), subtracting 1 gives \(\operatorname{Var}(a^k) - 1 = \alpha_k\,(v - 1)\), so the variance is pulled toward 1 and the chain converges to a standard Gaussian. This is called a variance-preserving (VP) process. It also means the network always sees inputs on a similar scale, whatever \(k\) is.
Jumping to any step in one shot
Because every step is Gaussian and linear, composing \(k\) of them is again Gaussian. Define \(\bar\alpha_k = \prod_{i=1}^{k} \alpha_i\). Then
The derivation below shows each step. The result is a clean action scaled down by \(\sqrt{\bar\alpha_k}\) plus noise scaled up by \(\sqrt{1-\bar\alpha_k}\), with the two squared weights summing to 1. Their ratio is the signal-to-noise ratio
which decreases monotonically with \(k\). A good schedule drives it close to 0 at \(k = K\), so that \(a^K\) is nearly indistinguishable from \(\mathcal{N}(0, I)\). Then sampling can start from plain Gaussian noise.
Schedules
Ho et al. used a linear schedule, \(\beta_k\) rising from \(10^{-4}\) to \(0.02\) [2]. It was designed for \(K = 1000\). With only \(K = 100\) steps the same range ends at \(\bar\alpha_K \approx 0.36\), so a good deal of signal is still left at the last step. Nichol and Dhariwal proposed a squared-cosine \(\bar\alpha_k\) that decays smoothly to 0 [4], and it is the schedule used in many robot diffusion codebases. With \(K = 100\) it ends at \(\bar\alpha_K \approx 2 \times 10^{-7}\). In the figure, switch the schedule and watch the inset curve of \(\bar\alpha_k\).
Press Play or drag the slider from \(k = 0\) to \(K\). Each particle keeps its own \(\varepsilon\), so it drifts steadily as \(k\) grows. The two clusters of action modes blur into each other and then into a single round Gaussian. The faint shape behind the particles is the exact density of \(a^k\).
The posterior the reverse model will imitate
To generate, we need to run this chain backwards. The reverse transition \(q(a^{k-1} \mid a^k)\) depends on the whole data distribution and is intractable. But if we also condition on the clean action \(a\), Bayes' rule gives a Gaussian in closed form:
The mean is a weighted blend of the clean action and the noisy one. The variance \(\tilde\beta_k\) is known and does not depend on \(a\). The derivation below multiplies two Gaussians and completes the square. Training will make the learned reverse step match this posterior, with the unknown \(a\) replaced by the network's estimate.
The forward process has no parameters and is known in closed form. You can jump to any noise level \(k\) in one shot during training, without simulating the chain, and the posterior \(q(a^{k-1} \mid a^k, a)\) gives the exact target for every reverse step.
Derivations
The DDPM closed form, and what the \(\varepsilon\)-loss learns
Goal: show that the step-by-step noising chain collapses to the one-shot formula \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\), then show that minimizing the \(\varepsilon\)-prediction loss makes the network output the conditional mean \(\mathbb{E}[\varepsilon \mid a^k]\).
- \[ a^k = \sqrt{1-\beta_k}\; a^{k-1} + \sqrt{\beta_k}\; \varepsilon_k, \qquad a^0 = a . \]
This is the DDPM forward chain. The \(\varepsilon_k \sim \mathcal{N}(0,I)\) are independent of each other and of \(a\). Define \(\bar\alpha_k = \prod_{i=1}^{k}(1-\beta_i)\).
- \[ a^1 = \sqrt{1-\beta_1}\; a + \sqrt{\beta_1}\; \varepsilon_1 . \]
Set \(k=1\) in step 1 and use \(a^0=a\).
- \[ \bar\alpha_1 = 1-\beta_1, \qquad 1-\bar\alpha_1 = \beta_1 . \]
Definition of \(\bar\alpha_k\) with a product of one factor.
- \[ a^1 = \sqrt{\bar\alpha_1}\; a + \sqrt{1-\bar\alpha_1}\; \varepsilon_1 . \]
Replace the two coefficients in step 2 using step 3. The formula already holds for \(k=1\).
- \[ a^2 = \sqrt{1-\beta_2}\; a^1 + \sqrt{\beta_2}\; \varepsilon_2 . \]
Step 1 with \(k=2\). Now we want \(a^2\) in terms of \(a\) only.
- \[ a^2 = \sqrt{1-\beta_2}\,\Big[\sqrt{1-\beta_1}\, a + \sqrt{\beta_1}\, \varepsilon_1\Big] + \sqrt{\beta_2}\; \varepsilon_2 . \]
Substitute the expression for \(a^1\) from step 2.
- \[ a^2 = \sqrt{(1-\beta_2)(1-\beta_1)}\; a + \sqrt{(1-\beta_2)\beta_1}\; \varepsilon_1 + \sqrt{\beta_2}\; \varepsilon_2 . \]
Distribute \(\sqrt{1-\beta_2}\) over the bracket and use \(\sqrt{x}\sqrt{y}=\sqrt{xy}\) for \(x,y\ge 0\).
- \[ (1-\beta_2)(1-\beta_1) = \bar\alpha_2 . \]
Definition of \(\bar\alpha_2\). The coefficient of \(a\) is therefore \(\sqrt{\bar\alpha_2}\).
- \[ n := \underbrace{\sqrt{(1-\beta_2)\beta_1}}_{c_1}\, \varepsilon_1 + \underbrace{\sqrt{\beta_2}}_{c_2}\, \varepsilon_2 . \]
Name the noise part of step 7. It is a sum of two independent Gaussians, each scaled by a constant.
- \[ c_i\, \varepsilon_i \sim \mathcal{N}\big(0,\; c_i^2\, I\big). \]
Scaling a Gaussian by a constant \(c\) multiplies its covariance by \(c^2\): \(\mathrm{Cov}(c\varepsilon) = c\,\mathrm{Cov}(\varepsilon)\,c = c^2 I\).
- \[ n \sim \mathcal{N}\big(0,\; (c_1^2 + c_2^2)\, I\big). \]
A sum of independent Gaussians is Gaussian. Means add (here \(0+0\)) and, because of independence, variances add.
- \[ c_1^2 + c_2^2 = (1-\beta_2)\beta_1 + \beta_2 = \beta_1 - \beta_1\beta_2 + \beta_2 . \]
Insert \(c_1^2=(1-\beta_2)\beta_1\) and \(c_2^2=\beta_2\), then expand the product.
- \[ 1-\bar\alpha_2 = 1 - (1-\beta_1)(1-\beta_2) = 1 - \big(1 - \beta_1 - \beta_2 + \beta_1\beta_2\big) . \]
Expand the product that defines \(\bar\alpha_2\).
- \[ 1-\bar\alpha_2 = \beta_1 + \beta_2 - \beta_1\beta_2 . \]
Distribute the minus sign and cancel the \(1\).
- \[ c_1^2 + c_2^2 = 1-\bar\alpha_2 . \]
Steps 12 and 14 give the same expression.
- \[ n \overset{d}{=} \sqrt{1-\bar\alpha_2}\; \varepsilon, \qquad \varepsilon \sim \mathcal{N}(0,I). \]
A zero-mean Gaussian with covariance \(s^2 I\) has the same distribution as \(s\,\varepsilon\) for a standard normal \(\varepsilon\). Here \(\varepsilon\) is a fresh sample that replaces the pair \((\varepsilon_1,\varepsilon_2)\).
- \[ a^2 = \sqrt{\bar\alpha_2}\; a + \sqrt{1-\bar\alpha_2}\; \varepsilon . \]
Combine steps 7, 8 and 16. This is the \(k=2\) case, and it already shows the pattern: signal coefficients multiply, noise variances combine into \(1-\bar\alpha_2\).
- \[ a^{k-1} = \sqrt{\bar\alpha_{k-1}}\; a + \sqrt{1-\bar\alpha_{k-1}}\; \tilde\varepsilon . \]
Induction hypothesis. Here \(\tilde\varepsilon \sim \mathcal{N}(0,I)\) is built from \(\varepsilon_1,\dots,\varepsilon_{k-1}\), so it is independent of \(\varepsilon_k\).
- \[ a^k = \sqrt{1-\beta_k}\,\Big[\sqrt{\bar\alpha_{k-1}}\, a + \sqrt{1-\bar\alpha_{k-1}}\, \tilde\varepsilon\Big] + \sqrt{\beta_k}\, \varepsilon_k . \]
Substitute step 18 into step 1.
- \[ a^k = \sqrt{(1-\beta_k)\bar\alpha_{k-1}}\; a + \sqrt{(1-\beta_k)(1-\bar\alpha_{k-1})}\; \tilde\varepsilon + \sqrt{\beta_k}\; \varepsilon_k . \]
Distribute \(\sqrt{1-\beta_k}\) and combine square roots, as in step 7.
- \[ (1-\beta_k)\,\bar\alpha_{k-1} = \prod_{i=1}^{k}(1-\beta_i) = \bar\alpha_k . \]
Definition of \(\bar\alpha_k\). The coefficient of \(a\) is \(\sqrt{\bar\alpha_k}\).
- \[ \text{noise variance} = (1-\beta_k)(1-\bar\alpha_{k-1}) + \beta_k . \]
Variances of the two independent noise terms add, exactly as in steps 10 and 11.
- \[ (1-\beta_k)(1-\bar\alpha_{k-1}) = 1-\beta_k - (1-\beta_k)\bar\alpha_{k-1} = 1 - \beta_k - \bar\alpha_k . \]
Distribute, then use step 21 for the second product.
- \[ \text{noise variance} = 1 - \beta_k - \bar\alpha_k + \beta_k = 1-\bar\alpha_k . \]
Insert step 23 into step 22. The \(-\beta_k\) and \(+\beta_k\) cancel.
- \[ a^k = \sqrt{\bar\alpha_k}\; a + \sqrt{1-\bar\alpha_k}\; \varepsilon, \qquad \varepsilon\sim\mathcal{N}(0,I). \]
Steps 21 and 24 give both coefficients. Combining the two noise terms into one fresh standard normal is the same move as step 16. This closes the induction: the formula holds for every \(k\).
- \[ \mathcal{L}(f) = \mathbb{E}\,\big\| f(x) - \varepsilon \big\|^2, \qquad x := a^k . \]
Now the loss. \(f\) is any function of the network input \(x\) (we fix \(k\); the observation \(o\) is part of the input and is omitted from the notation). Write \(m(x) := \mathbb{E}[\varepsilon \mid x]\).
- \[ f - \varepsilon = (f - m) + (m - \varepsilon) . \]
Add and subtract \(m(x)\). Nothing changes.
- \[ \|f-\varepsilon\|^2 = \|f-m\|^2 + 2\,(f-m)\cdot(m-\varepsilon) + \|m-\varepsilon\|^2 . \]
Expand \(\|p+q\|^2=\|p\|^2+2\,p\cdot q+\|q\|^2\) with \(p=f-m\), \(q=m-\varepsilon\).
- \[ \mathcal{L}(f) = \mathbb{E}\|f-m\|^2 + 2\,\mathbb{E}\big[(f-m)\cdot(m-\varepsilon)\big] + \mathbb{E}\|m-\varepsilon\|^2 . \]
Linearity of expectation, applied to each of the three terms.
- \[ \mathbb{E}\big[(f-m)\cdot(m-\varepsilon)\big] = \mathbb{E}\Big[\, \mathbb{E}\big[(f-m)\cdot(m-\varepsilon) \,\big|\, x\big]\Big] . \]
Tower property (law of iterated expectations): \(\mathbb{E}[Y]=\mathbb{E}[\mathbb{E}[Y\mid x]]\).
- \[ \mathbb{E}\big[(f-m)\cdot(m-\varepsilon) \,\big|\, x\big] = (f-m)\cdot\big(m - \mathbb{E}[\varepsilon \mid x]\big) . \]
Both \(f(x)\) and \(m(x)\) are functions of \(x\), so they are constants once we condition on \(x\) and can be pulled out ("taking out what is known"). Only \(\varepsilon\) is still random.
- \[ (f-m)\cdot\big(m - m\big) = 0 . \]
By definition \(\mathbb{E}[\varepsilon\mid x]=m(x)\). The cross term vanishes for every \(x\), so its outer expectation is \(0\) too.
- \[ \mathcal{L}(f) = \mathbb{E}\|f(x)-m(x)\|^2 + \mathbb{E}\|m(x)-\varepsilon\|^2 . \]
Steps 30 to 32 show that the middle term of step 29 is zero, so only the first and third terms remain.
- \[ \mathcal{L}(f) \ \ge\ \mathbb{E}\|m(x)-\varepsilon\|^2, \quad \text{with equality iff } f(x)=m(x) \text{ almost everywhere.} \]
The second term of step 33 does not contain \(f\). The first is a mean of squared norms, so it is \(\ge 0\) and equals \(0\) only when \(f=m\).
Result: the chain of one-step noisings equals the single Gaussian jump \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\), and the best possible \(\varepsilon\)-network is \(\varepsilon_\theta(a^k,k,o)=\mathbb{E}[\varepsilon \mid a^k]\), the conditional mean of the noise given what the network sees. The remaining error \(\mathbb{E}\|m-\varepsilon\|^2\) is irreducible, because many noises are compatible with one noisy input.
The DDPM posterior \(q(a^{k-1}\mid a^k,a)\) by completing the square
Goal: find the exact Gaussian \(q(a^{k-1}\mid a^k,a)=\mathcal{N}(\tilde\mu_k,\tilde\beta_k I)\) with \(\tilde\beta_k=\frac{(1-\bar\alpha_{k-1})\beta_k}{1-\bar\alpha_k}\) and \(\tilde\mu_k=\frac{\sqrt{\bar\alpha_{k-1}}\beta_k}{1-\bar\alpha_k}a+\frac{\sqrt{\alpha_k}(1-\bar\alpha_{k-1})}{1-\bar\alpha_k}a^k\), then rewrite the mean in the \(\varepsilon\) form \(\tilde\mu_k=\frac{1}{\sqrt{\alpha_k}}\big(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\varepsilon\big)\). The reverse step of the sampler is built from exactly this target.
- \[ q(a^{k-1}\mid a^k,a)=\frac{q(a^k\mid a^{k-1},a)\;q(a^{k-1}\mid a)}{q(a^k\mid a)} . \]
Bayes' rule for the variable \(a^{k-1}\), with \(a\) carried along as extra conditioning. Take \(k\ge 2\); \(k=1\) is treated in the result. We drop \(o\) from the notation: read every density as conditional on \(o\).
- \[ q(a^k\mid a^{k-1},a)=q(a^k\mid a^{k-1})=\mathcal{N}\big(a^k;\ \sqrt{\alpha_k}\,a^{k-1},\ \beta_k I\big) . \]
Markov property. \(a^k=\sqrt{\alpha_k}\,a^{k-1}+\sqrt{\beta_k}\,\varepsilon_k\) uses only \(a^{k-1}\) and a fresh \(\varepsilon_k\) independent of \(a\), so once \(a^{k-1}\) is known, \(a\) adds nothing.
- \[ q(a^{k-1}\mid a)=\mathcal{N}\big(a^{k-1};\ \sqrt{\bar\alpha_{k-1}}\,a,\ (1-\bar\alpha_{k-1})\,I\big) . \]
The closed-form marginal from the DDPM closed-form derivation, written for level \(k-1\).
- \[ q(a^{k-1}\mid a^k,a)\ \propto\ q(a^k\mid a^{k-1})\;q(a^{k-1}\mid a) \qquad\text{(as a function of } a^{k-1}\text{)}. \]
Insert steps 2 and 3 into step 1. The denominator \(q(a^k\mid a)\) does not contain \(a^{k-1}\), so for our purpose it is a constant. The normalization is fixed at the end by recognizing a Gaussian.
- \[ x := a^{k-1}, \qquad y := a^k, \qquad a,\ x,\ y \in \mathbb{R}\ \ (\text{one coordinate}). \]
Every covariance above is a multiple of \(I\), so the density factorizes over the \(d\) coordinates into \(d\) identical scalar problems. We solve one coordinate; the answer holds for each.
- \[ \log q(x\mid y,a) = -\frac{(y-\sqrt{\alpha_k}\,x)^2}{2\beta_k} - \frac{(x-\sqrt{\bar\alpha_{k-1}}\,a)^2}{2(1-\bar\alpha_{k-1})} + c_0 . \]
Take the log of step 4. The log of a product is a sum of logs, and a scalar Gaussian has log density \(-(z-m)^2/(2v)+\text{const}\). The constant \(c_0\) collects everything without \(x\): normalizing constants and the log of the denominator in step 1.
- \[ (y-\sqrt{\alpha_k}\,x)^2 = y^2 - 2\sqrt{\alpha_k}\,y\,x + \alpha_k\,x^2 . \]
Expand \((p-q)^2=p^2-2pq+q^2\) with \(p=y\), \(q=\sqrt{\alpha_k}\,x\), and use \((\sqrt{\alpha_k})^2=\alpha_k\).
- \[ (x-\sqrt{\bar\alpha_{k-1}}\,a)^2 = x^2 - 2\sqrt{\bar\alpha_{k-1}}\,a\,x + \bar\alpha_{k-1}\,a^2 . \]
The same expansion for the second square.
- \[ \begin{aligned} \log q(x\mid y,a) &= -\tfrac12\Big[\Big(\tfrac{\alpha_k}{\beta_k}+\tfrac{1}{1-\bar\alpha_{k-1}}\Big)x^2\\ &\qquad - 2\Big(\tfrac{\sqrt{\alpha_k}\,y}{\beta_k}+\tfrac{\sqrt{\bar\alpha_{k-1}}\,a}{1-\bar\alpha_{k-1}}\Big)x\Big] + c_1 . \end{aligned} \]
Insert steps 7 and 8 into step 6. Divide the first expansion by \(2\beta_k\) and the second by \(2(1-\bar\alpha_{k-1})\), then group by powers of \(x\). The \(y^2\) and \(a^2\) terms contain no \(x\), so they move into the constant \(c_1\).
- \[ A := \frac{\alpha_k}{\beta_k}+\frac{1}{1-\bar\alpha_{k-1}}, \qquad B := \frac{\sqrt{\alpha_k}\,y}{\beta_k}+\frac{\sqrt{\bar\alpha_{k-1}}\,a}{1-\bar\alpha_{k-1}} . \]
Names for the coefficient of \(x^2\) (the quadratic term) and the coefficient of \(x\) (the linear term). Then step 9 reads \(\log q=-\tfrac12(Ax^2-2Bx)+c_1\).
- \[ A x^2 - 2Bx = A\Big(x-\frac{B}{A}\Big)^2 - \frac{B^2}{A} . \]
Completing the square. Check by expanding the right side: \(A\big(x^2-2Bx/A+B^2/A^2\big)-B^2/A\) \(= Ax^2-2Bx+B^2/A-B^2/A\).
- \[ \log q(x\mid y,a) = -\frac{A}{2}\Big(x-\frac{B}{A}\Big)^2 + c_2, \qquad c_2 := c_1+\frac{B^2}{2A} . \]
Insert step 11 into \(-\tfrac12(Ax^2-2Bx)+c_1\). The extra term \(+B^2/(2A)\) has no \(x\), so it joins the constant.
- \[ q(x\mid y,a)\ \propto\ \exp\!\Big(-\frac{(x-B/A)^2}{2\,(1/A)}\Big) \ \Longrightarrow\ x\mid y,a\ \sim\ \mathcal{N}\Big(\frac{B}{A},\ \frac1A\Big). \]
Exponentiate step 12. This is the kernel of a Gaussian with mean \(B/A\) and variance \(1/A\). A density that is proportional to a Gaussian kernel and integrates to one is that Gaussian.
- \[ \tilde\beta_k := \frac{1}{A}, \qquad \tilde\mu_k := \frac{B}{A} = \tilde\beta_k\,B . \]
Names for the posterior variance and mean, so that \(q(a^{k-1}\mid a^k,a)=\mathcal{N}(\tilde\mu_k,\tilde\beta_k I)\). The next steps put them in closed form. The precision (inverse variance) is \(1/\tilde\beta_k=A=\alpha_k/\beta_k+1/(1-\bar\alpha_{k-1})\): precisions of the two factors add.
- \[ \bar\alpha_k=\alpha_k\,\bar\alpha_{k-1} \quad\Longrightarrow\quad \alpha_k\,(1-\bar\alpha_{k-1}) = \alpha_k-\bar\alpha_k . \]
Definition \(\bar\alpha_k=\prod_{i=1}^{k}\alpha_i\) peeled by one factor. Then distribute \(\alpha_k\) over \((1-\bar\alpha_{k-1})\).
- \[ \alpha_k\,(1-\bar\alpha_{k-1}) + \beta_k = \alpha_k - \bar\alpha_k + \beta_k = 1-\bar\alpha_k . \]
Insert step 15, then use \(\alpha_k+\beta_k=1\). This identity is used three times below: it says the noise variance after one more step splits into the old noise, shrunk by \(\alpha_k\), plus the fresh \(\beta_k\).
- \[ A=\frac{\alpha_k}{\beta_k}+\frac{1}{1-\bar\alpha_{k-1}} = \frac{\alpha_k(1-\bar\alpha_{k-1})+\beta_k}{\beta_k\,(1-\bar\alpha_{k-1})} . \]
Common denominator: multiply the first fraction top and bottom by \((1-\bar\alpha_{k-1})\) and the second by \(\beta_k\), then add the numerators.
- \[ A = \frac{1-\bar\alpha_k}{\beta_k\,(1-\bar\alpha_{k-1})} . \]
Replace the numerator in step 17 using the identity of step 16.
- \[ \tilde\beta_k=\frac1A=\frac{(1-\bar\alpha_{k-1})\,\beta_k}{1-\bar\alpha_k} . \]
Invert step 18. This is the posterior variance.
- \[ \tilde\mu_k=\tilde\beta_k B = \tilde\beta_k\,\frac{\sqrt{\alpha_k}}{\beta_k}\;a^k + \tilde\beta_k\,\frac{\sqrt{\bar\alpha_{k-1}}}{1-\bar\alpha_{k-1}}\;a . \]
Multiply \(B\) from step 10 by \(\tilde\beta_k\), term by term, and write \(y=a^k\).
- \[ \tilde\beta_k\,\frac{\sqrt{\alpha_k}}{\beta_k} = \frac{(1-\bar\alpha_{k-1})\,\beta_k}{1-\bar\alpha_k}\cdot\frac{\sqrt{\alpha_k}}{\beta_k} = \frac{\sqrt{\alpha_k}\,(1-\bar\alpha_{k-1})}{1-\bar\alpha_k} . \]
Coefficient of \(a^k\). Insert step 19 and cancel \(\beta_k\).
- \[ \tilde\beta_k\,\frac{\sqrt{\bar\alpha_{k-1}}}{1-\bar\alpha_{k-1}} = \frac{(1-\bar\alpha_{k-1})\,\beta_k}{1-\bar\alpha_k}\cdot\frac{\sqrt{\bar\alpha_{k-1}}}{1-\bar\alpha_{k-1}} = \frac{\sqrt{\bar\alpha_{k-1}}\,\beta_k}{1-\bar\alpha_k} . \]
Coefficient of \(a\). Insert step 19 and cancel \((1-\bar\alpha_{k-1})\).
- \[ \tilde\mu_k = \frac{\sqrt{\bar\alpha_{k-1}}\,\beta_k}{1-\bar\alpha_k}\;a + \frac{\sqrt{\alpha_k}\,(1-\bar\alpha_{k-1})}{1-\bar\alpha_k}\;a^k . \]
Put steps 21 and 22 into step 20. This is the posterior mean in the \((a,a^k)\) form.
- \[ \sqrt{\bar\alpha_k}\,a = a^k - \sqrt{1-\bar\alpha_k}\;\varepsilon . \]
Now the \(\varepsilon\)-form. Start from the closed form \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\) and subtract the noise term. Here \(\varepsilon\) is the noise that produced \(a^k\) from \(a\).
- \[ a=\frac{a^k-\sqrt{1-\bar\alpha_k}\;\varepsilon}{\sqrt{\bar\alpha_k}} . \]
Divide step 24 by \(\sqrt{\bar\alpha_k}\).
- \[ \frac{\sqrt{\bar\alpha_{k-1}}\,\beta_k}{1-\bar\alpha_k}\,a = \frac{\sqrt{\bar\alpha_{k-1}}\,\beta_k}{(1-\bar\alpha_k)\sqrt{\bar\alpha_k}}\,\big(a^k-\sqrt{1-\bar\alpha_k}\;\varepsilon\big) . \]
Replace \(a\) in the first term of step 23 by step 25. The second term of step 23 is left alone for now.
- \[ \frac{\sqrt{\bar\alpha_{k-1}}}{\sqrt{\bar\alpha_k}}=\frac{\sqrt{\bar\alpha_{k-1}}}{\sqrt{\alpha_k}\sqrt{\bar\alpha_{k-1}}}=\frac{1}{\sqrt{\alpha_k}} . \]
From step 15, \(\sqrt{\bar\alpha_k}=\sqrt{\alpha_k}\,\sqrt{\bar\alpha_{k-1}}\). Cancel \(\sqrt{\bar\alpha_{k-1}}\).
- \[ \frac{\sqrt{\bar\alpha_{k-1}}\,\beta_k}{1-\bar\alpha_k}\,a = \frac{\beta_k}{\sqrt{\alpha_k}\,(1-\bar\alpha_k)}\,a^k - \frac{\beta_k\sqrt{1-\bar\alpha_k}}{\sqrt{\alpha_k}\,(1-\bar\alpha_k)}\,\varepsilon . \]
Use step 27 in step 26 and distribute over the bracket.
- \[ \frac{\sqrt{1-\bar\alpha_k}}{1-\bar\alpha_k}=\frac{1}{\sqrt{1-\bar\alpha_k}} \quad\Longrightarrow\quad \frac{\sqrt{\bar\alpha_{k-1}}\,\beta_k}{1-\bar\alpha_k}\,a = \frac{\beta_k}{\sqrt{\alpha_k}\,(1-\bar\alpha_k)}\,a^k - \frac{\beta_k}{\sqrt{\alpha_k}\sqrt{1-\bar\alpha_k}}\,\varepsilon . \]
Write \(1-\bar\alpha_k=\sqrt{1-\bar\alpha_k}\sqrt{1-\bar\alpha_k}\) and cancel one factor in the last term of step 28.
- \[ \text{coeff. of } a^k:\quad \frac{\sqrt{\alpha_k}\,(1-\bar\alpha_{k-1})}{1-\bar\alpha_k}+\frac{\beta_k}{\sqrt{\alpha_k}\,(1-\bar\alpha_k)} . \]
Add the \(a^k\) coefficient of the second term of step 23 to the \(a^k\) coefficient from step 29. The noise \(\varepsilon\) appears only in step 29.
- \[ \text{coeff. of } a^k = \frac{\alpha_k\,(1-\bar\alpha_{k-1})+\beta_k}{\sqrt{\alpha_k}\,(1-\bar\alpha_k)} . \]
Common denominator \(\sqrt{\alpha_k}(1-\bar\alpha_k)\): the first fraction gets multiplied top and bottom by \(\sqrt{\alpha_k}\), and \(\sqrt{\alpha_k}\sqrt{\alpha_k}=\alpha_k\).
- \[ \text{coeff. of } a^k = \frac{1-\bar\alpha_k}{\sqrt{\alpha_k}\,(1-\bar\alpha_k)} = \frac{1}{\sqrt{\alpha_k}} . \]
The numerator is \(1-\bar\alpha_k\) by the identity of step 16. Cancel it.
- \[ \tilde\mu_k=\frac{1}{\sqrt{\alpha_k}}\,a^k-\frac{\beta_k}{\sqrt{\alpha_k}\sqrt{1-\bar\alpha_k}}\,\varepsilon=\frac{1}{\sqrt{\alpha_k}}\Big(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon\Big) . \]
Collect: the \(a^k\) coefficient is step 32 and the \(\varepsilon\) coefficient is \(-\beta_k/(\sqrt{\alpha_k}\sqrt{1-\bar\alpha_k})\) from step 29. Factor out \(1/\sqrt{\alpha_k}\).
Result: \(q(a^{k-1}\mid a^k,a)=\mathcal{N}(\tilde\mu_k,\tilde\beta_k I)\), with the variance of step 19, the mean of step 23, and the \(\varepsilon\)-form of step 33. At \(k=1\) we have \(\bar\alpha_0=1\), so \(\tilde\beta_1=0\) and step 23 gives \(\tilde\mu_1=a\): the posterior over \(a^0\) is a point mass at \(a\), which is what it must be. The step-33 form also reproduces \(a\) there, because \(a^1=\sqrt{\alpha_1}a+\sqrt{\beta_1}\varepsilon\).
Diffusion II: training, from the ELBO to the \(\varepsilon\)-loss
The reverse model is a learned Gaussian step, conditioned on the observation:
The variance \(\sigma_k^2\) is fixed, not learned. Only the mean is a network output. Together with the prior \(p(a^K) = \mathcal{N}(0, I)\), the chain \(p_\theta\) defines a distribution over \(a^0\). We want to maximize the likelihood of the demonstrated actions under it.
The ELBO
The likelihood of \(a^0\) involves integrating over all intermediate noisy chunks, which is intractable. Instead we minimize the usual variational upper bound on \(-\log p_\theta(a^0 \mid o)\), taking the forward chain \(q\) as the variational distribution. It splits into a sum over steps. Up to a constant term for the prior and a term for the last step, it is
Each term compares the true posterior from the previous part with the model's step. Both are Gaussians. Because the model's variance \(\sigma_k^2\) is fixed, the KL equals a squared distance between the means, scaled by \(1/(2\sigma_k^2)\), plus terms that do not depend on \(\theta\):
The derivation below shows how the bound is built and how each KL is computed.
Writing the mean in \(\varepsilon\)-form
Substitute \(a = (a^k - \sqrt{1-\bar\alpha_k}\,\varepsilon)/\sqrt{\bar\alpha_k}\) into \(\tilde\mu_k\) and simplify. The clean action disappears and the posterior mean depends on \(a^k\) and \(\varepsilon\) only:
Now the model has a natural parameterization. At test time it does not see \(\varepsilon\), so let a network guess it: \(\mu_\theta = \frac{1}{\sqrt{\alpha_k}}\big(a^k - \frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon_\theta(a^k, k, o)\big)\). The two means then differ only through \(\varepsilon_\theta - \varepsilon\), and each KL becomes a weighted \(\varepsilon\)-loss with weight \(\beta_k^2 / (2\sigma_k^2 \alpha_k (1-\bar\alpha_k))\) on \(\|\varepsilon - \varepsilon_\theta\|^2\).
Dropping the weights
Ho et al. found that ignoring those weights and giving every step the same importance works better in practice [2]. This gives the simple loss used by Diffusion Policy:
- Sample \((o, a)\) from the dataset, \(k \sim U\{1,\dots,K\}\) and \(\varepsilon \sim \mathcal{N}(0, I)\).
- Form \(a^k = \sqrt{\bar\alpha_k}\, a + \sqrt{1-\bar\alpha_k}\,\varepsilon\).
- Compute \(\|\varepsilon - \varepsilon_\theta(a^k, k, o)\|^2\).
- Take a gradient step.
What the optimal network outputs
The target \(\varepsilon\) belongs to one pair, but the network sees only \(a^k\). As in any MSE problem, its best output is a conditional mean: \(\hat\varepsilon = \mathbb{E}[\varepsilon \mid a^k, o]\). Inverting the closed form gives the network's best guess of the clean action:
The derivation below proves that last equality. So the \(\varepsilon\)-network is a denoiser: it estimates the average clean action consistent with a noisy one. Use the figure to see it for a bimodal target.
Drag the noisy point \(a^k\) and slide \(k\). At large \(k\) the point carries almost no information, the bars for the two modes are nearly equal, and \(\hat a\) sits near the mean of the modes. At small \(k\) the bars concentrate on the nearest mode and \(\hat a\) snaps to it. This is the same "mean first, modes later" behavior as the flow matching field in Track II.
Predicting the noise is the same as predicting the clean action, up to a known rescaling. The optimal \(\varepsilon\)-network gives the posterior mean \(\mathbb{E}[a \mid a^k, o]\), which is nearly the average of all modes at high noise and the nearest mode at low noise.
Derivations
From the likelihood to the variational bound
Goal: show that the negative log-likelihood of an action is bounded above by \(L=L_K+\sum_{k=2}^{K}L_{k-1}+L_0\), where \(L_K=\mathrm{KL}(q(a^K\mid a)\|p(a^K))\), \(L_{k-1}=\mathbb{E}\,\mathrm{KL}(q(a^{k-1}\mid a^k,a)\|p_\theta(a^{k-1}\mid a^k))\) and \(L_0=-\mathbb{E}\log p_\theta(a\mid a^1)\). Only the \(L_{k-1}\) terms carry a real training signal.
- \[ \log p_\theta(a)=\log\int p_\theta(a^{0:K})\;da^{1:K}, \qquad a^0=a . \]
Marginalization: the model defines a joint density over the whole chain \(a^{0:K}=(a^0,\dots,a^K)\), and the likelihood of the data point \(a=a^0\) integrates out the noisy variables \(a^{1:K}\). We drop \(o\) from the notation. \(\theta\) is the network.
- \[ \log p_\theta(a)=\log\int q(a^{1:K}\mid a)\;\frac{p_\theta(a^{0:K})}{q(a^{1:K}\mid a)}\;da^{1:K} . \]
Multiply and divide the integrand by the forward process \(q(a^{1:K}\mid a)\), which is positive wherever \(p_\theta(a^{0:K})\) is. Nothing changes, and the integral is now against a probability density.
- \[ \log p_\theta(a)=\log\mathbb{E}_{q}\Big[\frac{p_\theta(a^{0:K})}{q(a^{1:K}\mid a)}\Big] . \]
An integral against the density \(q(a^{1:K}\mid a)\) is an expectation. Write \(\mathbb{E}_q\) for the expectation over \(a^{1:K}\sim q(\cdot\mid a)\), with the data point \(a\) fixed.
- \[ \log\mathbb{E}[X]\ \ge\ \mathbb{E}[\log X] . \]
Jensen's inequality for the concave function \(\log\). Used with \(X=p_\theta(a^{0:K})/q(a^{1:K}\mid a)\).
- \[ \log p_\theta(a)\ \ge\ \mathbb{E}_q\Big[\log\frac{p_\theta(a^{0:K})}{q(a^{1:K}\mid a)}\Big] . \]
Apply step 4 to the right side of step 3.
- \[ -\log p_\theta(a)\ \le\ L:=\mathbb{E}_q\big[\log q(a^{1:K}\mid a)-\log p_\theta(a^{0:K})\big] . \]
Multiply step 5 by \(-1\), which flips the inequality, and split the log of the ratio into a difference. Minimizing \(L\) therefore pushes down an upper bound on the negative log-likelihood. The rest of the derivation rewrites \(L\) into terms we can compute.
- \[ \log p_\theta(a^{0:K}) = \log p(a^K)+\sum_{k=1}^{K}\log p_\theta(a^{k-1}\mid a^k) . \]
The model is a Markov chain run backward: start from \(p(a^K)=\mathcal{N}(0,I)\), then apply the learned steps \(p_\theta(a^{k-1}\mid a^k)\). The log of the product is the sum of logs.
- \[ \log q(a^{1:K}\mid a) = \sum_{k=1}^{K}\log q(a^k\mid a^{k-1}) . \]
The forward process is a Markov chain started at \(a^0=a\). Again log of a product.
- \[ L=\mathbb{E}_q\Big[-\log p(a^K)+\sum_{k=1}^{K}\log\frac{q(a^k\mid a^{k-1})}{p_\theta(a^{k-1}\mid a^k)}\Big] . \]
Insert steps 7 and 8 into step 6. Combine \(\log q-\log p_\theta\) term by term inside the sum, and keep \(-\log p(a^K)\) alone.
- \[ L=\mathbb{E}_q\Big[-\log p(a^K)+\log\frac{q(a^1\mid a)}{p_\theta(a\mid a^1)}+\sum_{k=2}^{K}\log\frac{q(a^k\mid a^{k-1})}{p_\theta(a^{k-1}\mid a^k)}\Big] . \]
Take the \(k=1\) term out of the sum. There \(a^0=a\), so \(q(a^1\mid a^0)=q(a^1\mid a)\) and \(p_\theta(a^0\mid a^1)=p_\theta(a\mid a^1)\).
- \[ q(a^{k-1},a^k\mid a)=q(a^k\mid a^{k-1},a)\,q(a^{k-1}\mid a)=q(a^{k-1}\mid a^k,a)\,q(a^k\mid a) . \]
Now the key rewrite for \(k\ge2\). The product rule factors the same joint density in two orders, both conditional on \(a\).
- \[ q(a^k\mid a^{k-1},a)=\frac{q(a^{k-1}\mid a^k,a)\;q(a^k\mid a)}{q(a^{k-1}\mid a)} . \]
Divide step 11 by \(q(a^{k-1}\mid a)\). This is Bayes' rule with \(a\) as extra conditioning.
- \[ q(a^k\mid a^{k-1})=q(a^k\mid a^{k-1},a)=\frac{q(a^{k-1}\mid a^k,a)\;q(a^k\mid a)}{q(a^{k-1}\mid a)} . \]
Markov property: given \(a^{k-1}\), the next noisy action \(a^k\) does not depend on \(a\), so the first equality holds. Then insert step 12. The left side is exactly the forward factor in step 10. The right side contains the posterior of the posterior derivation, which is Gaussian and known in closed form.
- \[ \sum_{k=2}^{K}\log\frac{q(a^k\mid a^{k-1})}{p_\theta(a^{k-1}\mid a^k)}=\sum_{k=2}^{K}\log\frac{q(a^{k-1}\mid a^k,a)}{p_\theta(a^{k-1}\mid a^k)}+\sum_{k=2}^{K}\log\frac{q(a^k\mid a)}{q(a^{k-1}\mid a)} . \]
Insert step 13 in the numerator. The log of a product of two ratios is the sum of the two logs, which splits the sum into two sums.
- \[ \begin{aligned} \sum_{k=2}^{3}\log\frac{q(a^k\mid a)}{q(a^{k-1}\mid a)} &= \log\frac{q(a^2\mid a)}{q(a^1\mid a)}+\log\frac{q(a^3\mid a)}{q(a^2\mid a)}\\ &= \log\frac{q(a^2\mid a)\,q(a^3\mid a)}{q(a^1\mid a)\,q(a^2\mid a)}=\log\frac{q(a^3\mid a)}{q(a^1\mid a)} . \end{aligned} \]
The second sum of step 14 for \(K=3\). Write out \(k=2\) and \(k=3\), combine the two logs into one, and cancel the factor \(q(a^2\mid a)\) that appears once upstairs and once downstairs.
- \[ \sum_{k=2}^{K}\Big[\log q(a^k\mid a)-\log q(a^{k-1}\mid a)\Big]=\log q(a^K\mid a)-\log q(a^1\mid a) . \]
General \(K\). Every \(\log q(a^j\mid a)\) with \(2\le j\le K-1\) occurs twice: with a plus sign at \(k=j\) and with a minus sign at \(k=j+1\). These cancel in pairs. Only \(+\log q(a^K\mid a)\) (from \(k=K\)) and \(-\log q(a^1\mid a)\) (from \(k=2\)) survive. This is step 15 for general \(K\).
- \[ \begin{aligned} L=\mathbb{E}_q\Big[&-\log p(a^K)+\log q(a^1\mid a)-\log p_\theta(a\mid a^1)\\ &+\sum_{k=2}^{K}\log\frac{q(a^{k-1}\mid a^k,a)}{p_\theta(a^{k-1}\mid a^k)}+\log q(a^K\mid a)-\log q(a^1\mid a)\Big] . \end{aligned} \]
Insert steps 14 and 16 into step 10, and write the \(k=1\) log ratio of step 10 as \(\log q(a^1\mid a)-\log p_\theta(a\mid a^1)\).
- \[ L=\mathbb{E}_q\Big[\log\frac{q(a^K\mid a)}{p(a^K)}\Big]+\sum_{k=2}^{K}\mathbb{E}_q\Big[\log\frac{q(a^{k-1}\mid a^k,a)}{p_\theta(a^{k-1}\mid a^k)}\Big]+\mathbb{E}_q\big[-\log p_\theta(a\mid a^1)\big] . \]
In step 17 the terms \(+\log q(a^1\mid a)\) and \(-\log q(a^1\mid a)\) cancel. Then combine \(-\log p(a^K)+\log q(a^K\mid a)\) into one log ratio, and split the expectation of a sum into a sum of expectations (linearity).
- \[ \mathbb{E}_q\Big[\log\frac{q(a^K\mid a)}{p(a^K)}\Big]=\mathbb{E}_{q(a^K\mid a)}\Big[\log\frac{q(a^K\mid a)}{p(a^K)}\Big]=\mathrm{KL}\big(q(a^K\mid a)\,\|\,p(a^K)\big)=:L_K . \]
The integrand depends on \(a^K\) only. Integrating the other variables of \(q(a^{1:K}\mid a)\) out leaves the marginal \(q(a^K\mid a)\). An expectation of \(\log(\text{density}/\text{density})\) under the first density is the definition of KL divergence.
- \[ \mathbb{E}_q\Big[\log\frac{q(a^{k-1}\mid a^k,a)}{p_\theta(a^{k-1}\mid a^k)}\Big]=\mathbb{E}_{q(a^k\mid a)}\Big[\,\mathbb{E}_{q(a^{k-1}\mid a^k,a)}\Big[\log\frac{q(a^{k-1}\mid a^k,a)}{p_\theta(a^{k-1}\mid a^k)}\Big]\Big] . \]
Only \(a^{k-1}\) and \(a^k\) appear, and their joint under \(q\) factors as \(q(a^k\mid a)\,q(a^{k-1}\mid a^k,a)\) (step 11). Tower property: draw \(a^k\) first, then \(a^{k-1}\) given \(a^k\).
- \[ L_{k-1}:=\mathbb{E}_{q(a^k\mid a)}\Big[\mathrm{KL}\big(q(a^{k-1}\mid a^k,a)\,\|\,p_\theta(a^{k-1}\mid a^k)\big)\Big],\qquad k=2,\dots,K . \]
The inner expectation of step 20 is again the definition of KL, now between two densities over \(a^{k-1}\) with \(a^k\) fixed.
- \[ L_0:=\mathbb{E}_{q(a^1\mid a)}\big[-\log p_\theta(a\mid a^1)\big] . \]
The last term of step 18 depends on \(a^1\) only, so the same marginalization as in step 19 applies. It is the negative log-likelihood of the clean action under the last reverse step.
- \[ L=L_K+\sum_{k=2}^{K}L_{k-1}+L_0 . \]
Insert steps 19, 21 and 22 into step 18. Then \(-\log p_\theta(a)\le L\), and training averages \(L\) over the data \(a\).
- \[ q(a^K\mid a)=\mathcal{N}\big(\sqrt{\bar\alpha_K}\,a,\ (1-\bar\alpha_K)I\big),\qquad p(a^K)=\mathcal{N}(0,I) . \]
Why \(L_K\) can be ignored. The first density is the closed form with a fixed schedule. The second is a fixed prior. Neither contains \(\theta\), so \(\nabla_\theta L_K=0\). It is also small when \(\bar\alpha_K\approx 0\), since then the two Gaussians nearly coincide.
- \[ L_{k-1}=\mathbb{E}\,\mathrm{KL}\big(\mathcal{N}(\tilde\mu_k,\tilde\beta_k I)\,\|\,p_\theta(a^{k-1}\mid a^k)\big) . \]
For \(k\ge2\) the first argument is the Gaussian posterior of the posterior derivation, and \(p_\theta\) is Gaussian too. So each \(L_{k-1}\) is a KL between two Gaussians, which the next derivation evaluates and simplifies to the \(\varepsilon\)-loss. \(L_0\) is a single reconstruction term for the last step.
Result: \(-\log p_\theta(a)\le L_K+\sum_{k=2}^{K}L_{k-1}+L_0\). The bound needs only two inputs: Jensen's inequality (step 4) and the identity of step 13 that re-expresses each forward factor through the posterior \(q(a^{k-1}\mid a^k,a)\). The telescoping product (steps 15 and 16) leaves a clean sum of KL divergences between a known Gaussian target and the model.
From the KL terms to the \(\varepsilon\)-loss, \(\hat a\)-loss and SNR weighting
Goal: evaluate \(L_{k-1}=\mathbb{E}\,\mathrm{KL}(q(a^{k-1}\mid a^k,a)\|p_\theta(a^{k-1}\mid a^k))\) for Gaussians, show it equals \(\lambda_k\|\varepsilon_\theta-\varepsilon\|^2\) plus a constant with \(\lambda_k=\beta_k^2/(2\sigma_k^2\alpha_k(1-\bar\alpha_k))\), drop \(\lambda_k\) to get \(L_{\text{simple}}\), and rewrite it as a signal-to-noise-weighted denoising loss on \(\hat a\).
- \[ L_{k-1}=\mathbb{E}_{q(a^k\mid a)}\,\mathrm{KL}\big(\mathcal{N}(\tilde\mu_k,\tilde\beta_k I)\ \|\ \mathcal{N}(\mu_\theta,\sigma_k^2 I)\big) . \]
The term from the ELBO derivation, with both distributions Gaussian in \(\mathbb{R}^d\). \(\tilde\mu_k,\tilde\beta_k\) come from the posterior derivation. \(\mu_\theta=\mu_\theta(a^k,k,o)\) is the network's mean and \(\sigma_k^2\) is a fixed number (\(\beta_k\) or \(\tilde\beta_k\)). We drop \(o\) from the notation. Fix \(k\).
- \[ \mathrm{KL}\big(\mathcal{N}(m_1,\Sigma_1)\|\mathcal{N}(m_2,\Sigma_2)\big)=\tfrac12\Big[\mathrm{tr}(\Sigma_2^{-1}\Sigma_1)+(m_2-m_1)^{\!\top}\Sigma_2^{-1}(m_2-m_1)-d+\log\tfrac{\det\Sigma_2}{\det\Sigma_1}\Big] . \]
The general Gaussian KL formula, stated first. We do not need it for full covariances: the next steps derive it for one scalar coordinate, which is all that \(\Sigma=s^2 I\) requires.
- \[ \mathrm{KL}(q\|p)=\mathbb{E}_{x\sim q}\big[\log q(x)-\log p(x)\big],\qquad q=\mathcal{N}(m_1,s_1^2),\quad p=\mathcal{N}(m_2,s_2^2)\quad (x\in\mathbb{R}) . \]
Definition of KL divergence, for scalars.
- \[ \log q(x)-\log p(x)=\tfrac12\log\frac{s_2^2}{s_1^2}-\frac{(x-m_1)^2}{2s_1^2}+\frac{(x-m_2)^2}{2s_2^2} . \]
Insert the Gaussian log density \(-\tfrac12\log(2\pi s^2)-(x-m)^2/(2s^2)\) for \(q\) and \(p\) and subtract. The \(\tfrac12\log 2\pi\) terms cancel; \(-\tfrac12\log s_1^2+\tfrac12\log s_2^2=\tfrac12\log(s_2^2/s_1^2)\).
- \[ \mathbb{E}_q\Big[\frac{(x-m_1)^2}{2s_1^2}\Big]=\frac{s_1^2}{2s_1^2}=\frac12 . \]
Under \(q\) the variance is \(\mathbb{E}_q(x-m_1)^2=s_1^2\) by definition.
- \[ (x-m_2)^2=(x-m_1)^2+2\,(x-m_1)(m_1-m_2)+(m_1-m_2)^2 . \]
Add and subtract \(m_1\) inside the square, then expand \((p+q)^2\) with \(p=x-m_1\), \(q=m_1-m_2\).
- \[ \mathbb{E}_q(x-m_2)^2=s_1^2+0+(m_1-m_2)^2 . \]
Take \(\mathbb{E}_q\) of step 6 term by term: the variance is \(s_1^2\), the cross term vanishes because \(\mathbb{E}_q(x-m_1)=0\), and \((m_1-m_2)^2\) is a constant.
- \[ \mathrm{KL}(q\|p)=\tfrac12\log\frac{s_2^2}{s_1^2}-\frac12+\frac{s_1^2+(m_1-m_2)^2}{2s_2^2} . \]
Take \(\mathbb{E}_q\) of step 4 (linearity) and insert steps 5 and 7. This is the scalar case of step 2 (the trace term is \(s_1^2/s_2^2\), the quadratic term is \((m_1-m_2)^2/s_2^2\)).
- \[ \mathrm{KL}\big(\mathcal{N}(\tilde\mu,\tilde\beta I)\|\mathcal{N}(\mu_\theta,\sigma^2 I)\big)=\frac{d}{2}\Big[\log\frac{\sigma^2}{\tilde\beta}-1+\frac{\tilde\beta}{\sigma^2}\Big]+\frac{\|\tilde\mu-\mu_\theta\|^2}{2\sigma^2} . \]
Both covariances are multiples of \(I\), so \(\log q\) and \(\log p\) are sums over \(d\) coordinates, and each coordinate's expectation depends only on that coordinate's marginal. The KL is the sum of \(d\) scalar KLs from step 8, with \(s_1^2=\tilde\beta\), \(s_2^2=\sigma^2\). The terms with no mean add to \(d\) times the same bracket, and \(\sum_i(m_{1,i}-m_{2,i})^2=\|\tilde\mu-\mu_\theta\|^2\).
- \[ \mathrm{KL}=\frac{\|\tilde\mu_k-\mu_\theta\|^2}{2\sigma_k^2}+C_k,\qquad C_k:=\frac d2\Big[\log\frac{\sigma_k^2}{\tilde\beta_k}-1+\frac{\tilde\beta_k}{\sigma_k^2}\Big] . \]
Only the last term of step 9 contains the network (through \(\mu_\theta\)). \(\sigma_k^2\) and \(\tilde\beta_k\) are fixed by the schedule, so \(C_k\) has no \(\theta\) and drops out of the gradient. If \(\sigma_k^2=\tilde\beta_k\) then \(C_k=0\).
- \[ \tilde\mu_k=\frac{1}{\sqrt{\alpha_k}}\Big(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon\Big) . \]
The \(\varepsilon\)-form of the posterior mean, from the posterior derivation. Here \(\varepsilon\) is the noise in \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\).
- \[ \mu_\theta=\frac{1}{\sqrt{\alpha_k}}\Big(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon_\theta(a^k,k,o)\Big) . \]
We choose to parameterize the network's mean in the same form, with the unknown \(\varepsilon\) replaced by the network output \(\varepsilon_\theta\). The network sees \(a^k\) in its input, so the \(a^k\) term can be matched exactly.
- \[ \tilde\mu_k-\mu_\theta=\frac{1}{\sqrt{\alpha_k}}\Big(-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon+\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon_\theta\Big) . \]
Subtract step 12 from step 11. The terms \(\tfrac{1}{\sqrt{\alpha_k}}a^k\) are identical and cancel, so \(a^k\) disappears from the difference.
- \[ \tilde\mu_k-\mu_\theta=\frac{\beta_k}{\sqrt{\alpha_k}\sqrt{1-\bar\alpha_k}}\,\big(\varepsilon_\theta-\varepsilon\big) . \]
Factor the common scalar \(\beta_k/(\sqrt{\alpha_k}\sqrt{1-\bar\alpha_k})\) out of step 13.
- \[ \|\tilde\mu_k-\mu_\theta\|^2=\frac{\beta_k^2}{\alpha_k\,(1-\bar\alpha_k)}\,\|\varepsilon_\theta-\varepsilon\|^2 . \]
\(\|c\,v\|^2=c^2\|v\|^2\) for a scalar \(c\), with \(c^2=\beta_k^2/(\alpha_k(1-\bar\alpha_k))\).
- \[ L_{k-1}=\mathbb{E}_{a,\varepsilon}\Big[\lambda_k\,\big\|\varepsilon_\theta(\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon,\ k,o)-\varepsilon\big\|^2\Big]+C_k,\qquad \lambda_k=\frac{\beta_k^2}{2\sigma_k^2\,\alpha_k\,(1-\bar\alpha_k)} . \]
Insert step 15 into step 10, and divide by \(2\sigma_k^2\). The expectation over \(a^k\sim q(a^k\mid a)\) is rewritten by sampling \(\varepsilon\sim\mathcal{N}(0,I)\) and setting \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\) (the closed form), then averaging over the data \(a\). This is the same \(\varepsilon\) that appears in step 11.
- \[ \sigma_k^2=\beta_k:\ \ \lambda_k=\frac{\beta_k}{2\alpha_k(1-\bar\alpha_k)},\qquad \sigma_k^2=\tilde\beta_k:\ \ \lambda_k=\frac{\beta_k}{2\alpha_k(1-\bar\alpha_{k-1})} . \]
The two variance choices. The first is a direct cancellation of one \(\beta_k\). For the second, insert \(\tilde\beta_k=(1-\bar\alpha_{k-1})\beta_k/(1-\bar\alpha_k)\): \(\frac{\beta_k^2(1-\bar\alpha_k)}{2(1-\bar\alpha_{k-1})\beta_k\alpha_k(1-\bar\alpha_k)}=\frac{\beta_k}{2\alpha_k(1-\bar\alpha_{k-1})}\).
- \[ L_{\text{simple}}(\theta)=\mathbb{E}_{k\sim\mathcal{U}\{1,\dots,K\},\,a,\,\varepsilon}\Big\|\varepsilon_\theta\big(\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon,\ k,o\big)-\varepsilon\Big\|^2 . \]
Drop \(\lambda_k\) and \(C_k\) and sample the level \(k\) uniformly instead of summing all \(K\) terms. This is the loss of Diffusion Policy. The weights \(\lambda_k\) are largest at small \(k\) (little noise); dropping them keeps the same minimizer in \(\varepsilon_\theta\) at each \(k\) (by the \(\varepsilon\)-loss part of the DDPM closed-form derivation), but, relative to the ELBO weights, puts more emphasis on the noisier levels. Ho et al. found that this gave better samples. At \(k=1\), the same \(\varepsilon\)-loss is used in practice instead of a separate \(L_0\).
- \[ \hat\varepsilon:=\varepsilon_\theta(a^k,k,o),\qquad \hat a:=\frac{a^k-\sqrt{1-\bar\alpha_k}\,\hat\varepsilon}{\sqrt{\bar\alpha_k}},\qquad a=\frac{a^k-\sqrt{1-\bar\alpha_k}\,\varepsilon}{\sqrt{\bar\alpha_k}} . \]
Now the same loss as a denoising loss. The first two are the network's noise estimate and the implied clean-action estimate (conversions derivation, with \(\alpha_t=\sqrt{\bar\alpha_k}\), \(\sigma_t=\sqrt{1-\bar\alpha_k}\)). The third solves the closed form \(a^k=\sqrt{\bar\alpha_k}a+\sqrt{1-\bar\alpha_k}\varepsilon\) for the true \(a\).
- \[ \hat a-a=\frac{-\sqrt{1-\bar\alpha_k}\,\hat\varepsilon+\sqrt{1-\bar\alpha_k}\,\varepsilon}{\sqrt{\bar\alpha_k}} . \]
Subtract the third expression of step 19 from the second. The \(a^k\) terms cancel.
- \[ \hat a-a=-\frac{\sqrt{1-\bar\alpha_k}}{\sqrt{\bar\alpha_k}}\,(\hat\varepsilon-\varepsilon) . \]
Factor \(-\sqrt{1-\bar\alpha_k}/\sqrt{\bar\alpha_k}\) out of step 20.
- \[ \|\hat a-a\|^2=\frac{1-\bar\alpha_k}{\bar\alpha_k}\,\|\hat\varepsilon-\varepsilon\|^2 . \]
Square the norm of step 21: \(\|cv\|^2=c^2\|v\|^2\).
- \[ \|\hat\varepsilon-\varepsilon\|^2=\mathrm{SNR}_k\,\|\hat a-a\|^2,\qquad \mathrm{SNR}_k:=\frac{\bar\alpha_k}{1-\bar\alpha_k} . \]
Multiply step 22 by \(\bar\alpha_k/(1-\bar\alpha_k)\). \(\mathrm{SNR}_k\) is the ratio of the squared signal coefficient to the squared noise coefficient in \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\), a signal-to-noise ratio. It is large at small \(k\) and near zero at \(k=K\).
- \[ \lambda_k\|\hat\varepsilon-\varepsilon\|^2=w_k\,\|\hat a-a\|^2,\qquad w_k=\lambda_k\,\mathrm{SNR}_k=\frac{\beta_k^2\,\bar\alpha_k}{2\sigma_k^2\,\alpha_k\,(1-\bar\alpha_k)^2} . \]
Insert step 23 into the weighted term of step 16 and multiply \(\lambda_k\) from step 16 by \(\mathrm{SNR}_k\).
- \[ L_{\text{simple}}=\mathbb{E}_{k,a,\varepsilon}\Big[\mathrm{SNR}_k\,\|\hat a-a\|^2\Big] . \]
Apply step 23 to \(L_{\text{simple}}\) of step 18. So the \(\varepsilon\)-loss is the plain denoising loss on the clean action, weighted by the signal-to-noise ratio. The ELBO weights \(w_k\) of step 24 are a different weighting of the same denoising loss, and the flow-matching loss is a third (see the loss-weighting derivation).
Result: \(L_{k-1}=\lambda_k\,\mathbb{E}\|\varepsilon_\theta-\varepsilon\|^2+C_k\) (step 16). Dropping \(\lambda_k\) gives \(L_{\text{simple}}\) (step 18). The same loss equals \(\mathbb{E}\,\mathrm{SNR}_k\|\hat a-a\|^2\) (step 25). So \(\varepsilon\)-prediction, \(\hat a\)-prediction and the ELBO differ only in the weight put on each noise level.
Diffusion III: sampling with DDPM and DDIM
With a trained \(\varepsilon_\theta\) in hand, generating an action chunk means running the reverse chain from noise. Draw \(a^K \sim \mathcal{N}(0, I)\) and step down to \(a^0\), always conditioning on the same observation \(o\).
DDPM: ancestral sampling
Each step samples from the learned Gaussian \(p_\theta(a^{k-1} \mid a^k, o)\). Plugging in the \(\varepsilon\)-form mean from the previous part gives the update
with \(z = 0\) at the final step so the output carries no extra noise. The variance has two common choices, \(\sigma_k^2 = \beta_k\) and \(\sigma_k^2 = \tilde\beta_k\). They bracket the true reverse variance. Ho et al. found that they give similar sample quality [2]. The derivation below shows how the update follows from the model and where the two choices come from.
Why does DDPM need many steps? The reverse step is modeled as a single Gaussian. That is an accurate description of the true reverse transition only when each forward step adds very little noise, that is, when \(\beta_k\) is small [1]. With a coarse schedule the true reverse step is far from Gaussian, and a Gaussian with the right mean is a poor fit. So you run all \(K\) small steps.
DDIM: the same network, a different chain
Song, Meng and Ermon observed that the training loss depends only on the marginals \(q(a^k \mid a)\), not on the chain that joins them [3]. Many different forward processes share those marginals. They defined a family of non-Markovian ones, indexed by a variance \(\sigma_k\), and derived the matching reverse step. With \(\hat\varepsilon = \varepsilon_\theta(a^k, k, o)\) and \(\hat a = (a^k - \sqrt{1-\bar\alpha_k}\,\hat\varepsilon)/\sqrt{\bar\alpha_k}\), it is
The same trained network works for every member of the family. Set \(\sigma_k = \eta\sqrt{\tilde\beta_k}\). With \(\eta = 1\) you recover the DDPM step. With \(\eta = 0\) the noise term vanishes and sampling is deterministic:
Read it as: take the clean guess \(\hat a\), then put it back at noise level \(k'\) using the same predicted noise \(\hat\varepsilon\). Nothing random is added, so the map from \(a^K\) to \(a^0\) is a deterministic function of the starting noise. Intermediate values of \(\eta\) interpolate between the two samplers.
Determinism buys something more. Because the update jumps from level \(k\) to any level \(k'\) using only \(\bar\alpha_k\) and \(\bar\alpha_{k'}\), \(k'\) does not have to equal \(k-1\). Choose a short subsequence of steps, for example every tenth, and run only those. This is respacing, and it is how Diffusion Policy gets fast inference.
Numbers from Diffusion Policy
Chi et al. train with \(K = 100\) DDPM iterations and run DDIM with 10 inference iterations, which gives 0.1 s latency on an RTX 3080 [25]. Their real-world experiments used 16 DDIM iterations [25]. The network is trained once. The sampler is chosen afterwards.
Both panes start from the same noise. The DDPM traces are jittery, because every step injects fresh noise, while the DDIM traces under \(\eta = 0\) are smooth curves. Lower the step count in each pane and watch the readout of distance to the nearest mode. DDIM stays accurate with far fewer steps than DDPM, whose quality drops quickly when you skip steps. Press Resample to draw new noise.
Respacing is not just calling the step function with fewer values of \(k\). The \(\bar\alpha\) values must come from the subsequence you actually visit. A skipped step has effective \(\alpha = \bar\alpha_k / \bar\alpha_{k'}\), so its \(\beta\) is \(1 - \bar\alpha_k/\bar\alpha_{k'}\) and its \(\tilde\beta\) must be recomputed from the subsequence too. Reusing the original per-step \(\beta_k\) with fewer steps uses the wrong noise amount for each jump, so the chain does not pass through the noise levels the network was trained on. The DDIM formula above is safe because it uses only \(\bar\alpha\), but stochastic DDPM sampling needs the recomputed \(\beta\).
Derivations
The DDPM ancestral sampling step, the variance choice, and respacing
Goal: turn the learned reverse Gaussian into the update \(a^{k-1}=\mu_\theta+\sigma_k z\), explain why the last step adds no noise and what the two variance choices are, and show that running the chain on a subsequence of levels keeps the same marginals so the same network applies.
- \[ p_\theta(a^{k-1}\mid a^k)=\mathcal{N}\big(\mu_\theta(a^k,k),\ \sigma_k^2 I\big),\qquad \mu_\theta=\frac{1}{\sqrt{\alpha_k}}\Big(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon_\theta(a^k,k)\Big) . \]
The reverse step as defined by the ELBO and \(\varepsilon\)-loss derivations. We drop \(o\) from the notation; the network is always called with the same \(o\).
- \[ z\sim\mathcal{N}(0,I)\quad\Longrightarrow\quad \mu+\sigma\,z\ \sim\ \mathcal{N}(\mu,\ \sigma^2 I) . \]
Reparameterization. Scaling \(z\) by \(\sigma\) multiplies its covariance by \(\sigma^2\) (as in the DDPM closed-form derivation), and adding \(\mu\) shifts the mean by \(\mu\) without changing the covariance.
- \[ a^{k-1}=\frac{1}{\sqrt{\alpha_k}}\Big(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\varepsilon_\theta(a^k,k)\Big)+\sigma_k\,z_k,\qquad z_k\sim\mathcal{N}(0,I) . \]
Draw from step 1 using step 2 with \(\mu=\mu_\theta\), \(\sigma=\sigma_k\). A fresh \(z_k\) is drawn at every step, independent of everything before.
- \[ a^K\sim\mathcal{N}(0,I);\qquad \text{for } k=K,K-1,\dots,1:\ \ a^{k-1}\ \text{from step 3};\qquad \text{return } a^0 . \]
The full ancestral sampler: start from the prior \(p(a^K)=\mathcal{N}(0,I)\), apply the update \(K\) times, and read off \(a^0\) as the action chunk. One network call per step.
- \[ \bar\alpha_0=\prod_{i=1}^{0}\alpha_i=1\quad\Longrightarrow\quad \tilde\beta_1=\frac{(1-\bar\alpha_0)\,\beta_1}{1-\bar\alpha_1}=0 . \]
The last step. An empty product is \(1\), so \(1-\bar\alpha_0=0\). The true posterior variance at \(k=1\) vanishes (posterior derivation: the posterior over the clean action is a point mass).
- \[ a^0=\frac{1}{\sqrt{\alpha_1}}\Big(a^1-\sqrt{\beta_1}\,\varepsilon_\theta(a^1,1)\Big)=\hat a . \]
Set \(k=1\) and \(z=0\) in step 3. With \(\bar\alpha_1=\alpha_1\) we have \(\beta_1/\sqrt{1-\bar\alpha_1}=\beta_1/\sqrt{\beta_1}=\sqrt{\beta_1}\). The result is exactly the denoised estimate \(\hat a=(a^1-\sqrt{1-\bar\alpha_1}\,\hat\varepsilon)/\sqrt{\bar\alpha_1}\), because \(\sqrt{\alpha_1}=\sqrt{\bar\alpha_1}\) and \(\sqrt{\beta_1}=\sqrt{1-\bar\alpha_1}\).
- \[ z_1:=0 . \]
So the sampler sets \(z=0\) at \(k=1\): the output is the clean estimate, with no noise added to the finished action. With \(\sigma_k^2=\tilde\beta_k\) this is automatic (step 5). With \(\sigma_k^2=\beta_k\) it is a convention: adding \(\sqrt{\beta_1}z\) to the output would only spoil the final action.
- \[ \frac{\tilde\beta_k}{\beta_k}=\frac{1-\bar\alpha_{k-1}}{1-\bar\alpha_k}\ \le\ 1 . \]
Divide \(\tilde\beta_k=(1-\bar\alpha_{k-1})\beta_k/(1-\bar\alpha_k)\) by \(\beta_k\). The inequality holds because \(\bar\alpha_k=\alpha_k\bar\alpha_{k-1}\le\bar\alpha_{k-1}\) (as \(\alpha_k\le1\)), so \(1-\bar\alpha_{k-1}\le 1-\bar\alpha_k\).
- \[ \tilde\beta_k\ \le\ \sigma_k^2\ \le\ \beta_k . \]
The two natural choices of \(\sigma_k^2\), bracketing each other by step 8. \(\sigma_k^2=\beta_k\) is the upper bound and \(\sigma_k^2=\tilde\beta_k\) the lower bound. Ho et al. note that the first is optimal when the data are \(\mathcal{N}(0,I)\) and the second when the data are a single point, and that both gave similar results in their experiments. The choice affects only sampling, never training: \(\sigma_k\) does not appear in \(L_{\text{simple}}\).
- \[ k_0:=0\ \lt\ k_1\ \lt\ \dots\ \lt\ k_S\le K,\qquad \beta'_i:=1-\frac{\bar\alpha_{k_i}}{\bar\alpha_{k_{i-1}}},\qquad \alpha'_i:=1-\beta'_i=\frac{\bar\alpha_{k_i}}{\bar\alpha_{k_{i-1}}} . \]
Respacing. Keep only \(S\) of the \(K\) levels (for example every tenth one) and define a shorter chain whose single step from level \(k_{i-1}\) to \(k_i\) stands for all the original steps in between. This is the construction of Nichol and Dhariwal.
- \[ \bar\alpha'_i:=\prod_{j=1}^{i}\alpha'_j . \]
The cumulative product of the new chain, defined exactly as in the original, so that the closed-form derivation applies to the new \(\beta'_j\) without change.
- \[ \bar\alpha'_3=\frac{\bar\alpha_{k_1}}{\bar\alpha_{k_0}}\cdot\frac{\bar\alpha_{k_2}}{\bar\alpha_{k_1}}\cdot\frac{\bar\alpha_{k_3}}{\bar\alpha_{k_2}}=\frac{\bar\alpha_{k_3}}{\bar\alpha_{k_0}}=\bar\alpha_{k_3} . \]
Insert step 10 and cancel: each numerator \(\bar\alpha_{k_j}\) meets the same factor as denominator in the next fraction. Shown for \(i=3\). Finally \(\bar\alpha_{k_0}=\bar\alpha_0=1\).
- \[ \bar\alpha'_i=\prod_{j=1}^{i}\frac{\bar\alpha_{k_j}}{\bar\alpha_{k_{j-1}}}=\frac{\bar\alpha_{k_i}}{\bar\alpha_{k_0}}=\bar\alpha_{k_i} . \]
The same cancellation for any \(i\): a telescoping product. Only the last numerator and the first denominator survive.
- \[ a'^{\,i}=\sqrt{\bar\alpha'_i}\,a+\sqrt{1-\bar\alpha'_i}\,\varepsilon=\sqrt{\bar\alpha_{k_i}}\,a+\sqrt{1-\bar\alpha_{k_i}}\,\varepsilon . \]
The closed form holds for the new chain (it was derived for any sequence of \(\beta\)'s in the DDPM closed-form derivation), and step 13 says it coincides with the original closed form at \(k=k_i\).
- \[ \varepsilon_\theta(\,\cdot\,,k_i)\ \text{serves the respaced chain at level } i . \]
Step 14 says the respaced chain has the same marginal \(q(a^{k_i}\mid a)\) as the original at every kept level. The training loss only involves these marginals (\(L_{\text{simple}}\) in the \(\varepsilon\)-loss derivation), so the network trained for \(K\) levels is already the right \(\varepsilon\)-predictor for the shorter chain: call it with the original index \(k_i\).
- \[ a'^{\,i-1}=\frac{1}{\sqrt{\alpha'_i}}\Big(a'^{\,i}-\frac{\beta'_i}{\sqrt{1-\bar\alpha_{k_i}}}\,\varepsilon_\theta(a'^{\,i},k_i)\Big)+\sigma'_i\,z,\qquad \sigma_i'^{\,2}=\beta'_i\ \text{or}\ \tilde\beta'_i . \]
The ancestral update of step 3 for the new chain: replace \(\alpha_k,\beta_k,\bar\alpha_k\) by \(\alpha'_i,\beta'_i,\bar\alpha'_i=\bar\alpha_{k_i}\) (step 13), and \(\tilde\beta'_i=(1-\bar\alpha_{k_{i-1}})\beta'_i/(1-\bar\alpha_{k_i})\). The posterior derivation holds for any positive \(\beta\) sequence, so the update remains valid. This gives \(S\) network calls instead of \(K\).
Result: Ancestral sampling is the update of step 3 repeated from \(k=K\) to \(1\), with \(z=0\) at the end (steps 6, 7). Both \(\sigma_k^2=\beta_k\) and \(\sigma_k^2=\tilde\beta_k\) are valid (step 9). A respaced chain (step 10) has the same closed-form marginals as the original (step 14), so fewer steps need no retraining.
The DDIM family: same marginals, any amount of noise
Goal: define the reverse conditionals \(q_\sigma(a^{k-1}\mid a^k,a)\), prove that every choice of \(\sigma_k\) keeps the DDPM marginals \(q(a^k\mid a)\) (so the \(\varepsilon\)-network is unchanged), then derive the sampling step and show that \(\eta=1\) reproduces the DDPM ancestral update while \(\eta=0\) is deterministic.
- \[ q_\sigma(a^{k-1}\mid a^k,a)=\mathcal{N}\Big(\sqrt{\bar\alpha_{k-1}}\,a+\sqrt{1-\bar\alpha_{k-1}-\sigma_k^2}\;\frac{a^k-\sqrt{\bar\alpha_k}\,a}{\sqrt{1-\bar\alpha_k}},\ \ \sigma_k^2 I\Big) . \]
The DDIM family: a reverse conditional chosen directly, for any \(0\le\sigma_k^2\le1-\bar\alpha_{k-1}\) (so the square root is real). It does not come from Bayes' rule. Instead we check below that it has the right marginals. We drop \(o\) from the notation.
- \[ q_\sigma(a^k\mid a)=\mathcal{N}\big(\sqrt{\bar\alpha_k}\,a,\ (1-\bar\alpha_k)I\big)\ \Longrightarrow\ q_\sigma(a^{k-1}\mid a)=\mathcal{N}\big(\sqrt{\bar\alpha_{k-1}}\,a,\ (1-\bar\alpha_{k-1})I\big) . \]
What we prove: if level \(k\) has the DDPM marginal, then so does level \(k-1\). At \(k=K\) the hypothesis holds by construction (\(q_\sigma(a^K\mid a)\) is set to the DDPM marginal), so by induction downward every level has the DDPM marginal.
- \[ a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\;\varepsilon,\qquad \varepsilon\sim\mathcal{N}(0,I) . \]
Assume the hypothesis of step 2, written by reparameterization.
- \[ a^k-\sqrt{\bar\alpha_k}\,a=\sqrt{1-\bar\alpha_k}\;\varepsilon . \]
Move \(\sqrt{\bar\alpha_k}\,a\) in step 3 to the left side.
- \[ \frac{a^k-\sqrt{\bar\alpha_k}\,a}{\sqrt{1-\bar\alpha_k}}=\varepsilon . \]
Divide step 4 by \(\sqrt{1-\bar\alpha_k}\). This is exactly the fraction that appears in the mean of step 1: the DDIM mean contains the noise \(\varepsilon\) that produced \(a^k\).
- \[ a^{k-1}=\sqrt{\bar\alpha_{k-1}}\,a+\sqrt{1-\bar\alpha_{k-1}-\sigma_k^2}\;\frac{a^k-\sqrt{\bar\alpha_k}\,a}{\sqrt{1-\bar\alpha_k}}+\sigma_k\,z,\qquad z\sim\mathcal{N}(0,I)\ \text{independent of }\varepsilon . \]
Draw \(a^{k-1}\) from step 1 by reparameterization (mean plus \(\sigma_k\) times a standard normal). The new \(z\) is independent of the \(\varepsilon\) in step 3.
- \[ a^{k-1}=\sqrt{\bar\alpha_{k-1}}\,a+\sqrt{1-\bar\alpha_{k-1}-\sigma_k^2}\;\varepsilon+\sigma_k\,z . \]
Insert step 5 into step 6.
- \[ n:=c_1\,\varepsilon+c_2\,z,\qquad c_1^2=1-\bar\alpha_{k-1}-\sigma_k^2,\quad c_2^2=\sigma_k^2 . \]
Name the noise part of step 7. It is a sum of two independent, scaled standard normals.
- \[ n\sim\mathcal{N}\big(0,\ (c_1^2+c_2^2)\,I\big) . \]
Scaling by \(c\) multiplies the covariance by \(c^2\), a sum of independent Gaussians is Gaussian, means add (\(0+0\)) and variances add (same argument as in the DDPM closed-form derivation).
- \[ c_1^2+c_2^2=(1-\bar\alpha_{k-1}-\sigma_k^2)+\sigma_k^2=1-\bar\alpha_{k-1} . \]
Insert step 8. The \(\sigma_k^2\) terms cancel: whatever variance we remove from the \(\varepsilon\) term, the fresh noise puts back.
- \[ a^{k-1}=\sqrt{\bar\alpha_{k-1}}\,a+\sqrt{1-\bar\alpha_{k-1}}\;\tilde\varepsilon,\qquad \tilde\varepsilon\sim\mathcal{N}(0,I) . \]
Combine steps 7, 9 and 10: the mean part is \(\sqrt{\bar\alpha_{k-1}}\,a\) and the noise part is a zero-mean Gaussian with covariance \((1-\bar\alpha_{k-1})I\), the same as \(\sqrt{1-\bar\alpha_{k-1}}\,\tilde\varepsilon\).
- \[ q_\sigma(a^{k-1}\mid a)=\mathcal{N}\big(\sqrt{\bar\alpha_{k-1}}\,a,\ (1-\bar\alpha_{k-1})I\big)\quad\text{for every admissible }\sigma_k . \]
Read off step 11. This is the claim of step 2. The marginals do not depend on \(\sigma\).
- \[ L_{\text{simple}}(\theta)=\mathbb{E}\Big\|\varepsilon_\theta\big(\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon,\ k,o\big)-\varepsilon\Big\|^2 \ \ \text{for every }\sigma . \]
Consequence for training. \(L_{\text{simple}}\) (the \(\varepsilon\)-loss derivation) samples \(a^k\) from the closed-form marginal, and step 12 says that marginal is the same for every \(\sigma\). Song, Meng and Ermon show that the variational objective of the whole DDIM family is a \(\sigma\)-dependent weighting of this same loss; with the weights dropped, one trained network \(\varepsilon_\theta\) serves every member, including DDPM.
- \[ \hat\varepsilon:=\varepsilon_\theta(a^k,k,o),\qquad \hat a:=\frac{a^k-\sqrt{1-\bar\alpha_k}\,\hat\varepsilon}{\sqrt{\bar\alpha_k}}\ \Longrightarrow\ \frac{a^k-\sqrt{\bar\alpha_k}\,\hat a}{\sqrt{1-\bar\alpha_k}}=\hat\varepsilon . \]
Sampling. At test time \(a\) and \(\varepsilon\) are unknown, so replace them by the network's estimates: \(\hat\varepsilon\) for \(\varepsilon\) and \(\hat a\) for \(a\) (conversions derivation). The implication on the right is the consistency check: \(\sqrt{\bar\alpha_k}\,\hat a=a^k-\sqrt{1-\bar\alpha_k}\,\hat\varepsilon\), so the numerator is \(\sqrt{1-\bar\alpha_k}\,\hat\varepsilon\). Hence the replacement \(a\to\hat a\) turns the fraction of step 5 into \(\hat\varepsilon\), the same as \(\varepsilon\to\hat\varepsilon\).
- \[ a^{k-1}=\sqrt{\bar\alpha_{k-1}}\,\hat a+\sqrt{1-\bar\alpha_{k-1}-\sigma_k^2}\;\hat\varepsilon+\sigma_k\,z . \]
Step 7 with \(a\to\hat a\) and \(\varepsilon\to\hat\varepsilon\). This is the DDIM sampling step for any \(\sigma_k\). One network call per step.
- \[ \sigma_k(\eta)=\eta\,\sqrt{\tilde\beta_k}=\eta\,\sqrt{\frac{(1-\bar\alpha_{k-1})\,\beta_k}{1-\bar\alpha_k}} . \]
A one-parameter family. \(\eta\) interpolates between the two extremes below. We need \(\sigma_k^2\le1-\bar\alpha_{k-1}\) for the square root in step 15. For \(\eta\le1\) this holds because \(\tilde\beta_k=(1-\bar\alpha_{k-1})\beta_k/(1-\bar\alpha_k)\le1-\bar\alpha_{k-1}\), since \(\beta_k\le1-\bar\alpha_k\) (as \(1-\bar\alpha_k=1-\alpha_k\bar\alpha_{k-1}\ge1-\alpha_k=\beta_k\)).
- \[ \eta=0:\qquad a^{k-1}=\sqrt{\bar\alpha_{k-1}}\,\hat a+\sqrt{1-\bar\alpha_{k-1}}\,\hat\varepsilon . \]
Set \(\sigma_k=0\) in step 15; the \(z\) term disappears. The step is a deterministic function of \(a^k\): the same noise \(a^K\) always gives the same action. It is the DDIM update of the DDIM-is-Euler derivation, where it is shown to be an Euler step in rescaled variables and, on the linear schedule, the flow-matching Euler step.
- \[ \eta=1:\qquad 1-\bar\alpha_{k-1}-\tilde\beta_k=(1-\bar\alpha_{k-1})\Big[1-\frac{\beta_k}{1-\bar\alpha_k}\Big] . \]
Now \(\sigma_k^2=\tilde\beta_k\). Insert \(\tilde\beta_k=(1-\bar\alpha_{k-1})\beta_k/(1-\bar\alpha_k)\) and factor out \((1-\bar\alpha_{k-1})\). We want the \(\hat\varepsilon\) coefficient of step 15 and compare it with DDPM.
- \[ 1-\frac{\beta_k}{1-\bar\alpha_k}=\frac{1-\bar\alpha_k-\beta_k}{1-\bar\alpha_k}=\frac{\alpha_k-\bar\alpha_k}{1-\bar\alpha_k}=\frac{\alpha_k\,(1-\bar\alpha_{k-1})}{1-\bar\alpha_k} . \]
Common denominator; then \(1-\beta_k=\alpha_k\); then \(\alpha_k-\bar\alpha_k=\alpha_k-\alpha_k\bar\alpha_{k-1}=\alpha_k(1-\bar\alpha_{k-1})\).
- \[ 1-\bar\alpha_{k-1}-\tilde\beta_k=\frac{\alpha_k\,(1-\bar\alpha_{k-1})^2}{1-\bar\alpha_k}\quad\Longrightarrow\quad \sqrt{1-\bar\alpha_{k-1}-\tilde\beta_k}=\frac{\sqrt{\alpha_k}\,(1-\bar\alpha_{k-1})}{\sqrt{1-\bar\alpha_k}} . \]
Insert step 19 into step 18, then take the positive square root (all factors are positive).
- \[ a^{k-1}=\frac{\sqrt{\bar\alpha_{k-1}}}{\sqrt{\bar\alpha_k}}\big(a^k-\sqrt{1-\bar\alpha_k}\,\hat\varepsilon\big)+\frac{\sqrt{\alpha_k}\,(1-\bar\alpha_{k-1})}{\sqrt{1-\bar\alpha_k}}\,\hat\varepsilon+\sqrt{\tilde\beta_k}\,z . \]
Insert step 20 and the definition of \(\hat a\) (step 14) into step 15.
- \[ \frac{\sqrt{\bar\alpha_{k-1}}}{\sqrt{\bar\alpha_k}}=\frac{1}{\sqrt{\alpha_k}}\quad\Longrightarrow\quad \text{coeff. of }a^k=\frac{1}{\sqrt{\alpha_k}} . \]
\(\bar\alpha_k=\alpha_k\bar\alpha_{k-1}\), as in step 19. This matches the \(a^k\) coefficient of the DDPM mean \(\mu_\theta\).
- \[ \text{coeff. of }\hat\varepsilon=-\frac{\sqrt{1-\bar\alpha_k}}{\sqrt{\alpha_k}}+\frac{\sqrt{\alpha_k}\,(1-\bar\alpha_{k-1})}{\sqrt{1-\bar\alpha_k}} . \]
From step 21: the first term is \(-\frac{1}{\sqrt{\alpha_k}}\sqrt{1-\bar\alpha_k}\) (step 22), the second is the one from step 20.
- \[ \text{coeff. of }\hat\varepsilon=\frac{-(1-\bar\alpha_k)+\alpha_k\,(1-\bar\alpha_{k-1})}{\sqrt{\alpha_k}\,\sqrt{1-\bar\alpha_k}} . \]
Common denominator \(\sqrt{\alpha_k}\sqrt{1-\bar\alpha_k}\): multiply the first term top and bottom by \(\sqrt{1-\bar\alpha_k}\), the second by \(\sqrt{\alpha_k}\), and use \(\sqrt{x}\sqrt{x}=x\).
- \[ -(1-\bar\alpha_k)+\alpha_k(1-\bar\alpha_{k-1})=-(1-\bar\alpha_k)+(1-\bar\alpha_k-\beta_k)=-\beta_k . \]
Rearrange the identity \(\alpha_k(1-\bar\alpha_{k-1})+\beta_k=1-\bar\alpha_k\) from the posterior derivation.
- \[ a^{k-1}=\frac{1}{\sqrt{\alpha_k}}\Big(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\,\hat\varepsilon\Big)+\sqrt{\tilde\beta_k}\,z=\mu_\theta+\sigma_k z\Big|_{\sigma_k^2=\tilde\beta_k} . \]
Insert step 25 into step 24, and use step 22 for the \(a^k\) coefficient. This is the DDPM ancestral update of the sampler derivation with \(\sigma_k^2=\tilde\beta_k\). So \(\eta=1\) is DDPM.
- \[ \text{replace }\hat\varepsilon\to\varepsilon,\ \hat a\to a\ \text{in steps 21 to 26}:\quad \text{mean}=\tilde\mu_k . \]
The identical algebra with the true \(\varepsilon\) gives the posterior-derivation form \(\tilde\mu_k=\frac{1}{\sqrt{\alpha_k}}(a^k-\frac{\beta_k}{\sqrt{1-\bar\alpha_k}}\varepsilon)\). So \(q_\sigma\) with \(\sigma_k^2=\tilde\beta_k\) is exactly the DDPM posterior \(q(a^{k-1}\mid a^k,a)\). DDPM is the member of the DDIM family that is also a Markov noising chain.
Result: Every \(\sigma_k\) gives the marginals of step 12, so one network trained with \(L_{\text{simple}}\) serves the whole family. The sampling step is \(a^{k-1}=\sqrt{\bar\alpha_{k-1}}\hat a+\sqrt{1-\bar\alpha_{k-1}-\sigma_k^2}\,\hat\varepsilon+\sigma_k z\) (step 15). \(\eta=1\) equals DDPM ancestral sampling (step 26), and \(\eta=0\) is deterministic DDIM (step 17).
Diffusion IV: the score and SDE view
So far diffusion is a discrete chain with a noise-prediction network. There is a second, equivalent reading in which the network estimates a gradient, and the chain becomes a differential equation. This reading is what connects diffusion to flow matching.
The network is a scaled score
The score of the noisy distribution \(p_k(a^k)\) is \(\nabla_{a^k} \log p_k(a^k)\). It points in the direction where the density of noisy actions increases. Tweedie's formula relates it to the denoiser: the score at \(a^k\) is the posterior mean of the noise, scaled by minus the noise standard deviation \(\sigma = \sqrt{1-\bar\alpha_k}\),
So training \(\varepsilon_\theta\) is training a score model, and \(-\varepsilon_\theta/\sqrt{1-\bar\alpha_k}\) is its estimate. This is denoising score matching [7]: regress onto the score of the single-sample conditional, \(-\varepsilon/\sqrt{1-\bar\alpha_k}\), and the network learns the score of the marginal. The reasoning is the same conditional-mean argument that makes the flow matching loss work in Track II. Intuitively, the score points from a noisy action back toward the likely clean actions, which is why denoising and "climbing the density" are the same move.
The continuous limit
Let the number of steps grow and the step size shrink. Use a continuous time \(\tau \in [0, 1]\) for the forward process, with \(\tau = 0\) at the data and \(\tau = 1\) at noise, and a noise rate \(\beta(\tau)\). The chain becomes a stochastic differential equation [5]:
where \(W\) is a Brownian motion. The first term shrinks the signal, the second adds noise, and together they are the continuous version of the \(\sqrt{\alpha_k}\) scaling. The marginal at time \(\tau\) has the same form as before, \(a_\tau = \sqrt{\bar\alpha(\tau)}\,a + \sqrt{1-\bar\alpha(\tau)}\,\varepsilon\) with \(\bar\alpha(\tau) = \exp(-\int_0^\tau \beta(s)\,ds)\).
The diffusion time \(\tau\) runs from data (\(\tau = 0\)) to noise (\(\tau = 1\)). Flow matching time \(t\) runs the other way, \(t = 0\) at noise. When you move between the two views, \(t\) and \(1-\tau\) play the same role. The discrete index \(k\) runs with \(\tau\), not with \(t\).
Reverse SDE and probability-flow ODE
Anderson showed that a diffusion can be run backwards in time, and the reverse process is again an SDE [6]. Its drift involves the score of the forward marginals:
integrated from \(\tau = 1\) down to \(\tau = 0\), with \(d\tau\) negative and \(\bar W\) a Brownian motion running backward. Replacing the score by the network estimate gives a sampler. There is also a deterministic alternative with the same marginals at every \(\tau\) [5], the probability-flow ODE:
The derivation below shows each step, including why the ODE has the same marginals as the SDE.
The figure starts both samplers from the same noise. The individual paths differ. The SDE paths wiggle, the ODE paths are smooth. But the histograms of the final x-coordinate match the target for both, because they share the same marginal at every time.
Back to the discrete samplers
DDPM ancestral sampling is a discretization of the reverse SDE. DDIM with \(\eta = 0\) is a discretization of the probability-flow ODE. This explains why DDIM can take big steps and DDPM cannot: an ODE solver can use a large step when the path is smooth, while an SDE step also has to resolve the noise it injects. It also explains why the same trained network serves both.
The probability-flow ODE is a velocity field. It carries samples of the noise distribution to samples of the data distribution along deterministic paths. That is a flow. Diffusion trains it indirectly, by learning a score and deriving the field from the schedule. Track II asks whether we can learn such a field directly.
Written in flow time \(t = 1 - \tau\), the velocity of the probability-flow ODE is \(\tfrac12\beta\,[\,a + \nabla \log p\,]\), evaluated at the matching noise level. Flow matching keeps the idea of a velocity field and drops the SDE, the score and the forward chain. You choose the path, and you regress its velocity.
Derivations
The continuous limit, the reverse SDE and the probability-flow ODE
Goal: take the DDPM chain to its SDE limit, use the Fokker–Planck equation to show that dropping the noise and halving the score term gives an ODE with the same marginals (the probability-flow ODE), derive the reverse SDE, identify DDPM and DDIM as their discretizations, and show that the probability-flow ODE is a flow-matching velocity field in time \(t=1-\tau\).
- \[ \nabla_a\log p_\tau(a)=-\frac{\hat\varepsilon}{\sigma_\tau},\qquad \sigma_\tau=\sqrt{1-\bar\alpha(\tau)},\quad \hat\varepsilon=\mathbb{E}[\varepsilon\mid a_\tau=a] . \]
Tweedie's formula for the score, restated from the conversions derivation (there \(\alpha_t=\sqrt{\bar\alpha}\), \(\sigma_t=\sqrt{1-\bar\alpha}\)). \(p_\tau\) is the density of the noised action at forward time \(\tau\in[0,1]\) (\(\tau=0\) data, \(\tau=1\) noise). We drop \(o\) from the notation. The \(\varepsilon\)-network estimates \(\hat\varepsilon\), so it also estimates the score.
- \[ a^k=\sqrt{1-\beta_k}\;a^{k-1}+\sqrt{\beta_k}\;\varepsilon_k,\qquad \tau_k=k\,\Delta\tau,\quad \Delta\tau=\tfrac1K,\quad \beta_k=\beta(\tau_k)\,\Delta\tau . \]
Part 1: the continuous limit of the forward chain. The DDPM chain, with the per-step variance written as a rate \(\beta(\tau)\) times the time step. As \(K\to\infty\), \(\Delta\tau\to0\) and each \(\beta_k\) becomes small. Below, \(\beta:=\beta(\tau_k)\).
- \[ \sqrt{1-x}=1-\tfrac12x+O(x^2) . \]
Taylor expansion of \(f(x)=(1-x)^{1/2}\) at \(0\): \(f(0)=1\) and \(f'(x)=-\tfrac12(1-x)^{-1/2}\), so \(f'(0)=-\tfrac12\).
- \[ \sqrt{1-\beta_k}=1-\tfrac12\,\beta\,\Delta\tau+O(\Delta\tau^2) . \]
Step 3 with \(x=\beta_k=\beta\,\Delta\tau\).
- \[ a^k=\Big(1-\tfrac12\beta\,\Delta\tau+O(\Delta\tau^2)\Big)a^{k-1}+\sqrt{\beta\,\Delta\tau}\;\varepsilon_k . \]
Insert step 4 into step 2, and write \(\sqrt{\beta_k}=\sqrt{\beta\,\Delta\tau}\).
- \[ a^k-a^{k-1}=-\tfrac12\,\beta\,a^{k-1}\,\Delta\tau+\sqrt{\beta\,\Delta\tau}\;\varepsilon_k+O(\Delta\tau^2) . \]
Subtract \(a^{k-1}\) from both sides of step 5 and distribute.
- \[ \Delta W_k:=\sqrt{\Delta\tau}\;\varepsilon_k\ \sim\ \mathcal{N}(0,\Delta\tau\,I),\qquad \sqrt{\beta\,\Delta\tau}\;\varepsilon_k=\sqrt{\beta}\;\Delta W_k . \]
A Brownian motion \(W\) has independent increments over disjoint intervals, each distributed as \(\mathcal{N}(0,\Delta\tau\,I)\). The \(\varepsilon_k\) are independent standard normals, so \(\sqrt{\Delta\tau}\,\varepsilon_k\) has exactly this law. Then \(\sqrt{\beta\Delta\tau}=\sqrt\beta\sqrt{\Delta\tau}\).
- \[ \Delta a=-\tfrac12\,\beta\,a\,\Delta\tau+\sqrt{\beta}\;\Delta W+O(\Delta\tau^2)\ \ \longleftrightarrow\ \ da=-\tfrac12\beta(\tau)\,a\,d\tau+\sqrt{\beta(\tau)}\;dW . \]
Insert step 7 into step 6. The left side is the Euler–Maruyama discretization \(\Delta a=f\,\Delta\tau+g\,\Delta W\) of the SDE \(da=f\,d\tau+g\,dW\) with \(f=-\tfrac12\beta a\) and \(g=\sqrt\beta\). The leftover \(O(\Delta\tau^2)\) is smaller than both the drift term \(O(\Delta\tau)\) and the noise term \(O(\sqrt{\Delta\tau})\), so it vanishes in the limit. This is the forward SDE.
- \[ \partial_\tau p=-\nabla\!\cdot\!\big(f\,p\big)+\tfrac12\,g^2\,\nabla^2p . \]
Part 2: the probability-flow ODE. For \(da=f(a,\tau)\,d\tau+g(\tau)\,dW\) the density \(p=p_\tau(a)\) obeys the Fokker–Planck equation, which we use as a known result (no Itô calculus needed). One-line reason: the drift moves probability like a flow with velocity \(f\), which is the continuity equation \(\partial_\tau p=-\nabla\cdot(fp)\); the noise spreads it like heat with diffusivity \(\tfrac12g^2\). Here \(\nabla^2p=\sum_i\partial_{a_i}^2p\) is the Laplacian.
- \[ \nabla^2p=\nabla\!\cdot\!(\nabla p) . \]
Definition: the Laplacian is the divergence of the gradient.
- \[ \nabla p=p\,\nabla\log p . \]
Chain rule \(\nabla\log p=\nabla p/p\), multiplied by \(p\).
- \[ \tfrac12g^2\,\nabla^2p=\tfrac12g^2\,\nabla\!\cdot\!\big(p\,\nabla\log p\big) . \]
Insert step 11 into step 10.
- \[ \partial_\tau p=-\nabla\!\cdot\!\big(f\,p\big)+\tfrac12g^2\,\nabla\!\cdot\!\big(p\,\nabla\log p\big) . \]
Insert step 12 into step 9.
- \[ \partial_\tau p=-\nabla\!\cdot\!\Big(f\,p-\tfrac12g^2\,p\,\nabla\log p\Big) . \]
Linearity of the divergence: the factor \(g^2\) depends on \(\tau\) only, so it can sit inside \(\nabla\cdot\), and the two divergences combine into one. The minus sign is pulled out front.
- \[ \partial_\tau p=-\nabla\!\cdot\!\Big(\big[f-\tfrac12g^2\,\nabla\log p\big]\,p\Big) . \]
Factor \(p\) out of the bracket in step 14.
- \[ v_{\text{PF}}(a,\tau):=f-\tfrac12g^2\,\nabla\log p_\tau\ \ \Longrightarrow\ \ \partial_\tau p=-\nabla\!\cdot\!(p\,v_{\text{PF}}),\qquad \frac{da}{d\tau}=v_{\text{PF}}(a,\tau) . \]
Name the bracket of step 15. The equation is then a continuity equation (see the continuity derivation) for the pair \((p_\tau,v_{\text{PF}})\). So the deterministic ODE \(da/d\tau=v_{\text{PF}}\), started from samples of \(p_0\), has marginals \(p_\tau\) at every \(\tau\) (same uniqueness argument as in step 14 of the conditional flow matching proof, with the ODE solution's law solving the same linear PDE). This ODE is the probability-flow ODE.
- \[ f=-\tfrac12\beta\,a,\quad g^2=\beta\ \Longrightarrow\ v_{\text{PF}}=-\tfrac12\beta\,a-\tfrac12\beta\,\nabla\log p_\tau=-\tfrac12\beta\,\big(a+\nabla\log p_\tau\big) . \]
Insert the VP drift and noise level of step 8 into step 16 and factor \(-\tfrac12\beta\).
- \[ \frac{da}{d\tau}=-\tfrac12\,\beta(\tau)\Big(a-\frac{\hat\varepsilon}{\sigma_\tau}\Big) . \]
Replace \(\nabla\log p_\tau\) in step 17 by \(-\hat\varepsilon/\sigma_\tau\) from step 1. So the trained \(\varepsilon\)-network gives the probability-flow ODE directly.
- \[ -\nabla\!\cdot\!\big((f-g^2\nabla\log p)\,p\big)=-\nabla\!\cdot\!(f\,p)+g^2\,\nabla\!\cdot\!\big(p\,\nabla\log p\big)=-\nabla\!\cdot\!(f\,p)+g^2\,\nabla^2p . \]
Part 3: the reverse SDE. Expand the divergence (linearity), then use steps 11 and 10 to turn \(\nabla\cdot(p\nabla\log p)\) into \(\nabla^2p\). This is the same manipulation as in steps 12 to 14, with \(g^2\) in place of \(\tfrac12g^2\).
- \[ \partial_\tau p=\Big[-\nabla\!\cdot\!(f\,p)+g^2\nabla^2p\Big]-\tfrac12g^2\nabla^2p=-\nabla\!\cdot\!\big((f-g^2\nabla\log p)\,p\big)-\tfrac12g^2\nabla^2p . \]
Start from the Fokker–Planck equation, step 9. Add and subtract \(\tfrac12g^2\nabla^2p\): then \(-\tfrac12g^2\nabla^2p\) is \(+\tfrac12g^2\nabla^2p-g^2\nabla^2p\). The bracket equals the right side of step 19.
- \[ s:=1-\tau,\qquad \hat p_s(a):=p_{1-s}(a)\ \Longrightarrow\ \partial_s\hat p_s=-\,(\partial_\tau p)\big|_{\tau=1-s} . \]
Run time backward. By the chain rule, \(\frac{d}{ds}=\frac{d\tau}{ds}\frac{d}{d\tau}=-\frac{d}{d\tau}\). Now \(s=0\) is noise and \(s=1\) is data. Below, \(f,g,p\) are evaluated at \(\tau=1-s\).
- \[ \partial_s\hat p=+\nabla\!\cdot\!\big((f-g^2\nabla\log p)\,p\big)+\tfrac12g^2\nabla^2p . \]
Multiply step 20 by \(-1\), as step 21 requires. Both terms flip sign.
- \[ \partial_s\hat p=-\nabla\!\cdot\!\Big(\big(-f+g^2\nabla\log\hat p\big)\,\hat p\Big)+\tfrac12g^2\nabla^2\hat p . \]
Move the sign of the first term inside the divergence: \(+\nabla\cdot(Xp)=-\nabla\cdot(-Xp)\) with \(X=f-g^2\nabla\log p\). Note \(\nabla\log p_{1-s}=\nabla\log\hat p_s\), and the last term is unchanged.
- \[ da=\big[-f+g^2\,\nabla\log p_{1-s}\big]\,ds+g\;d\bar W_s . \]
Step 23 has exactly the form of the Fokker–Planck equation, step 9, with time \(s\), drift \(-f+g^2\nabla\log\hat p\), and noise level \(g\). So the SDE displayed here (with \(\bar W\) a Brownian motion in \(s\)) has marginals \(\hat p_s=p_{1-s}\): started from noise at \(s=0\), it reaches the data distribution at \(s=1\).
- \[ da=\big[f-g^2\,\nabla\log p_\tau\big]\,d\tau+g\;d\bar W,\qquad\text{integrated with } d\tau\lt 0 . \]
The same SDE in \(\tau\): since \(ds=-d\tau\), the drift term \([-f+g^2\nabla\log p]\,ds=[f-g^2\nabla\log p]\,d\tau\). This is the reverse SDE: the forward drift corrected by \(-g^2\nabla\log p_\tau\), plus fresh noise, run backward in \(\tau\). Compared with the probability-flow ODE of step 16 the score coefficient doubles (\(g^2\) instead of \(\tfrac12g^2\)) and noise is added.
- \[ f-g^2\nabla\log p_\tau=-\tfrac12\beta\,a-\beta\,\nabla\log p_\tau=-\tfrac12\beta\,\big(a+2\nabla\log p_\tau\big)=-\tfrac12\beta\Big(a-\frac{2\hat\varepsilon}{\sigma_\tau}\Big) . \]
VP case: insert \(f=-\tfrac12\beta a\), \(g^2=\beta\), factor \(-\tfrac12\beta\), then use \(\nabla\log p_\tau=-\hat\varepsilon/\sigma_\tau\) (step 1).
- \[ a^{k-1}=a^k+\big[-f+g^2\nabla\log p\big]\Delta\tau+g\sqrt{\Delta\tau}\;z=\Big(1+\tfrac12\beta_k\Big)a^k-\frac{\beta_k}{\sigma_k}\,\hat\varepsilon+\sqrt{\beta_k}\;z . \]
Part 4: the samplers are discretizations. One Euler–Maruyama step of step 24 with \(\Delta s=\Delta\tau\), \(z\sim\mathcal{N}(0,I)\). Insert \(f=-\tfrac12\beta a\), \(g^2=\beta\), \(\beta\Delta\tau=\beta_k\), \(\nabla\log p=-\hat\varepsilon/\sigma_k\) with \(\sigma_k=\sqrt{1-\bar\alpha_k}\).
- \[ \frac{1}{\sqrt{\alpha_k}}=\frac{1}{\sqrt{1-\beta_k}}=1+\tfrac12\beta_k+O(\beta_k^2),\qquad \frac{\beta_k}{\sqrt{\alpha_k}\sqrt{1-\bar\alpha_k}}=\frac{\beta_k}{\sigma_k}\,\big(1+O(\beta_k)\big) . \]
Taylor expansion of \((1-x)^{-1/2}\) at \(0\) (its derivative at \(0\) is \(+\tfrac12\)), used for both coefficients of the DDPM update from the sampler derivation. We write \(\sigma_k=\sqrt{1-\bar\alpha_k}\).
- \[ a^{k-1}_{\text{DDPM}}=\frac{1}{\sqrt{\alpha_k}}\Big(a^k-\frac{\beta_k}{\sigma_k}\hat\varepsilon\Big)+\sigma\,z=\Big(1+\tfrac12\beta_k\Big)a^k-\frac{\beta_k}{\sigma_k}\hat\varepsilon+\sigma\,z+O(\beta_k^2) . \]
The DDPM ancestral update of the sampler derivation, with step 28 inserted. With \(\sigma^2=\beta_k\) it agrees with step 27 up to \(O(\beta_k^2)\) terms. So DDPM ancestral sampling is the Euler–Maruyama discretization of the reverse SDE.
- \[ a^{k-1}_{\text{DDIM}}=\frac{1}{\sqrt{\alpha_k}}\,a^k+\Big[\sqrt{1-\bar\alpha_{k-1}}-\frac{\sqrt{1-\bar\alpha_k}}{\sqrt{\alpha_k}}\Big]\hat\varepsilon . \]
DDIM with \(\eta=0\) (step of the DDIM-family derivation): insert \(\hat a=(a^k-\sqrt{1-\bar\alpha_k}\hat\varepsilon)/\sqrt{\bar\alpha_k}\) into \(\sqrt{\bar\alpha_{k-1}}\hat a+\sqrt{1-\bar\alpha_{k-1}}\hat\varepsilon\) and use \(\sqrt{\bar\alpha_{k-1}}/\sqrt{\bar\alpha_k}=1/\sqrt{\alpha_k}\).
- \[ 1-\bar\alpha_k=(1-\bar\alpha_{k-1})+\bar\alpha_{k-1}\beta_k\ \Longrightarrow\ \sqrt{1-\bar\alpha_k}=\sqrt{1-\bar\alpha_{k-1}}+\frac{\bar\alpha_{k-1}\beta_k}{2\sqrt{1-\bar\alpha_{k-1}}}+O(\beta_k^2) . \]
\(\bar\alpha_k=\bar\alpha_{k-1}(1-\beta_k)\), so \(1-\bar\alpha_k=1-\bar\alpha_{k-1}+\bar\alpha_{k-1}\beta_k\). Then Taylor: \(\sqrt{c+\delta}=\sqrt c+\delta/(2\sqrt c)+O(\delta^2)\).
- \[ \frac{\sqrt{1-\bar\alpha_k}}{\sqrt{\alpha_k}}=\Big(\sqrt{1-\bar\alpha_{k-1}}+\frac{\bar\alpha_{k-1}\beta_k}{2\sqrt{1-\bar\alpha_{k-1}}}\Big)\Big(1+\tfrac12\beta_k\Big)+O(\beta_k^2)=\sqrt{1-\bar\alpha_{k-1}}+\frac{\beta_k}{2\sqrt{1-\bar\alpha_{k-1}}}+O(\beta_k^2) . \]
Multiply step 31 by the expansion of \(1/\sqrt{\alpha_k}\) from step 28 and drop \(O(\beta_k^2)\). The \(\beta_k\) terms are \(\frac{\bar\alpha_{k-1}\beta_k}{2\sqrt{1-\bar\alpha_{k-1}}}+\frac{\beta_k\sqrt{1-\bar\alpha_{k-1}}}{2}=\frac{\beta_k\,[\bar\alpha_{k-1}+(1-\bar\alpha_{k-1})]}{2\sqrt{1-\bar\alpha_{k-1}}}\).
- \[ a^{k-1}_{\text{DDIM}}=\Big(1+\tfrac12\beta_k\Big)a^k-\frac{\beta_k}{2\sigma}\,\hat\varepsilon+O(\beta_k^2),\qquad \sigma\approx\sqrt{1-\bar\alpha_{k-1}}\approx\sqrt{1-\bar\alpha_k} . \]
Insert step 32 into step 30: the bracket becomes \(-\beta_k/(2\sqrt{1-\bar\alpha_{k-1}})\). The two values of \(\sigma\) differ by \(O(\beta_k)\), which only changes the \(\hat\varepsilon\) term at order \(\beta_k^2\). Use step 28 for the \(a^k\) coefficient.
- \[ a^{k-1}=a^k-v_{\text{PF}}\,\Delta\tau=\Big(1+\tfrac12\beta_k\Big)a^k-\frac{\beta_k}{2\sigma_k}\,\hat\varepsilon . \]
One Euler step of the probability-flow ODE of step 18, going from \(\tau_k\) to \(\tau_k-\Delta\tau\): \(a^{k-1}=a^k-\Delta\tau\,v_{\text{PF}}\) with \(v_{\text{PF}}=-\tfrac12\beta(a^k-\hat\varepsilon/\sigma_k)\). This equals step 33 up to \(O(\beta_k^2)\). So DDIM (\(\eta=0\)) is the Euler discretization of the probability-flow ODE. Compared with step 27, the noise term is gone and the score term is halved, as step 25 predicted.
- \[ t:=1-\tau\ \Longrightarrow\ \frac{da}{dt}=-\frac{da}{d\tau}=-v_{\text{PF}}=\tfrac12\beta\Big(a-\frac{\hat\varepsilon}{\sigma_\tau}\Big) . \]
Part 5: connection to flow matching. Flow matching runs from noise (\(t=0\)) to data (\(t=1\)), so set \(t=1-\tau\). By the chain rule \(d/dt=-d/d\tau\). Insert step 18.
- \[ \log\bar\alpha_k=\sum_{i=1}^{k}\log(1-\beta_i)=-\sum_{i=1}^{k}\beta(\tau_i)\,\Delta\tau+O(\Delta\tau)\ \longrightarrow\ \bar\alpha(\tau)=\exp\!\Big(-\!\int_0^\tau\beta(u)\,du\Big) . \]
We need \(\bar\alpha\) as a function of continuous time. \(\log(1-x)=-x+O(x^2)\), so each term is \(-\beta(\tau_i)\Delta\tau+O(\Delta\tau^2)\), and the \(k\le K\) error terms add up to \(O(\Delta\tau)\). The sum is a Riemann sum for the integral.
- \[ \alpha_t:=\sqrt{\bar\alpha(1-t)}=\exp\!\Big(-\tfrac12\!\int_0^{1-t}\beta(u)\,du\Big),\qquad \sigma_t:=\sqrt{1-\alpha_t^2},\qquad a_t=\alpha_t\,a+\sigma_t\,\varepsilon . \]
The VP path in flow time: closed form \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\) with \(\bar\alpha\) from step 36 at \(\tau=1-t\).
- \[ \frac{d}{dt}\log\alpha_t=\frac{d}{dt}\Big(-\tfrac12\!\int_0^{1-t}\beta(u)\,du\Big)=+\tfrac12\,\beta(1-t)\ \Longrightarrow\ \dot\alpha_t=\tfrac12\,\beta\,\alpha_t . \]
Differentiate the exponent of step 37. The upper limit \(1-t\) has derivative \(-1\), which cancels the minus sign. Here \(\beta=\beta(1-t)=\beta(\tau)\).
- \[ \sigma_t^2=1-\alpha_t^2\ \Longrightarrow\ 2\sigma_t\dot\sigma_t=-2\alpha_t\dot\alpha_t\ \Longrightarrow\ \dot\sigma_t=-\frac{\alpha_t\dot\alpha_t}{\sigma_t}=-\frac{\tfrac12\beta\,\alpha_t^2}{\sigma_t} . \]
Differentiate \(\sigma_t^2=1-\alpha_t^2\) with the chain rule, divide by \(2\sigma_t\), and insert step 38.
- \[ v=\dot\alpha_t\,\hat a+\dot\sigma_t\,\hat\varepsilon=\frac{\dot\alpha_t}{\alpha_t}\,\big(a_t-\sigma_t\hat\varepsilon\big)+\dot\sigma_t\,\hat\varepsilon=\tfrac12\beta\,a_t-\tfrac12\beta\,\sigma_t\hat\varepsilon-\frac{\tfrac12\beta\,\alpha_t^2}{\sigma_t}\,\hat\varepsilon . \]
The flow-matching velocity of a Gaussian path, from the conversions derivation, \(v=\dot\alpha_t\hat a+\dot\sigma_t\hat\varepsilon\) with \(\hat a=(a_t-\sigma_t\hat\varepsilon)/\alpha_t\). Insert \(\dot\alpha_t/\alpha_t=\tfrac12\beta\) from step 38 and \(\dot\sigma_t\) from step 39, and distribute.
- \[ v=\tfrac12\beta\,a_t-\tfrac12\beta\,\hat\varepsilon\,\frac{\sigma_t^2+\alpha_t^2}{\sigma_t}=\tfrac12\beta\Big(a_t-\frac{\hat\varepsilon}{\sigma_t}\Big) . \]
Collect the two \(\hat\varepsilon\) terms of step 40 over the common denominator \(\sigma_t\) (\(\sigma_t=\sigma_t^2/\sigma_t\)). Then \(\sigma_t^2+\alpha_t^2=1\) by the definition in step 37.
- \[ v(a,t)=\tfrac12\beta\Big(a-\frac{\hat\varepsilon}{\sigma_t}\Big)=\frac{da}{dt}\ \text{of step 35} . \]
Step 41 equals the right side of step 35 (with \(\sigma_\tau=\sigma_t\) at \(\tau=1-t\)). So the probability-flow ODE of the diffusion model, read in flow time \(t=1-\tau\), is the flow-matching ODE \(\dot a=v(a,t)\) for the VP path of step 37, with velocity \(v=-v_{\text{PF}}=\dot\alpha_t\hat a+\dot\sigma_t\hat\varepsilon\).
Result: The VP forward chain is the SDE \(da=-\tfrac12\beta a\,d\tau+\sqrt\beta\,dW\) (step 8). Its marginals \(p_\tau\) are carried by two processes: the reverse SDE of step 25 (drift \(f-g^2\nabla\log p\), plus noise), whose Euler–Maruyama step is DDPM (step 29), and the probability-flow ODE of step 16 (drift \(f-\tfrac12g^2\nabla\log p\), no noise), whose Euler step is DDIM (step 34). In flow time \(t=1-\tau\) the ODE has velocity \(v=-v_{\text{PF}}=\dot\alpha_t\hat a+\dot\sigma_t\hat\varepsilon\) (step 42): a diffusion model's deterministic sampler is a flow-matching sampler for the VP schedule.
Diffusion V: Diffusion Policy, the system
The earlier parts define the denoiser and its sampler. A policy needs more. It must decide which observations it sees, how many actions it predicts and executes, which network runs at each denoising step, and how it is trained. Chi et al. [25] make all of these choices.
What is diffused
The diffused object is an action sequence, not one action. The policy conditions on the last \(T_o\) observation steps \(o\). It starts from noise and denoises a chunk of \(T_p\) future actions. It executes \(T_a\) of them, and in the code the executed slice starts at index \(T_o - 1\) of the chunk. Then it observes again and plans a new chunk. This is receding-horizon control. The paper defines \(T_o\), \(T_p\) and \(T_a\) as the observation, prediction and execution horizons, and describes the closed-loop policy as taking the latest \(T_o\) observation steps and outputting \(T_a\) actions [25].
For the CNN policy on most tasks the paper uses \(T_o = 2\), \(T_p = 16\) and \(T_a = 8\), and it reports an action horizon of 8 as the best setting for most tasks [25]. Block Push is the exception, with \(T_o = 3\), \(T_a = 1\) and \(T_p = 12\).
The network
The noise predictor \(\varepsilon_\theta\) is a 1-D temporal convolutional U-Net over the \(T_p\) steps of the chunk. The noisy chunk enters as a sequence with \(d_a\) channels, and the output has the same shape. The paper adapts a 1-D temporal CNN from prior work with a few modifications (Sec. 3.1).
Conditioning enters in two places. The observation features are flattened into one vector. The step \(k\) is embedded by a sinusoidal encoding followed by a two-layer MLP with Mish, and the two parts are concatenated. Each residual block then has a small encoder that maps this vector to a scale \(\gamma\) and a bias \(b\). The block output is \(\gamma h + b\). This is FiLM [8].
The observation encoder is a ResNet-18 without pretraining. Two changes follow the paper: global average pooling is replaced by spatial softmax, which keeps spatial information, and BatchNorm is replaced by GroupNorm, which the paper says matters when used with EMA (Sec. 3.2). The config crops inputs to 76 by 76, and Table 7 lists the same crop for 84 by 84 images.
The paper also introduces a transformer denoiser built on the minGPT architecture (Sec. 3.1), with its horizons in Table 8. The repository's train_diffusion_unet_hybrid_workspace.yaml builds the CNN policy. The denoiser's noise schedule is the iDDPM square-cosine schedule [4], and the target is \(\varepsilon\) as in DDPM [2].
Training and inference settings
The values come from the paper's appendix tables and from the default config.
| Setting | Value | Source |
|---|---|---|
| Observation horizon \(T_o\) | 2 (Block Push: 3) | Tables 7 and 8; App. B.1 ("an observation horizon of 2 is good for most of the tasks") |
| Prediction horizon \(T_p\) | 16 (Block Push: 12 CNN, 5 transformer) | Tables 7 and 8; config horizon: 16 |
| Execution horizon \(T_a\) | 8 (Block Push: 1; real Push-T: 6) | Table 7; Sec. 5.3; config n_action_steps: 8 |
| Training steps \(K\) | 100 | Table 7 "D-Iters Train"; config num_train_timesteps: 100 |
| Inference steps | 100 in simulation (iDDPM); 16 on real robots (DDIM) | App. A.4; Tables 7 and 8 "D-Iters Eval" |
| Noise schedule | squaredcos_cap_v2 in a DDPMScheduler | Config beta_schedule; Sec. 3.3 |
| Prediction target | \(\varepsilon\) | Config prediction_type: epsilon; Sec. 2.2 |
| Action space | Position control | Sec. 4.2 and 5.2; Table 7 "Ctrl" |
| Optimizer | Learning rate \(10^{-4}\), weight decay \(10^{-6}\) | Table 7; config lr and weight_decay |
| Learning-rate schedule | Cosine with linear warmup | App. A.4 |
| Batch size | 256 (state), 64 (image) | App. A.4 |
| EMA | power 0.75, max value 0.9999, inv_gamma 1.0 | Config ema block; the paper gives no decay value |
| Epochs | 3050 | Config num_epochs |
The paper gives two DDIM step counts for real robots. Section 3.4 reports 10 DDIM steps for 0.1 s latency on an RTX 3080. Appendix A.4 and Tables 7 and 8 use 16. The two numbers are not reconciled in the paper.
The EMA weights track the model with a decay that ramps up over training. The code computes the decay at optimization step \(s\) as
with \(\gamma\) = inv_gamma and \(p\) = power. The config sets \(p = 0.75\), and the class default is \(2/3\).
Why it worked well
These are the paper's claims.
- Multimodality. The paper says the model expresses multimodal action distributions naturally and precisely (Sec. 4.1).
- Action sequences. Predicting one action at a time can give jittery motion that alternates between two valid trajectories. Predicting a whole chunk avoids this (Sec. 4.3).
- High-dimensional actions. The paper states that DDPMs scale to high output dimensions without losing expressiveness (Sec. 4.3).
- Training. The model learns the gradient of an energy function rather than the energy itself. The paper argues this avoids the negative sampling that energy-based policies need (Sec. 4.4).
In the paper's comparison, position control outperforms velocity control consistently (Sec. 4.2).
A flow-matching policy keeps this whole system. What changes is the loss and the sampler, plus the meaning of the step input and the network output: \(t\) replaces \(k\), and \(v\) replaces \(\varepsilon\). See the side-by-side code.
Flow Matching
Flow matching trains a velocity field directly, with no forward noising chain. This track covers the idea and the loss, the choice of paths and couplings, training in practice, ODE solvers, straight paths and few-step generation, and flow policies on real robots.
Flow matching I: the idea
Take a time-dependent velocity field \(v(a, t)\) and follow it:
Time runs over \(t \in [0,1]\). Here \(t = 0\) is noise and \(t = 1\) is data. Start a particle at a noise sample \(a_0 = \varepsilon\), integrate to \(t = 1\), and you get an action. Do this for every noise sample and the whole Gaussian is pushed into a distribution \(p_t\) that changes with time. The continuity equation, \(\partial_t p_t + \nabla \cdot (p_t v) = 0\), says that this is the only bookkeeping you need: the field alone determines how the distribution moves. Choose a field whose \(p_1\) is the action distribution and sampling is just an ODE solve.
The problem and the trick
We do not know the field that does this. It depends on the whole data distribution. What we do have is single pairs \((\varepsilon, a)\), and for a single pair we can write down any path we like. Pick the straight line:
Its velocity \(u = a - \varepsilon\) does not depend on \(t\). The line starts at noise and ends at the action, and the arrow along it is constant. Drag the two points below to see this.
The training loss asks the network to output that arrow at every point of the line:
Training recipe
- Sample \((o, a)\) from the dataset, \(\varepsilon \sim \mathcal{N}(0, I)\) and \(t \sim U[0,1]\).
- Build \(a_t = (1-t)\,\varepsilon + t\,a\).
- Compute the loss \(\| v_\theta(a_t, t, o) - (a - \varepsilon) \|^2\).
- Take a gradient step.
Sampling
Set \(a \leftarrow \varepsilon\). Choose \(N\) steps with \(\Delta t = 1/N\). For \(n = 0, \dots, N-1\), set \(t = n\,\Delta t\) and update \(a \leftarrow a + \Delta t \cdot v_\theta(a, t, o)\). The final \(a\) is the action chunk. This is Euler integration. Any ODE solver works.
Diffusion
Network predicts: the noise \(\varepsilon_\theta(a^k, k, o)\).
Loss regresses: \(\varepsilon\), the noise that was added.
Sampling does: reverse steps from \(k = K\) down to \(0\), with a stochastic (DDPM) or deterministic (DDIM) update.
Flow matching
Network predicts: the velocity \(v_\theta(a_t, t, o)\).
Loss regresses: \(a - \varepsilon\), the velocity of the straight line.
Sampling does: integrate an ODE from \(t = 0\) to \(1\), for example with Euler steps.
One catch
The target \(a - \varepsilon\) belongs to one pair. The network sees only the point \(a_t\), not which pair produced it. Switch the figure to "show many random pairs". The straight lines from different pairs cross. At a crossing, two or more different targets land on the same input, and the only thing MSE can do is output their average. That average is exactly what you want the network to learn, and the next part shows why.
Derivations
The straight-line path, its velocity and its conditional law
Goal: derive the velocity target \(u=a-\varepsilon\), rewrite it as a function of the current point \(a_t\), and show that for a fixed \(a\) the point \(a_t\) is Gaussian with mean \(t\,a\) and covariance \((1-t)^2 I\), collapsing onto \(a\) at \(t=1\).
- \[ a_t = (1-t)\,\varepsilon + t\,a . \]
The straight-line path for one pair \((\varepsilon, a)\). Both \(\varepsilon\) and \(a\) are fixed numbers (vectors) along the path. Only \(t\) varies. At \(t=0\) it is \(\varepsilon\) (noise), at \(t=1\) it is \(a\) (data).
- \[ u = \frac{d a_t}{dt} = \frac{d}{dt}\big[(1-t)\,\varepsilon\big] + \frac{d}{dt}\big[t\,a\big] . \]
The velocity is the time derivative. The derivative of a sum is the sum of derivatives (linearity).
- \[ \frac{d}{dt}\big[(1-t)\,\varepsilon\big] = -\varepsilon, \qquad \frac{d}{dt}\big[t\,a\big] = a . \]
\(\varepsilon\) and \(a\) do not depend on \(t\), so they are constant factors. \(\tfrac{d}{dt}(1-t)=-1\) and \(\tfrac{d}{dt}t=1\).
- \[ u = a - \varepsilon . \]
Add the two derivatives of step 3. The result has no \(t\) in it: the line is traversed at constant speed.
- \[ a_t - t\,a = (1-t)\,\varepsilon . \]
Now express \(u\) through \(a_t\), which is what the network sees. Start from step 1 and subtract \(t\,a\) from both sides.
- \[ \varepsilon = \frac{a_t - t\,a}{1-t}, \qquad t\lt 1 . \]
Divide both sides of step 5 by \(1-t\). This needs \(t\neq 1\).
- \[ u = a - \frac{a_t - t\,a}{1-t} . \]
Substitute step 6 into \(u=a-\varepsilon\) from step 4.
- \[ u = \frac{a\,(1-t) - (a_t - t\,a)}{1-t} . \]
Write \(a = \dfrac{a(1-t)}{1-t}\) to get a common denominator, then combine the two fractions.
- \[ a\,(1-t) - a_t + t\,a = a - t\,a - a_t + t\,a . \]
Distribute the minus sign over \((a_t - t\,a)\) and expand \(a(1-t)\).
- \[ a - t\,a - a_t + t\,a = a - a_t . \]
The terms \(-t\,a\) and \(+t\,a\) cancel.
- \[ u = \frac{a - a_t}{1-t} . \]
Put step 10 over the denominator of step 8. Reading: from the current point, head straight to \(a\), covering the remaining distance in the remaining time \(1-t\).
- \[ T_t(\varepsilon) := (1-t)\,\varepsilon + t\,a, \qquad \varepsilon \sim \mathcal{N}(0,I). \]
Now the law of \(a_t\) given \(a\). With \(a\) and \(t\) fixed, \(a_t\) is a function of the random \(\varepsilon\) only.
- \[ T_t(\varepsilon) = A\,\varepsilon + b, \qquad A = (1-t)\,I, \quad b = t\,a . \]
Match the form of an affine map: a matrix times \(\varepsilon\) plus a constant vector.
- \[ \mathbb{E}[A\varepsilon + b] = A\,\mathbb{E}[\varepsilon] + b = b . \]
Linearity of expectation and \(\mathbb{E}[\varepsilon]=0\). This is the mean.
- \[ \mathrm{Cov}(A\varepsilon + b) = A\,\mathbb{E}[\varepsilon\varepsilon^\top]\,A^\top = A\,I\,A^\top = A A^\top . \]
Adding a constant does not change the covariance. For the linear part, \(\mathrm{Cov}(A\varepsilon)=A\,\mathrm{Cov}(\varepsilon)\,A^\top\), and \(\mathrm{Cov}(\varepsilon)=I\).
- \[ A A^\top = (1-t)\,I\cdot (1-t)\,I = (1-t)^2\, I . \]
\(A\) is a scalar multiple of the identity, so it is symmetric and the product multiplies the scalars.
- \[ a_t \mid a \ \sim\ \mathcal{N}\big(t\,a,\ (1-t)^2 I\big), \qquad p_t(x\mid a) = \mathcal{N}\big(x;\ t\,a,\ (1-t)^2 I\big). \]
An affine image of a Gaussian is Gaussian, so steps 14 and 16 (mean and covariance) fully describe it.
- \[ T_1(\varepsilon) = (1-1)\,\varepsilon + 1\cdot a = a \quad \text{for every } \varepsilon . \]
Set \(t=1\) in the map of step 12. The coefficient of \(\varepsilon\) is \(0\), so the noise has no influence.
- \[ p_1(x\mid a) = \delta_a(x), \qquad p_0(x\mid a)=\mathcal{N}(x;\,0,\,I). \]
At \(t=1\) the covariance \((1-t)^2 I\) of step 17 is \(0\): a point mass at \(a\). At \(t=0\) the mean is \(0\) and the covariance is \(I\): the noise distribution.
Result: along a straight pair the velocity is the constant \(u=a-\varepsilon=(a-a_t)/(1-t)\), and the conditional path is \(p_t(x\mid a)=\mathcal{N}(x;\,t\,a,\,(1-t)^2 I)\). It starts as the noise distribution at \(t=0\) and shrinks to the single point \(a\) at \(t=1\), so every noise sample ends exactly on its data point.
The continuity equation, and a hand check on the straight-line path
Goal: derive \(\partial_t p + \nabla\!\cdot(p\,v)=0\) from "probability mass is neither created nor destroyed", then verify it explicitly for the one-dimensional conditional path \(p_t(x\mid a)=\mathcal{N}(x;\,t a,\,(1-t)^2)\) with velocity \(u=(a-x)/(1-t)\).
- \[ M(t) = \int_{x_1}^{x_2} p(x,t)\, dx . \]
One dimension first. \(p(x,t)\) is the density of particles, each moving with \(dx/dt = v(x,t)\). \(M\) is the probability mass inside the fixed interval \([x_1,x_2]\).
- \[ \text{mass crossing a point } x \text{ in time } dt \;=\; p(x,t)\cdot v(x,t)\, dt . \]
In time \(dt\) every particle within distance \(v\,dt\) behind the point reaches it. Those particles occupy a length \(v\,dt\) with density \(p\), so they carry mass \(p\,v\,dt\). The flux is \(p\,v\) (positive means moving right).
- \[ \frac{dM}{dt} = p(x_1,t)\,v(x_1,t) - p(x_2,t)\,v(x_2,t) . \]
Mass enters through the left end at rate \(p v\) there and leaves through the right end at rate \(p v\) there. Particles cannot appear or vanish inside, so these two flows are the only change.
- \[ \frac{dM}{dt} = \int_{x_1}^{x_2} \partial_t p(x,t)\, dx . \]
Differentiate step 1. The limits \(x_1,x_2\) are fixed, so the derivative goes inside the integral (Leibniz rule).
- \[ p\,v\Big|_{x_1} - p\,v\Big|_{x_2} = -\int_{x_1}^{x_2} \partial_x\big(p\,v\big)\, dx . \]
Fundamental theorem of calculus: \(\int_{x_1}^{x_2}\partial_x g\,dx = g(x_2)-g(x_1)\), applied to \(g=p\,v\). The minus sign flips \(g(x_2)-g(x_1)\) into \(g(x_1)-g(x_2)\).
- \[ \int_{x_1}^{x_2} \partial_t p\, dx = -\int_{x_1}^{x_2} \partial_x(p\,v)\, dx . \]
Equate steps 4 and 5 through step 3.
- \[ \int_{x_1}^{x_2} \Big[\partial_t p + \partial_x(p\,v)\Big]\, dx = 0 . \]
Move the right-hand side of step 6 to the left and combine the integrals (linearity of the integral).
- \[ \frac{1}{h}\int_{x_1}^{x_1+h} \Big[\partial_t p + \partial_x(p\,v)\Big]\, dx = 0 . \]
Step 7 holds for every interval, so choose \(x_2=x_1+h\) and divide by \(h>0\).
- \[ \lim_{h\to 0}\frac{1}{h}\int_{x_1}^{x_1+h} g(x)\, dx = g(x_1) . \]
Average of a continuous function over a shrinking interval converges to its value at the point (mean value theorem for integrals).
- \[ \partial_t p + \partial_x(p\,v) = 0 \quad \text{at every } x_1 . \]
Take \(h\to 0\) in step 8 and apply step 9 with \(g=\partial_t p+\partial_x(p v)\).
- \[ \frac{d}{dt}\int_\Omega p\, dx = -\oint_{\partial\Omega} p\, v\cdot n\; dS . \]
Now \(n\) dimensions. \(\Omega\) is a fixed region. Mass leaves exactly through the boundary \(\partial\Omega\) at the rate of the flux component along the outward normal \(n\). This replaces step 3.
- \[ \oint_{\partial\Omega} p\, v\cdot n\; dS = \int_\Omega \nabla\!\cdot(p\,v)\, dx . \]
Divergence theorem. It is the \(n\)-dimensional version of step 5.
- \[ \int_\Omega \Big[\partial_t p + \nabla\!\cdot(p\,v)\Big]\, dx = 0 \quad \text{for every region } \Omega . \]
Move the derivative inside the integral on the left of step 11 (fixed \(\Omega\)), insert step 12 on the right, and combine as in step 7.
- \[ \boxed{\ \partial_t p + \nabla\!\cdot(p\,v) = 0\ } \]
A continuous integrand that integrates to zero over every region is zero everywhere (shrink \(\Omega\) to a point, as in steps 8 to 10). This is the continuity equation.
- \[ m(t) = t\,a, \qquad s(t) = 1-t, \qquad p = \mathcal{N}(x;\, m,\, s^2), \qquad u = \frac{a-x}{s}. \]
Now the check. One dimension, one fixed \(a\). Abbreviate the mean and standard deviation of the conditional path. Note \(\dot m = a\) and \(\dot s=-1\).
- \[ r := x - m = x - t\,a . \]
A shorthand for the offset from the mean. Then \(\partial_x r = 1\) and \(\partial_t r = -\dot m = -a\).
- \[ \log p = -\tfrac12\log(2\pi) - \log s - \frac{r^2}{2 s^2} . \]
Take the log of the Gaussian density \(\frac{1}{\sqrt{2\pi}\,s}\exp\!\big(-\frac{r^2}{2s^2}\big)\).
- \[ \partial_t\big[-\log s\big] = -\frac{\dot s}{s} = \frac{1}{s} . \]
Chain rule for the log, and \(\dot s=-1\). The constant \(-\tfrac12\log 2\pi\) has zero derivative.
- \[ \partial_t\Big[-\frac{r^2}{2}\, s^{-2}\Big] = -\frac{2r\,\partial_t r}{2}\, s^{-2} \;-\; \frac{r^2}{2}\,\partial_t\big(s^{-2}\big) . \]
Product rule on \(r^2\) times \(s^{-2}\), with the chain rule on \(r^2\).
- \[ -\,r\,(-a)\, s^{-2} = \frac{a\,r}{s^2}, \qquad \partial_t\big(s^{-2}\big) = -2\,s^{-3}\,\dot s = \frac{2}{s^3}. \]
Insert \(\partial_t r=-a\). For the second, power rule and chain rule, then \(\dot s=-1\).
- \[ -\frac{r^2}{2}\cdot\frac{2}{s^3} = -\frac{r^2}{s^3}. \]
Multiply out the second term of step 19 using step 20.
- \[ \partial_t \log p = \frac{1}{s} + \frac{a\,r}{s^2} - \frac{r^2}{s^3} . \]
Sum steps 18, 20 (first part) and 21.
- \[ \partial_t p = p\,\Big[\frac{1}{s} + \frac{a\,r}{s^2} - \frac{r^2}{s^3}\Big] . \]
\(\partial_t p = p\,\partial_t\log p\), because \(\partial_t \log p = \partial_t p/p\) (chain rule).
- \[ \partial_x \log p = -\frac{r}{s^2}, \qquad \partial_x p = -\,p\,\frac{r}{s^2} . \]
Differentiate step 17 in \(x\): only the last term depends on \(x\), and \(\partial_x r^2 = 2r\). Then \(\partial_x p=p\,\partial_x\log p\).
- \[ a - x = a - (r + t\,a) = a\,(1-t) - r = a\,s - r . \]
Rewrite the numerator of \(u\) using \(x = r + t\,a\) from step 16, and \(1-t=s\).
- \[ u = \frac{a\,s - r}{s} = a - \frac{r}{s}, \qquad \partial_x u = -\frac{1}{s} . \]
Divide step 25 by \(s\). Then differentiate in \(x\) using \(\partial_x r=1\); \(a\) and \(s\) do not depend on \(x\).
- \[ \partial_x(p\,u) = u\,\partial_x p + p\,\partial_x u . \]
Product rule.
- \[ \partial_x(p\,u) = -\,u\,p\,\frac{r}{s^2} - \frac{p}{s} = p\Big[-\Big(a - \frac{r}{s}\Big)\frac{r}{s^2} - \frac{1}{s}\Big] . \]
Insert \(\partial_x p\) from step 24, \(\partial_x u\) and \(u\) from step 26, and factor out \(p\).
- \[ \partial_x(p\,u) = p\,\Big[-\frac{a\,r}{s^2} + \frac{r^2}{s^3} - \frac{1}{s}\Big] . \]
Distribute \(-\frac{r}{s^2}\) over \(\big(a - \frac{r}{s}\big)\): \(-\frac{a r}{s^2}\) and \(+\frac{r^2}{s^3}\).
- \[ \partial_t p + \partial_x(p\,u) = p\Big[\frac{1}{s} + \frac{a\,r}{s^2} - \frac{r^2}{s^3} - \frac{a\,r}{s^2} + \frac{r^2}{s^3} - \frac{1}{s}\Big] . \]
Add steps 23 and 29. Both are \(p\) times a bracket, so factor \(p\) out.
- \[ \partial_t p + \partial_x(p\,u) = p\cdot 0 = 0 . \]
Cancel pairwise: \(\frac1s-\frac1s\), \(\frac{ar}{s^2}-\frac{ar}{s^2}\), \(-\frac{r^2}{s^3}+\frac{r^2}{s^3}\).
Result: mass conservation gives \(\partial_t p+\nabla\!\cdot(p\,v)=0\). The straight-line conditional path \(p_t(x\mid a)=\mathcal{N}(x;\,t a,(1-t)^2)\) with velocity \(u=(a-x)/(1-t)\) satisfies it exactly, so that velocity field really transports the path's density. This is the "conditional continuity equation" used in the proof that single-pair training works.
Flow matching II: why the simple loss works
The field that actually moves the whole distribution from noise to data is the marginal field. At a point \(x\) and time \(t\) it averages the velocities of every pair whose line passes through \(x\):
This is the field we want the network to match. Regressing onto it directly would need the expectation, which needs the data distribution. We never compute it. We regress onto the single-pair target \(u = a - \varepsilon\) instead. Compare the two losses:
The two losses differ by a constant that does not depend on \(\theta\), so they have the same gradient. Training on single pairs optimizes the marginal field. This is the conditional flow matching result.
Three-line reason
Write \(u = a - \varepsilon\) and condition on \(a_t\).
- The minimizer of an MSE is the conditional mean, so the best \(v_\theta(x,t)\) is \(\mathbb{E}[u \mid a_t = x] = v(x,t)\).
- Expand the square: \(\mathbb{E}\|v_\theta - u\|^2 = \mathbb{E}\|v_\theta\|^2 - 2\,\mathbb{E}[v_\theta \cdot u] + \mathbb{E}\|u\|^2\).
- \(v_\theta\) depends only on \(a_t\), so \(\mathbb{E}[v_\theta \cdot u] = \mathbb{E}\big[v_\theta \cdot \mathbb{E}[u \mid a_t]\big] = \mathbb{E}[v_\theta \cdot v]\). Completing the square gives \(\mathcal{L}_{\text{flow}} = \mathcal{L}_{\text{marg}} + \mathbb{E}\|u\|^2 - \mathbb{E}\|v\|^2\).
The last two terms contain no \(\theta\). Diffusion's \(\varepsilon\)-prediction loss works for the same reason: the network is trained on a noisy single-sample target and learns its conditional mean.
The field as a weighted average
On the line, \(a_t = x\) fixes \(\varepsilon = (x - t a)/(1-t)\) once \(a\) is known, so \(u = (a - x)/(1-t)\). Then
So the field at \(x\) points toward a posterior-weighted average of actions. The weights favor actions \(a\) for which \(t\,a\) lies close to \(x\). For a dataset of actions, \(p(a)\) puts equal weight on each one.
Slide \(t\) from 0 upward. At \(t\) near 0, the point \(x\) carries almost no information about \(a\), the weights equal the prior, and every arrow points toward the mean of the modes, which sits between them. As \(t\) approaches 1, the weights concentrate on the nearest mode and the arrows split toward individual modes. Toggle to the VP-diffusion field to see the same effect with a different schedule.
What you actually sample
At inference you integrate the marginal field, not the individual straight lines. Following the marginal field gives the same distribution \(p_t\) at every time as the straight-line pairs do, so the endpoint distribution is correct. Individual trajectories are different. Two straight lines can cross, but trajectories of an ODE cannot: a smooth field gives one direction at each \((x,t)\), and uniqueness of ODE solutions forbids crossing. Where lines would cross, the marginal paths bend away from each other. This is why flow matching paths are straighter than diffusion paths but not perfectly straight.
Derivations
The conditional flow matching theorem
Goal: prove two facts. (A) The averaged field \(v(x,t)=\mathbb{E}[u\mid a_t=x]\) generates the marginal \(p_t\). (B) Regressing onto the single-pair target \(u\) has the same gradient in \(\theta\) as regressing onto \(v\), so training on pairs trains the marginal field.
- \[ a\sim p(a),\quad \varepsilon\sim\mathcal{N}(0,I)\ \text{independent},\quad a_t=(1-t)\,\varepsilon+t\,a,\quad u = a-\varepsilon . \]
Setup. We drop \(o\) from the notation: read every probability and expectation here as conditional on \(o\). Along one pair, \(u\) equals the function \(u_t(x\mid a)=(a-x)/(1-t)\) evaluated at \(x=a_t\) (derived in the straight-line derivation).
- \[ p_t(x) = \int p_t(x\mid a)\, p(a)\, da . \]
Part A. Law of total probability: the density of \(a_t\) is the average of the conditional densities over the data distribution.
- \[ \partial_t p_t(x) = \int \partial_t p_t(x\mid a)\; p(a)\, da . \]
Differentiate step 2 in \(t\). The data density \(p(a)\) does not depend on \(t\), so only \(p_t(x\mid a)\) is differentiated. We exchange derivative and integral (Leibniz rule, valid for smooth, integrable densities).
- \[ \partial_t p_t(x\mid a) = -\,\nabla_x\!\cdot\!\big(p_t(x\mid a)\, u_t(x\mid a)\big) . \]
The conditional continuity equation: for a fixed \(a\), the field \(u_t(\cdot\mid a)\) moves the conditional density \(p_t(\cdot\mid a)\) (derived and checked in the continuity derivation).
- \[ \partial_t p_t(x) = -\int \nabla_x\!\cdot\!\big(p_t(x\mid a)\, u_t(x\mid a)\big)\, p(a)\, da . \]
Substitute step 4 into step 3.
- \[ \partial_t p_t(x) = -\int \nabla_x\!\cdot\!\big(p_t(x\mid a)\, u_t(x\mid a)\, p(a)\big)\, da . \]
\(p(a)\) does not depend on \(x\), so it is a constant for \(\nabla_x\cdot\) and can be moved inside the divergence.
- \[ \partial_t p_t(x) = -\nabla_x\!\cdot\!\int p_t(x\mid a)\, u_t(x\mid a)\, p(a)\, da . \]
The divergence is a sum of \(x\)-derivatives and the integral is over \(a\). Linearity lets us pull the divergence outside the integral.
- \[ \int p_t(x\mid a)\, u_t(x\mid a)\, p(a)\, da = p_t(x)\int u_t(x\mid a)\,\frac{p_t(x\mid a)\, p(a)}{p_t(x)}\, da . \]
Multiply and divide by \(p_t(x)\) and move the factor \(p_t(x)\), which does not depend on \(a\), out of the integral. Valid wherever \(p_t(x)>0\).
- \[ p(a\mid a_t=x) = \frac{p_t(x\mid a)\, p(a)}{p_t(x)} . \]
Bayes' rule for the posterior over which data point \(a\) the point \(x\) came from.
- \[ \int u_t(x\mid a)\; p(a\mid a_t=x)\, da = \mathbb{E}\big[u \mid a_t=x\big] =: v(x,t) . \]
Replace the weight in step 8 by step 9. An integral of a function against a posterior is a conditional expectation, and this is the definition of the marginal field.
- \[ \int p_t(x\mid a)\, u_t(x\mid a)\, p(a)\, da = p_t(x)\, v(x,t) . \]
Combine steps 8 and 10.
- \[ \partial_t p_t(x) = -\nabla_x\!\cdot\!\big(p_t(x)\, v(x,t)\big) . \]
Insert step 11 into step 7. This is the continuity equation for the pair \((p_t, v)\).
- \[ p_0=\mathcal{N}(0,I), \qquad p_1 = p(a) . \]
Endpoints of the marginal, from step 2 and the conditional endpoints (\(p_0(x\mid a)=\mathcal{N}(x;0,I)\) for every \(a\), and \(p_1(x\mid a)=\delta_a\)).
- \[ \text{ODE } \dot x = v(x,t),\ x_0\sim p_0 \ \Rightarrow\ x_t\sim p_t . \]
The distribution of the ODE solution also solves the continuity equation of step 12 starting from \(p_0\). That linear PDE has a unique solution for a smooth field, so it is \(p_t\). Therefore integrating \(v\) from noise ends at \(p_1=p(a)\). Part A is done.
- \[ \mathcal{L}_{\text{marg}}(\theta) = \mathbb{E}_{t,\,a_t}\big\|v_\theta(a_t,t) - v(a_t,t)\big\|^2 . \]
Part B. The loss we cannot compute (it needs \(v\)). Here \(a_t\sim p_t\).
- \[ \mathcal{L}_{\text{flow}}(\theta) = \mathbb{E}_{t,\,a,\,\varepsilon}\big\|v_\theta(a_t,t) - u\big\|^2 . \]
The loss we do compute, with one pair per sample.
- \[ \|v_\theta - v\|^2 = \|v_\theta\|^2 - 2\,v_\theta\cdot v + \|v\|^2 . \]
Expand the square: \(\|p-q\|^2=\|p\|^2-2\,p\cdot q+\|q\|^2\). Here \(v_\theta=v_\theta(a_t,t)\), \(v=v(a_t,t)\).
- \[ \|v_\theta - u\|^2 = \|v_\theta\|^2 - 2\,v_\theta\cdot u + \|u\|^2 . \]
The same expansion for the flow loss.
- \[ \mathcal{L}_{\text{marg}} = \mathbb{E}\|v_\theta\|^2 - 2\,\mathbb{E}[v_\theta\cdot v] + \mathbb{E}\|v\|^2 . \]
Take the expectation of step 17 term by term (linearity).
- \[ \mathcal{L}_{\text{flow}} = \mathbb{E}\|v_\theta\|^2 - 2\,\mathbb{E}[v_\theta\cdot u] + \mathbb{E}\|u\|^2 . \]
Take the expectation of step 18 term by term.
- \[ \text{first terms: } \mathbb{E}\|v_\theta(a_t,t)\|^2 \ \text{is identical in steps 19 and 20.} \]
Both depend only on \(a_t\), and the law of \(a_t\) is \(p_t\) whether we sample it as "draw \(a_t\) from \(p_t\)" or as "draw a pair and build \(a_t\)". Same variable, same distribution, same expectation.
- \[ \mathbb{E}[v_\theta\cdot u] = \mathbb{E}\Big[\ \mathbb{E}\big[\, v_\theta(a_t,t)\cdot u \ \big|\ a_t\big]\ \Big] . \]
Tower property of conditional expectation: condition on \(a_t\) inside, average over \(a_t\) outside. (For each fixed \(t\); the average over \(t\sim U[0,1]\) is another outer expectation.)
- \[ \mathbb{E}\big[v_\theta(a_t,t)\cdot u \,\big|\, a_t\big] = v_\theta(a_t,t)\cdot\mathbb{E}\big[u \,\big|\, a_t\big] . \]
Given \(a_t\), the vector \(v_\theta(a_t,t)\) is a known constant, so it comes out of the conditional expectation (taking out what is known). The dot product is linear in \(u\).
- \[ \mathbb{E}\big[v_\theta(a_t,t)\cdot u \,\big|\, a_t\big] = v_\theta(a_t,t)\cdot v(a_t,t) . \]
By definition (step 10), \(\mathbb{E}[u\mid a_t]=v(a_t,t)\).
- \[ \mathbb{E}[v_\theta\cdot u] = \mathbb{E}[v_\theta\cdot v] . \]
Put step 24 into step 22 and take the outer expectation. The cross terms in steps 19 and 20 are equal.
- \[ \mathcal{L}_{\text{flow}} - \mathcal{L}_{\text{marg}} = \mathbb{E}\|u\|^2 - \mathbb{E}\|v\|^2 =: C . \]
Subtract step 19 from step 20. The first terms (step 21) and the cross terms (step 25) cancel; only the last terms remain.
- \[ \partial_\theta C = 0 . \]
\(u\) and \(v\) are determined by the data distribution and the path. Neither contains \(\theta\), so \(C\) is a constant with respect to the network weights.
- \[ \nabla_\theta \mathcal{L}_{\text{flow}} = \nabla_\theta \mathcal{L}_{\text{marg}} + \nabla_\theta C = \nabla_\theta \mathcal{L}_{\text{marg}} . \]
Differentiate step 26 in \(\theta\) and use step 27.
- \[ \mathbb{E}\|u-v\|^2 = \mathbb{E}\|u\|^2 - 2\,\mathbb{E}[u\cdot v] + \mathbb{E}\|v\|^2 . \]
What is \(C\)? Expand the squared distance between the pair target and the marginal field.
- \[ \mathbb{E}[u\cdot v] = \mathbb{E}\big[\,\mathbb{E}[u\mid a_t]\cdot v(a_t,t)\,\big] = \mathbb{E}\|v\|^2 . \]
Tower property, then take \(v(a_t,t)\) (a function of \(a_t\)) out of the inner expectation as in step 23, then step 10.
- \[ \mathbb{E}\|u-v\|^2 = \mathbb{E}\|u\|^2 - 2\,\mathbb{E}\|v\|^2 + \mathbb{E}\|v\|^2 = C . \]
Insert step 30 into step 29 and combine like terms.
Result: (A) the averaged field \(v(x,t)=\mathbb{E}[u\mid a_t=x]\) satisfies \(\partial_t p_t+\nabla\!\cdot(p_t v)=0\), so integrating it carries \(\mathcal{N}(0,I)\) to \(p(a)\). (B) \(\mathcal{L}_{\text{flow}}=\mathcal{L}_{\text{marg}}+C\) with \(C=\mathbb{E}\|u-v\|^2\ge 0\) independent of \(\theta\), hence \(\nabla_\theta\mathcal{L}_{\text{flow}}=\nabla_\theta\mathcal{L}_{\text{marg}}\). The constant \(C\) is the irreducible spread of pair targets around their average, which is why the flow loss never reaches zero.
The marginal field as a posterior average, and its closed form for Gaussian mixtures
Goal: show that on the straight-line path the field is \(v(x,t)=(\mathbb{E}[a\mid x]-x)/(1-t)\), then compute \(v\) exactly when the action distribution is a Gaussian mixture and the path is any \(a_t=\alpha_t a+\sigma_t\varepsilon\).
- \[ v(x,t) = \mathbb{E}\big[\,a-\varepsilon \mid a_t=x\,\big] . \]
Part I, the straight-line path. This is the definition of the marginal field with \(u=a-\varepsilon\). Write \(\mathbb{E}[\cdot\mid x]\) for \(\mathbb{E}[\cdot\mid a_t=x]\).
- \[ v(x,t) = \mathbb{E}[a\mid x] - \mathbb{E}[\varepsilon\mid x] . \]
Linearity of conditional expectation.
- \[ \varepsilon = \frac{a_t - t\,a}{1-t} \ \ \Rightarrow\ \ \varepsilon = \frac{x - t\,a}{1-t} \ \text{ on the event } a_t=x. \]
The path equation solved for \(\varepsilon\) (see the straight-line derivation), then \(a_t\) replaced by the value \(x\) we condition on.
- \[ \mathbb{E}[\varepsilon\mid x] = \mathbb{E}\Big[\frac{x - t\,a}{1-t}\ \Big|\ x\Big] . \]
Substitute step 3 inside the conditional expectation.
- \[ \mathbb{E}[\varepsilon\mid x] = \frac{x - t\,\mathbb{E}[a\mid x]}{1-t} . \]
Linearity again. \(x\), \(t\) and \(1-t\) are constants given the conditioning.
- \[ v(x,t) = \mathbb{E}[a\mid x] - \frac{x - t\,\mathbb{E}[a\mid x]}{1-t} . \]
Substitute step 5 into step 2.
- \[ v(x,t) = \frac{(1-t)\,\mathbb{E}[a\mid x] - x + t\,\mathbb{E}[a\mid x]}{1-t} . \]
Common denominator \(1-t\). Distribute the minus sign over the numerator of the fraction.
- \[ (1-t)\,\mathbb{E}[a\mid x] + t\,\mathbb{E}[a\mid x] = \mathbb{E}[a\mid x] . \]
The coefficients \((1-t)\) and \(t\) add to \(1\).
- \[ v(x,t) = \frac{\mathbb{E}[a\mid x] - x}{1-t} . \]
Insert step 8 into step 7. The field points from \(x\) toward the posterior mean of the clean action, scaled by the remaining time.
- \[ p(a\mid x) = \frac{p_t(x\mid a)\,p(a)}{p_t(x)}, \qquad p_t(x) = \int p_t(x\mid a')\,p(a')\,da' . \]
Bayes' rule, and the law of total probability for the denominator.
- \[ p_t(x\mid a) = \frac{1}{(2\pi(1-t)^2)^{d/2}}\exp\!\Big(-\frac{\|x-t\,a\|^2}{2(1-t)^2}\Big) . \]
The conditional path is \(\mathcal{N}(t\,a,(1-t)^2 I)\) in \(d\) dimensions (straight-line derivation).
- \[ \mathbb{E}[a\mid x] = \frac{\int a\; p(a)\, \exp\!\big(-\|x-ta\|^2/(2(1-t)^2)\big)\, da}{\int p(a)\,\exp\!\big(-\|x-ta\|^2/(2(1-t)^2)\big)\, da} . \]
\(\mathbb{E}[a\mid x]=\int a\,p(a\mid x)\,da\). Insert steps 10 and 11. The prefactor \((2\pi(1-t)^2)^{-d/2}\) and the factor \(1/p_t(x)\) do not depend on \(a\), and they cancel after we write \(p_t(x)\) as the integral in the denominator.
- \[ \text{Part II. } p(a)=\sum_{k=1}^{K} w_k\,\mathcal{N}(a;\,\mu_k,\,s_k^2 I),\quad a_t=\alpha\,a+\sigma\,\varepsilon . \]
Gaussian mixture with weights \(w_k\ge0\), \(\sum_k w_k=1\). Write \(\alpha=\alpha_t\), \(\sigma=\sigma_t\), \(\dot\alpha=\dot\alpha_t\), \(\dot\sigma=\dot\sigma_t\) for brevity. Let \(k\) be the (hidden) component that generated \(a\).
- \[ a = \mu_k + s_k\, z, \qquad z\sim\mathcal{N}(0,I)\ \text{independent of } \varepsilon . \]
(i) Given component \(k\), write \(a\) in terms of a standard normal \(z\).
- \[ a_t = \alpha\,\mu_k + \alpha\, s_k\, z + \sigma\,\varepsilon . \]
Substitute step 14 into \(a_t=\alpha a+\sigma\varepsilon\).
- \[ \alpha s_k z\sim\mathcal{N}(0,\alpha^2 s_k^2 I), \qquad \sigma\varepsilon\sim\mathcal{N}(0,\sigma^2 I) . \]
Scaling a standard normal by \(c\) gives covariance \(c^2 I\).
- \[ a_t\mid k \ \sim\ \mathcal{N}\big(\alpha\,\mu_k,\ V_k\, I\big), \qquad V_k := \alpha^2 s_k^2 + \sigma^2 . \]
The sum of independent Gaussians is Gaussian: means add, variances add. The constant \(\alpha\mu_k\) shifts the mean.
- \[ \tilde a := a-\mu_k = s_k z, \qquad \tilde a_t := a_t - \alpha\mu_k = \alpha s_k z + \sigma\varepsilon . \]
(ii) Centered variables, given \(k\). Their means are zero, so covariances are just \(\mathbb{E}[\,\cdot\,\cdot^\top]\).
- \[ \mathrm{Cov}(a, a_t\mid k) = \mathbb{E}\big[\,s_k z\,(\alpha s_k z + \sigma\varepsilon)^\top\big] = \alpha s_k^2\,\mathbb{E}[zz^\top] + s_k\sigma\,\mathbb{E}[z\varepsilon^\top] . \]
Definition of covariance for centered variables, then expand the product (linearity).
- \[ \mathbb{E}[zz^\top]=I, \qquad \mathbb{E}[z\varepsilon^\top] = \mathbb{E}[z]\,\mathbb{E}[\varepsilon]^\top = 0 . \]
\(z\) is standard normal. \(z\) and \(\varepsilon\) are independent with zero means, so the expectation of the product factorizes.
- \[ \Sigma_{a,a_t} = \alpha\, s_k^2\, I . \]
Insert step 20 into step 19.
- \[ \mathrm{Cov}(\varepsilon, a_t\mid k) = \mathbb{E}\big[\varepsilon\,(\alpha s_k z + \sigma\varepsilon)^\top\big] = \alpha s_k\,\mathbb{E}[\varepsilon z^\top] + \sigma\,\mathbb{E}[\varepsilon\varepsilon^\top] . \]
Same expansion for the noise. \(\varepsilon\) has mean zero, so it is already centered.
- \[ \Sigma_{\varepsilon,a_t} = \sigma\, I . \]
\(\mathbb{E}[\varepsilon z^\top]=0\) by independence and \(\mathbb{E}[\varepsilon\varepsilon^\top]=I\).
- \[ \Sigma_{a_t,a_t} = V_k\, I, \quad \mathbb{E}[a\mid k]=\mu_k,\ \ \mathbb{E}[\varepsilon\mid k]=0,\ \ \mathbb{E}[a_t\mid k]=\alpha\mu_k . \]
Covariance of \(a_t\) from step 17, and the means from the definitions given \(k\).
- \[ \text{for jointly Gaussian } (y,x):\quad w := y - \mu_y - B\,(x-\mu_x), \qquad B := \Sigma_{yx}\Sigma_{xx}^{-1} . \]
(iii) Derive Gaussian conditioning. Define the part of \(y\) that is left after subtracting the best linear prediction from \(x\).
- \[ \mathrm{Cov}(w,x) = \mathbb{E}\big[w\,(x-\mu_x)^\top\big] = \Sigma_{yx} - B\,\Sigma_{xx} = \Sigma_{yx} - \Sigma_{yx}\Sigma_{xx}^{-1}\Sigma_{xx} = 0 . \]
Expand \(w\), use \(\Sigma_{yx}=\mathbb{E}[(y-\mu_y)(x-\mu_x)^\top]\) and \(\Sigma_{xx}=\mathbb{E}[(x-\mu_x)(x-\mu_x)^\top]\), insert \(B\).
- \[ w \ \text{and}\ x \ \text{are independent.} \]
\(w\) and \(x\) are jointly Gaussian (both are linear in \((y,x)\)), and for jointly Gaussian variables uncorrelated means independent.
- \[ \mathbb{E}[w\mid x] = \mathbb{E}[w] = 0 . \]
Independence removes the conditioning. \(\mathbb{E}[w]=\mu_y-\mu_y-B\cdot 0=0\).
- \[ \mathbb{E}[y\mid x] = \mu_y + B\,(x-\mu_x) = \mu_y + \Sigma_{yx}\Sigma_{xx}^{-1}(x-\mu_x) . \]
Solve \(w\) for \(y\) in step 25 and take \(\mathbb{E}[\cdot\mid x]\), using step 28 and the fact that \(\mu_y\), \(B\), \(x\), \(\mu_x\) are constants given \(x\).
- \[ \mathbb{E}[a\mid x,k] = \mu_k + \alpha s_k^2\,I\,\big(V_k I\big)^{-1}\big(x - \alpha\mu_k\big) = \mu_k + \frac{\alpha s_k^2}{V_k}\,\big(x-\alpha\mu_k\big) . \]
Apply step 29 with \(y=a\), conditioning variable \(a_t\) (observed value \(x\)). Use \(\mu_y=\mu_k\), \(\Sigma_{yx}\) from step 21, \(\Sigma_{xx}\) and \(\mu_x\) from step 24. \((V_kI)^{-1}=I/V_k\).
- \[ \mathbb{E}[\varepsilon\mid x,k] = 0 + \sigma\,I\,\big(V_k I\big)^{-1}\big(x-\alpha\mu_k\big) = \frac{\sigma}{V_k}\,\big(x-\alpha\mu_k\big) . \]
Step 29 with \(y=\varepsilon\), using \(\mu_y=0\) and \(\Sigma_{yx}\) from step 23.
- \[ \alpha\,\mathbb{E}[a\mid x,k]+\sigma\,\mathbb{E}[\varepsilon\mid x,k] = \alpha\mu_k + \frac{\alpha^2s_k^2+\sigma^2}{V_k}(x-\alpha\mu_k) = x . \]
Consistency check. On the event \(a_t=x\) we must have \(\alpha a+\sigma\varepsilon=x\), so the same combination of the two means must equal \(x\). Add \(\alpha\) times step 30 and \(\sigma\) times step 31. The fraction equals \(1\) by the definition of \(V_k\), leaving \(\alpha\mu_k+x-\alpha\mu_k=x\).
- \[ r_k(x) := P(k\mid a_t=x) = \frac{w_k\;\mathcal{N}(x;\,\alpha\mu_k,\,V_kI)}{\sum_{j} w_j\;\mathcal{N}(x;\,\alpha\mu_j,\,V_jI)} . \]
(iv) Bayes' rule for the discrete variable \(k\): prior \(w_k\), likelihood \(p(x\mid k)\) from step 17. The denominator is \(p_t(x)\), by the law of total probability.
- \[ v(x,t) = \mathbb{E}\big[\dot\alpha\, a + \dot\sigma\,\varepsilon \mid x\big] . \]
(v) The marginal field for the general path. The velocity of one pair \(\alpha_t a+\sigma_t\varepsilon\) is \(\dot\alpha a+\dot\sigma\varepsilon\), because \(a\) and \(\varepsilon\) are constant in \(t\). Then condition on \(a_t=x\).
- \[ \mathbb{E}[Y\mid x] = \sum_k P(k\mid x)\; \mathbb{E}[Y\mid x,k] . \]
Law of total expectation, splitting over the hidden component \(k\).
- \[ v(x,t) = \sum_k r_k(x)\,\Big(\dot\alpha\,\mathbb{E}[a\mid x,k] + \dot\sigma\,\mathbb{E}[\varepsilon\mid x,k]\Big) . \]
Apply step 35 with \(Y=\dot\alpha a+\dot\sigma\varepsilon\), use \(P(k\mid x)=r_k(x)\) from step 33, and linearity inside each conditional expectation.
- \[ v(x,t) = \sum_k r_k(x)\Big[\dot\alpha\,\mu_k + \frac{\dot\alpha\,\alpha\, s_k^2 + \dot\sigma\,\sigma}{V_k}\,\big(x - \alpha\mu_k\big)\Big] . \]
Insert steps 30 and 31 into step 36. This gives \(\dot\alpha\mu_k + \dot\alpha\frac{\alpha s_k^2}{V_k}(x-\alpha\mu_k) + \dot\sigma\frac{\sigma}{V_k}(x-\alpha\mu_k)\). The last two terms share the factor \((x-\alpha\mu_k)/V_k\), so combine them.
- \[ \mathbb{E}[a\mid x] = \sum_k r_k(x)\Big[\mu_k + \frac{\alpha s_k^2}{V_k}(x-\alpha\mu_k)\Big] . \]
The same law of total expectation (step 35) applied to \(a\) alone, with step 30. For the linear path this feeds \(v=(\mathbb{E}[a\mid x]-x)/(1-t)\) from step 9.
- \[ \alpha=0:\quad V_k = \sigma^2 = 1,\qquad \mathbb{E}[a\mid x,k]=\mu_k + 0 = \mu_k . \]
Sanity check at \(t=0\), where \(\alpha_0=0\) and \(\sigma_0=1\). Put \(\alpha=0\) in the definition of \(V_k\) and in step 30. The factor \(\alpha s_k^2/V_k\) vanishes.
- \[ r_k(x) = \frac{w_k\,\mathcal{N}(x;0,I)}{\sum_j w_j\,\mathcal{N}(x;0,I)} = w_k . \]
At \(\alpha=0\) every component has the same likelihood \(\mathcal{N}(x;0,I)\) (step 33), so it cancels. The pure-noise point carries no information about \(k\).
- \[ \mathbb{E}[a\mid x] = \sum_k w_k\,\mu_k, \qquad v(x,0)=\sum_k w_k\mu_k - x . \]
Insert steps 39 and 40 into step 38. Then step 9 with \(t=0\) (so \(1-t=1\)) gives the field. At the noise end every point is pushed toward the mean of the mixture, which for two modes is between them.
Result: on the straight path, \(v(x,t)=(\mathbb{E}[a\mid x]-x)/(1-t)\). For a Gaussian mixture and a general path \(a_t=\alpha_t a+\sigma_t\varepsilon\), \(v(x,t)=\sum_k r_k(x)\big[\dot\alpha\,\mu_k+\frac{\dot\alpha\alpha s_k^2+\dot\sigma\sigma}{V_k}(x-\alpha\mu_k)\big]\) with \(V_k=\alpha^2s_k^2+\sigma^2\) and \(r_k\propto w_k\,\mathcal{N}(x;\alpha\mu_k,V_kI)\).
Flow matching III: probability paths and couplings
The loss from the idea and the proof fixed three choices without saying so. It used a particular path between a noise point and an action, it paired noise and actions independently, and it drew noise from \(\mathcal{N}(0,I)\). Each can change. The recipe stays the same, but the field you learn, and the number of solver steps it needs, do not.
The conditional path
Condition on the action only. A Gaussian path has \(p_t(x \mid a) = \mathcal{N}(\alpha_t a, \sigma_t^2 I)\), sampled by \(\psi_t(\varepsilon \mid a) = \alpha_t a + \sigma_t \varepsilon\). Solve \(\varepsilon = (x - \alpha_t a)/\sigma_t\) and differentiate in \(t\):
Three schedules cover most uses.
- Linear (OT) path. \(\alpha_t = t,\ \sigma_t = 1-t\) gives \(u_t(x \mid a) = (a - x)/(1-t)\), which equals \(a - \varepsilon\) on the path. Each pair moves at constant velocity.
- Linear with \(\sigma_{\min}\). \(\alpha_t = t,\ \sigma_t = 1-(1-\sigma_{\min})\,t\) gives pair velocity \(a - (1-\sigma_{\min})\,\varepsilon\). The path ends at \(a + \sigma_{\min}\varepsilon\), not at \(a\).
- VP-cosine. \(\alpha_t = \sin(\pi t/2),\ \sigma_t = \cos(\pi t/2)\) gives \(a_t = \sin(\pi t/2)\,a + \cos(\pi t/2)\,\varepsilon\), a quarter arc. Even a single pair travels on a curve, so Euler is not exact for one pair.
Why \(\sigma_{\min}\)? With \(\sigma_1 = 0\), the conditional \(p_1(x \mid a)\) is a point mass, and the factor \(\dot\sigma_t/\sigma_t\) in \(u_t(x \mid a)\) blows up as \(t \to 1\). Anything that divides by \(\sigma_t\), such as the score in the solver part, is singular there too. A small \(\sigma_{\min} \gt 0\) keeps \(p_t(x \mid a)\) a proper Gaussian for every \(t \in [0,1]\) [9]. The price is that samples are the data blurred by \(\sigma_{\min}\), so choose it below the action precision you care about.
Diffusion models are Gaussian paths too, with \(\alpha_t^2 + \sigma_t^2 = 1\) (see the bridge), so choosing a path is choosing a noise schedule. For any Gaussian path the field a network learns is
For the linear path this is \((\mathbb{E}[a \mid x] - x)/(1-t)\), the formula from the proof. The derivation below shows each step. The linear path is the usual default for robot flow policies, \(\pi_0\) among them [26]. The path changes how curved the marginal trajectories are, which is what straightening works on.
The coupling
A coupling is any joint distribution \(\pi(\varepsilon, a)\) whose marginals are the source \(p_0\) and the data \(p_1\). So far \(\pi = p_0 \times p_1\). The loss draws pairs from \(\pi\):
The conditional flow matching theorem holds for every coupling. The derivation below shows why: the minimizer is the marginal field of the mixture of pair paths, and that mixture has marginals \(p_0\) at \(t=0\) and \(p_1\) at \(t=1\). Integrating the field still turns \(p_0\) into \(p_1\). What the coupling changes is which field you get.
With the independent coupling, a noise point is as likely to meet a far action as a near one, so lines cross a lot. Minibatch optimal transport pairs within a batch [12] [19]. Draw \(B\) noise points and \(B\) actions, build the matrix \(C_{ij} = \|\varepsilon_i - a_j\|^2\), solve the assignment problem, and use the matched pairs. An optimal assignment cannot be improved by swapping two partners, which rules out long crossing pairs. For the exact OT plan with squared cost, two straight pair paths never occupy the same point at the same time. The marginal field then equals the pair velocity and the marginal paths are straight. A minibatch plan only approximates this, coarsely when \(B\) is small relative to the chunk dimension. The cost is one assignment solve per batch plus a \(B \times B\) distance matrix. Inference is unchanged.
For a policy, the theorem needs the coupling to have source marginal \(p_0\) given each observation \(o\). If you match noise to actions from different observations, the noise paired with a given \(o\) depends on actions that belong to other observations, so the source seen by \(o\) is no longer \(\mathcal{N}(0,I)\). With one demonstrated chunk per observation there is nothing to pair against. Use minibatch OT only when you can pair within the same \(o\).
The source
The source \(p_0\) can be any distribution you can sample at inference time. One option is a narrow Gaussian around the previous action chunk. Streaming-style flow policies likewise start the flow near the last action [30]. The transport distance is then short. The cost is that the starts are close together, so the choice of mode is made by small differences in the start. The posterior over modes splits earlier in \(t\), and the field changes quickly near \(t = 0\). That is a stiff region for a solver.
Stochastic interpolants are the general framework that contains all of this [20]. They define \(a_t = I_t(\varepsilon, a) + \gamma_t z\) with extra independent noise \(z\), an arbitrary source and target, and a choice between ODE and SDE sampling. Flow matching with the linear path is the case \(\gamma_t = 0\).
Try these in order. With the linear path and independent coupling, see the thin pair lines cross while the thick marginal trajectories bend apart. Switch to minibatch OT and compare. Switch to VP-cosine and see single-pair paths curve. Set \(\sigma_{\min} = 0.1\) and see the thin lines stop short of the data points. Finally choose the previous-chunk source. The OT and previous-chunk fields are estimated by kernel regression on sampled pairs, so small wiggles there are estimation error.
A flow matching model is three choices: the conditional path, the coupling and the source. The loss recipe is identical for all of them. The choices decide how often pair lines cross, and so how curved the learned paths are and how many solver steps they need.
Derivations
The conditional velocity of a Gaussian path, and why it generates the path
Goal: for the Gaussian path \(a_t=\alpha_t a+\sigma_t\varepsilon\) derive the law of \(a_t\), the conditional velocity \(u_t(x\mid a)=\dot\alpha_t a+\frac{\dot\sigma_t}{\sigma_t}(x-\alpha_t a)\), its three special cases (linear, \(\sigma_{\min}\), VP-cosine), and prove that this field satisfies the continuity equation of the path.
- \[ \psi_t(\varepsilon\mid a)=\alpha_t\,a+\sigma_t\,\varepsilon,\qquad \varepsilon\sim\mathcal{N}(0,I). \]
Setup. The action \(a\) is fixed, \(\alpha_t,\sigma_t\) are smooth scalar functions with \(\sigma_t\gt 0\) for \(t\lt 1\), \(\alpha_0=0,\sigma_0=1\), \(\alpha_1=1\). So \(\psi_0=\varepsilon\) (noise) and \(\psi_1\approx a\). We drop \(o\) from the notation: read every density as conditional on \(o\) (this is why \(\psi_t\) is written given \(a\) only). The map \(\psi_t\) carries one noise sample to its position at time \(t\).
- \[ \mathbb{E}[\psi_t] = \sigma_t\,\mathbb{E}[\varepsilon] + \alpha_t\,a = \alpha_t\,a . \]
Part 1, the law of \(\psi_t\). Mean of an affine map: linearity of expectation, \(\mathbb{E}[\varepsilon]=0\), and \(\alpha_t,\sigma_t,a\) are constants.
- \[ \mathrm{Cov}(\psi_t)=\mathbb{E}\big[(\sigma_t\varepsilon)(\sigma_t\varepsilon)^\top\big]=\sigma_t^2\,\mathbb{E}[\varepsilon\varepsilon^\top]=\sigma_t^2\, I . \]
Covariance. By step 2 the centered variable is \(\psi_t-\alpha_t a=\sigma_t\varepsilon\). The scalar \(\sigma_t\) comes out of the expectation twice, and \(\mathbb{E}[\varepsilon\varepsilon^\top]=I\).
- \[ \mathbb{E}\big[e^{\,i\,w^\top\varepsilon}\big]=e^{-\frac12\|w\|^2}\qquad\text{for every } w\in\mathbb{R}^d . \]
Is \(\psi_t\) Gaussian, not just a variable with this mean and covariance? Use characteristic functions. This is the characteristic function of \(\mathcal{N}(0,I)\).
- \[ \mathbb{E}\big[e^{\,i\,s^\top\psi_t}\big]=e^{\,i\,\alpha_t s^\top a}\;\mathbb{E}\big[e^{\,i\,(\sigma_t s)^\top\varepsilon}\big] . \]
Insert \(\psi_t=\alpha_t a+\sigma_t\varepsilon\) into \(e^{i s^\top\psi_t}\) and split the exponential of a sum into a product. The deterministic factor \(e^{i\alpha_t s^\top a}\) leaves the expectation, and \(s^\top(\sigma_t\varepsilon)=(\sigma_t s)^\top\varepsilon\).
- \[ \mathbb{E}\big[e^{\,i\,s^\top\psi_t}\big]=e^{\,i\,s^\top(\alpha_t a)\,-\,\frac12\,\sigma_t^2\|s\|^2} . \]
Apply step 4 with \(w=\sigma_t s\), so \(\|w\|^2=\sigma_t^2\|s\|^2\), and keep the first factor of step 5.
- \[ p_t(x\mid a)=\mathcal{N}\big(x;\ \alpha_t\,a,\ \sigma_t^2\,I\big) . \]
Step 6 is the characteristic function \(e^{i s^\top m-\frac12 s^\top C s}\) of a Gaussian with mean \(m=\alpha_t a\) and covariance \(C=\sigma_t^2 I\), the values found in steps 2 and 3. A characteristic function determines the distribution, so \(\psi_t(\varepsilon)\) has this law. Rule used: an affine image of a Gaussian vector is Gaussian, with mean \(Am+b\) and covariance \(ACA^\top\) (here \(A=\sigma_t I\), \(b=\alpha_t a\)).
- \[ \frac{d}{dt}\psi_t(\varepsilon\mid a)=\dot\alpha_t\,a+\dot\sigma_t\,\varepsilon . \]
Part 2, the velocity. Differentiate step 1 in \(t\). Linearity of the derivative; \(a\) and \(\varepsilon\) do not depend on \(t\), so they are constant factors.
- \[ x=\alpha_t\,a+\sigma_t\,\varepsilon \ \Rightarrow\ \sigma_t\,\varepsilon = x-\alpha_t\,a . \]
A particle sitting at \(x\) at time \(t\) has \(x=\psi_t(\varepsilon)\). Subtract \(\alpha_t a\) from both sides.
- \[ \varepsilon=\psi_t^{-1}(x)=\frac{x-\alpha_t\,a}{\sigma_t} . \]
Divide step 9 by \(\sigma_t\), allowed because \(\sigma_t\gt 0\). So \(\psi_t\) is invertible and the noise that produced position \(x\) is known.
- \[ u_t(x\mid a):=\dot\psi_t\big(\psi_t^{-1}(x)\big) . \]
Definition of the field. To move every particle along its own path, the field at \(x\) must equal the velocity of the particle that is at \(x\) at time \(t\): the velocity step 8 of the noise \(\psi_t^{-1}(x)\).
- \[ u_t(x\mid a)=\dot\alpha_t\,a+\dot\sigma_t\,\frac{x-\alpha_t\,a}{\sigma_t} . \]
Substitute \(\varepsilon=\psi_t^{-1}(x)\) from step 10 into the velocity of step 8.
- \[ u_t(x\mid a)=\dot\alpha_t\,a+\frac{\dot\sigma_t}{\sigma_t}\,\big(x-\alpha_t\,a\big) . \]
Write \(\dot\sigma_t\cdot\frac{x-\alpha_t a}{\sigma_t}\) as \(\frac{\dot\sigma_t}{\sigma_t}(x-\alpha_t a)\). This is the conditional velocity of any Gaussian path.
- \[ u_t(x\mid a)=\frac{\dot\sigma_t}{\sigma_t}\,x+\Big(\dot\alpha_t-\frac{\dot\sigma_t}{\sigma_t}\,\alpha_t\Big)\,a . \]
Distribute \(\frac{\dot\sigma_t}{\sigma_t}\) over \((x-\alpha_t a)\) and collect the terms in \(a\). The field is affine in \(x\): a linear pull on the current position plus a push toward \(a\).
- \[ x_t=\psi_t(\varepsilon)\ \Rightarrow\ u_t(x_t\mid a)=\dot\psi_t\big(\psi_t^{-1}(\psi_t(\varepsilon))\big)=\dot\psi_t(\varepsilon) . \]
Check that the field does what we want. On the curve \(x_t=\psi_t(\varepsilon)\), apply step 11 and use \(\psi_t^{-1}(\psi_t(\varepsilon))=\varepsilon\). So \(\dot x_t=\dot\psi_t(\varepsilon)=u_t(x_t\mid a)\): each curve is a solution of the ODE \(\dot x=u_t(x\mid a)\).
- \[ \alpha_t=t,\quad \sigma_t=1-t,\quad \dot\alpha_t=1,\quad \dot\sigma_t=-1,\quad \frac{\dot\sigma_t}{\sigma_t}=-\frac{1}{1-t} . \]
Case 1, the linear path. Read off the schedule and differentiate (power rule).
- \[ u_t(x\mid a)=a-\frac{x-t\,a}{1-t} . \]
Insert step 16 into step 13: \(\dot\alpha_t a=a\) and \(\frac{\dot\sigma_t}{\sigma_t}(x-\alpha_t a)=-\frac{x-ta}{1-t}\).
- \[ u_t(x\mid a)=\frac{(1-t)\,a-(x-t\,a)}{1-t} . \]
Write \(a=\frac{(1-t)a}{1-t}\) and combine the two fractions over the common denominator \(1-t\).
- \[ (1-t)\,a-(x-t\,a)=(1-t)\,a+t\,a-x=a-x . \]
Distribute the minus sign, then add the coefficients of \(a\): \((1-t)+t=1\).
- \[ u_t(x\mid a)=\frac{a-x}{1-t} . \]
Insert step 19 into step 18. This is the field used in the straight-line derivation and the CFM proof.
- \[ u_t(x\mid a)=a-\varepsilon . \]
The fraction in step 17 is \(\frac{x-ta}{1-t}=\psi_t^{-1}(x)=\varepsilon\) by step 10 with \(\alpha_t=t,\sigma_t=1-t\). So the field evaluated on the path of the pair \((\varepsilon,a)\) is the constant \(a-\varepsilon\), as it must be by step 15.
- \[ c:=1-\sigma_{\min},\qquad \alpha_t=t,\quad \sigma_t=1-c\,t,\quad \dot\alpha_t=1,\quad \dot\sigma_t=-c . \]
Case 2, Lipman's \(\sigma_{\min}\) path. Abbreviate \(c=1-\sigma_{\min}\). Then \(\sigma_0=1\) and \(\sigma_1=1-c=\sigma_{\min}\). The derivative of \(1-ct\) is \(-c\).
- \[ u_t(x\mid a)=a-\frac{c\,(x-t\,a)}{1-c\,t} . \]
Insert step 22 into step 13: \(\dot\sigma_t/\sigma_t=-c/(1-ct)\).
- \[ u_t(x\mid a)=\frac{(1-c\,t)\,a-c\,(x-t\,a)}{1-c\,t} . \]
Write \(a=\frac{(1-ct)a}{1-ct}\) and combine over the common denominator \(1-ct\).
- \[ (1-c\,t)\,a-c\,(x-t\,a)=a-c\,t\,a-c\,x+c\,t\,a . \]
Distribute: \((1-ct)a=a-cta\) and \(-c(x-ta)=-cx+cta\).
- \[ a-c\,t\,a-c\,x+c\,t\,a=a-c\,x . \]
The terms \(-cta\) and \(+cta\) cancel.
- \[ u_t(x\mid a)=\frac{a-c\,x}{1-c\,t}=\frac{a-(1-\sigma_{\min})\,x}{1-(1-\sigma_{\min})\,t} . \]
Insert steps 25 and 26 into step 24 and put \(c=1-\sigma_{\min}\) back.
- \[ u_t(x\mid a)=a-c\,\varepsilon=a-(1-\sigma_{\min})\,\varepsilon . \]
On the path \(x=\psi_t(\varepsilon)\), step 23 contains \(\frac{x-ta}{1-ct}=\varepsilon\) (step 10 with \(\sigma_t=1-ct\)), so the target is \(a-c\varepsilon\). Checks: \(\sigma_{\min}=0\) gives \(c=1\), and steps 27 and 28 reduce to steps 20 and 21. For \(\sigma_{\min}\gt 0\) the denominator \(1-ct\ge\sigma_{\min}\) never vanishes, so the field stays finite at \(t=1\).
- \[ \theta:=\tfrac{\pi t}{2},\quad \alpha_t=\sin\theta,\quad \sigma_t=\cos\theta,\quad \dot\alpha_t=\tfrac{\pi}{2}\cos\theta,\quad \dot\sigma_t=-\tfrac{\pi}{2}\sin\theta . \]
Case 3, the VP-cosine path. Chain rule with \(\dot\theta=\pi/2\): \(\frac{d}{dt}\sin\theta=\cos\theta\,\dot\theta\) and \(\frac{d}{dt}\cos\theta=-\sin\theta\,\dot\theta\). Check: \(\alpha_0=0,\sigma_0=1,\alpha_1=1,\sigma_1=0\).
- \[ u_t(x\mid a)=\tfrac{\pi}{2}\cos\theta\;a-\tfrac{\pi}{2}\,\frac{\sin\theta}{\cos\theta}\,\big(x-\sin\theta\;a\big) . \]
Insert step 29 into step 13, with \(\dot\sigma_t/\sigma_t=-\frac{\pi}{2}\frac{\sin\theta}{\cos\theta}\).
- \[ u_t(x\mid a)=\tfrac{\pi}{2}\Big[\Big(\cos\theta+\frac{\sin^2\theta}{\cos\theta}\Big)a-\frac{\sin\theta}{\cos\theta}\,x\Big] . \]
Factor out \(\frac{\pi}{2}\), distribute \(-\frac{\sin\theta}{\cos\theta}\) over \((x-\sin\theta\,a)\), and collect the terms in \(a\).
- \[ \cos\theta+\frac{\sin^2\theta}{\cos\theta}=\frac{\cos^2\theta+\sin^2\theta}{\cos\theta}=\frac{1}{\cos\theta} . \]
Common denominator \(\cos\theta\), then the identity \(\cos^2\theta+\sin^2\theta=1\).
- \[ u_t(x\mid a)=\frac{\pi}{2}\;\frac{a-\sin\theta\;x}{\cos\theta} . \]
Insert step 32 into step 31 and put \(\frac{1}{\cos\theta}\) as a common factor of both terms. As \(t\to 1\), \(\cos\theta\to 0\), so the field blows up like \(1/(1-t)\) in Case 1: \(\sigma_1=0\) in both.
- \[ \psi(\varepsilon,t)\ \text{smooth},\quad \partial_\varepsilon\psi\gt 0,\quad \varepsilon\sim p_0\ \text{with CDF } F_0,\quad F_0'=p_0 . \]
Part 3, the field generates the path (1-D). Let \(\psi\) be any smooth map that is strictly increasing in \(\varepsilon\) at each \(t\). Our map has \(\partial_\varepsilon\psi=\sigma_t\gt 0\). Write \(\dot\psi=\partial_t\psi\). Goal: the density of \(\psi_t(\varepsilon)\) satisfies the continuity equation with \(v=\dot\psi\circ\psi_t^{-1}\). In \(d\) dimensions the same statement is proved with test functions in the coupling derivation.
- \[ F_t(x):=P\big(\psi_t(\varepsilon)\le x\big) . \]
The CDF of the position at time \(t\); its \(x\)-derivative will be the density \(p_t\).
- \[ y(x,t):=\psi_t^{-1}(x),\qquad \psi_t(\varepsilon)\le x\iff \varepsilon\le y(x,t) . \]
\(\psi_t\) is strictly increasing, so it preserves inequalities, and \(y\) is the unique solution of \(\psi(y,t)=x\).
- \[ F_t(x)=F_0\big(y(x,t)\big) . \]
Apply step 36 inside step 35: \(P(\varepsilon\le y)=F_0(y)\).
- \[ \psi\big(y(x,t),t\big)=x . \]
The defining relation of \(y\). The right side does not depend on \(t\) or on anything else.
- \[ \partial_\varepsilon\psi\;\partial_x y=1\quad\Rightarrow\quad \partial_x y=\frac{1}{\partial_\varepsilon\psi} . \]
Differentiate step 38 in \(x\) (chain rule), then divide by \(\partial_\varepsilon\psi\gt 0\). Here \(\partial_\varepsilon\psi\) is evaluated at \((y,t)\).
- \[ \partial_\varepsilon\psi\;\partial_t y+\dot\psi=0 . \]
Differentiate step 38 in \(t\) (chain rule, two dependences on \(t\): through \(y\) and directly). The right side \(x\) is constant in \(t\), so its derivative is \(0\).
- \[ \partial_t y=-\frac{\dot\psi}{\partial_\varepsilon\psi}=-\dot\psi\;\partial_x y . \]
Solve step 40 for \(\partial_t y\), then replace \(1/\partial_\varepsilon\psi\) by \(\partial_x y\) using step 39.
- \[ v(x,t):=\dot\psi\big(y(x,t),t\big)\quad\Rightarrow\quad \partial_t y=-v\;\partial_x y . \]
The field is the velocity of the particle at \(x\), as in step 11. Insert it into step 41.
- \[ p_t(x)=\partial_x F_t(x)=p_0(y)\;\partial_x y . \]
A density is the \(x\)-derivative of its CDF. Differentiate step 37 with the chain rule and \(F_0'=p_0\). (This is the change-of-variables formula \(p_t=p_0/\partial_\varepsilon\psi\) after step 39.)
- \[ \partial_t F_t(x)=p_0(y)\;\partial_t y . \]
Differentiate step 37 in \(t\) with the chain rule and \(F_0'=p_0\).
- \[ \partial_t F_t(x)=-\,v\;p_0(y)\;\partial_x y=-\,p_t(x)\,v(x,t) . \]
Insert step 42 into step 44, then step 43. Reading: the mass to the left of \(x\) changes at rate minus the flux \(p\,v\) through \(x\).
- \[ \partial_x\partial_t F_t=\partial_t\partial_x F_t=\partial_t p_t . \]
Mixed partial derivatives commute for smooth functions, and \(\partial_x F_t=p_t\) by step 43.
- \[ \partial_t p_t(x)=-\,\partial_x\big(p_t(x)\,v(x,t)\big) . \]
Differentiate step 45 in \(x\) and use step 46 on the left.
- \[ \partial_t p+\partial_x(p\,v)=0\quad\text{with}\quad v=\dot\psi\circ\psi_t^{-1} . \]
Move the right side of step 47 to the left. The velocity field of a smooth increasing flow map generates the density it pushes forward.
- \[ \partial_\varepsilon\psi=\sigma_t,\quad y=\frac{x-\alpha_t a}{\sigma_t},\quad v(x,t)=\dot\alpha_t\,a+\dot\sigma_t\,y=u_t(x\mid a) . \]
Apply this to the Gaussian path. \(\partial_\varepsilon\psi=\sigma_t\) from step 1. \(y=\psi_t^{-1}(x)\) is step 10. Then \(v=\dot\psi(y,t)\) with step 8 equals the field of step 12.
- \[ p_t(x)=\frac{p_0(y)}{\sigma_t}=\frac{1}{\sigma_t}\,\mathcal{N}\Big(\frac{x-\alpha_t a}{\sigma_t};0,1\Big)=\mathcal{N}\big(x;\alpha_t a,\sigma_t^2\big) . \]
Step 43 with \(\partial_x y=1/\sigma_t\) (step 39) and \(p_0=\mathcal{N}(0,1)\). Rewriting the Gaussian density with scale \(\sigma_t\) gives \(\mathcal{N}(\alpha_t a,\sigma_t^2)\), in agreement with step 7.
- \[ \partial_t p_t(x\mid a)+\partial_x\big(p_t(x\mid a)\,u_t(x\mid a)\big)=0 . \]
Combine steps 48, 49 and 50. The conditional velocity of step 13 satisfies the conditional continuity equation for \(p_t(x\mid a)=\mathcal{N}(\alpha_t a,\sigma_t^2)\), for every Gaussian path. The continuity derivation checks the Case 1 instance by hand, term by term; here it follows in one pass for all schedules.
Result: for \(\psi_t(\varepsilon\mid a)=\alpha_t a+\sigma_t\varepsilon\): the position is \(\mathcal{N}(\alpha_t a,\sigma_t^2 I)\) and the conditional velocity is \(u_t(x\mid a)=\dot\alpha_t a+\frac{\dot\sigma_t}{\sigma_t}(x-\alpha_t a)\). Linear path: \(\frac{a-x}{1-t}=a-\varepsilon\). \(\sigma_{\min}\) path: \(\frac{a-(1-\sigma_{\min})x}{1-(1-\sigma_{\min})t}\). VP-cosine: \(\frac{\pi}{2}\frac{a-\sin(\pi t/2)\,x}{\cos(\pi t/2)}\). In 1-D, for any increasing flow map, CDF bookkeeping shows \(\partial_t p+\partial_x(p v)=0\) with \(v=\dot\psi\circ\psi_t^{-1}\), so each conditional field transports its conditional path, which is the ingredient that the conditional flow matching theorem needs.
Flow matching with any coupling, and why optimal-transport pairs do not cross
Goal: prove the conditional flow matching theorem for an arbitrary coupling \(\pi(\varepsilon,a)\) of source and data on the linear path (the marginal field \(v=\mathbb{E}[a-\varepsilon\mid a_t=x]\) generates \(p_t\), and pair regression has the same gradient as marginal regression); then define minibatch optimal-transport pairing, show it is a valid coupling, and prove that its straight segments cannot cross at the same time.
- \[ (\varepsilon,a)\sim\pi,\quad \pi\ \text{with marginals } p_0 \text{ (of }\varepsilon) \text{ and } p_1 \text{ (of } a),\quad a_t=(1-t)\,\varepsilon+t\,a,\quad u=a-\varepsilon . \]
Setup. Part A. The coupling \(\pi\) is any joint law whose \(\varepsilon\)-marginal is the source \(p_0\) and whose \(a\)-marginal is the data \(p_1\). The independent coupling \(\pi=p_0\times p_1\) is one choice; minibatch optimal transport (Part C) is another. We drop \(o\) from the notation: read every law as conditional on \(o\). We assume \(\mathbb{E}\|\varepsilon\|\lt\infty\) and \(\mathbb{E}\|a\|\lt\infty\).
- \[ v(x,t):=\mathbb{E}\big[\,a-\varepsilon\ \big|\ a_t=x\,\big],\qquad p_t:=\text{law of } a_t . \]
The marginal field and the marginal path. Nothing in the definition uses independence of \(\varepsilon\) and \(a\).
- \[ \varphi\in C_c^\infty(\mathbb{R}^d),\qquad m(t):=\mathbb{E}\big[\varphi(a_t)\big]=\int\varphi(x)\,p_t(x)\,dx . \]
We avoid conditional densities by working with a test function \(\varphi\): smooth, zero outside a bounded set. \(m(t)\) is the average of \(\varphi\) under \(p_t\). The second equality is the definition of the law of \(a_t\) (assume \(p_t\) has a density).
- \[ \frac{d}{dt}a_t=\frac{d}{dt}\big((1-t)\,\varepsilon+t\,a\big)=a-\varepsilon=u . \]
Differentiate the path of step 1 in \(t\) for fixed \((\varepsilon,a)\): \(\frac{d}{dt}(1-t)=-1\) and \(\frac{d}{dt}t=1\).
- \[ \frac{d}{dt}\varphi(a_t)=\nabla\varphi(a_t)\cdot\frac{d a_t}{dt}=\nabla\varphi(a_t)\cdot u . \]
Chain rule for a scalar function of a curve, then step 4.
- \[ m'(t)=\mathbb{E}\big[\nabla\varphi(a_t)\cdot u\big] . \]
Differentiate \(m(t)=\mathbb{E}[\varphi(a_t)]\) of step 3. Exchanging \(\frac{d}{dt}\) and \(\mathbb{E}\) is allowed by dominated convergence: \(\|\nabla\varphi\|\) is bounded and \(\|u\|\le\|a\|+\|\varepsilon\|\) is integrable (step 1).
- \[ \mathbb{E}\big[\nabla\varphi(a_t)\cdot u\big]=\mathbb{E}\Big[\,\mathbb{E}\big[\nabla\varphi(a_t)\cdot u\ \big|\ a_t\big]\,\Big] . \]
Tower property of conditional expectation: condition on \(a_t\) inside, average over \(a_t\) outside.
- \[ \mathbb{E}\big[\nabla\varphi(a_t)\cdot u\ \big|\ a_t\big]=\nabla\varphi(a_t)\cdot\mathbb{E}\big[u\ \big|\ a_t\big]=\nabla\varphi(a_t)\cdot v(a_t,t) . \]
Given \(a_t\), the vector \(\nabla\varphi(a_t)\) is a known constant, so it leaves the conditional expectation (taking out what is known), and the dot product is linear in \(u\). Then the definition of \(v\) in step 2 with \(u=a-\varepsilon\).
- \[ m'(t)=\mathbb{E}\big[\nabla\varphi(a_t)\cdot v(a_t,t)\big]=\int\nabla\varphi(x)\cdot v(x,t)\,p_t(x)\,dx . \]
Insert step 8 into step 7 and step 6. The last equality writes the expectation of a function of \(a_t\) as an integral against its law \(p_t\).
- \[ \frac{d}{dt}\int\varphi\,p_t\,dx=\int\nabla\varphi\cdot(p_t\,v)\,dx\qquad\text{for every test function }\varphi . \]
Combine step 3 with step 9. This is the weak continuity equation: it says that \(v\) moves the mass of \(p_t\), without ever needing a conditional density or a pair-by-pair field.
- \[ \nabla\!\cdot\!\big(\varphi\,w\big)=\nabla\varphi\cdot w+\varphi\,\nabla\!\cdot w,\qquad w:=p_t\,v . \]
Integrate by parts, part 1. Product rule for a scalar times a vector field, per coordinate: \(\partial_i(\varphi w_i)=\partial_i\varphi\,w_i+\varphi\,\partial_i w_i\), then sum over \(i\).
- \[ \int\nabla\!\cdot\!(\varphi\,w)\,dx=0 . \]
Divergence theorem on a ball \(B\) that contains the support of \(\varphi\): \(\int_B\nabla\!\cdot(\varphi w)\,dx=\oint_{\partial B}\varphi\,w\cdot n\,dS=0\), because \(\varphi=0\) on \(\partial B\).
- \[ \int\nabla\varphi\cdot(p_t\,v)\,dx=-\int\varphi\;\nabla\!\cdot(p_t\,v)\,dx . \]
Integrate step 11 over \(\mathbb{R}^d\), use step 12 for the left side, and move the second term to the other side.
- \[ \int\varphi\;\Big[\partial_t p_t+\nabla\!\cdot(p_t\,v)\Big]\,dx=0\qquad\text{for every }\varphi . \]
Differentiate under the integral on the left of step 10 (\(\varphi\) does not depend on \(t\); \(p_t\) is assumed differentiable in \(t\)), insert step 13 on the right, and combine.
- \[ \partial_t p_t+\nabla\!\cdot(p_t\,v)=0 . \]
A continuous function that integrates to zero against every test function is zero everywhere (fundamental lemma of the calculus of variations). So \(v\) satisfies the continuity equation for the path \(p_t\).
- \[ a_0=\varepsilon\sim p_0,\qquad a_1=a\sim p_1 . \]
Endpoints. Set \(t=0\) and \(t=1\) in the path of step 1. The law of \(a_0\) is the \(\varepsilon\)-marginal of \(\pi\), which is \(p_0\), and the law of \(a_1\) is the \(a\)-marginal, which is \(p_1\).
- \[ \dot x=v(x,t),\ x_0\sim p_0\ \Longrightarrow\ x_t\sim p_t,\ \ x_1\sim p_1 . \]
The law of an ODE solution solves the same continuity equation (step 15) from the same start, and that linear equation has a unique solution for a smooth field (as in the CFM proof). So integrating \(v\) from \(p_0\) lands on \(p_1\). Only the marginals of \(\pi\) entered, through step 16. The coupling decides which \(p_t\) in between and which \(v\).
- \[ \mathcal{L}_{\text{marg}}=\mathbb{E}\big\|v_\theta(a_t,t)-v(a_t,t)\big\|^2,\qquad \mathcal{L}_{\text{flow}}=\mathbb{E}\big\|v_\theta(a_t,t)-u\big\|^2 . \]
Part B, the same-gradient argument. Both expectations are over \(t\sim U[0,1]\) and \((\varepsilon,a)\sim\pi\). The first is not computable (it needs \(v\)); the second is, from sampled pairs. The expansion proof for independent pairs is in the CFM proof; here is a shorter route that holds for any coupling.
- \[ v_\theta-u=(v_\theta-v)+(v-u) . \]
Add and subtract \(v=v(a_t,t)\). Write \(v_\theta=v_\theta(a_t,t)\).
- \[ \|v_\theta-u\|^2=\|v_\theta-v\|^2+2\,(v_\theta-v)\cdot(v-u)+\|v-u\|^2 . \]
Square step 19: \(\|p+q\|^2=\|p\|^2+2\,p\cdot q+\|q\|^2\).
- \[ \mathbb{E}\big[(v_\theta-v)\cdot(v-u)\big]=\mathbb{E}\Big[\,\mathbb{E}\big[(v_\theta-v)\cdot(v-u)\ \big|\ a_t\big]\,\Big] . \]
Tower property, as in step 7.
- \[ \mathbb{E}\big[(v_\theta-v)\cdot(v-u)\ \big|\ a_t\big]=(v_\theta-v)\cdot\big(v-\mathbb{E}[u\mid a_t]\big)=(v_\theta-v)\cdot(v-v)=0 . \]
Both \(v_\theta\) and \(v\) are functions of \((a_t,t)\), so they come out of the conditional expectation (taking out what is known). Then \(\mathbb{E}[u\mid a_t]=v\) by step 2.
- \[ \mathcal{L}_{\text{flow}}=\mathcal{L}_{\text{marg}}+C,\qquad C:=\mathbb{E}\|u-v(a_t,t)\|^2 . \]
Take the expectation of step 20; the cross term vanishes by steps 21 and 22, and \(\|v-u\|^2=\|u-v\|^2\).
- \[ \nabla_\theta\mathcal{L}_{\text{flow}}=\nabla_\theta\mathcal{L}_{\text{marg}} . \]
\(C\) contains \(\pi\), the path and \(v\), but no \(\theta\), so \(\nabla_\theta C=0\). Differentiate step 23. Both minimize at \(v_\theta=v\). Note that \(C\) depends on the coupling: it is the irreducible loss, the spread of the pair targets \(u\) around their average \(v\). A coupling with smaller \(C\) gives lower-variance training targets.
- \[ \{\varepsilon_i\}_{i=1}^B\ \text{i.i.d. from } p_0,\qquad \{a_j\}_{j=1}^B\ \text{i.i.d. from } p_1,\qquad C_{ij}=\|\varepsilon_i-a_j\|^2 . \]
Part C, minibatch optimal transport. Draw a batch of \(B\) noise samples and \(B\) actions independently and compute all pairwise squared distances.
- \[ \rho^\star=\arg\min_{\rho}\ \sum_{i=1}^{B}\big\|\varepsilon_i-a_{\rho(i)}\big\|^2 ,\qquad \rho\ \text{a permutation of } \{1,\dots,B\} . \]
The batch assignment problem. (We call the permutation \(\rho\), since \(\sigma\) is already the path noise level.) It is solved exactly by the Hungarian algorithm in \(O(B^3)\) time, once per training batch.
- \[ \pi_B=\frac1B\sum_{i=1}^{B}\delta_{(\varepsilon_i,\ a_{\rho^\star(i)})} . \]
The pairs \((\varepsilon_i,a_{\rho^\star(i)})\), each with probability \(1/B\), form an empirical coupling. Training draws pairs from it and applies the loss of step 18.
- \[ \pi_B(\cdot\times\mathbb{R}^d)=\frac1B\sum_i\delta_{\varepsilon_i}=:\hat p_0 . \]
First marginal of \(\pi_B\): sum over the second slot, which removes it.
- \[ \pi_B(\mathbb{R}^d\times\cdot)=\frac1B\sum_i\delta_{a_{\rho^\star(i)}}=\frac1B\sum_j\delta_{a_j}=:\hat p_1 . \]
Second marginal. \(\rho^\star\) is a bijection, so substituting \(j=\rho^\star(i)\) visits every \(j\) exactly once.
- \[ \pi_B\in\Pi(\hat p_0,\hat p_1),\qquad \mathbb{E}_{\text{batch}}[\hat p_0]=p_0,\quad \mathbb{E}_{\text{batch}}[\hat p_1]=p_1 . \]
By steps 28 and 29, inside one batch \(\pi_B\) is exactly a valid coupling of the two empirical batch distributions, so Part A applies to it. The average of an empirical measure over fresh i.i.d. batches is the true law (linearity of expectation: \(\mathbb{E}\,\delta_{\varepsilon_i}=p_0\)). Hence the training pairs, averaged over batches, have exact marginals \(p_0\) and \(p_1\) (the ones Part A needs, step 16). What is only approximate is optimality. \(\pi_B\) is the optimal plan for the batch, not for the full distributions: it equals the independent coupling at \(B=1\) and approaches the true optimal transport plan as \(B\to\infty\). With observations: pair only actions that share one \(o\). Across different \(o\), the noise paired with an action is no longer \(\mathcal{N}(0,I)\) given that action's \(o\).
- \[ \|\varepsilon_1-a_1\|^2+\|\varepsilon_2-a_2\|^2\ \le\ \|\varepsilon_1-a_2\|^2+\|\varepsilon_2-a_1\|^2 . \]
No-crossing property. Take two pairs of an optimal assignment (step 26). Swapping their partners gives another permutation; the other \(B-2\) pairs are unchanged and cancel from the comparison, so optimality means the swap cannot be cheaper.
- \[ \|\varepsilon_1-a_2\|^2+\|\varepsilon_2-a_1\|^2-\|\varepsilon_1-a_1\|^2-\|\varepsilon_2-a_2\|^2=:\Delta . \]
Define \(\Delta\) as the cost of the swap minus the cost of the original. Step 31 says \(\Delta\ge 0\).
- \[ \|p-q\|^2=\|p\|^2-2\langle p,q\rangle+\|q\|^2 . \]
Expansion of a squared distance, applied to each of the four terms of \(\Delta\).
- \[ \Delta=\big(\|\varepsilon_1\|^2+\|a_2\|^2+\|\varepsilon_2\|^2+\|a_1\|^2\big)-\big(\|\varepsilon_1\|^2+\|a_1\|^2+\|\varepsilon_2\|^2+\|a_2\|^2\big)-2\langle\varepsilon_1,a_2\rangle-2\langle\varepsilon_2,a_1\rangle+2\langle\varepsilon_1,a_1\rangle+2\langle\varepsilon_2,a_2\rangle . \]
Insert step 33 into the four terms of step 32, keeping the squared-norm parts and the inner products apart. The minus signs of the last two squared distances flip the sign of their inner-product terms.
- \[ \Delta=-2\langle\varepsilon_1,a_2\rangle-2\langle\varepsilon_2,a_1\rangle+2\langle\varepsilon_1,a_1\rangle+2\langle\varepsilon_2,a_2\rangle . \]
The two bracketed groups of squared norms in step 34 contain the same four terms, so they cancel.
- \[ \Delta=2\big[\langle\varepsilon_1,a_1\rangle-\langle\varepsilon_1,a_2\rangle-\langle\varepsilon_2,a_1\rangle+\langle\varepsilon_2,a_2\rangle\big]=2\,\langle\varepsilon_1-\varepsilon_2,\ a_1-a_2\rangle . \]
Factor out \(2\), then bilinearity of the inner product: \(\langle\varepsilon_1-\varepsilon_2,a_1-a_2\rangle\) \(=\langle\varepsilon_1,a_1\rangle-\langle\varepsilon_1,a_2\rangle-\langle\varepsilon_2,a_1\rangle+\langle\varepsilon_2,a_2\rangle\).
- \[ \langle\varepsilon_1-\varepsilon_2,\ a_1-a_2\rangle\ \ge\ 0 . \]
Combine \(\Delta\ge 0\) (step 32, from optimality) with step 36. This is cyclical monotonicity for two pairs: in an optimal pairing, the noise displacement and the action displacement between two pairs never point against each other.
- \[ (1-t)\,\varepsilon_1+t\,a_1=(1-t)\,\varepsilon_2+t\,a_2\qquad\text{for some } t\in(0,1) . \]
Suppose the two straight segments are at the same point at the same time \(t\). (Passing through the same point at different times is allowed and does not matter, because the field depends on \((x,t)\).)
- \[ (1-t)\,(\varepsilon_1-\varepsilon_2)=-\,t\,(a_1-a_2) . \]
Move the \(\varepsilon\) terms to the left and the \(a\) terms to the right in step 38.
- \[ \Delta\varepsilon:=\varepsilon_1-\varepsilon_2,\quad \Delta a:=a_1-a_2,\qquad \Delta\varepsilon=-\frac{t}{1-t}\,\Delta a . \]
Abbreviate the differences and divide step 39 by \(1-t\gt 0\).
- \[ \langle\Delta\varepsilon,\Delta a\rangle=-\frac{t}{1-t}\,\|\Delta a\|^2\ \le\ 0 . \]
Insert step 40 into the inner product (the scalar leaves the inner product). \(\frac{t}{1-t}\gt 0\) for \(t\in(0,1)\).
- \[ \Delta=2\,\langle\Delta\varepsilon,\Delta a\rangle=-\,\frac{2t}{1-t}\,\|\Delta a\|^2 . \]
Step 36 with the notation of step 40 and step 41. The swap changes the cost by this amount.
- \[ \Delta\ge 0\ \text{ (step 32)}\quad\text{and}\quad\Delta=-\tfrac{2t}{1-t}\|\Delta a\|^2\le 0\ \Longrightarrow\ \|\Delta a\|=0 . \]
Both hold, so \(\Delta=0\), and since \(\frac{2t}{1-t}\gt 0\) this forces \(\|\Delta a\|^2=0\). Equivalently: unless \(a_1=a_2\), the swapped pairing is strictly cheaper, which contradicts optimality.
- \[ a_1=a_2\ \Rightarrow\ \Delta\varepsilon=-\tfrac{t}{1-t}\cdot 0=0\ \Rightarrow\ \varepsilon_1=\varepsilon_2 . \]
Step 43 gives \(\Delta a=0\); then step 40 gives \(\Delta\varepsilon=0\). The two pairs are the same pair, so the two segments coincide.
- \[ \text{two distinct pairs of an optimal assignment never occupy the same point at the same time } t\in(0,1). \]
Combine steps 43 and 44. At \(t=0\) a meeting means equal noise points and at \(t=1\) equal actions, both of probability zero for continuous distributions.
- \[ v_B(x,t)=\mathbb{E}_{\pi_B}\big[a-\varepsilon\ \big|\ a_t=x\big]=a_i-\varepsilon_i\ \text{ at } x=(1-t)\varepsilon_i+t\,a_{\rho^\star(i)} . \]
Consequence. In the empirical coupling \(\pi_B\) of one batch, each point \((x,t)\) that is hit lies on exactly one segment (step 45), so the conditional expectation has nothing to average and equals that pair's constant velocity. The marginal ODE then follows the straight segments, and \(C=0\) for \(\pi_B\). Caveat: this holds within one batch. Segments from different batches can still cross, so for the batch-averaged coupling \(C\gt 0\) in general, only smaller than for the independent coupling, and the gap closes as \(B\) grows.
Result: (A) For any coupling \(\pi\) with marginals \(p_0,p_1\), the field \(v(x,t)=\mathbb{E}[a-\varepsilon\mid a_t=x]\) satisfies \(\frac{d}{dt}\int\varphi p_t=\int\nabla\varphi\cdot p_tv\) for all test functions, hence \(\partial_t p+\nabla\!\cdot(pv)=0\) with \(p_0\) and \(p_1\) the marginals of \(\pi\). (B) \(\mathcal{L}_{\text{flow}}=\mathcal{L}_{\text{marg}}+C\) with \(C=\mathbb{E}\|u-v\|^2\) free of \(\theta\). (C) Minibatch OT pairs form an exact coupling of the two empirical batches and, averaged over batches, have exact marginals \(p_0,p_1\) (only optimality is approximate). For an optimal pairing, \(\Delta=2\langle\varepsilon_1-\varepsilon_2,a_1-a_2\rangle\ge 0\), and a same-time meeting forces \(\Delta=-\frac{2t}{1-t}\|a_1-a_2\|^2\), so distinct pairs' segments never meet at the same time. That is why OT pairing straightens the marginal paths.
Flow matching IV: training in practice
The loss in full, with the observation and the time density written out, is
The action chunk \(a\) is a vector with one entry per waypoint and joint. Average the squared error over all entries. Nothing here fixes \(p(t)\) or what the network outputs. Both are choices, and they turn out to be one choice.
How to sample t
Uniform \(t\) is the default. Others concentrate samples where the loss is more informative. In this page's convention (\(t = 0\) is noise) the three common densities are
Logit-normal with \(m = 0,\ s = 1\) is symmetric around \(t = 1/2\) and thins out both ends. Esser et al. compared several schedules for training rectified flows and favored it [14]. \(\pi_0\) samples from a Beta(1.5, 1) skewed to the noisy end [26]. Its code uses \(t = 1\) for noise, and the density above is already converted to the convention here.
Why: the irreducible loss
The target \(u = a - \varepsilon\) depends on a pair, but the network sees only \(a_t\) and \(o\). Even the exact marginal field leaves a residual,
The argument in why the simple loss works gives \(\mathcal{L}(\theta) = \mathcal{L}_{\text{marg}}(\theta) + \int L^*(t)\,p(t)\,dt\). Only the first term depends on \(\theta\). At \(t = 0\), \(a_t = \varepsilon\) tells you nothing about \(a\), so \(L^*(0) = \operatorname{tr}\operatorname{Cov}(a \mid o)\), and for a bimodal target this includes the gap between the modes. So a loss that plateaus well above zero does not mean learning stopped. Judge progress on held-out data or by samples. The hard region is where the field changes fast, which for separated modes is the intermediate \(t\) at which the posterior over modes switches from the prior to one mode.
What the network outputs
On the linear path, three outputs carry the same information: a velocity \(\hat v\), a clean-action estimate \(\hat a\), or a noise estimate \(\hat\varepsilon\), related by \(x = t\,\hat a + (1-t)\,\hat\varepsilon\) and \(\hat v = \hat a - \hat\varepsilon\). A loss on each is a weighted velocity loss:
The derivation below shows each step. The \(\varepsilon\) case is the same identity as in the bridge part, read the other way: the velocity loss is an \(\varepsilon\)-loss with weight \(1/t^2\). So the weight on the velocity error is \(w(t) = 1\) for \(v\), \((1-t)^2\) for \(\hat a\), and \(t^2\) for \(\hat\varepsilon\). \(\hat a\)-prediction favors the noisy end and \(\varepsilon\)-prediction the data end.
Changing \(w(t)\) and changing \(p(t)\) both change the same product \(p(t)\,w(t)\), the effective weight on the velocity error. Kingma and Gao make this the unifying view for diffusion: common objectives are weighted integrals of one denoising error over noise level, and differ in the weight [24]. Drawing \(t\) from \(p(t)\) is importance sampling of the weight, which usually gives a lower-variance gradient than weighting a uniform draw.
Pick a density and an output type. Compare the effective weight, the product of the two curves, with \(L^*(t)\). Uniform \(t\) with \(\hat v\) is flat. The \(\pi_0\) density piles up samples at small \(t\).
Conditioning and guidance
The observation \(o\) enters the network exactly as in Diffusion Policy. Classifier-free guidance carries over if you drop \(o\) with some probability in training: at fixed \((x,t)\) the velocity is affine in the score, so \(\tilde v = v(x,t,\varnothing) + w\,[\,v(x,t,o) - v(x,t,\varnothing)\,]\) mixes scores with the same weights. It costs two network calls per step and is standard in image models. This tutorial does not rely on it for policies.
Exact likelihood
Along an ODE trajectory the log-density changes by the divergence, \(\tfrac{d}{dt}\log p_t(x_t) = -\nabla\!\cdot v(x_t, t)\) [17]. To score a chunk \(a\), integrate the ODE backward from \(x_1 = a\) to \(x_0\) and add up the divergence:
The divergence is the trace of a \(d \times d\) Jacobian, where \(d\) is the chunk dimension. Computing it exactly takes \(d\) backward passes per evaluation. Hutchinson's estimator uses \(\operatorname{tr}(J) = \mathbb{E}_z[z^\top J z]\) with \(\mathbb{E}z = 0,\ \operatorname{Cov}z = I\), so one vector-Jacobian product per probe gives an unbiased estimate [18]. Uses include ranking candidate chunks, comparing policies, and flagging observations where the policy puts low density on its own actions. Likelihoods are in normalized action coordinates, and any threshold must be calibrated on held-out data.
Diffusion training minimizes a bound, as in the training part. The probability-flow ODE of a trained diffusion model supports the same formula [5], so the difference is not that diffusion cannot do this. It is that here the ODE is the model you trained and sample from. The flow matching loss is a regression objective, not a likelihood bound. You get the likelihood by running the ODE afterward.
- Normalize actions per dimension, so the unit Gaussian source matches the data scale.
- Keep an exponential moving average of the weights and sample with it.
- Scale the time embedding. A sinusoidal embedding built for integer steps barely changes over \(t \in [0,1]\), so multiply \(t\) by a constant such as 1000.
- Clamp \(t\) away from 1 whenever you divide by \(1-t\): the score, or a network that predicts \(\hat a\). Clamp away from 0 when you divide by \(t\), as with an \(\varepsilon\)-network.
- Check the time convention when you copy code. \(\pi_0\)'s has noise at 1 and regresses \(\varepsilon - a\).
The choice of output (\(v\), \(\hat a\) or \(\hat\varepsilon\)) and the density of \(t\) are two ways to set one thing, the weight on the velocity error at each noise level. The irreducible loss \(L^*(t)\) shows where the target is mostly unpredictable and where the field is hard to fit.
Derivations
Parameterizations on the linear path, and the effective time weighting
Goal: on the linear path, express \(a\) and \(\varepsilon\) through \(x\) and \(u\); show that velocity, clean-action and noise prediction are the same network seen through \(\hat a=x+(1-t)\hat v\), \(\hat\varepsilon=x-t\hat v\); derive \(\|\hat a-a\|^2=(1-t)^2\|\hat v-u\|^2\) and \(\|\hat\varepsilon-\varepsilon\|^2=t^2\|\hat v-u\|^2\); and show that the time-sampling density \(p(t)\) and the parameterization weight \(w(t)\) act only through the product \(p(t)\,w(t)\).
- \[ x=t\,a+(1-t)\,\varepsilon,\qquad u=a-\varepsilon,\qquad t\in(0,1) . \]
Setup. One pair \((\varepsilon,a)\) on the linear path, \(x=a_t\). We drop \(o\) from the notation. The goal is to switch freely between three things a network can output: the velocity, the clean action, or the noise.
- \[ \varepsilon=a-u . \]
Part 1, solve for \(a\) and \(\varepsilon\) from \(x\) and \(u\). Rearrange \(u=a-\varepsilon\).
- \[ x=t\,a+(1-t)\,(a-u) . \]
Substitute step 2 for \(\varepsilon\) in the path of step 1.
- \[ x=t\,a+(1-t)\,a-(1-t)\,u=a-(1-t)\,u . \]
Distribute \((1-t)\) over \((a-u)\), then add the coefficients of \(a\): \(t+(1-t)=1\).
- \[ a=x+(1-t)\,u . \]
Move \((1-t)u\) to the other side of step 4.
- \[ a=\varepsilon+u . \]
Rearrange \(u=a-\varepsilon\) the other way.
- \[ x=t\,(\varepsilon+u)+(1-t)\,\varepsilon=\varepsilon+t\,u . \]
Substitute step 6 for \(a\) in step 1 and add the coefficients of \(\varepsilon\): \(t+(1-t)=1\).
- \[ \varepsilon=x-t\,u . \]
Move \(t\,u\) to the other side of step 7.
- \[ a-\varepsilon=\big(x+(1-t)u\big)-\big(x-tu\big)=(1-t)\,u+t\,u=u . \]
Consistency check of steps 5 and 8: subtracting them returns the velocity.
- \[ \hat a:=x+(1-t)\,\hat v,\qquad \hat\varepsilon:=x-t\,\hat v,\qquad \hat v:=v_\theta(x,t) . \]
Part 2, the network's three views. The network outputs \(\hat v\). Define its implied clean-action and noise estimates by the same formulas as steps 5 and 8, with \(\hat v\) in place of \(u\).
- \[ \hat a-\hat\varepsilon=(1-t)\,\hat v+t\,\hat v=\hat v . \]
Subtract the two definitions of step 10; the \(x\) cancels.
- \[ t\,\hat a+(1-t)\,\hat\varepsilon=t\,x+t(1-t)\hat v+(1-t)\,x-(1-t)\,t\,\hat v=x . \]
Insert step 10. The \(\hat v\) terms \(\pm t(1-t)\hat v\) cancel and \(t+(1-t)=1\). So \((\hat a,\hat\varepsilon)\) lie on the same line through \(x\) as a true pair, with \(\hat v=\hat a-\hat\varepsilon\) (step 11).
- \[ \hat v=\frac{\hat a-x}{1-t}\quad (t\lt 1),\qquad \hat v=\frac{x-\hat\varepsilon}{t}\quad (t\gt 0) . \]
Conversely, a network that outputs \(\hat a\) or \(\hat\varepsilon\) gives a velocity by solving step 10 for \(\hat v\): subtract \(x\) and divide by \(1-t\), or move \(t\hat v\) and divide by \(t\).
- \[ \hat a-a=\big(x+(1-t)\hat v\big)-\big(x+(1-t)u\big) . \]
Part 3, loss identities. Use step 10 for \(\hat a\) and step 5 for \(a\), at the same \((x,t)\).
- \[ \hat a-a=(1-t)\,(\hat v-u) . \]
The \(x\) terms cancel and \((1-t)\) is a common factor.
- \[ \|\hat a-a\|^2=(1-t)^2\,\|\hat v-u\|^2 . \]
Use \(\|c\,w\|^2=c^2\|w\|^2\) for a scalar \(c\), here \(c=1-t\).
- \[ \hat\varepsilon-\varepsilon=\big(x-t\hat v\big)-\big(x-t u\big)=-\,t\,(\hat v-u) . \]
Same move for the noise: step 10 and step 8; the \(x\) terms cancel.
- \[ \|\hat\varepsilon-\varepsilon\|^2=t^2\,\|\hat v-u\|^2 . \]
\(\|c\,w\|^2=c^2\|w\|^2\) with \(c=-t\), and \((-t)^2=t^2\).
- \[ \|\hat v-u\|^2=\frac{\|\hat a-a\|^2}{(1-t)^2}=\frac{\|\hat\varepsilon-\varepsilon\|^2}{t^2} . \]
Solve steps 16 and 18 for \(\|\hat v-u\|^2\). The second form is the identity of the loss-weighting derivation, which went through the \(\varepsilon\) view.
- \[ \hat v-u=\frac{\hat a-a}{1-t} . \]
The division at \(t\to 1\). Divide step 15 by \(1-t\). Any error in the clean-action estimate is amplified by \(1/(1-t)\) in the velocity: at \(t=0.99\) the factor is \(100\), so an error of size \(0.01\) in \(\hat a\) becomes an error of size \(1\) in \(\hat v\).
- \[ x_{\text{next}}=x+\Delta t\;\frac{\hat a-x}{1-t}\quad\xrightarrow{\ \Delta t=1-t\ }\quad x_{\text{next}}=x+(\hat a-x)=\hat a . \]
One Euler step from \(t\) to \(t+\Delta t\) with the converted velocity of step 13. When the last step has \(\Delta t=1-t\), the fraction cancels and the step lands exactly on \(\hat a\). Also, both \(\hat a-x\) and \(1-t\) go to zero as \(t\to 1\) (the path ends at the data), so for a trained network the ratio is a \(0/0\) limit, numerically fragile. The \(\varepsilon\) view has the mirror problem: \(\hat v=(x-\hat\varepsilon)/t\) divides by \(t\to 0\), the noise end.
- \[ g(t):=\mathbb{E}_{\varepsilon,a}\big[\|\hat v-u\|^2\ \big|\ t\big],\qquad \lambda(t):=p(t)\,w(t),\qquad w(t)=\begin{cases}1&\text{velocity (v)}\\(1-t)^2&\text{clean action (x)}\\t^2&\text{noise }(\varepsilon)\end{cases} . \]
Part 4, weights. \(g(t)\) is the velocity-space error at time \(t\) (averaged over pairs). \(w(t)\) is the parameterization weight: training the v-, x- or \(\varepsilon\)-loss is the velocity error times \(1\), \((1-t)^2\) or \(t^2\), by steps 16 and 18. \(p(t)\) is the density from which \(t\) is sampled.
- \[ \mathcal{L}_{p,w}=\mathbb{E}_{t\sim p}\Big[\,w(t)\,g(t)\,\Big]=\int_0^1 p(t)\,w(t)\,g(t)\,dt . \]
Tower property over \(t\) (average over \(\varepsilon,a\) given \(t\), then over \(t\)), and the definition of an expectation under the density \(p\).
- \[ \mathcal{L}_{p,w}=\int_0^1\lambda(t)\,g(t)\,dt . \]
Insert \(\lambda=p\,w\) from step 22. The sampling density and the parameterization enter only through their product: the effective weight on the velocity error is \(p(t)\,w(t)\).
- \[ \mathbb{E}_{t\sim p}\big[f(t)\big]=\int_0^1 p(t)\,f(t)\,dt . \]
Importance-weighting identity: definition of the expectation under \(p\).
- \[ \int_0^1 p(t)\,f(t)\,dt=\int_0^1 1\cdot\big(p(t)\,f(t)\big)\,dt=\mathbb{E}_{t\sim U[0,1]}\big[\,p(t)\,f(t)\,\big] . \]
The uniform density on \([0,1]\) equals \(1\), so multiplying the integrand by \(1\) turns the integral into a uniform-time expectation.
- \[ \mathbb{E}_{t\sim p}\big[f(t)\big]=\mathbb{E}_{t\sim U}\big[\,p(t)\,f(t)\,\big] . \]
Chain steps 25 and 26. Sampling \(t\) from \(p\) and not reweighting is the same objective as sampling \(t\) uniformly and multiplying the loss at \(t\) by \(p(t)\).
- \[ \mathcal{L}_{p,w}=\mathbb{E}_{t\sim U}\big[\,p(t)\,w(t)\,g(t)\,\big] . \]
Apply step 27 with \(f=w\,g\) to step 23.
- \[ \begin{aligned}\text{x-loss, }t\sim U:&\quad \lambda=(1-t)^2\cdot 1=(1-t)^2,\\ \varepsilon\text{-loss, }t\sim U:&\quad \lambda=t^2,\\ \text{v-loss, }t\sim p:&\quad \lambda=p(t).\end{aligned} \]
Three examples read off from step 24. The x-loss with uniform \(t\) puts weight \(0.01\) at \(t=0.9\) and \(1\) at \(t=0\): it nearly ignores the data end. For the v-loss with the \(\pi_0\) density \(p(t)=1.5\,(1-t)^{1/2}\) the weight is large at the noisy end \(t\to 0\) and falls to \(0\) at \(t=1\). A logit-normal \(p(t)\) peaks in the middle.
- \[ \arg\min_{v_\theta}\ \mathcal{L}_{p,w}=v(x,t)\quad\text{for every } \lambda\gt 0 . \]
With unlimited capacity, the weights change nothing about the optimum. At each fixed \(t\) the error \(g(t)\) is minimized by \(v_\theta(x,t)=v(x,t)=\mathbb{E}[u\mid a_t=x]\) (the decomposition of the coupling derivation), so any positive weighting has the same minimizer. The weights decide only where a finite-capacity network spends its accuracy, and how large the gradient noise is at each \(t\).
- \[ \int_0^1\lambda(t)\,dt\ \ \text{rescales the loss; it does not move the minimizer.} \]
A weight that is not normalized, such as \((1-t)^2\) with integral \(1/3\), only scales the loss, which matters for the learning rate but not for the optimum. When one samples \(t\sim p\) in practice, step 27 shows the price of the equivalent uniform reweighting: if \(p\) is sharply peaked, \(p(t)\,w(t)\,g(t)\) under uniform \(t\) typically has higher variance than sampling \(t\) from \(p\) directly, so sampling from \(p\) is the usual way to realize the same objective.
Result: \(a=x+(1-t)u\), \(\varepsilon=x-tu\); a velocity network implies \(\hat a=x+(1-t)\hat v\), \(\hat\varepsilon=x-t\hat v\) with \(x=t\hat a+(1-t)\hat\varepsilon\) and \(\hat v=\hat a-\hat\varepsilon\). Hence \(\|\hat a-a\|^2=(1-t)^2\|\hat v-u\|^2\) and \(\|\hat\varepsilon-\varepsilon\|^2=t^2\|\hat v-u\|^2\). The x-to-velocity conversion \(\hat v=(\hat a-x)/(1-t)\) amplifies errors by \(1/(1-t)\) near the data end. A loss with time density \(p(t)\) and parameterization weight \(w(t)\) is a velocity loss with effective weight \(p(t)\,w(t)\), and by \(\mathbb{E}_{t\sim p}[f]=\mathbb{E}_{t\sim U}[p\,f]\) changing \(p\) is the same as reweighting the uniform-time loss. The optimum \(v_\theta=v\) does not depend on the weights.
Exact log-likelihood from the flow: the instantaneous change of variables and Hutchinson's trace
Goal: derive \(\frac{d}{dt}\log p_t(x_t)=-\nabla\!\cdot v(x_t,t)\) from the continuity equation, turn it into an algorithm for \(\log p_1(a)\) of a given action, make the divergence cheap with Hutchinson's estimator, and check the formula on a linear field.
- \[ \partial_t p_t(x)+\nabla\!\cdot\big(p_t(x)\,v(x,t)\big)=0,\qquad \nabla\!\cdot w:=\sum_{i=1}^{d}\partial_{x_i}w_i . \]
Start from the continuity equation (derived in the continuity derivation; it holds for the marginal field by the CFM proof). \(x\in\mathbb{R}^d\), and \(v\) is smooth and Lipschitz in \(x\), so ODE solutions exist and are unique. We drop \(o\) from the notation: read every density as conditional on \(o\). The goal is an exact formula for \(\log p_1\), with no lower bound.
- \[ \partial_{x_i}\big(p\,v_i\big)=v_i\,\partial_{x_i}p+p\,\partial_{x_i}v_i . \]
Part 1, a total derivative along a trajectory. Product rule, one coordinate \(i\) at a time. Here \(p=p_t(x)\) and \(v_i\) is the \(i\)-th component of \(v(x,t)\).
- \[ \nabla\!\cdot(p\,v)=\sum_i v_i\,\partial_{x_i}p+p\sum_i\partial_{x_i}v_i=v\cdot\nabla p+p\,\nabla\!\cdot v . \]
Sum step 2 over \(i=1,\dots,d\). \(\sum_i v_i\partial_{x_i}p\) is the dot product of \(v\) with the gradient of \(p\).
- \[ \partial_t p=-\,v\cdot\nabla p-p\,\nabla\!\cdot v . \]
Insert step 3 into step 1 and move everything except \(\partial_t p\) to the right.
- \[ \dot x_t=v(x_t,t),\qquad q(t):=p_t(x_t) . \]
Follow one ODE trajectory and record the density at the moving point. \(q(t)\) is a function of one variable.
- \[ \frac{dq}{dt}=\partial_t p+\sum_i\partial_{x_i}p\;\dot x_i=\partial_t p+\nabla p\cdot\dot x_t . \]
Multivariable chain rule: \(q(t)=p(x_t,t)\) depends on \(t\) directly and through the \(d\) coordinates of \(x_t\).
- \[ \frac{dq}{dt}=\partial_t p+\nabla p\cdot v . \]
Insert \(\dot x_t=v(x_t,t)\) from step 5 into step 6.
- \[ \frac{dq}{dt}=\big(-v\cdot\nabla p-p\,\nabla\!\cdot v\big)+\nabla p\cdot v=-\,p\,\nabla\!\cdot v . \]
Substitute \(\partial_t p\) from step 4 into step 7. The two terms \(\mp v\cdot\nabla p\) cancel (the dot product is symmetric). The density at a moving particle changes only through the divergence of the flow; the transport term \(v\cdot\nabla p\) is exactly what moving along the trajectory removes.
- \[ \frac{d}{dt}\log p_t(x_t)=\frac{1}{q}\,\frac{dq}{dt}=-\,\nabla\!\cdot v(x_t,t) . \]
Chain rule for the logarithm, \(\frac{d}{dt}\log q=\frac{1}{q}\frac{dq}{dt}\), then divide step 8 by \(q=p_t(x_t)\gt 0\). This is the instantaneous change of variables.
- \[ \log p_1(x_1)-\log p_0(x_0)=-\int_0^1\nabla\!\cdot v(x_t,t)\,dt . \]
Integrate step 9 from \(t=0\) to \(t=1\) (fundamental theorem of calculus). We need \(p_1\) to have a density, so that \(\log p_1(x_1)\) is finite.
- \[ \log p_1(x_1)=\log p_0(x_0)-\int_0^1\nabla\!\cdot v(x_t,t)\,dt . \]
Move \(\log p_0(x_0)\) to the right side of step 10. Reading: positive divergence means the flow expands volume, so the density thins out and \(\log p\) drops; negative divergence compresses and raises it.
- \[ x_1=a,\qquad \frac{dx}{dt}=v(x,t)\ \text{ integrated from } t=1\ \text{down to } t=0\ \ \Rightarrow\ \ x_0 . \]
Part 2, the likelihood of a given action. Step 11 needs the trajectory that ends at the action \(a\). Start at \(x_1=a\) and solve the ODE backward in time. Because solutions of an ODE with a Lipschitz field are unique, exactly one starting noise \(x_0\) leads to \(a\).
- \[ \frac{d}{dt}\begin{pmatrix}x\\ \ell\end{pmatrix}=\begin{pmatrix}v(x,t)\\ -\nabla\!\cdot v(x,t)\end{pmatrix},\qquad \ell(1)=0 . \]
Carry the integral along as an extra state. With \(\ell(t):=\int_t^1\nabla\!\cdot v(x_\tau,\tau)\,d\tau\) we have \(\ell(1)=0\) and, by the fundamental theorem of calculus, \(\dot\ell=-\nabla\!\cdot v\). One backward solve of this augmented ODE gives both \(x_0\) and \(\ell(0)\).
- \[ \ell(0)=\int_0^1\nabla\!\cdot v(x_t,t)\,dt . \]
Set \(t=0\) in the definition of \(\ell\) in step 13.
- \[ \log p_0(x_0)=\log\mathcal{N}(x_0;0,I)=-\frac d2\log(2\pi)-\frac12\|x_0\|^2 . \]
Log of the standard Gaussian density \((2\pi)^{-d/2}e^{-\|x\|^2/2}\).
- \[ \log p_1(a)=-\frac d2\log(2\pi)-\frac12\|x_0\|^2-\ell(0) . \]
Insert steps 15 and 14 into step 11 with \(x_1=a\). With a trained \(v_\theta\), this is the exact log-likelihood of the model density \(p_\theta\) (up to ODE solver error). Diffusion gives only a lower bound (the ELBO derivation). A caveat: if the data lie on a lower-dimensional set, \(p_1\) has no density and the number is meaningless, so one evaluates it on a slightly smoothed distribution (for example \(\sigma_{\min}\gt 0\)).
- \[ J(x,t):=\frac{\partial v}{\partial x},\quad J_{ij}=\frac{\partial v_i}{\partial x_j},\qquad \nabla\!\cdot v=\sum_i\frac{\partial v_i}{\partial x_i}=\sum_i J_{ii}=\mathrm{tr}\,J . \]
Part 3, the cost of the divergence, and Hutchinson's estimator. The divergence is the sum of the diagonal entries of the Jacobian, which is the trace. Computing the trace exactly needs the diagonal of \(J\): \(d\) separate backward passes through the network, where \(d\) is the chunk dimension (horizon times action dimension). We want one.
- \[ \mathbb{E}[z]=0,\qquad \mathbb{E}\big[zz^\top\big]=I . \]
A random probe vector \(z\in\mathbb{R}^d\) with identity covariance: standard Gaussian, or independent \(\pm 1\) signs (Rademacher).
- \[ z^\top J z=\mathrm{tr}\big(z^\top (J z)\big) . \]
The scalar \(z^\top J z\) equals the trace of the \(1\times 1\) matrix \(z^\top(Jz)\).
- \[ \mathrm{tr}\big(z^\top (Jz)\big)=\mathrm{tr}\big((Jz)\,z^\top\big)=\mathrm{tr}\big(J\,zz^\top\big) . \]
Cyclic property \(\mathrm{tr}(AB)=\mathrm{tr}(BA)\) with \(A=z^\top\) (\(1\times d\)) and \(B=Jz\) (\(d\times 1\)). Then \((Jz)z^\top=J(zz^\top)\) by associativity.
- \[ \mathbb{E}\big[z^\top Jz\big]=\mathbb{E}\big[\mathrm{tr}(J\,zz^\top)\big]=\mathrm{tr}\big(J\,\mathbb{E}[zz^\top]\big) . \]
Combine steps 19 and 20. The trace and multiplication by the fixed matrix \(J\) are linear, so they commute with the expectation.
- \[ \mathbb{E}\big[z^\top Jz\big]=\mathrm{tr}(J\,I)=\mathrm{tr}\,J=\nabla\!\cdot v . \]
Insert \(\mathbb{E}[zz^\top]=I\) from step 18. So \(z^\top Jz\) is an unbiased estimate of the divergence.
- \[ z^\top Jz=\sum_{i,j}z_i\,J_{ij}\,z_j,\qquad \mathbb{E}[z_iz_j]=\delta_{ij}\ \Rightarrow\ \mathbb{E}\big[z^\top Jz\big]=\sum_i J_{ii} . \]
Check in coordinates. Expand the quadratic form; step 18 says \(\mathbb{E}[z_iz_j]=1\) if \(i=j\) and \(0\) otherwise, so only the diagonal survives. For Rademacher \(z_i^2=1\) exactly, so the diagonal contributes no variance.
- \[ \frac{\partial}{\partial x_j}\Big(\sum_i z_i\,v_i(x,t)\Big)=\sum_i z_i\,J_{ij}=\big(z^\top J\big)_j . \]
One backward pass. The gradient with respect to \(x\) of the scalar \(z^\top v(x,t)\) is the row vector \(z^\top J\). This is a vector-Jacobian product, which reverse-mode autodiff computes with one backward pass through the network, at about the cost of one forward pass.
- \[ \big(z^\top J\big)\,z=z^\top Jz . \]
One dot product of the result of step 24 with \(z\) gives the estimate of step 22. Cost per evaluation: one forward and one backward pass, instead of \(d\) backward passes.
- \[ \mathbb{E}_z\Big[\int_0^1 z^\top J(x_t,t)\,z\,dt\Big]=\int_0^1\mathbb{E}_z\big[z^\top J(x_t,t)\,z\big]\,dt=\int_0^1\nabla\!\cdot v\,dt . \]
Inside an ODE solver, draw \(z\) once and keep it fixed for the whole trajectory, so the augmented ODE of step 13 stays deterministic. Because \(x_t\) does not depend on \(z\), the expectation commutes with the time integral, and step 22 at each \(t\) gives the integral of step 14. Hence \(\log p_1(a)\) in step 16 is estimated without bias, since it is linear in \(\ell(0)\) and \(x_0\) does not depend on \(z\).
- \[ v(x,t)=c\,x,\qquad c\in\mathbb{R},\qquad x_0\sim\mathcal{N}(0,I) . \]
Part 4, sanity check against the change-of-variables formula. A linear field, with \(c\) a constant.
- \[ \dot x=c\,x\ \Rightarrow\ x_t=e^{ct}\,x_0,\qquad x_1=e^{c}\,x_0 . \]
Solve the linear ODE (separate variables \(\dot x/x=c\)).
- \[ \nabla\!\cdot v=\sum_{i=1}^{d}\partial_{x_i}(c\,x_i)=d\,c . \]
Differentiate each coordinate, \(\partial_{x_i}(c\,x_i)=c\), and sum over \(d\) coordinates.
- \[ \int_0^1\nabla\!\cdot v\,dt=\int_0^1 d\,c\,dt=d\,c . \]
The divergence of step 29 does not depend on \(t\) or \(x\).
- \[ \log p_1(x_1)=\log p_0(x_0)-d\,c . \]
Insert step 30 into the main formula, step 11.
- \[ x_1=A\,x_0,\quad A=e^{c}I,\quad \log p_1(x_1)=\log p_0(A^{-1}x_1)-\log|\det A| . \]
Now the classical change of variables for an invertible linear map \(x_1=Ax_0\), applied to the map of step 28.
- \[ \det A=\det\big(e^{c}I\big)=\big(e^{c}\big)^d=e^{c\,d}\ \Rightarrow\ \log|\det A|=c\,d,\qquad A^{-1}x_1=x_0 . \]
The determinant of \(e^{c}I\) is the product of its \(d\) equal diagonal entries.
- \[ \log p_1(x_1)=\log p_0(x_0)-c\,d . \]
Insert step 33 into step 32. It equals step 31: the integrated divergence is the log-determinant. For a matrix field \(v=Cx\) the same works, because \(\det e^{C}=e^{\mathrm{tr}\,C}\) (Jacobi's formula) and \(\nabla\!\cdot v=\mathrm{tr}\,C\).
- \[ p_1=\mathcal{N}\big(0,e^{2c}I\big):\quad \log p_1(x_1)=-\frac d2\log(2\pi)-d\,c-\frac12\,e^{-2c}\|x_1\|^2 . \]
Closed-form check. \(x_1=e^{c}x_0\) with \(x_0\sim\mathcal{N}(0,I)\) has covariance \(e^{2c}I\). Log of the Gaussian density: \(-\frac d2\log(2\pi e^{2c})-\frac{\|x_1\|^2}{2e^{2c}}\), and \(\frac d2\log e^{2c}=dc\).
- \[ \log p_0(x_0)-d\,c=-\frac d2\log(2\pi)-\frac12\|x_0\|^2-d\,c\ \overset{x_0=e^{-c}x_1}{=}\ -\frac d2\log(2\pi)-\frac12\,e^{-2c}\|x_1\|^2-d\,c . \]
Step 31 with step 15 and the backward solution \(x_0=e^{-c}x_1\) from step 28. It matches step 35 exactly.
Result: Along a trajectory of \(\dot x=v(x,t)\), \(\frac{d}{dt}\log p_t(x_t)=-\nabla\!\cdot v\), so \(\log p_1(a)=-\frac d2\log 2\pi-\frac12\|x_0\|^2-\int_0^1\nabla\!\cdot v\,dt\), where \(x_0\) comes from integrating the ODE backward from \(x_1=a\) together with the accumulated divergence. The divergence is \(\mathrm{tr}\,\partial v/\partial x\); Hutchinson's \(\mathbb{E}[z^\top Jz]=\mathrm{tr}\,J\) for \(\mathbb{E}[zz^\top]=I\) estimates it with one vector-Jacobian product. For \(v=cx\) the formula reproduces the log-determinant \(cd\) of the linear map \(e^{c}I\). Unlike the diffusion ELBO, this is an exact likelihood of the model density.
Flow matching V: sampling with ODE solvers
A trained \(v_\theta\) defines the ODE \(\dot a = v_\theta(a, t, o)\). Sampling is numerical integration from \(t = 0\) to \(t = 1\) over a grid \(0 = t_0 \lt t_1 \lt \dots \lt t_N = 1\), with step \(h_n = t_{n+1} - t_n\). Euler, which the idea part used, is the simplest rule. Better rules spend more network calls per step to follow the path more closely.
The solvers
Euler is \(a_{n+1} = a_n + h\,v(a_n, t_n)\). Midpoint evaluates the field at the middle of the step, and RK4 combines four evaluations. Heun, the second-order rule used in EDM [21], takes an Euler step, re-evaluates the field at its end point, and averages the two slopes:
EDM skips the correction in its last step, so \(N\) steps cost \(2N - 1\) evaluations. A solver of order \(p\) has local error of order \(h^{p+1}\) per step. Over \(N \approx 1/h\) steps the errors add up to a global error of order \(h^p\). For Euler the local term is the \(\tfrac12 h^2\) times acceleration from the few-step part. The derivation below shows how the orders arise.
| Solver | Evaluations per step | Global order \(p\) | Error at a budget of \(N_e\) evaluations |
|---|---|---|---|
| Euler | 1 | 1 | \(\propto N_e^{-1}\) |
| Midpoint | 2 | 2 | \(\propto N_e^{-2}\) |
| Heun | 2 | 2 | \(\propto N_e^{-2}\) |
| RK4 | 4 | 4 | \(\propto N_e^{-4}\) |
The cost that matters is the number of function evaluations (NFE), because each one is a network forward pass. The observation encoder does not depend on \(t\), so you can run it once and pay the action network only per evaluation. Compare solvers at equal NFE. Heun with 5 steps costs about the same as Euler with 10.
Choose an NFE budget and compare the trajectories with the RK4-400 reference, then read the slopes on the log-log plot. In theory the slopes are 1, 2, 2 and 4. On the sharp two-mode target the fitted slopes over NFE 16 to 64 come out lower, roughly 1, 1.5, 1.6 and 2.8, because the field changes quickly near \(t = 1\) where the modes are narrow; a smoother target recovers the textbook orders. At the smallest budgets higher order does not win, because the error formula holds only when \(h\) is small against the scale on which the field changes. And where the field is not smooth, the observed slope falls below the nominal one. Multimodal fields change fast near the boundary between modes. Near \(t = 1\) the field is also stiff: inside a narrow mode it behaves like \((m - x)/(1-t)\), a pull whose strength grows without bound, so steps must shrink with \(1 - t\).
Time-step schedules
The grid need not be uniform. Write \(t_n = s(n/N)\) with a monotone warp \(s\). For example \(s(u) = 1 - (1-u)^2\) takes large steps near \(t = 0\), where the field is smooth, and small ones near \(t = 1\). EDM does the same with a power-law schedule that concentrates steps at low noise [21], which here means \(t\) near 1. The goal is equal error per step. A uniform grid wastes evaluations where the field is nearly constant. Adaptive solvers choose the step from an error estimate, but then NFE varies from chunk to chunk, which a fixed control rate does not allow.
Adding noise back: an SDE with the same marginals
The ODE is not the only process that follows \(p_t\). For any noise level \(g_t \ge 0\), the SDE
has the same marginals \(p_t\) as the ODE, and \(g_t = 0\) gives back the ODE. The score is computed from the velocity, so no new network is needed. The derivation below checks the marginals with the Fokker-Planck equation and derives the score formula, which holds for \(t \lt 1\). The drift term adds a push toward higher density to balance the noise. A particular \(g_t\) recovers the reverse SDE of the score view, and \(g_t\) plays the role of DDIM's \(\eta\) in the sampling part.
Noise helps in two ways. With an accurate score, the push toward density corrects earlier errors, while an ODE carries them forward. And the noise is a second source of randomness besides \(\varepsilon\): a sample can still change its mind while its mode is undecided, so it is not fixed by the start alone. RL exploration needs exactly this. It costs steps. The noise must be resolved, so SDE samplers typically need smaller steps than ODE samplers for the same accuracy. In practice \(g_t\) should shrink toward 0 as \(t \to 1\), because the score has a \(1/(1-t)\) factor that amplifies any error in the last steps. Noise also makes the policy a stochastic Markov chain with per-step likelihoods, which RL fine-tuning of flow policies uses [33].
DDIM and flow Euler are the same update on the linear schedule, shown in the bridge part. On other schedules they differ: DDIM takes Euler steps in the rescaled variable \(a_t/\alpha_t\), and flow Euler takes them in \(a_t\). Do not assume a diffusion sampler's step count transfers to a flow solver without testing.
Sampling cost is NFE, and error falls as \(h^p\) only while the field is smooth enough for the order to matter. Higher order pays off at moderate budgets where the field is smooth. At the very small budgets robot policies aim for, the curvature of the field is the limit, which the next part addresses.
Derivations
Order of accuracy of ODE solvers: Euler, Heun, midpoint, RK4
Goal: derive, by Taylor expansion, how fast the error of Euler, Heun, midpoint and RK4 shrinks with the step \(h\) for the sampling ODE \(\dot x=v(x,t)\); show how local error \(O(h^{p+1})\) accumulates to global error \(O(h^p)\); verify the eight order conditions of RK4 by arithmetic; compare the methods at an equal budget of network evaluations.
- \[ \dot x(t)=v\big(x(t),t\big),\qquad x(t)=x \ \text{given},\qquad h\gt 0 . \]
The flow-matching sampling ODE, \(x\in\mathbb{R}^d\), advanced over one step from \(t\) to \(t+h\). Below \(v\), \(\partial_t v\), \(\nabla v\) (the Jacobian with entries \(\partial v_i/\partial x_j\)) are all evaluated at \((x,t)\) unless a different argument is shown. Notation: \(O(h^k)\) means a remainder bounded by \(Ch^k\) for small \(h\). We assume \(v\) is smooth enough for every derivative that appears.
- \[ x(t+h)=x+h\,\dot x+\frac{h^2}{2}\,\ddot x+\frac{h^3}{6}\,\dddot x+O(h^4),\qquad \dot x,\ddot x,\dddot x \text{ at } t . \]
Part (i): the exact solution. Taylor expansion of \(x(\cdot)\) around \(t\), to third order with a fourth-order remainder.
- \[ \dot x = v . \]
The ODE of step 1.
- \[ \ddot x=\frac{d}{dt}\,v\big(x(t),t\big)=\partial_t v+(\nabla v)\,\dot x . \]
Differentiate step 3 in \(t\). Multivariable chain rule: \(v\) depends on \(t\) directly and through \(x(t)\).
- \[ \ddot x=\partial_t v+(\nabla v)\,v=:\dot v . \]
Replace \(\dot x\) by \(v\) (step 3). We name the result \(\dot v\): the derivative of \(v\) along the path, that is, the acceleration of a particle riding the field.
- \[ \dddot x=\frac{d}{dt}\,\dot v=:\ddot v . \]
Differentiate \(\ddot x=\dot v\) once more along the path and name the result \(\ddot v\). The next four steps expand it.
- \[ \frac{d}{dt}\big(\partial_t v\big)=\partial_{tt}v+(\nabla\partial_t v)\,v . \]
First piece of \(\ddot v=\frac{d}{dt}\big[\partial_t v+(\nabla v)v\big]\). Chain rule applied to the function \(\partial_t v(x(t),t)\), with \(\dot x=v\).
- \[ \frac{d}{dt}\big[(\nabla v)\,v\big]=\Big(\frac{d}{dt}\nabla v\Big)v+(\nabla v)\,\dot v . \]
Second piece. Product rule, and \(\frac{d}{dt}v=\dot v\) by step 5.
- \[ \frac{d}{dt}\nabla v=\partial_t\nabla v+(\nabla^2 v)[v,\cdot\,] . \]
Chain rule applied to the Jacobian \(\nabla v(x(t),t)\). Here \((\nabla^2 v)[v,w]_i=\sum_{j,k}\frac{\partial^2 v_i}{\partial x_j\partial x_k}\,v_j\,w_k\).
- \[ \ddot v=\partial_{tt}v+2(\nabla\partial_t v)\,v+(\nabla^2 v)[v,v]+(\nabla v)\,\partial_t v+(\nabla v)^2 v . \]
Add steps 7 and 8. In 8 insert step 9 for \(\frac{d}{dt}\nabla v\) and step 5 for \(\dot v\). The two mixed terms \((\nabla\partial_t v)v\) and \((\partial_t\nabla v)v\) are equal because mixed partial derivatives commute (Schwarz), which gives the factor 2. The point of this formula: \(\ddot v\) contains the second derivatives of \(v\).
- \[ x(t+h)=x+h\,v+\frac{h^2}{2}\,\dot v+\frac{h^3}{6}\,\ddot v+O(h^4) . \]
Insert steps 3, 5 and 6 into step 2. Call this the exact expansion (E). Every method below is compared with it.
- \[ x_{\mathrm{E}}=x+h\,v . \]
Part (ii): Euler. One step with the velocity at the start of the step.
- \[ \delta_{\mathrm{E}}:=x(t+h)-x_{\mathrm{E}}=\frac{h^2}{2}\,\dot v+O(h^3) . \]
Subtract step 12 from (E) in step 11. The terms \(x\) and \(hv\) cancel; the \(h^3\) term and the remainder merge into \(O(h^3)\).
- \[ \|\delta\|\le C\,h^{p+1}\ \Longrightarrow\ \text{order } p;\qquad \text{Euler: } \|\delta_{\mathrm{E}}\|\approx\tfrac{h^2}{2}\|\dot v\|\ \Rightarrow\ p=1 . \]
Definition: a method has order \(p\) if its local error (the error of one step from an exact starting value) is \(O(h^{p+1})\). By step 13 Euler has local error \(O(h^2)\), with nonzero leading coefficient wherever \(\dot v\neq0\), so \(p=1\).
- \[ x_{n+1}=x_n+h\,v(x_n,t_n)+\delta_n,\quad \|\delta_n\|\le C\,h^2;\qquad y_{n+1}=y_n+h\,v(y_n,t_n),\quad y_0=x_0 . \]
Global error, step 1 of 3 (set-up). Grid \(t_n=nh\), \(N=1/h\) steps. \(x_n=x(t_n)\) is the exact solution and \(y_n\) the Euler iterate. The first equation is the definition of the local error \(\delta_n\) at \(t_n\), bounded by step 13 (\(C\approx\frac12\sup\|\dot v\|\)). We assume \(v\) is \(L\)-Lipschitz in \(x\): \(\|v(y,t)-v(x,t)\|\le L\|y-x\|\).
- \[ y_{n+1}-x_{n+1}=(y_n-x_n)+h\big[v(y_n,t_n)-v(x_n,t_n)\big]-\delta_n . \]
Subtract the two equations of step 15.
- \[ e_{n+1}\le e_n+hL\,e_n+C\,h^2=(1+hL)\,e_n+C\,h^2,\qquad e_n:=\|y_n-x_n\| . \]
Triangle inequality on step 16, then the Lipschitz bound on the bracket and \(\|\delta_n\|\le Ch^2\). This is the recursion \(e_{n+1}\le(1+hL)e_n+Ch^2\): old error is kept and amplified by \(1+hL\), and each step adds a new local error.
- \[ e_n\le C\,h^2\sum_{j=0}^{n-1}(1+hL)^j . \]
Global error, step 2 of 3 (unroll). Induction from \(e_0=0\). For \(n=1\): \(e_1\le Ch^2\). If it holds for \(n\), step 17 gives \(e_{n+1}\le(1+hL)\,Ch^2\sum_{j=0}^{n-1}(1+hL)^j+Ch^2\) \(=Ch^2\big[\sum_{j=1}^{n}(1+hL)^j+1\big]\) \(=Ch^2\sum_{j=0}^{n}(1+hL)^j\).
- \[ e_n\le C\,h^2\,\frac{(1+hL)^n-1}{hL}=\frac{C\,h}{L}\Big[(1+hL)^n-1\Big] . \]
Geometric sum \(\sum_{j=0}^{n-1}q^j=(q^n-1)/(q-1)\) with ratio \(q=1+hL\neq1\), so \(q-1=hL\).
- \[ (1+hL)^N\le e^{hLN}=e^{L} . \]
Global error, step 3 of 3 (bound the growth). \(1+z\le e^z\) for all real \(z\) (the exponential lies above its tangent at 0, by convexity). Apply it with \(z=hL\), raise both sides to the power \(N\), and use \(hN=1\).
- \[ e_N\le\frac{C\,h}{L}\big(e^{L}-1\big)=O(h) . \]
Set \(n=N\) in step 19 and insert step 20. Reading: \(N=1/h\) steps times a local error \(Ch^2\) gives \(Ch\) (the naive sum). The factor \((e^L-1)/L\ge1\) is the price of error propagation. As \(L\to0\) it tends to 1 and the bound becomes exactly \(NCh^2=Ch\). Euler has local order 2 and global order 1.
- \[ k_1=v(x,t),\qquad k_2=v(x+h\,k_1,\;t+h),\qquad x_{\mathrm{H}}=x+\frac h2\,(k_1+k_2) . \]
Part (iii): Heun. Use the average of the velocity at the start and the velocity at the Euler-predicted end point. Two evaluations of \(v\) per step.
- \[ k_1=v . \]
\(k_1\) is \(v\) at \((x,t)\), by definition in step 22.
- \[ k_2=v+(\nabla v)\,(h\,k_1)+\partial_t v\;h+O(h^2) . \]
First-order Taylor expansion of \(v\) about \((x,t)\), for the increment \((h k_1,\,h)\) in \((x,t)\). The remainder is quadratic in the increment, hence \(O(h^2)\).
- \[ k_2=v+h\big[\partial_t v+(\nabla v)\,v\big]+O(h^2)=v+h\,\dot v+O(h^2) . \]
Insert \(k_1=v\) (step 23), factor out \(h\), and use the definition of \(\dot v\) in step 5.
- \[ k_1+k_2=2v+h\,\dot v+O(h^2) . \]
Add steps 23 and 25.
- \[ x_{\mathrm{H}}=x+\frac h2\big(2v+h\,\dot v+O(h^2)\big)=x+h\,v+\frac{h^2}{2}\,\dot v+O(h^3) . \]
Insert step 26 into the update of step 22. The \(O(h^2)\) remainder is multiplied by \(h/2\), so it becomes \(O(h^3)\).
- \[ x(t+h)-x_{\mathrm{H}}=O(h^3)\ \Longrightarrow\ p=2 . \]
Compare step 27 with (E) in step 11. The terms \(x\), \(hv\) and \(\frac{h^2}{2}\dot v\) agree, so they cancel in the difference. Local error \(O(h^3)\) means order 2 by the definition in step 14. The global order is then 2 by the same three steps as for Euler, with \(Ch^3\) in place of \(Ch^2\) in step 17.
- \[ \dot x=x:\quad k_2=x(1+h),\quad x_{\mathrm{H}}=x\Big(1+h+\frac{h^2}{2}\Big),\quad x(t+h)-x_{\mathrm{H}}=\frac{h^3}{6}\,x+O(h^4) . \]
The order is exactly 2, not higher. Test on \(v(x,t)=x\). Then \(k_1=x\), \(k_2=x+hx\), and \(x_{\mathrm{H}}=x+\frac h2(2x+hx)\). The exact solution is \(x\,e^{h}=x(1+h+\frac{h^2}{2}+\frac{h^3}{6}+\dots)\). The \(h^3\) coefficient is \(\frac16\ne0\).
- \[ k_1=v(x,t),\qquad k_2=v\big(x+\tfrac h2\,k_1,\;t+\tfrac h2\big),\qquad x_{\mathrm{M}}=x+h\,k_2 . \]
Part (iv): midpoint. Take a half Euler step to the middle of the interval, evaluate \(v\) there, and use that velocity for the full step. Two evaluations per step.
- \[ k_2=v+(\nabla v)\Big(\frac h2\,k_1\Big)+\partial_t v\,\frac h2+O(h^2) . \]
Same first-order Taylor expansion as in step 24, now with increment \((\frac h2 k_1,\,\frac h2)\).
- \[ k_2=v+\frac h2\big[\partial_t v+(\nabla v)\,v\big]+O(h^2)=v+\frac h2\,\dot v+O(h^2) . \]
Insert \(k_1=v\) (step 23; the first stage is the same), factor out \(h/2\), and use step 5.
- \[ x_{\mathrm{M}}=x+h\Big(v+\frac h2\,\dot v+O(h^2)\Big)=x+h\,v+\frac{h^2}{2}\,\dot v+O(h^3) . \]
Insert step 32 into the update of step 30 and multiply by \(h\).
- \[ x(t+h)-x_{\mathrm{M}}=O(h^3)\ \Longrightarrow\ p=2 . \]
Step 33 equals step 27, so it matches (E) through \(h^2\), exactly as in step 28. Heun and midpoint agree with the exact expansion through \(h^2\) and differ from each other only at \(h^3\). For \(\dot x=x\) both give \(x(1+h+\frac{h^2}{2})\) (here \(k_2=x(1+\frac h2)\)), so the same \(\frac{h^3}{6}x\) error appears and the order is exactly 2.
- \[ k_i=v\Big(x+h\sum_{j}a_{ij}\,k_j,\;t+c_i h\Big),\qquad x^{+}=x+h\sum_i b_i\,k_i,\qquad c_i=\sum_j a_{ij} . \]
Part (v): RK4 and the order conditions. The general Runge–Kutta step in Butcher form: stage \(i\) uses a weighted combination of earlier stages. The coefficients \(a_{ij}\) (matrix \(A\)), \(b_i\) and \(c_i\) define the method. The row-sum rule \(c_i=\sum_j a_{ij}\) says the time offset matches the state offset. Euler is one stage with \(b_1=1\). Heun and midpoint are two stages.
- \[ \begin{aligned} k_1&=v(x,t), & k_2&=v\big(x+\tfrac h2k_1,\,t+\tfrac h2\big),\\ k_3&=v\big(x+\tfrac h2k_2,\,t+\tfrac h2\big), & k_4&=v\big(x+h\,k_3,\,t+h\big),\end{aligned}\qquad x^{+}=x+\frac h6\,(k_1+2k_2+2k_3+k_4) . \]
The classical RK4 stages. Four evaluations per step. The weights \(\frac16,\frac13,\frac13,\frac16\) average the slope at the start, twice at the midpoint (two different estimates), and at the end.
- \[ c=\Big(0,\tfrac12,\tfrac12,1\Big),\qquad A=\begin{pmatrix}0&0&0&0\\ \tfrac12&0&0&0\\ 0&\tfrac12&0&0\\ 0&0&1&0\end{pmatrix},\qquad b=\Big(\tfrac16,\tfrac13,\tfrac13,\tfrac16\Big) . \]
Read off the Butcher tableau by comparing step 36 with step 35. The only nonzero entries of \(A\) are \(a_{21}=\frac12\), \(a_{32}=\frac12\), \(a_{43}=1\). The row sums are \(0,\frac12,\frac12,1\), equal to \(c\), as the rule requires.
- \[ k_i=v+h\,c_i\,\dot v+O(h^2) . \]
How the conditions arise, at low order. In stage \(i\) the state increment is \(h\sum_j a_{ij}k_j=h\sum_j a_{ij}\,(v+O(h))=h\,c_i\,v+O(h^2)\) (every stage equals \(v+O(h)\); then the row-sum rule). First-order Taylor as in step 24 with increment \((h c_i v,\,c_i h)\) gives \(k_i=v+h c_i[\partial_t v+(\nabla v)v]+O(h^2)\), which is the stated form by step 5.
- \[ x^{+}=x+h\Big(\sum_i b_i\Big)v+h^2\Big(\sum_i b_ic_i\Big)\dot v+O(h^3) . \]
Insert step 38 into the update of step 35 and collect powers of \(h\).
- \[ \sum_i b_i=1,\qquad \sum_i b_ic_i=\frac12 . \]
Match step 39 with (E) in step 11: the coefficient of \(hv\) must be 1 and that of \(h^2\dot v\) must be \(\frac12\). Check Heun: \(b=(\frac12,\frac12)\), \(c=(0,1)\) gives \(1\) and \(\frac12\). Check midpoint: \(b=(0,1)\), \(c=(0,\frac12)\) gives \(1\) and \(\frac12\). This is why both are order 2.
- \[ \begin{array}{lll} \text{order 3:} & \sum_i b_ic_i^2=\tfrac13, & \sum_{i,j} b_ia_{ij}c_j=\tfrac16,\\[2pt] \text{order 4:} & \sum_i b_ic_i^3=\tfrac14, & \sum_{i,j} b_ic_ia_{ij}c_j=\tfrac18,\\[2pt] & \sum_{i,j} b_ia_{ij}c_j^2=\tfrac1{12}, & \sum_{i,j,k} b_ia_{ij}a_{jk}c_k=\tfrac1{24}. \end{array} \]
Continuing the matching of step 39 to higher powers of \(h\) is the content of the order theory of Butcher, which we quote without proof. The coefficient of \(h^q\) in the numerical step is a sum over rooted trees with \(q\) vertices. Each tree gives one equation. Together with the two conditions of step 40 there are \(1+1+2+4=8\) trees with at most 4 vertices, so 8 order conditions for order 4. Each right-hand side is \(1/\gamma\), where \(\gamma\) is the product of the subtree sizes of the tree. We now check all 8 for RK4.
- \[ w_i:=\sum_j a_{ij}c_j=(0,\;0,\;\tfrac12\cdot\tfrac12,\;1\cdot\tfrac12)=\big(0,0,\tfrac14,\tfrac12\big) . \]
A helper vector used in three checks. Row 1 of \(A\) is zero, so \(w_1=0\). Row 2: \(a_{21}c_1=\frac12\cdot0=0\). Row 3: \(a_{32}c_2=\frac12\cdot\frac12=\frac14\). Row 4: \(a_{43}c_3=1\cdot\frac12=\frac12\). Values from step 37.
- \[ q_i:=\sum_j a_{ij}c_j^2=\big(0,\;0,\;\tfrac12\cdot\tfrac14,\;1\cdot\tfrac14\big)=\big(0,0,\tfrac18,\tfrac14\big) . \]
Second helper vector, same rows as step 42 with \(c_j\) squared: \(c_2^2=\frac14\), \(c_3^2=\frac14\).
- \[ r_i:=\sum_{j}a_{ij}\,w_j=\big(0,\;a_{21}w_1,\;a_{32}w_2,\;a_{43}w_3\big)=\big(0,0,0,\tfrac14\big) . \]
Third helper vector. Since \(w_j=\sum_k a_{jk}c_k\), we have \(r_i=\sum_{j,k}a_{ij}a_{jk}c_k\). Row 2: \(\frac12\cdot w_1=0\). Row 3: \(\frac12\cdot w_2=0\). Row 4: \(1\cdot w_3=\frac14\).
- \[ \sum_i b_i=\tfrac16+\tfrac13+\tfrac13+\tfrac16=\tfrac16+\tfrac26+\tfrac26+\tfrac16=\tfrac66=1\ \ \checkmark \]
Check 1 (order 1). Common denominator 6.
- \[ \sum_i b_ic_i=\tfrac16\cdot0+\tfrac13\cdot\tfrac12+\tfrac13\cdot\tfrac12+\tfrac16\cdot1=\tfrac16+\tfrac16+\tfrac16=\tfrac12\ \ \checkmark \]
Check 2 (order 2). Values \(b\), \(c\) from step 37.
- \[ \sum_i b_ic_i^2=\tfrac13\cdot\tfrac14+\tfrac13\cdot\tfrac14+\tfrac16\cdot1=\tfrac1{12}+\tfrac1{12}+\tfrac2{12}=\tfrac4{12}=\tfrac13\ \ \checkmark \]
Check 3 (order 3). The first term has \(c_1=0\).
- \[ \sum_{i,j} b_ia_{ij}c_j=\sum_i b_iw_i=\tfrac13\cdot\tfrac14+\tfrac16\cdot\tfrac12=\tfrac1{12}+\tfrac1{12}=\tfrac16\ \ \checkmark \]
Check 4 (order 3). Use \(w\) from step 42. Only \(i=3\) (\(b_3=\frac13\), \(w_3=\frac14\)) and \(i=4\) (\(b_4=\frac16\), \(w_4=\frac12\)) contribute.
- \[ \sum_i b_ic_i^3=\tfrac13\cdot\tfrac18+\tfrac13\cdot\tfrac18+\tfrac16\cdot1=\tfrac1{24}+\tfrac1{24}+\tfrac4{24}=\tfrac6{24}=\tfrac14\ \ \checkmark \]
Check 5 (order 4). \(c_2^3=c_3^3=\frac18\), \(c_4^3=1\).
- \[ \sum_{i,j} b_ic_ia_{ij}c_j=\sum_i b_ic_iw_i=\tfrac13\cdot\tfrac12\cdot\tfrac14+\tfrac16\cdot1\cdot\tfrac12=\tfrac1{24}+\tfrac2{24}=\tfrac3{24}=\tfrac18\ \ \checkmark \]
Check 6 (order 4). Use \(w\) from step 42. Terms \(i=3\) (\(b_3c_3w_3=\frac13\cdot\frac12\cdot\frac14\)) and \(i=4\) (\(b_4c_4w_4=\frac16\cdot1\cdot\frac12\)).
- \[ \sum_{i,j} b_ia_{ij}c_j^2=\sum_i b_iq_i=\tfrac13\cdot\tfrac18+\tfrac16\cdot\tfrac14=\tfrac1{24}+\tfrac1{24}=\tfrac1{12}\ \ \checkmark \]
Check 7 (order 4). Use \(q\) from step 43.
- \[ \sum_{i,j,k} b_ia_{ij}a_{jk}c_k=\sum_i b_ir_i=\tfrac16\cdot\tfrac14=\tfrac1{24}\ \ \checkmark \]
Check 8 (order 4). Use \(r\) from step 44. Only \(i=4\) contributes.
- \[ x(t+h)-x^{+}=O(h^5)\ \Longrightarrow\ p=4,\qquad e_N\le\frac{C\,h^4}{\tilde L}\big(e^{\tilde L}-1\big) . \]
All 8 conditions of step 41 hold (steps 45 to 52), so the numerical step matches (E) through \(h^4\) and the local error is \(O(h^5)\). The 9 further conditions at order 5 are not all met (no 4-stage explicit method can meet them, a known barrier), so the order is exactly 4. The three-step accumulation argument of steps 15 to 21 goes through with \(Ch^5\) in step 17 and with \(\tilde L\) (the Lipschitz constant of the step map) in place of \(L\), giving global order 4.
- \[ \text{NFE per step}:\quad \text{Euler}=1,\quad \text{Heun}=2,\quad \text{midpoint}=2,\quad \text{RK4}=4 . \]
Part (vi): cost. Each stage \(k_i\) is one evaluation of \(v\), that is, one forward pass of the network. Steps 12, 22, 30 and 36.
- \[ n=\sigma N\ \text{evaluations}\ \Longrightarrow\ N=\frac n\sigma,\qquad h=\frac1N=\frac\sigma n,\qquad \sigma=\text{NFE per step} . \]
At a fixed budget of \(n\) network evaluations, a method with \(\sigma\) evaluations per step can take only \(N=n/\sigma\) steps.
- \[ E_{\text{Euler}}\approx C_1\,n^{-1},\qquad E_{\text{Heun}},E_{\text{mid}}\approx C_2\Big(\frac n2\Big)^{-2},\qquad E_{\text{RK4}}\approx C_4\Big(\frac n4\Big)^{-4} . \]
Global error \(C_ph^p\) (steps 21, 28, 53) with \(h=\sigma/n\) from step 55: \(h^p=(\sigma/n)^p=(n/\sigma)^{-p}\). On a log-log plot of error against \(n\) the slopes are \(-1,-2,-2,-4\), shifted by the factor \(\sigma^p\) (a constant).
- \[ n=16:\qquad n^{-1}=\tfrac1{16},\qquad (n/2)^{-2}=\tfrac1{64},\qquad (n/4)^{-4}=\tfrac1{256} . \]
Numbers for the \(h^p\) factors only, with all constants \(C_p\) set equal. RK4 pays 4 evaluations per step and still wins by powers of \(h\), if \(h\) is small enough for the asymptotic law of step 56 to hold.
- \[ u(x,t\mid a)=\frac{a-x}{1-t}:\qquad \partial_x u=-\frac1{1-t},\qquad \partial_t u=\frac{a-x}{(1-t)^2} . \]
The constants \(C_p\) are built from derivatives of \(v\) (steps 10 and 13 show \(\nabla v\), \(\partial_t v\) and second derivatives entering), and \(L\) is a bound on \(\nabla v\). Example: the conditional velocity of the straight path. Differentiate with the quotient rule. Both derivatives grow as \(t\to1\), and higher ones grow faster (\((1-t)^{-3}\) for \(\partial_t^2u\)). A marginal field with sharp modes behaves alike near \(t=1\).
- \[ h\ll 1-t\ \text{ is needed for } C_p\,h^p \text{ to describe the error.} \]
The expansions above are asymptotic: the remainders are small only when \(h\) is small compared with the time scale on which \(v\) changes, here \(1-t\). Where the field is stiff (late in sampling for sharply peaked data) a high-order method with few large steps can lose its advantage, and the Lipschitz factor \(e^{L}\) of step 21 becomes large. Hence the practical advice: use a few more steps near the stiff end, or a time grid that is denser there.
Result: for \(\dot x=v(x,t)\) the exact expansion is \(x+hv+\frac{h^2}{2}\dot v+\frac{h^3}{6}\ddot v+O(h^4)\) with \(\dot v=\partial_tv+(\nabla v)v\). Euler matches the first term: local error \(\frac{h^2}{2}\dot v\), global error \(O(h)\) with factor \((e^L-1)/L\). Heun and midpoint match through \(h^2\) (local \(O(h^3)\), order 2). RK4 satisfies all 8 order conditions (arithmetic above), so its local error is \(O(h^5)\) and its order is 4. At equal budget of \(n\) network evaluations the errors scale as \(n^{-1}\), \((n/2)^{-2}\), \((n/4)^{-4}\), but the constants contain derivatives of \(v\), which blow up where the field is stiff.
From velocity to score to a stochastic sampler
Goal: derive the score of the linear-path marginal from the velocity, \(\nabla\log p_t=(tv-x)/(1-t)\); show that for every noise level \(g(t)\ge0\) the SDE \(dx=[v+\frac12g^2\nabla\log p_t]dt+g\,dW\) has the same marginals as the flow-matching ODE (Fokker–Planck); turn it into an implementable Euler–Maruyama sampler; and fix the \(1/(1-t)\) blow-up at \(t\to1\).
- \[ x_t=t\,a+(1-t)\,\varepsilon,\qquad \hat\varepsilon=\mathbb{E}[\varepsilon\mid x_t=x],\qquad \hat a=\mathbb{E}[a\mid x_t=x],\qquad v(x,t)=\mathbb{E}[a-\varepsilon\mid x_t=x] . \]
Setup: the linear path, \(t=0\) noise and \(t=1\) data. \(x_t\) has density \(p_t\) and \(x\) denotes its value. We drop \(o\) from the notation. \(\hat\varepsilon\) and \(\hat a\) are the posterior means of noise and data given \(x_t=x\); \(v\) is the marginal velocity field.
- \[ x=t\,\hat a+(1-t)\,\hat\varepsilon . \]
Part (i): solve for \(\hat\varepsilon,\hat a\). Take \(\mathbb{E}[\cdot\mid x_t=x]\) of \(x_t=ta+(1-t)\varepsilon\). On the conditioning event \(x_t=x\), so the left side is \(x\). Linearity of conditional expectation on the right, with \(t\) a number.
- \[ v=\hat a-\hat\varepsilon . \]
The linear-path form of the velocity, from the conversions derivation: \(v=\dot\alpha_t\hat a+\dot\sigma_t\hat\varepsilon\) with \(\alpha_t=t\), \(\sigma_t=1-t\). The two equations 2 and 3 are a linear system in the two unknowns \((\hat a,\hat\varepsilon)\) with known right-hand sides \((x,v)\).
- \[ \hat a=v+\hat\varepsilon . \]
Add \(\hat\varepsilon\) to both sides of step 3.
- \[ x=t\,(v+\hat\varepsilon)+(1-t)\,\hat\varepsilon . \]
Substitute step 4 into step 2 to remove \(\hat a\).
- \[ x=t\,v+t\,\hat\varepsilon+(1-t)\,\hat\varepsilon=t\,v+\hat\varepsilon . \]
Distribute \(t\). Then \(t\hat\varepsilon+(1-t)\hat\varepsilon=\hat\varepsilon\).
- \[ \boxed{\ \hat\varepsilon=x-t\,v\ } . \]
Subtract \(tv\) from both sides of step 6.
- \[ \hat a=v+(x-t\,v)=\boxed{\ x+(1-t)\,v\ } . \]
Insert step 7 into step 4. Then \(v-tv=(1-t)v\).
- \[ \hat a-\hat\varepsilon=\big(x+(1-t)v\big)-\big(x-tv\big)=(1-t)v+tv=v\ \ \checkmark \]
Check 1: step 3. The \(x\) terms cancel.
- \[ t\,\hat a+(1-t)\,\hat\varepsilon=t x+t(1-t)v+(1-t)x-t(1-t)v=x\ \ \checkmark \]
Check 2: step 2. The \(v\) terms cancel and \(tx+(1-t)x=x\). Both formulas hold for every \(t\in[0,1]\) (no division by \(t\) or \(1-t\)), unlike the form \(\hat a=(x-(1-t)\hat\varepsilon)/t\) of the conversions derivation.
- \[ \nabla_x\log p_t(x)=-\frac{\hat\varepsilon}{\sigma_t},\qquad \sigma_t=1-t . \]
Part (ii): the score. Tweedie formula, last step of the conversions derivation, with \(\sigma_t=1-t\) for the linear path. Valid for \(t\lt1\), where \(\sigma_t\gt0\).
- \[ \nabla_x\log p_t(x)=-\frac{x-t\,v}{1-t} . \]
Insert \(\hat\varepsilon=x-tv\) from step 7 into step 11.
- \[ \boxed{\ \nabla_x\log p_t(x)=\frac{t\,v(x,t)-x}{1-t}\ } . \]
Move the minus sign into the numerator: \(-(x-tv)=tv-x\).
- \[ a\sim\mathcal{N}(\mu,s^2),\quad x_t\sim\mathcal{N}(t\mu,\,V),\quad V:=t^2s^2+(1-t)^2 . \]
Hand check on a 1-D Gaussian target. \(x_t\) is a sum of independent Gaussians \(ta\) and \((1-t)\varepsilon\): the means add and the variances add (\(t^2s^2\) and \((1-t)^2\)).
- \[ v=\mu+\frac{\mathrm{Cov}(a-\varepsilon,\,x_t)}{V}\,(x-t\mu),\qquad \mathrm{Cov}(a-\varepsilon,\,x_t)=t s^2-(1-t) . \]
Conditional mean for jointly Gaussian variables: \(\mathbb{E}[Y\mid X=x]=\mathbb{E}Y+\frac{\mathrm{Cov}(Y,X)}{\mathrm{Var}X}(x-\mathbb{E}X)\). Here \(Y=a-\varepsilon\), with \(\mathbb{E}Y=\mu\). Covariance: \(a\) and \(\varepsilon\) are independent, \(\mathrm{Cov}(a,ta)=ts^2\) and \(\mathrm{Cov}(\varepsilon,(1-t)\varepsilon)=1-t\).
- \[ tv-x=t\mu+\frac{t\,(ts^2-(1-t))}{V}(x-t\mu)-x=-(x-t\mu)+\frac{t\,(ts^2-(1-t))}{V}(x-t\mu) . \]
Multiply step 15 by \(t\) and subtract \(x\). Write \(t\mu-x=-(x-t\mu)\).
- \[ tv-x=\frac{(x-t\mu)}{V}\Big[-V+t^2s^2-t(1-t)\Big]=\frac{(x-t\mu)}{V}\Big[-(1-t)^2-t(1-t)\Big] . \]
Factor out \((x-t\mu)/V\), then use \(V=t^2s^2+(1-t)^2\) so that \(-V+t^2s^2=-(1-t)^2\).
- \[ tv-x=-\frac{(x-t\mu)}{V}\,(1-t)\big[(1-t)+t\big]=-\frac{(x-t\mu)(1-t)}{V} . \]
Factor \((1-t)\) from the bracket; \((1-t)+t=1\).
- \[ \frac{tv-x}{1-t}=-\frac{x-t\mu}{V}=\nabla_x\log\mathcal{N}(x;\,t\mu,\,V) \ \ \checkmark \]
Divide step 18 by \(1-t\). The right side is the score of the Gaussian \(\mathcal{N}(t\mu,V)\) (derivative of \(-(x-t\mu)^2/(2V)\)). So step 13 reproduces the true score in this case.
- \[ dx=\Big[v(x,t)+\tfrac12\,g(t)^2\,\nabla_x\log p_t(x)\Big]dt+g(t)\,dW_t,\qquad x_0\sim p_0,\quad g(t)\ge0 . \]
Part (iii): an SDE with the same marginals. Run forward in flow time \(t\). \(W_t\) is a Brownian motion and \(g\) any nonnegative function of time (the noise level). The drift is the ODE velocity \(v\) plus half the squared noise level times the score of the ODE marginal \(p_t\). The claim: \(x_t\sim p_t\) for every \(t\).
- \[ \partial_t q=-\nabla\!\cdot\!(b\,q)+\tfrac12\,g^2\,\nabla^2 q . \]
Fokker–Planck equation (used as a known result, stated in the score-SDE derivation) for the density \(q_t\) of the solution of \(dx=b\,dt+g\,dW\): the drift moves probability like a flow with velocity \(b\), and the noise spreads it with diffusivity \(\frac12g^2\). \(\nabla^2q=\sum_i\partial_{x_i}^2q\) is the Laplacian. Below \(b:=v+\frac12g^2\nabla\log p_t\) from step 20.
- \[ \partial_t p_t=-\nabla\!\cdot\!(v\,p_t) . \]
The continuity equation: the ODE velocity \(v\) transports the marginals \(p_t\) (continuity derivation and conditional flow matching theorem). This is the equation we must recover.
- \[ \mathrm{RHS}\big|_{q=p_t}=-\nabla\!\cdot\!\big(\big[v+\tfrac12g^2\nabla\log p_t\big]p_t\big)+\tfrac12g^2\nabla^2p_t . \]
Test whether \(q_t=p_t\) solves the Fokker–Planck equation: put \(q=p_t\) and the drift \(b\) into its right-hand side.
- \[ -\nabla\!\cdot\!(v\,p_t)-\tfrac12g^2\,\nabla\!\cdot\!\big(p_t\nabla\log p_t\big)+\tfrac12g^2\nabla^2p_t . \]
Distribute \(p_t\) over the sum inside the bracket of step 23, and the divergence over the two terms (linearity). \(g\) depends on \(t\) only, so it leaves the divergence.
- \[ p_t\,\nabla\log p_t=\nabla p_t . \]
Chain rule for the logarithm: \(\nabla\log p=\nabla p/p\).
- \[ \nabla\!\cdot\!\big(p_t\nabla\log p_t\big)=\nabla\!\cdot\!\nabla p_t=\nabla^2p_t . \]
Take the divergence of step 25. The divergence of a gradient is the Laplacian.
- \[ -\nabla\!\cdot\!(v\,p_t)-\tfrac12g^2\,\nabla^2p_t+\tfrac12g^2\,\nabla^2p_t=-\nabla\!\cdot\!(v\,p_t) . \]
Insert step 26 into step 24. The two Laplacian terms have equal size and opposite sign and cancel.
- \[ \partial_t p_t=-\nabla\!\cdot\!(v\,p_t)=-\nabla\!\cdot\!(b\,p_t)+\tfrac12g^2\nabla^2p_t . \]
The left equality is step 22. The right equality: the right side of step 27 is the right side of step 23, which is the Fokker–Planck right-hand side for \(b\). So \(p_t\) solves the Fokker–Planck equation of step 21.
- \[ q_0=p_0\ \text{ and both solve the same Fokker–Planck equation}\ \Longrightarrow\ q_t=p_t\quad\text{for all }t . \]
The SDE of step 20 starts from \(x_0\sim p_0\), so its density \(q_t\) has \(q_0=p_0\). Uniqueness of solutions of the (linear, parabolic) Fokker–Planck equation for given initial data, assumed here (it holds under standard smoothness and growth conditions on \(b\) and \(g\)), then gives \(q_t=p_t\). The marginals of the SDE and of the ODE are the same. Individual paths differ: the SDE paths are random.
- \[ b(x,t)=v+\frac{g^2}{2}\cdot\frac{t\,v-x}{1-t} . \]
Part (iv): an implementable drift. Replace the unknown score in step 20 by the expression of step 13. The network predicts \(v\), and nothing else is needed.
- \[ b(x,t)=\Big[1+\frac{g^2\,t}{2(1-t)}\Big]v-\frac{g^2}{2(1-t)}\,x . \]
Collect the coefficients of \(v\) and \(x\) in step 30. Reading: the ODE velocity is boosted, and a linear restoring force pulls \(x\) toward the origin (a Langevin-type term).
- \[ b=v-\frac{g^2}{2}\,\frac{\hat\varepsilon}{1-t} . \]
The same drift in another form: \(tv-x=-\hat\varepsilon\) (step 7), so \(\frac{tv-x}{1-t}=-\frac{\hat\varepsilon}{1-t}\). The correction is minus the score magnitude \(\hat\varepsilon/\sigma_t\), scaled by \(g^2/2\).
- \[ t_n=n\,h,\qquad h=\frac1N,\qquad x_0=\varepsilon\sim\mathcal{N}(0,I) . \]
Part (v): Euler–Maruyama. Discretize time in \(N\) steps of size \(h\). The sampler starts from noise, \(t=0\).
- \[ x_{t_n+h}-x_{t_n}=\int_{t_n}^{t_n+h}b\,dt+\int_{t_n}^{t_n+h}g\,dW_t\;\approx\;b(x_{t_n},t_n)\,h+g(t_n)\,\big(W_{t_n+h}-W_{t_n}\big) . \]
The SDE in integral form over one step. Freeze the integrands at the start of the step (the same approximation as the Euler method for ODEs).
- \[ W_{t_n+h}-W_{t_n}\sim\mathcal{N}(0,\,h\,I)\ \ \Longrightarrow\ \ W_{t_n+h}-W_{t_n}=\sqrt h\;\xi_n,\quad \xi_n\sim\mathcal{N}(0,I) . \]
Brownian increments are Gaussian with variance equal to the elapsed time \(h\), independent across steps. Write them as \(\sqrt h\) times a standard normal.
- \[ x_{n+1}=x_n+h\,\Big[v_\theta(x_n,t_n)+\frac{g(t_n)^2}{2}\cdot\frac{t_n\,v_\theta(x_n,t_n)-x_n}{1-t_n}\Big]+g(t_n)\sqrt h\;\xi_n . \]
Insert step 30 (with the network \(v_\theta\) for \(v\)) and step 35 into step 34. Each step costs one network evaluation, the same as an Euler step of the ODE.
- \[ \frac{g^2}{2}\cdot\frac{t\,v-x}{1-t}=-\frac{g^2}{2}\,\frac{\hat\varepsilon}{1-t},\qquad \|\hat\varepsilon\|=O(1) . \]
Part (vi): the end point \(t\to1\). By step 32 the correction carries the factor \(1/(1-t)\). The numerator \(\hat\varepsilon\) does not vanish: for sharply peaked data \(\hat\varepsilon\approx\varepsilon\) is of order one. So with constant \(g\) the correction grows like \(1/(1-t)\).
- \[ \mathbb{E}\|\hat\varepsilon\|^2\le\mathbb{E}\|\varepsilon\|^2=d . \]
The size of \(\hat\varepsilon\) is bounded in the mean. Conditional Jensen for the convex function \(\|\cdot\|^2\) gives \(\|\mathbb{E}[\varepsilon\mid x_t]\|^2\le\mathbb{E}[\|\varepsilon\|^2\mid x_t]\), and the tower property turns the expectation of the right side into \(\mathbb{E}\|\varepsilon\|^2=d\). The bound holds for every \(t\).
- \[ \mathbb{E}\|v\|^2\le\mathbb{E}\|a-\varepsilon\|^2=\mathbb{E}\|a\|^2+d . \]
Same argument for \(v=\mathbb{E}[a-\varepsilon\mid x_t]\). Then \(\mathbb{E}\|a-\varepsilon\|^2=\mathbb{E}\|a\|^2-2\,\mathbb{E}\langle a,\varepsilon\rangle+\mathbb{E}\|\varepsilon\|^2\), the cross term is zero (independence and \(\mathbb{E}\varepsilon=0\)), and \(\mathbb{E}\|\varepsilon\|^2=d\).
- \[ g(t)^2=c\,(1-t),\quad c\ge0 \qquad\Longrightarrow\qquad \frac{g^2}{2(1-t)}=\frac c2,\qquad g(t)=\sqrt{c\,(1-t)}\to0 . \]
The fix. Let the noise level shrink with \((1-t)\). The factor \(g^2/(1-t)\) is then the constant \(c\), and the noise itself vanishes at \(t=1\).
- \[ b=v-\frac c2\,\hat\varepsilon=v+\frac c2\,(t\,v-x) . \]
Insert step 40 into step 32. The singular factor has disappeared. The second form uses \(\hat\varepsilon=x-tv\) (step 7).
- \[ \|b\|^2\le2\|v\|^2+\frac{c^2}{2}\|\hat\varepsilon\|^2 . \]
Triangle inequality \(\|b\|\le\|v\|+\frac c2\|\hat\varepsilon\|\), then \((A+B)^2\le2A^2+2B^2\) with \(A=\|v\|\), \(B=\frac c2\|\hat\varepsilon\|\).
- \[ \mathbb{E}\|b(x_t,t)\|^2\le2\big(\mathbb{E}\|a\|^2+d\big)+\frac{c^2}{2}\,d\quad\text{for all }t\in[0,1] . \]
Take the expectation of step 42 over \(x_t\sim p_t\) and insert steps 38 and 39. The bound does not depend on \(t\): the drift stays bounded up to \(t=1\), in contrast with the \(1/(1-t)\) growth of step 37.
- \[ x_{n+1}=x_n+h\,\Big[v+\frac c2\,(t_n\,v-x_n)\Big]+\sqrt{c\,(1-t_n)\,h}\;\xi_n . \]
The Euler–Maruyama step of step 36 for this noise schedule (\(g(t_n)\sqrt h=\sqrt{c(1-t_n)h}\)). The last step starts at \(t_n=1-h\), where the noise scale is \(\sqrt{c}\,h\): the sampler ends almost deterministically.
- \[ g\equiv0:\qquad b=v+0=v,\qquad dx=v\,dt . \]
Part (vii): no noise. Put \(g=0\) in steps 20 and 30. The score term and the Brownian term are both multiplied by \(g\) or \(g^2\) and vanish. What is left is the flow-matching ODE.
- \[ x_{n+1}=x_n+h\,v_\theta(x_n,t_n) . \]
Step 36 with \(g=0\) is the Euler step of the ODE. For \(g=0\), step 27 is not even needed: step 28 reduces to the continuity equation of step 22.
Result: on the linear path \(\hat\varepsilon=x-tv\) and \(\hat a=x+(1-t)v\), so the score is \(\nabla\log p_t=(tv-x)/(1-t)\) (checked exactly on a Gaussian). For every \(g(t)\ge0\), the SDE \(dx=[v+\frac12g^2\nabla\log p_t]dt+g\,dW\) has the same marginals as the ODE, because the extra Fokker–Planck term \(\frac12g^2\nabla^2p\) is cancelled by the extra drift \(-\frac12g^2\nabla\cdot(p\nabla\log p)\). Its implementable drift is \(v+\frac{g^2}{2}\frac{tv-x}{1-t}\), and the Euler–Maruyama step costs one network evaluation. The factor \(1/(1-t)\) blows up at \(t\to1\) for constant \(g\). The choice \(g^2=c(1-t)\) keeps the drift bounded and switches the noise off at the end, and \(g=0\) is the ODE. Marginals agree, individual paths do not.
Flow matching VI: straight paths and few-step generation
The Taylor argument in the few-step part says an Euler step has error about \(\tfrac12 h^2\) times the acceleration of the path. Curvature costs steps, and a straight path costs one. Liu et al. turn this into a number, the straightness of a flow [10]:
where \(X_t\) follows the ODE from \(X_0 \sim p_0\) to \(X_1\). \(S = 0\) exactly when every trajectory is a straight line at constant speed, and then one Euler step is exact. The marginal field of the independent coupling has \(S \gt 0\), because crossing pair lines are bent apart. For a robot, a straighter field means fewer network calls per chunk and lower latency.
Rectified flow and reflow
Reflow is a way to reduce \(S\) after training. Train \(v^0\) as usual. Run its ODE from fresh noise \(X_0\) to get \(X_1^0\). The new coupling \((X_0, X_1^0)\) is deterministic. Train \(v^1\) with the same loss on these pairs, and repeat. Liu et al. prove three things about this procedure [10]. The derivation below works through the construction.
- Marginals are preserved. Each round's flow has the same law at every time \(t\) as the pair interpolation it was trained on, so the output stays distributed as \(p_1\).
- Transport cost does not increase. For any convex cost \(c\), the expected cost \(\mathbb{E}\,c(X_1 - X_0)\) of the new coupling is no larger than the old one.
- The fixed points are straight flows. A flow is unchanged by reflow only if it is straight, and the straightness averaged over rounds shrinks like \(1/k\).
Straight is not the same as optimal transport. The limit is a straight coupling, which need not minimize the cost. Why does it help? The pairs are now (noise, that noise's own output), a deterministic map \(x \mapsto a(x)\). Such pairs cross less than random ones, so there is less averaging and the paths bend less. At \(t = 0\) the exact field is \(v(x, 0) = a(x) - x\), so one Euler step from noise \(x\) lands on \(a(x)\), a sample of the previous model, instead of on the mean between the modes.
The price is the pair generation. You simulate the ODE, which costs a full sampling run for every training pair, and you keep the pairs or regenerate them. The new targets are the previous model's samples, not the demonstrations, so its errors become the next round's data and compound. For a policy, the pairs are generated per observation \(o\), and the retrained model inherits whatever the teacher got wrong there. Most uses stop after one or two rounds.
Step through rounds 0 to 3. Watch the trajectories straighten, the straightness readout fall, and the one-step sample move from between the modes (round 0, the mean collapse of the few-step part) onto a mode. Later rounds use fields estimated from the previous round's pairs, so the figure also shows estimation error building up.
Learning to jump
The other route leaves the path curved and teaches the network to jump along it. Define the average velocity over \([t, s]\):
With the exact \(\bar v\), one call crosses any interval, even a curved one. As \(s \to t\) it reduces to \(v\). MeanFlow differentiates \((s-t)\,\bar v\) in \(t\) to get an identity that needs no integral [15]:
The derivation below shows each step. Train a network \(\bar v_\theta\) to satisfy it, using the pair velocity \(a - \varepsilon\) for \(v\) and a Jacobian-vector product for the derivative, with a stop-gradient on the target. The sampler is \(x_1 = x_0 + \bar v_\theta(x_0, 0, 1)\). The papers use different time conventions, so check the direction before comparing code.
Shortcut models condition on the step size \(d\) [16]. Their self-consistency rule says one step of size \(2d\) equals two steps of size \(d\): \(\bar v(x,t,t+2d)\) \(= \tfrac12 \bar v(x,t,t+d) + \tfrac12 \bar v(x', t+d, t+2d)\) with \(x' = x + d\,\bar v(x,t,t+d)\). One network then supports one, two or many steps. Consistency models learn a different object [22]: the endpoint map \(f(x_t, t)\), which must agree for any two points on the same trajectory. Consistency flow matching applies a velocity-consistency idea to straight flow matching paths [23], and FlowPolicy uses it for one-step robot policies [31].
| Method | What is learned | Training cost | Steps at inference | Main failure mode |
|---|---|---|---|---|
| Flow matching (baseline) | Instantaneous velocity \(v\) | One regression pass per batch | Several to tens | One step collapses to the mean; discretization error |
| Reflow | Velocity on a straightened coupling | Base training, then ODE simulation for the pairs and a retraining per round | Fewer, ideally one | Teacher errors compound; targets drift from the demonstrations |
| Consistency model | Endpoint map \(f(x_t, t)\) | Distillation from a trained model, or a self-referential loss from scratch | One or few | Quality limited by how well self-consistency is fit |
| Consistency flow matching | Velocity-consistent straight flow | One run; the target needs a second network evaluation | One or few | Same as consistency models |
| Shortcut model | Average velocity with step size \(d\) as input | One run, with self-consistency targets from two half steps | Any number, chosen at inference | Large-step accuracy depends on the self-consistency fit |
| MeanFlow | Average velocity \(\bar v(x_t, t, s)\) | One run; a Jacobian-vector product per step | One or few | Stop-gradient target is an approximation; extra memory and compute per step |
One-step methods can lose mode coverage. A model that lands on one mode for every noise sample looks fine on average error and fails the task whenever the missing mode is the right one. Measure success rate and diversity together, for example how the generated chunks split between left and right, against the demonstrations.
Derivations
Rectified flow: marginals, cost and straightness under reflow
Goal: prove the guarantees of rectified flow (Liu et al.): (A) the ODE with the averaged field has the same marginals as the straight pair lines; (B) it does not increase any convex transport cost; (C) zero straightness means straight paths, on which one Euler step is exact; (D) reflowing on the new coupling repeats this, and the straightness of the best round shrinks like \(1/R\).
- \[ (X_0,X_1)\sim\pi,\qquad X_t=(1-t)X_0+t\,X_1,\qquad U:=X_1-X_0,\qquad v(x,t)=\mathbb{E}\big[U\mid X_t=x\big] . \]
Setup. \(\pi\) is any coupling of the source \(p_0\) (law of \(X_0\)) and the data \(p_1\) (law of \(X_1\)); \(X_0\) and \(X_1\) need not be independent. \(U\) is the constant velocity of the pair. \(v\) is the marginal field. We drop \(o\) from the notation.
- \[ \dot Z_t=v(Z_t,t),\qquad Z_0=X_0 . \]
The rectified flow: the ODE driven by \(v\), started from the same source sample \(X_0\) as the pair. It follows the field, not the straight line of the pair.
- \[ \text{(a) } v \text{ is locally Lipschitz in } x;\quad \text{(b) } \mathbb{E}\|U\|^2\lt\infty;\quad \text{(c) the continuity equation for } v \text{ has a unique solution for given initial law.} \]
Assumptions, used below and flagged where needed. (a) makes the ODE of step 2 have a unique solution. (c) is a uniqueness statement about weak solutions of \(\partial_t\mu+\nabla\!\cdot(v\mu)=0\); it holds, for example, when \(v\) is Lipschitz in \(x\) with at most linear growth. For general couplings \(v\) can be rough near crossing points, so these are real assumptions, not formalities. \(c:\mathbb{R}^d\to[0,\infty)\) denotes a convex cost, such as \(\|\cdot\|^2\) or \(\|\cdot\|\), with \(\mathbb{E}\,c(U)\lt\infty\).
- \[ \frac{d}{dt}\,\mathbb{E}\,\varphi(X_t)=\mathbb{E}\big[\nabla\varphi(X_t)\cdot U\big],\qquad \varphi\in C_c^\infty(\mathbb{R}^d) . \]
Part (A): marginal preservation. Test with a smooth compactly supported function \(\varphi\). \(X_t=(1-t)X_0+tX_1\) is differentiable in \(t\) with derivative \(U\), so the chain rule gives \(\frac{d}{dt}\varphi(X_t)=\nabla\varphi(X_t)\cdot U\). Differentiation and expectation exchange because \(\nabla\varphi\) is bounded and \(\mathbb{E}\|U\|\lt\infty\) (dominated convergence).
- \[ \mathbb{E}\big[\nabla\varphi(X_t)\cdot U\big]=\mathbb{E}\Big[\mathbb{E}\big[\nabla\varphi(X_t)\cdot U\mid X_t\big]\Big]=\mathbb{E}\Big[\nabla\varphi(X_t)\cdot\mathbb{E}[U\mid X_t]\Big] . \]
Tower property, then "taking out what is known": \(\nabla\varphi(X_t)\) is a function of \(X_t\), so it passes outside the conditional expectation.
- \[ \frac{d}{dt}\,\mathbb{E}\,\varphi(X_t)=\mathbb{E}\big[\nabla\varphi(X_t)\cdot v(X_t,t)\big]=\int\nabla\varphi\cdot v\;d\mu_t,\qquad \mu_t:=\mathrm{Law}(X_t) . \]
Combine steps 4 and 5 and insert the definition of \(v\) from step 1.
- \[ \frac{d}{dt}\,\mathbb{E}\,\varphi(Z_t)=\mathbb{E}\big[\nabla\varphi(Z_t)\cdot\dot Z_t\big]=\mathbb{E}\big[\nabla\varphi(Z_t)\cdot v(Z_t,t)\big]=\int\nabla\varphi\cdot v\;d\nu_t,\qquad \nu_t:=\mathrm{Law}(Z_t) . \]
The same computation for \(Z_t\): chain rule, then the ODE of step 2 for \(\dot Z_t\). No conditional expectation is needed because \(\dot Z_t\) is already a function of \(Z_t\).
- \[ \frac{d}{dt}\int\varphi\,d\mu=\int\nabla\varphi\cdot v\;d\mu\ \text{ for all }\varphi\quad\Longleftrightarrow\quad\partial_t\mu+\nabla\!\cdot(v\,\mu)=0 . \]
This is the weak form of the continuity equation: for a density \(p\), integration by parts (divergence theorem, \(\varphi\) has compact support) gives \(\int\nabla\varphi\cdot v\,p\,dx=-\int\varphi\,\nabla\!\cdot(v\,p)\,dx\). By steps 6 and 7 both \((\mu_t)\) and \((\nu_t)\) solve it with the same field \(v\). The conditional flow matching theorem and the continuity derivation show the same for an independent coupling and a single pair (see also the couplings derivation, d-fm-coupling).
- \[ \mu_0=\mathrm{Law}(X_0)=p_0=\mathrm{Law}(Z_0)=\nu_0 . \]
Same initial law, because \(Z_0=X_0\) by step 2.
- \[ \boxed{\ \mathrm{Law}(Z_t)=\mathrm{Law}(X_t)\quad\text{for all }t\in[0,1]\ } . \]
Uniqueness, assumption (c) of step 3: two solutions of the same continuity equation with the same initial law coincide. In words: the ODE pushes the source to exactly the same intermediate laws as the straight pair lines do, although individual particles follow different paths.
- \[ \mathrm{Law}(Z_0)=p_0,\qquad \mathrm{Law}(Z_1)=\mathrm{Law}(X_1)=p_1 . \]
Set \(t=0\) and \(t=1\) in step 10. So \((Z_0,Z_1)\) is again a coupling of \(p_0\) and \(p_1\). This is what lets us reuse it as a new coupling in part (D).
- \[ Z_1-Z_0=\int_0^1\dot Z_t\,dt=\int_0^1 v(Z_t,t)\,dt . \]
Part (B): the transport cost does not increase. Fundamental theorem of calculus for \(Z_t\), then the ODE of step 2.
- \[ c\Big(\int_0^1 w(t)\,dt\Big)\le\int_0^1c\big(w(t)\big)\,dt,\qquad w(t):=v(Z_t,t) . \]
Jensen inequality for the convex function \(c\) on the probability space \([0,1]\) with the uniform measure, so that \(\int_0^1w\,dt\) is the mean of \(w\). Applied path by path.
- \[ c(Z_1-Z_0)\le\int_0^1c\big(v(Z_t,t)\big)\,dt . \]
Insert step 12 into the left side of step 13.
- \[ \mathbb{E}\,c(Z_1-Z_0)\le\int_0^1\mathbb{E}\,c\big(v(Z_t,t)\big)\,dt . \]
Take the expectation of step 14. Exchange \(\mathbb{E}\) and \(\int dt\) (Tonelli, since \(c\ge0\)).
- \[ \mathbb{E}\,c\big(v(Z_t,t)\big)=\mathbb{E}\,c\big(v(X_t,t)\big) . \]
By step 10, \(Z_t\) and \(X_t\) have the same law, and \(\mathbb{E}\,g(Y)\) depends on \(Y\) only through its law. Apply this to the fixed function \(g(y)=c(v(y,t))\).
- \[ v(X_t,t)=\mathbb{E}\big[U\mid X_t\big] . \]
Definition of \(v\), step 1, evaluated at the random point \(X_t\).
- \[ c\big(\mathbb{E}[U\mid X_t]\big)\le\mathbb{E}\big[c(U)\mid X_t\big] . \]
Conditional Jensen inequality for the convex \(c\).
- \[ c\big(v(X_t,t)\big)\le\mathbb{E}\big[c(U)\mid X_t\big] . \]
Insert step 17 into the left side of step 18.
- \[ \mathbb{E}\,c\big(v(X_t,t)\big)\le\mathbb{E}\Big[\mathbb{E}\big[c(U)\mid X_t\big]\Big]=\mathbb{E}\,c(U)=\mathbb{E}\,c(X_1-X_0) . \]
Take the expectation of step 19. Tower property: \(\mathbb{E}[\mathbb{E}[Y\mid X_t]]=\mathbb{E}Y\).
- \[ \mathbb{E}\,c(Z_1-Z_0)\le\int_0^1\mathbb{E}\,c\big(v(X_t,t)\big)\,dt\le\int_0^1\mathbb{E}\,c(X_1-X_0)\,dt . \]
Chain: step 15, then steps 16 and 20 (the bound of step 20 holds for every \(t\)).
- \[ \boxed{\ \mathbb{E}\,c(Z_1-Z_0)\le\mathbb{E}\,c(X_1-X_0)\ } . \]
The integrand of the last integral in step 21 does not depend on \(t\) and \(\int_0^1dt=1\). The new coupling \((Z_0,Z_1)\) is a valid coupling of \(p_0,p_1\) (step 11) and its expected cost is no larger. Two Jensen steps are involved: step 13 (over time, along a path) and step 18 (over pairs, at a point).
- \[ S:=\int_0^1\mathbb{E}\big\|(Z_1-Z_0)-v(Z_t,t)\big\|^2\,dt . \]
Part (C): straightness. Definition of Liu et al.: how far the velocity along a path is, on average, from the average velocity \(Z_1-Z_0\) of that path.
- \[ \int_0^1\|w(t)-\bar w\|^2\,dt=\int_0^1\|w\|^2\,dt-2\Big\langle\bar w,\int_0^1w\,dt\Big\rangle+\|\bar w\|^2=\int_0^1\|w\|^2\,dt-\|\bar w\|^2 . \]
Fix one path and put \(w(t)=v(Z_t,t)\) and \(\bar w=\int_0^1w\,dt=Z_1-Z_0\) (step 12). Expand the square, use linearity of the integral for the cross term, and \(\int_0^1\|\bar w\|^2dt=\|\bar w\|^2\). The cross term is \(-2\|\bar w\|^2\), which combines with \(+\|\bar w\|^2\).
- \[ S=\mathbb{E}\int_0^1\big\|v(Z_t,t)\big\|^2dt-\mathbb{E}\|Z_1-Z_0\|^2 . \]
Take the expectation of step 24 and exchange \(\mathbb{E}\) with \(\int dt\) (Tonelli). So \(S\) is exactly the gap in the Jensen inequality of step 13 for the cost \(c=\|\cdot\|^2\).
- \[ S\ge0,\qquad S=0\iff\big\|v(Z_t,t)-(Z_1-Z_0)\big\|=0\ \text{ for almost every } t \text{ on almost every path} . \]
\(S\) is the integral of a nonnegative quantity. It is zero exactly when the integrand vanishes almost everywhere. Since \(t\mapsto v(Z_t,t)\) is continuous (assumption (a) and continuity of \(Z\)), "almost every \(t\)" upgrades to every \(t\).
- \[ S=0\iff v(Z_t,t)=Z_1-Z_0\ \ \forall\,t,\ \text{ i.e. } v(Z_t,t)\ \text{is constant in } t \text{ along each path} . \]
Restate step 26. The constant must be \(Z_1-Z_0\) by step 12.
- \[ Z_t=Z_0+\int_0^t v(Z_s,s)\,ds=Z_0+t\,(Z_1-Z_0) . \]
If \(S=0\): insert the constant velocity of step 27 into the integral form of the ODE. The path is a straight line traversed at constant speed. Conversely, a straight constant-speed path has constant velocity, so \(S=0\). Hence \(S=0\iff\) all paths are straight.
- \[ x_1^{\mathrm{Euler}}=x_0+1\cdot v(x_0,0),\qquad x_0=Z_0 . \]
One Euler step with \(h=1\) from the source sample, as in the \(N=1\) derivation (Euler error).
- \[ x_1^{\mathrm{Euler}}=Z_0+(Z_1-Z_0)=Z_1\qquad\text{if }S=0 . \]
Set \(t=0\) in step 27: \(v(Z_0,0)=Z_1-Z_0\). Insert into step 29. One Euler step is exact for straight paths.
- \[ Z_1-x_1^{\mathrm{Euler}}=\int_0^1\big[v(Z_t,t)-v(Z_0,0)\big]\,dt\qquad\text{in general.} \]
For \(S\gt0\): step 12 gives \(Z_1=Z_0+\int_0^1v(Z_t,t)\,dt\); subtract step 29 and write \(v(Z_0,0)=\int_0^1v(Z_0,0)\,dt\). The one-step error is the average drift of the velocity away from its initial value. It is zero iff the velocity along the path stays equal to its value at \(t=0\).
- \[ \pi^{(0)}:=\pi,\qquad \pi^{(r+1)}:=\mathrm{Law}\big(Z^{(r)}_0,\,Z^{(r)}_1\big),\qquad C^{(r)}:=\mathbb{E}_{\pi^{(r)}}\,c(X_1-X_0) . \]
Part (D): reflow. Round \(r\) has coupling \(\pi^{(r)}\), field \(v^{(r)}\), and rectified flow \(Z^{(r)}\) (started at \(Z_0^{(r)}=X_0\) with \(X_0\) from \(\pi^{(r)}\)). The next coupling pairs each noise sample with the point the ODE maps it to. \(C^{(r)}\) is the expected cost of round \(r\).
- \[ \pi^{(r+1)}\ \text{has marginals } p_0 \text{ and } p_1 . \]
Step 11 applied in round \(r\). So steps (A) to (C) apply again to \(\pi^{(r+1)}\), with \(v^{(r+1)}\) and \(Z^{(r+1)}\).
- \[ C^{(r+1)}=\mathbb{E}\,c\big(Z_1^{(r)}-Z_0^{(r)}\big)\le C^{(r)} . \]
The first equality is the definition in step 32. The inequality is step 22 in round \(r\).
- \[ C^{(0)}\ge C^{(1)}\ge C^{(2)}\ge\dots\ge0 . \]
Apply step 34 for \(r=0,1,2,\dots\) The cost is non-increasing over rounds, and bounded below by 0, so it converges.
- \[ S^{(r)}=\int_0^1\mathbb{E}\big\|v^{(r)}(X_t,t)\big\|^2dt-C^{(r+1)}\le C^{(r)}-C^{(r+1)},\qquad c=\|\cdot\|^2 . \]
A quantitative consequence, for \(c=\|\cdot\|^2\). Step 25 in round \(r\): \(\mathbb{E}\|v^{(r)}(Z_t,t)\|^2=\mathbb{E}\|v^{(r)}(X_t,t)\|^2\) by steps 10 and 16, and \(\mathbb{E}\|Z_1-Z_0\|^2=C^{(r+1)}\) by the definition in step 34. The inequality is step 20, integrated over \(t\in[0,1]\): the first term is at most \(C^{(r)}\).
- \[ \sum_{r=0}^{R-1}S^{(r)}\le\sum_{r=0}^{R-1}\big(C^{(r)}-C^{(r+1)}\big)=C^{(0)}-C^{(R)}\le C^{(0)} . \]
Sum step 36 over \(r=0,\dots,R-1\). The right side telescopes. Then \(C^{(R)}\ge0\).
- \[ \min_{0\le r\lt R}S^{(r)}\le\frac1R\sum_{r=0}^{R-1}S^{(r)}\le\frac{C^{(0)}}{R}\ \xrightarrow{R\to\infty}\ 0 . \]
The smallest of \(R\) numbers is at most their average; insert step 37. Some round has straightness at most \(C^{(0)}/R\). Reflow therefore makes the flow arbitrarily straight, at rate \(1/R\) for the best round. It does not say that \(S^{(r)}\) decreases at every round.
- \[ \text{Not guaranteed:}\quad \mathrm{Law}\big(\tilde Z_1^{(r)}\big)\ne p_1\ \text{ when } v^{(r)}\text{ is replaced by a learned } v^{(r)}_\theta . \]
What the derivation does not give. Every step used the exact field \(v=\mathbb{E}[U\mid X_t]\) and the exact ODE solution. In practice a network \(v_\theta\) fits \(v\) with some error, and its flow \(\tilde Z\) satisfies step 10 only approximately: \(\mathrm{Law}(\tilde Z_1)\) differs slightly from \(p_1\). Round \(r+1\) is then trained on pairs whose "data" end is a sample from the model of round \(r\), not from \(p_1\). Errors compound over rounds, so a few rounds (one or two) are used in practice. Also: step 35 says the cost does not increase, not that the limit is the optimal transport coupling. And each round costs a full generation of pairs (one ODE solve per noise sample) plus a training run. Assumptions (a) and (c) of step 3 are needed throughout.
Result: for the rectified flow \(\dot Z=v(Z,t)\), \(Z_0=X_0\), with \(v=\mathbb{E}[X_1-X_0\mid X_t]\): (A) \(\mathrm{Law}(Z_t)=\mathrm{Law}(X_t)\) for all \(t\) (both solve the continuity equation with the same \(v\) and initial law; uniqueness assumed). (B) For convex \(c\), \(\mathbb{E}\,c(Z_1-Z_0)\le\mathbb{E}\,c(X_1-X_0)\): Jensen over time, then conditional Jensen and the tower property over pairs. (C) \(S=0\) iff paths are straight, and then one Euler step is exact. (D) Reflowing on \((Z_0,Z_1)\) gives a non-increasing cost sequence, and \(\min_{r\lt R}S^{(r)}\le C^{(0)}/R\) for \(c=\|\cdot\|^2\). Not guaranteed: the exact-field assumption fails for a learned network, so errors compound across rounds, and the limit need not be the optimal coupling.
Average velocity, the MeanFlow identity and one-step generation
Goal: define the average velocity \(\bar v\) of the flow over a time interval; show that one step with it is exact; derive the MeanFlow identity \(\bar v=v+(s-t)\frac{d}{dt}\bar v\) and the shortcut identity, explain how each becomes a training target, and contrast one-step generation with the \(N=1\) Euler collapse.
- \[ \bar v(x_t,t,s)=\frac1{s-t}\int_t^s v(x_\tau,\tau)\,d\tau,\qquad s\ne t . \]
Setup. \(x_\tau\) is the ODE trajectory \(\dot x_\tau=v(x_\tau,\tau)\) through the point \(x_t\) at time \(t\). It is unique because \(v\) is Lipschitz in \(x\), as assumed for the solvers. \(\bar v\) is the average velocity along this trajectory between times \(t\) and \(s\); as a function it takes the starting point and time \((x,t)\) and the end time \(s\). We drop \(o\) from the notation.
- \[ (s-t)\,\bar v(x_t,t,s)=\int_t^s v(x_\tau,\tau)\,d\tau . \]
Multiply step 1 by \(s-t\).
- \[ x_s-x_t=\int_t^s\dot x_\tau\,d\tau=\int_t^sv(x_\tau,\tau)\,d\tau . \]
Fundamental theorem of calculus for the trajectory, then the ODE \(\dot x_\tau=v(x_\tau,\tau)\).
- \[ \boxed{\ x_s=x_t+(s-t)\,\bar v(x_t,t,s)\ } . \]
Insert step 2 into step 3 and add \(x_t\). One Euler-type step with the average velocity is exact, for any step length \(s-t\), because the average velocity absorbs all the curvature of the path.
- \[ F(t):=(s-t)\,\bar v(x_t,t,s)=\int_t^sv(x_\tau,\tau)\,d\tau,\qquad s \text{ fixed},\ x_t \text{ moving along the trajectory} . \]
Part (A): the MeanFlow identity. Fix the end time \(s\) and one trajectory. Define \(F\) as a function of the time \(t\) alone, by step 2. We differentiate \(F\) in two ways.
- \[ \frac{dF}{dt}=-\,v(x_t,t) . \]
Right-hand side. The trajectory is a fixed curve, so the integrand \(v(x_\tau,\tau)\) does not depend on \(t\); only the lower limit does. Fundamental theorem of calculus: \(\frac{d}{dt}\int_t^sg(\tau)d\tau=-g(t)\). Here \(g(\tau)=v(x_\tau,\tau)\).
- \[ \frac{dF}{dt}=-\,\bar v+(s-t)\,\frac{d}{dt}\bar v(x_t,t,s) . \]
Left-hand side. Product rule on \((s-t)\cdot\bar v\), with \(\frac{d}{dt}(s-t)=-1\) (\(s\) is fixed).
- \[ \frac{d}{dt}\bar v(x_t,t,s)=\partial_t\bar v+(\nabla_x\bar v)\,\dot x_t,\qquad \dot x_t=v(x_t,t) . \]
Chain rule: \(\bar v\) depends on \(t\) directly (second argument) and through the moving point \(x_t\) (first argument). \(\nabla_x\bar v\) is the Jacobian of \(\bar v\) in its first argument, \(\partial_t\bar v\) the partial derivative in the second argument. The velocity of the point is \(\dot x_t=v\) (the ODE).
- \[ -\,\bar v+(s-t)\,\frac{d}{dt}\bar v=-\,v(x_t,t) . \]
Both computations of \(\frac{dF}{dt}\) (steps 7 and 6) describe the same function \(F\) of step 5, so they are equal.
- \[ \boxed{\ \bar v(x_t,t,s)=v(x_t,t)+(s-t)\,\frac{d}{dt}\bar v(x_t,t,s)\ } . \]
Add \(\bar v+v(x_t,t)\) to both sides of step 9. This is the MeanFlow identity.
- \[ \bar v=v+(s-t)\Big[\partial_t\bar v+(\nabla_x\bar v)\,v\Big] . \]
Insert step 8 into step 10. The right side contains only \(v\) at the point and derivatives of \(\bar v\) itself, no integral.
- \[ \bar v_\theta(x,t,s)\approx\bar v(x,t,s),\qquad \text{target: } \ u+(s-t)\Big[\partial_t\bar v_\theta+(\nabla_x\bar v_\theta)\,u\Big] . \]
As a training target. A network \(\bar v_\theta(x,t,s,o)\) is trained so that step 11 holds. The field \(v\) is unknown, so replace it by the pair velocity \(u=a-\varepsilon\) of a sampled pair, with \(x=x_t=(1-t)\varepsilon+ta\). This is unbiased: for a fixed function \(\bar v_\theta\), the target is affine in \(v\), and \(\mathbb{E}[u\mid x_t=x]=v(x,t)\) (the conditional flow matching theorem), so the conditional expectation of the target is the target with \(v\) in place of \(u\) (linearity of conditional expectation).
- \[ \partial_t\bar v_\theta+(\nabla_x\bar v_\theta)\,u=\frac{d}{d\epsilon}\Big|_{\epsilon=0}\bar v_\theta\big(x+\epsilon\,u,\;t+\epsilon,\;s\big) . \]
The derivative in step 12 is a Jacobian–vector product (JVP): the directional derivative of \(\bar v_\theta\) along the tangent \((u,1,0)\) in the arguments \((x,t,s)\). By the chain rule the right side is \(\nabla_x\bar v_\theta\cdot u+\partial_t\bar v_\theta\cdot1+\partial_s\bar v_\theta\cdot0\). Forward-mode autodiff computes it at the cost of about one extra forward pass, without forming the Jacobian. The tangent has \(0\) in the \(s\) slot because \(s\) is held fixed (step 5).
- \[ \mathcal{L}(\theta)=\mathbb{E}\Big\|\bar v_\theta(x_t,t,s)-\mathrm{sg}\Big(u+(s-t)\,\mathrm{JVP}\Big)\Big\|^2 . \]
The loss. \(\mathrm{sg}\) is the stop-gradient: the target is treated as a constant, so no gradient flows through the JVP (no second-order derivatives), and \(\theta\) is updated only through the left term. The minimizer is the conditional mean of the target, which by step 12 is the right side of step 11.
- \[ \bar v-v=(s-t)\,\frac{d}{dt}\bar v\ \xrightarrow{\,s\to t\,}\ 0,\qquad\text{so}\qquad \lim_{s\to t}\bar v(x,t,s)=v(x,t) . \]
Limit. Rearrange step 10. If \(\frac{d}{dt}\bar v\) stays bounded (smooth \(\bar v\)), the right side tends to 0 as \(s\to t\). Independent check from the definition (step 1): the average of the continuous function \(\tau\mapsto v(x_\tau,\tau)\) over a shrinking interval \([t,s]\) tends to its value at \(t\), which is \(v(x_t,t)\). For \(s=t\) the network is an ordinary flow matching velocity.
- \[ x_\tau\ \text{ trajectory with } x_t=x;\qquad x:=x_{t+d} . \]
Part (B): the shortcut identity. Fix \(x,t\) and a step length \(d\gt0\). Follow the trajectory through \(x\) at time \(t\), and call \(x^{+}\) the point it reaches at time \(t+d\).
- \[ \int_t^{t+2d}v(x_\tau,\tau)\,d\tau=\int_t^{t+d}v(x_\tau,\tau)\,d\tau+\int_{t+d}^{t+2d}v(x_\tau,\tau)\,d\tau . \]
Additivity of the integral over adjacent intervals.
- \[ \int_t^{t+d}v(x_\tau,\tau)\,d\tau=d\;\bar v(x,t,t+d) . \]
Step 2 with \(s=t+d\), so \(s-t=d\).
- \[ \int_{t+d}^{t+2d}v(x_\tau,\tau)\,d\tau=d\;\bar v(x^{+},t+d,t+2d) . \]
Step 2 with start time \(t+d\), start point \(x^{+}=x_{t+d}\) and end time \(t+2d\). This is legitimate because the trajectory through \((x^{+},t+d)\) is the continuation of the same curve \(x_\tau\) (uniqueness of ODE solutions), so the integrand is the same.
- \[ \int_t^{t+2d}v(x_\tau,\tau)\,d\tau=2d\;\bar v(x,t,t+2d) . \]
Step 2 with \(s=t+2d\), so \(s-t=2d\).
- \[ 2d\;\bar v(x,t,t+2d)=d\;\bar v(x,t,t+d)+d\;\bar v(x^{+},t+d,t+2d) . \]
Insert steps 18, 19 and 20 into step 17.
- \[ \boxed{\ \bar v(x,t,t+2d)=\tfrac12\,\bar v(x,t,t+d)+\tfrac12\,\bar v\big(x^{+},t+d,t+2d\big)\ } . \]
Divide step 21 by \(2d\). The average over a long interval is the average of the averages over its two halves, because the halves have equal length.
- \[ x^{+}=x+d\;\bar v(x,t,t+d) . \]
Step 4 with \(s=t+d\). So the second half-step is evaluated at a point the network itself can compute from the first half. Use in training: the target for \(\bar v_\theta(x,t,t+2d)\) is the average of two network outputs, \(\frac12\bar v_\theta(x,t,t+d)+\frac12\bar v_\theta(x^{+},t+d,t+2d)\), with stop-gradient, and the smallest steps are anchored by the flow matching loss (step 15). A large jump is thereby learned from two smaller jumps.
- \[ x_1=x_0+(1-0)\,\bar v(x_0,0,1)=\varepsilon+\bar v(\varepsilon,0,1) . \]
Part (C): one-step generation. Step 4 with \(t=0\), \(s=1\), start \(x_0=\varepsilon\) (noise). The ODE endpoint \(x_1\) is a sample of the data distribution. With a trained \(\bar v_\theta\) this costs one network evaluation, NFE \(=1\), and is exact in principle, however curved the path is.
- \[ v(x_0,0)=\mathbb{E}[a]-x_0\quad\Longrightarrow\quad x_0+v(x_0,0)=\mathbb{E}[a] . \]
Part (D): contrast with the \(N=1\) Euler collapse. The marginal field at \(t=0\) was computed in the Euler error derivation (steps 17 to 19 there): \(v(x,0)=\mathbb{E}[a]-x\), because \(a\) is independent of \(\varepsilon\). One Euler step from \(x_0=\varepsilon\) with \(h=1\) lands on the mean of the data, for every \(\varepsilon\).
- \[ \bar v(x_0,0,1)=\int_0^1v(x_\tau,\tau)\,d\tau=x_1-x_0 . \]
Step 1 with \(t=0,s=1\), then step 3. Here \(x_1\) is the endpoint of the ODE trajectory from \(x_0\).
- \[ x_0+\bar v(x_0,0,1)=x_1\sim p_1\qquad\text{versus}\qquad x_0+v(x_0,0)=\mathbb{E}[a] . \]
Insert step 26 and compare with step 25. The ODE endpoint of step 26 has the data distribution (marginal preservation, derived in the reflow derivation). The Euler endpoint is a single point, independent of \(x_0\).
- \[ \bar v(x_0,0,1)-v(x_0,0)=x_1-\mathbb{E}[a] . \]
Subtract the velocity of step 25 from step 26: \((x_1-x_0)-(\mathbb{E}[a]-x_0)\). The difference is generally nonzero: it is the position of the sample relative to the data mean.
- \[ \bar v(x_0,0,1)=\int_0^1v(x_\tau,\tau)\,d\tau\quad(\text{average along one path}),\qquad v(x_0,0)=\mathbb{E}[u\mid x_0]\quad(\text{average over pairs at one point}) . \]
The two averages are different operations. The marginal field \(v\) averages the pair velocities \(u=a-\varepsilon\) over all pairs whose straight lines pass through the point \(x\) at time \(t\) (a conditional expectation, taken over \((a,\varepsilon)\) at fixed \((x,t)\)). The average velocity \(\bar v\) averages the already-averaged field over time along a single trajectory (an integral over \(\tau\) at fixed path).
- \[ \bar v(x_0,0,1)=v(x_0,0)\iff v(x_\tau,\tau)\ \text{constant in }\tau\iff\text{path straight} . \]
If \(v(x_\tau,\tau)=v(x_0,0)\) for all \(\tau\), the integral in step 26 is \(1\cdot v(x_0,0)\). Conversely, if the average of a continuous function on \([0,1]\) equals its value at 0 for every start \(t\) and endpoint \(s\) (all sub-intervals), it is constant. This is the straight-path case of the reflow derivation (\(S=0\)), in which one Euler step already works and the two quantities coincide.
- \[ \text{Gaussian check } (a\sim\mathcal{N}(\mu,s_a^2)):\quad v(x,0)=\mu-x,\qquad x_1=\mu+s_a\,\varepsilon,\qquad \bar v(\varepsilon,0,1)=\mu+(s_a-1)\,\varepsilon . \]
A closed-form example (1-D, \(a\sim\mathcal{N}(\mu,s_a^2)\)). The ODE map from noise to data is the affine map \(\varepsilon\mapsto\mu+s_a\varepsilon\), which sends \(\mathcal{N}(0,1)\) to \(\mathcal{N}(\mu,s_a^2)\). Then \(\bar v=x_1-\varepsilon\) by step 26. The Euler velocity has \(\mu-\varepsilon\), whose endpoint is the constant \(\mu\). They agree only when \(s_a=0\), that is, when the data is a single point.
Result: with \(\bar v(x_t,t,s)=\frac1{s-t}\int_t^sv(x_\tau,\tau)d\tau\): (i) \(x_s=x_t+(s-t)\bar v\) exactly (fundamental theorem of calculus). (A) Differentiating \((s-t)\bar v=\int_t^sv\,d\tau\) in \(t\) (product rule on the left, fundamental theorem on the right, chain rule for \(\frac{d}{dt}\bar v=\partial_t\bar v+(\nabla_x\bar v)v\)) gives the MeanFlow identity \(\bar v=v+(s-t)\frac{d}{dt}\bar v\). Swapping \(v\) for the pair velocity \(u\) is unbiased, the derivative is a JVP, and the target is stop-gradiented. (B) Splitting the interval gives the shortcut identity \(\bar v(x,t,t+2d)\) \(=\frac12\bar v(x,t,t+d)+\frac12\bar v(x^{+},t+d,t+2d)\) with \(x^{+}=x+d\,\bar v(x,t,t+d)\). (C) One step \(x_1=x_0+\bar v(x_0,0,1)\) is exact. (D) This is not the same as one Euler step with \(v(x_0,0)=\mathbb{E}[a]-x_0\), which collapses to the mean: \(\bar v\) averages the field along a path, \(v\) averages pair velocities over pairs. They coincide only for straight paths.
Flow matching VII: flow policies, the system
Earlier parts built the path, the loss and the solvers for one data point. A robot policy must also produce a whole action chunk from images and language, fast enough to keep the robot moving. π0 [26] does this with a flow head on a vision-language model.
What flows
The object that flows is an action chunk of \(H = 50\) future actions. It is conditioned on the images and language \(o\) and on the proprioceptive state \(q\). Sampling starts from noise and takes ten Euler steps:
The paper writes the chunk as \(A^\tau\) and counts \(\tau\) in the same direction as \(t\) here.
At \(t = 0\) the chunk is a random curve. Under the independent coupling the exact field there is \(v(x, 0) = \mathbb E[a] - x\), so one Euler step with \(\Delta t = 1\) lands every point on \(\mathbb E[a]\). That is the mean-collapse from the few-step part. With ten steps the chunk settles onto one route around the obstacle.
Real robots run only part of a chunk. The paper's appendix runs inference every 0.8 s after 16 actions on its 20 Hz arms, and every 0.5 s after 25 actions on its 50 Hz robots. The actions run open loop, with no aggregation [26].
The network: a VLM plus an action expert
π0 is one transformer with two sets of weights. The first is PaliGemma, a 3B vision-language model. The second is an action expert of about 300M parameters, initialized from scratch, with width 1024 and MLP width 4096 [26]. The code gives it 18 layers, the same depth as the VLM [35].
The prefix is the image tokens, then the language tokens. The suffix is one state token, then the 50 action tokens. Each expert has its own weights, but attention is computed jointly in every layer, so the action tokens read the prefix's keys and values.
Attention is block-wise, as the figure shows. Prefix tokens see only the prefix. The state token sees the prefix and itself. Action tokens see the prefix, the state and each other. The paper states the action-to-action rule [26]. The code adds the rule that the prefix never sees the suffix.
Flow time enters the action tokens. The code embeds it with a sine-cosine encoding, repeats it over the 50 positions, concatenates it with each action token, and passes the result through two linear layers with a swish between them. Training draws the time from Beta(1.5, 1), rescaled to \([0.001, 1]\). In the code, time 1 is noise, so the samples favor the noisy end. The paper says the same: the distribution "emphasizes lower (noisier) timesteps" [26].
Inference cost
The ten steps do not rerun the VLM. The prefix cannot see the suffix, so the code runs it once, keeps its attention keys and values, and reruns only the suffix at each integration step [35]. The paper describes the same caching [26]. On an RTX 4090 its Table I lists 73 ms on board, of which 27 ms covers the ten action passes.
Executing chunks in real time
Inference takes time, and the robot cannot wait for it. Synchronous inference pauses the arm between chunks. Asynchronous inference starts early, but the first actions of the new chunk come from an old observation and may not join smoothly. Black et al. [34] fix this without retraining. The actions that will run during the delay are frozen, and the rest of the chunk is sampled with guidance so that the final prediction agrees with them. The paper reports that performance holds as delay grows, and that on six real bimanual tasks it has the best average throughput at every delay. Its real-world tests use π0.5 as the base policy. Streaming Flow Policy [30] takes another route, starting from a narrow Gaussian around the last action and streaming actions during sampling.
Training and inference settings
Each value comes from the paper or the openpi code. The source column says which.
| Setting | Value | Source |
|---|---|---|
| Chunk length \(H\) | 50 | Sec. IV ("we use H=50 for our tasks"); config action_horizon |
| Action dimension | 32 (config default) | Config action_dim |
| Euler steps | 10, \(\Delta t = 0.1\) | Sec. IV; sample_actions default num_steps=10 |
| Training time density | Beta(1.5, 1) rescaled to \([0.001, 1]\); time 1 is noise | compute_loss in pi0.py |
| VLM backbone | PaliGemma, 3B; gemma_2b: width 2048, depth 18, MLP 16384 | Sec. IV; pi0_config.py; gemma.py |
| Action expert | About 300M; gemma_300m: width 1024, depth 18, MLP 4096 | Appendix B; gemma.py |
| Time embedding | Sine-cosine, min period 4e-3, max period 4.0; two linear layers with swish | embed_suffix in pi0.py; Appendix B |
| Attention | Prefix sees prefix. State sees prefix and state. Actions see prefix, state and actions. | make_attn_mask in pi0.py; Sec. IV (action-to-action) |
| Re-planning, 20 Hz arms | New chunk every 0.8 s, after 16 actions | Appendix D |
| Re-planning, 50 Hz robots | New chunk every 0.5 s, after 25 actions | Appendix D |
| Latency, RTX 4090 | 73 ms on board (27 ms for ten action passes) | Appendix D, Table I |
| Example runtime default | replan_steps = 5 (LIBERO example, not the paper) | examples/libero/main.py |
Check two conventions before porting. The code uses \(s = 1 - t\), which runs from 1 (noise) to 0 (data), with path \(a_s = s\,\varepsilon + (1 - s)\,a\) and target \(\varepsilon - a\). The velocity flips sign. Second, the paper places the joint state in the same embedding space as the language tokens, which reads as part of the prefix. The code puts the state token in the action expert's block. Follow the code.
Against Diffusion Policy. What stays: the chunk is the unit of prediction, the policy re-plans after part of it runs, and the network is trained by regression with one output per action step. What changes: the target is \(a - \varepsilon\) instead of \(\varepsilon\); the sampler is Euler with 10 steps instead of DDPM or DDIM steps; the velocity network is a 3B VLM with a 300M expert in place of a 1-D conv U-Net with FiLM; and the observation encoder is the VLM instead of a ResNet-18. Chi et al. [25] give the Diffusion Policy system in full.
Head to head
How the two methods relate: diffusion as a special case of the flow view, the number of sampling steps each needs, side-by-side code, robot policies, and a cheat sheet.
Diffusion is a flow too
Both methods are instances of one template, a Gaussian path between noise and data:
The velocity of this path for a given pair is \(\dot\alpha_t\, a + \dot\sigma_t\, \varepsilon\). Two choices of schedule give the two methods. Flow matching uses \(\alpha_t = t,\ \sigma_t = 1-t\). Diffusion with a variance-preserving cosine schedule uses \(\alpha_t = \sin(\pi t/2),\ \sigma_t = \cos(\pi t/2)\), where \(\alpha_t^2 + \sigma_t^2 = 1\) and \(\alpha_t^2\) plays the role of \(\bar\alpha_k\).
The linear schedule moves signal and noise at a constant rate. The cosine schedule changes slowly at both ends and fastest in the middle.
Converting between predictions
Suppose a network gives you the noise estimate \(\hat\varepsilon\) at \(a_t\). Then
For the linear path \(\dot\alpha_t = 1\) and \(\dot\sigma_t = -1\), so
A velocity network and an \(\varepsilon\)-network are the same information in different clothes, up to the schedule and a rescaling. The conversion from \(\hat\varepsilon\) to \(\hat a\) divides by \(\alpha_t\), which is zero at the noise end, so near \(t = 0\) that direction is ill-conditioned.
Translation dictionary
| Diffusion Policy | Flow matching | |
|---|---|---|
| Time convention | Discrete \(k\in\{1..K\}\); \(k=K\) is noise, small \(k\) is nearly clean | Continuous \(t\in[0,1]\); \(t=0\) is noise, \(t=1\) is data |
| Path / noise schedule | \(a^k=\sqrt{\bar\alpha_k}\,a+\sqrt{1-\bar\alpha_k}\,\varepsilon\), from a \(\beta\) / cosine table | \(a_t=(1-t)\,\varepsilon+t\,a\) (any \(\alpha_t,\sigma_t\) is allowed) |
| What the net predicts | \(\varepsilon_\theta(a^k,k,o)\). Clean-action (x) and v-prediction variants also exist | \(v_\theta(a_t,t,o)\), the velocity |
| Training loss | \(\|\varepsilon_\theta-\varepsilon\|^2\) | \(\|v_\theta-(a-\varepsilon)\|^2\) |
| Sampler | DDPM ancestral (an SDE); DDIM, roughly Euler on the probability-flow ODE | Any ODE solver: Euler, Heun, Runge-Kutta |
| Timestep sampling | Uniform over discrete \(k\) | Continuous \(t\), often non-uniform: logit-normal in SD3, Beta in \(\pi_0\) |
| Typical inference steps | About 10 with DDIM in Diffusion Policy; 100 for full DDPM | Often on the order of 10 Euler steps for robot policies |
Conventions differ between sources. Lipman et al. put noise at \(x_0\) and data at \(x_1\), as this page does. DDPM puts data at \(x_0\). The openpi code for \(\pi_0\) uses \(t = 1\) for noise and regresses \(\varepsilon - a\). The "v-prediction" of Salimans and Ho is a related but different quantity from the flow velocity here. Check the sign and the direction of time before mixing code from two repos.
With Gaussian paths, flow matching and diffusion are the same model family. The real differences are three: (1) the schedule or path, (2) the prediction target and the loss weighting it implies, and (3) a deterministic versus stochastic sampler. Flow matching also gives simpler code: no \(\bar\alpha\) tables, no \(\beta\) schedule, and a continuous \(t\) you can feed straight into the network.
Flow matching is not limited to Gaussian paths. The source does not have to be \(\mathcal{N}(0,I)\), and the pairs \((a_0, a_1)\) can come from any coupling. For example, you can start the flow from the previous action chunk instead of from noise.
Derivations
Converting between \(\hat\varepsilon\), \(\hat a\), velocity and score
Goal: derive \(\hat a=(a_t-\sigma_t\hat\varepsilon)/\alpha_t\), \(v=\dot\alpha_t\hat a+\dot\sigma_t\hat\varepsilon\) and \(\nabla\log p_t=-\hat\varepsilon/\sigma_t\), so that an \(\varepsilon\)-network, a velocity network and a score network are the same object.
- \[ a_t = \alpha_t\, a + \sigma_t\, \varepsilon . \]
The Gaussian path with time-dependent scalars \(\alpha_t,\sigma_t\). Below, \(\alpha=\alpha_t\), \(\sigma=\sigma_t\), \(x\) is the value of \(a_t\), and we need \(\alpha\neq 0\) (so \(t>0\)).
- \[ \alpha\, a = a_t - \sigma\,\varepsilon . \]
Subtract \(\sigma\varepsilon\) from both sides of step 1.
- \[ a = \frac{a_t - \sigma\,\varepsilon}{\alpha} . \]
Divide by \(\alpha\).
- \[ \mathbb{E}[a\mid a_t=x] = \frac{x - \sigma\,\mathbb{E}[\varepsilon\mid a_t=x]}{\alpha} . \]
Take \(\mathbb{E}[\cdot\mid a_t=x]\) of step 3. On the conditioning event \(a_t=x\), so replace \(a_t\) by \(x\). \(\alpha,\sigma\) are constants, so linearity applies.
- \[ \hat\varepsilon := \mathbb{E}[\varepsilon\mid a_t=x], \qquad \hat a := \mathbb{E}[a\mid a_t=x] . \]
Definitions. The \(\varepsilon\)-prediction network learns \(\hat\varepsilon\) (see the DDPM derivation). \(\hat a\) is the matching estimate of the clean action.
- \[ \hat a = \frac{a_t - \sigma\,\hat\varepsilon}{\alpha} . \]
Insert the definitions of step 5 into step 4.
- \[ u = \frac{d a_t}{dt} = \frac{d}{dt}\big(\alpha_t a\big) + \frac{d}{dt}\big(\sigma_t\varepsilon\big) . \]
Velocity of one pair. Differentiate step 1, using linearity of the derivative.
- \[ u = \dot\alpha_t\, a + \dot\sigma_t\, \varepsilon . \]
\(a\) and \(\varepsilon\) do not depend on \(t\), so they stay as constant factors.
- \[ v(x,t) = \mathbb{E}\big[u \mid a_t=x\big] = \mathbb{E}\big[\dot\alpha_t a + \dot\sigma_t \varepsilon \mid a_t=x\big] . \]
The marginal field is the conditional mean of the pair velocity (the conditional flow matching theorem). Insert step 8.
- \[ v(x,t) = \dot\alpha_t\,\mathbb{E}[a\mid a_t=x] + \dot\sigma_t\,\mathbb{E}[\varepsilon\mid a_t=x] . \]
Linearity of conditional expectation. \(\dot\alpha_t\) and \(\dot\sigma_t\) are deterministic numbers.
- \[ v = \dot\alpha_t\,\hat a + \dot\sigma_t\,\hat\varepsilon . \]
Insert the definitions of step 5.
- \[ \alpha_t=t,\quad \sigma_t=1-t \ \Rightarrow\ \dot\alpha_t = 1,\quad \dot\sigma_t=-1 . \]
Specialize to the linear path.
- \[ v = \hat a - \hat\varepsilon . \]
Insert step 12 into step 11. This is the first form.
- \[ \hat a = \frac{a_t - (1-t)\,\hat\varepsilon}{t} . \]
Step 6 with \(\alpha=t\), \(\sigma=1-t\).
- \[ v = \frac{a_t - (1-t)\,\hat\varepsilon}{t} - \hat\varepsilon . \]
Insert step 14 into step 13.
- \[ v = \frac{a_t - (1-t)\,\hat\varepsilon - t\,\hat\varepsilon}{t} . \]
Write \(\hat\varepsilon=\dfrac{t\,\hat\varepsilon}{t}\) and combine the fractions.
- \[ v = \frac{a_t - \hat\varepsilon}{t} . \]
\(-(1-t)\hat\varepsilon - t\hat\varepsilon = -\hat\varepsilon\). This is the second form. Check by rearranging step 14: \(a_t=t\hat a+(1-t)\hat\varepsilon\), so \(a_t-\hat\varepsilon = t\hat a-t\hat\varepsilon\), and dividing by \(t\) gives step 13 again.
- \[ \nabla_x\log p_t(x)=\frac{\nabla_x p_t(x)}{p_t(x)} . \]
Score. Chain rule for the logarithm: \(\nabla\log p=\nabla p/p\).
- \[ p_t(x) = \int p_t(x\mid a)\,p(a)\,da . \]
Law of total probability.
- \[ \nabla_x p_t(x) = \int \nabla_x p_t(x\mid a)\; p(a)\,da . \]
Differentiate step 19 in \(x\). \(p(a)\) does not depend on \(x\); exchange gradient and integral.
- \[ \nabla_x p_t(x\mid a) = p_t(x\mid a)\,\nabla_x\log p_t(x\mid a) . \]
Rearrange the chain rule of step 18, applied to the conditional density.
- \[ \nabla_x\log p_t(x) = \frac{1}{p_t(x)}\int p_t(x\mid a)\,\nabla_x\log p_t(x\mid a)\; p(a)\,da . \]
Insert steps 20 and 21 into step 18.
- \[ \nabla_x\log p_t(x) = \int \frac{p_t(x\mid a)\,p(a)}{p_t(x)}\;\nabla_x\log p_t(x\mid a)\, da . \]
The factor \(1/p_t(x)\) does not depend on \(a\), so move it inside the integral.
- \[ \frac{p_t(x\mid a)\,p(a)}{p_t(x)} = p(a\mid a_t=x) . \]
Bayes' rule.
- \[ \nabla_x\log p_t(x) = \mathbb{E}\big[\nabla_x\log p_t(x\mid a)\ \big|\ a_t=x\big] . \]
Step 23 with step 24: an integral against the posterior \(p(a\mid x)\) is a conditional expectation. This is Tweedie's formula.
- \[ \log p_t(x\mid a) = -\frac{d}{2}\log(2\pi\sigma^2) - \frac{\|x-\alpha a\|^2}{2\sigma^2} . \]
The conditional is \(p_t(x\mid a)=\mathcal{N}(x;\alpha a,\sigma^2 I)\) in \(d\) dimensions. Take the log of the Gaussian density.
- \[ \nabla_x\log p_t(x\mid a) = -\frac{2\,(x-\alpha a)}{2\sigma^2} = -\frac{x-\alpha a}{\sigma^2} . \]
The first term of step 26 has no \(x\). For the second, \(\nabla_x\|x-c\|^2 = 2(x-c)\).
- \[ x - \alpha a = \sigma\,\varepsilon \quad \text{on the event } a_t=x . \]
Step 1 with \(a_t=x\), rearranged.
- \[ \nabla_x\log p_t(x\mid a) = -\frac{\sigma\,\varepsilon}{\sigma^2} = -\frac{\varepsilon}{\sigma} . \]
Insert step 28 into step 27 and cancel one \(\sigma\).
- \[ \nabla_x\log p_t(x) = \mathbb{E}\Big[-\frac{\varepsilon}{\sigma}\ \Big|\ a_t=x\Big] = -\frac{\mathbb{E}[\varepsilon\mid a_t=x]}{\sigma} . \]
Insert step 29 into step 25. \(\sigma\) is deterministic, so it leaves the expectation (linearity).
- \[ \nabla_x\log p_t(x) = -\frac{\hat\varepsilon}{\sigma_t} . \]
Definition of \(\hat\varepsilon\) in step 5.
Result: with \(\hat\varepsilon=\mathbb{E}[\varepsilon\mid a_t]\): \(\hat a=(a_t-\sigma_t\hat\varepsilon)/\alpha_t\), \(v=\dot\alpha_t\hat a+\dot\sigma_t\hat\varepsilon\), and \(\nabla\log p_t(a_t)=-\hat\varepsilon/\sigma_t\). On the linear path \(v=\hat a-\hat\varepsilon=(a_t-\hat\varepsilon)/t\). One trained network gives all four quantities, so the choice between \(\varepsilon\)-, \(a\)-, velocity- and score-prediction is a choice of parameterization and loss weighting, not of model class.
The flow loss is a weighted \(\varepsilon\)-loss
Goal: show that on the straight-line path, \(\|v_\theta-u\|^2=\tfrac{1}{t^2}\|\hat\varepsilon_\theta-\varepsilon\|^2\), so flow matching is \(\varepsilon\)-prediction with the time weight \(1/t^2\), which strongly emphasizes the noisy end.
- \[ v_\theta = \frac{a_t - \hat\varepsilon_\theta}{t} . \]
Define the velocity network through an \(\varepsilon\)-estimate \(\hat\varepsilon_\theta(a_t,t)\) using the linear-path conversion (see the conversions derivation). This is only a change of parameterization and needs \(t>0\).
- \[ a_t = (1-t)\,\varepsilon + t\,a . \]
The straight-line path for one pair.
- \[ t\,a = a_t - (1-t)\,\varepsilon . \]
Subtract \((1-t)\varepsilon\) from both sides of step 2.
- \[ a = \frac{a_t - (1-t)\,\varepsilon}{t} . \]
Divide by \(t\).
- \[ u = a - \varepsilon = \frac{a_t - (1-t)\,\varepsilon}{t} - \varepsilon . \]
The pair target \(u=a-\varepsilon\), with step 4 inserted for \(a\).
- \[ u = \frac{a_t - (1-t)\,\varepsilon - t\,\varepsilon}{t} . \]
Write \(\varepsilon = \dfrac{t\,\varepsilon}{t}\) and combine the fractions.
- \[ u = \frac{a_t - \varepsilon}{t} . \]
\(-(1-t)\varepsilon - t\varepsilon = -\varepsilon\). Now \(u\) has the same form as \(v_\theta\) in step 1.
- \[ v_\theta - u = \frac{a_t - \hat\varepsilon_\theta}{t} - \frac{a_t - \varepsilon}{t} . \]
Subtract step 7 from step 1.
- \[ v_\theta - u = \frac{a_t - \hat\varepsilon_\theta - a_t + \varepsilon}{t} . \]
Common denominator \(t\); distribute the minus sign.
- \[ v_\theta - u = -\,\frac{\hat\varepsilon_\theta - \varepsilon}{t} . \]
The \(a_t\) terms cancel. What remains is \(-\hat\varepsilon_\theta+\varepsilon=-(\hat\varepsilon_\theta-\varepsilon)\).
- \[ \|v_\theta - u\|^2 = \Big(\frac{1}{t}\Big)^2 \big\|\hat\varepsilon_\theta - \varepsilon\big\|^2 . \]
\(\|c\,w\|^2=c^2\|w\|^2\) for a scalar \(c\). Here \(c=-1/t\), and \((-1/t)^2=1/t^2\).
- \[ \mathcal{L}_{\text{flow}} = \mathbb{E}_{t,\varepsilon,a}\Big[\frac{1}{t^2}\,\big\|\hat\varepsilon_\theta(a_t,t)-\varepsilon\big\|^2\Big] . \]
Take the expectation of step 11 over \(t\), \(\varepsilon\), \(a\).
- \[ w(t) = \frac{1}{t^2}: \quad w(0.1)=100,\quad w(0.5)=4,\quad w(1)=1 . \]
Evaluate the weight at three times. Near \(t=0\) (the noisy end) an error in \(\hat\varepsilon\) costs far more than near \(t=1\).
- \[ \mathcal{L}_{\text{diff}} = \mathbb{E}\|\varepsilon_\theta - \varepsilon\|^2 \quad (\text{weight } 1 \text{ at every noise level}). \]
The standard \(\varepsilon\)-loss in Diffusion Policy for comparison. Same quantity inside the norm, different weight.
Result: \(\|v_\theta-u\|^2=\tfrac{1}{t^2}\|\hat\varepsilon_\theta-\varepsilon\|^2\). For the same linear path, flow matching and \(\varepsilon\)-prediction differ only in how they weight noise levels: \(1/t^2\) for flow matching, a constant for the plain \(\varepsilon\)-loss. This is what "loss weighting" means in the literature. The identity holds for \(t>0\). If you train \(v_\theta\) directly, nothing diverges, because the network outputs \(v\), not \(\varepsilon\). Choosing a non-uniform density for \(t\) multiplies this weight by that density, so it changes the effective weighting too.
DDIM is an exact Euler step in rescaled variables, and flow Euler is DDIM
Goal: show that the deterministic DDIM update \(a_{t'}=\alpha_{t'}\hat a+\sigma_{t'}\hat\varepsilon\) is one Euler step of an ODE in the variables \(\bar x=a_t/\alpha_t\) and \(\lambda=\sigma_t/\alpha_t\), and that on the linear path plain Euler in \(t\) gives the identical update.
- \[ a_t = \alpha_t\, a + \sigma_t\, \varepsilon . \]
The Gaussian path. Abbreviate \(\alpha=\alpha_t\), \(\sigma=\sigma_t\) at the current time and \(\alpha'=\alpha_{t'}\), \(\sigma'=\sigma_{t'}\) at the next time \(t'\). Assume \(\alpha>0\).
- \[ \bar x := \frac{a_t}{\alpha_t}, \qquad \lambda := \frac{\sigma_t}{\alpha_t} . \]
Rescaled variables. Dividing by \(\alpha_t\) removes the signal scaling.
- \[ \bar x = \frac{\alpha\, a + \sigma\,\varepsilon}{\alpha} = a + \lambda\,\varepsilon . \]
Divide step 1 by \(\alpha\) and use the definition of \(\lambda\).
- \[ \frac{d\bar x}{d\lambda} = \frac{d}{d\lambda}\big(a + \lambda\,\varepsilon\big) = \varepsilon . \]
For one pair, \(a\) and \(\varepsilon\) are constant, so the path is a straight line in \(\lambda\) with slope \(\varepsilon\). \(\lambda\) is a valid clock because \(\sigma_t/\alpha_t\) decreases monotonically from \(\infty\) to about \(0\) as \(t\) goes from \(0\) to \(1\).
- \[ \frac{d\bar x}{d\lambda} = \mathbb{E}\big[\varepsilon \mid \bar x\big] =: \hat\varepsilon(\bar x,\lambda) . \]
The marginal field is the conditional mean of the per-pair velocity (the same argument as the conditional flow matching theorem, now for the path \(a+\lambda\varepsilon\)). Conditioning on \(\bar x\) is the same as conditioning on \(a_t\), because \(\bar x=a_t/\alpha_t\) is a bijection.
- \[ \bar x' = \bar x + (\lambda' - \lambda)\,\hat\varepsilon . \]
One Euler step of step 5 from \(\lambda\) to \(\lambda'=\sigma'/\alpha'\), holding \(\hat\varepsilon\) fixed. If \(\hat\varepsilon\) were exactly constant along the path, this would be exact.
- \[ a_{t'} = \alpha'\,\bar x' . \]
Undo the rescaling at the new time: \(\bar x'=a_{t'}/\alpha'\).
- \[ a_{t'} = \alpha'\,\bar x + \alpha'(\lambda'-\lambda)\,\hat\varepsilon . \]
Insert step 6 into step 7.
- \[ \alpha'\bar x = \frac{\alpha'}{\alpha}\,a_t, \qquad \alpha'\lambda' = \sigma', \qquad \alpha'\lambda = \frac{\alpha'}{\alpha}\,\sigma . \]
Substitute \(\bar x=a_t/\alpha\), \(\lambda'=\sigma'/\alpha'\) and \(\lambda=\sigma/\alpha\).
- \[ a_{t'} = \frac{\alpha'}{\alpha}\,a_t + \sigma'\,\hat\varepsilon - \frac{\alpha'}{\alpha}\,\sigma\,\hat\varepsilon . \]
Insert step 9 into step 8 and distribute \(\hat\varepsilon\) over \((\alpha'\lambda'-\alpha'\lambda)\).
- \[ a_{t'} = \frac{\alpha'}{\alpha}\,\big(a_t - \sigma\,\hat\varepsilon\big) + \sigma'\,\hat\varepsilon . \]
Factor \(\alpha'/\alpha\) out of the first and third terms.
- \[ \hat a = \frac{a_t - \sigma\,\hat\varepsilon}{\alpha} . \]
Definition of the clean-action estimate (conversions derivation).
- \[ a_{t'} = \alpha'\,\hat a + \sigma'\,\hat\varepsilon . \]
In step 11, \(\frac{\alpha'}{\alpha}(a_t-\sigma\hat\varepsilon)=\alpha'\hat a\) by step 12. This is the DDIM update: take the current clean estimate and noise estimate and re-mix them with the next level's coefficients.
- \[ \alpha_t=\sqrt{\bar\alpha_k},\ \ \sigma_t=\sqrt{1-\bar\alpha_k} \ \Rightarrow\ a^{k-1} = \sqrt{\bar\alpha_{k-1}}\;\hat a + \sqrt{1-\bar\alpha_{k-1}}\;\hat\varepsilon . \]
Diffusion Policy notation: the current level \(k\) plays \(t\) and the next, cleaner level \(k-1\) plays \(t'\). Here \(\hat a=(a^k-\sqrt{1-\bar\alpha_k}\,\hat\varepsilon)/\sqrt{\bar\alpha_k}\) and \(\hat\varepsilon=\varepsilon_\theta(a^k,k,o)\). This is DDIM with \(\eta=0\) (no added noise).
- \[ \alpha_t = t,\quad \sigma_t = 1-t,\quad t' = t+\Delta t . \]
Now the linear path. Take the Euler step in \(t\) itself.
- \[ a_{t'} = a_t + \Delta t\,\big(\hat a - \hat\varepsilon\big) . \]
Euler for the flow ODE with \(v=\hat a-\hat\varepsilon\) (conversions derivation).
- \[ a_t = t\,\hat a + (1-t)\,\hat\varepsilon . \]
Rearrange step 12 for \(\alpha=t\), \(\sigma=1-t\): \(t\,\hat a=a_t-(1-t)\hat\varepsilon\). This holds by the definition of \(\hat a\).
- \[ a_{t'} = t\,\hat a + (1-t)\,\hat\varepsilon + \Delta t\,\hat a - \Delta t\,\hat\varepsilon . \]
Insert step 17 into step 16 and distribute \(\Delta t\).
- \[ a_{t'} = (t+\Delta t)\,\hat a + (1-t-\Delta t)\,\hat\varepsilon . \]
Collect the \(\hat a\) terms: \(t+\Delta t\). Collect the \(\hat\varepsilon\) terms: \((1-t)-\Delta t\).
- \[ a_{t'} = \alpha_{t'}\,\hat a + \sigma_{t'}\,\hat\varepsilon . \]
\(\alpha_{t'}=t+\Delta t\) and \(\sigma_{t'}=1-(t+\Delta t)\) for the linear schedule. Compare with step 13: identical.
Result: DDIM is exactly an Euler step of \(d\bar x/d\lambda=\hat\varepsilon\), the ODE in rescaled variables, and equals \(a_{t'}=\alpha_{t'}\hat a+\sigma_{t'}\hat\varepsilon\). On the linear schedule, Euler on the flow ODE in plain \(t\) produces the same numbers. So flow-matching Euler on the linear path is DDIM on the linear schedule. The two samplers differ only through the schedule \((\alpha_t,\sigma_t)\), and through which quantity (\(a_t\) or \(\bar x\)) is assumed to move at constant velocity during a step.
Few-step sampling
Euler replaces the true path by a straight segment of length \(\Delta t\) along the current velocity. The local error of one step is about \(\tfrac12 \Delta t^2\) times the acceleration of the path, that is, its curvature. If the path is straight, the acceleration is zero and a single Euler step is exact. The more a path bends, the more steps you need to follow it. Straighter paths therefore mean fewer steps, which for a robot policy means lower latency per action chunk.
Use the slider to change the number of Euler steps \(N\). Both samplers see the same noise.
- \(N = 1\). The flow matching sample lands on the mean of the modes, between them, where no action exists. At \(t = 0\) the field gives \(v = \mathbb{E}[a] - a_0\) at every point, so one Euler step ends at \(\mathbb{E}[a]\) regardless of the noise. This is the classic mode-averaging failure. It is also why one-step generation needs extra machinery: the model must know about the whole trajectory, not only the local direction.
- \(N \approx 4\) to \(8\). Flow matching is already close to the target distribution.
- The VP ODE. The diffusion probability-flow sampler needs noticeably more steps for the same quality, because its paths curve more.
Straighter and shorter
Even the exact marginal flow matching field does not give straight paths, as the conditional flow matching part showed. Several methods go further.
- Rectified flow with reflow. Train a model, run it to get pairs \((\varepsilon, a)\) where \(a\) is the model's own output for noise \(\varepsilon\), and retrain on those pairs. The new coupling is deterministic, so the lines cross less and the new paths are straighter.
- Minibatch optimal-transport couplings. Instead of pairing noise and data at random within a batch, match them to minimize total distance. Pairs that are close in space cross less.
- Consistency, shortcut and MeanFlow models. Instead of making the path straight, learn to jump along it. A consistency model maps any point on a trajectory to its endpoint. A shortcut model takes the step size as an extra input. MeanFlow learns the average velocity over an interval, so one network call can cover a long step.
Fewer steps is a property of the learned field, not free. Real policies with multimodal data still bend. Measure success rate against \(N\) on your own task before you cut the step count.
Derivations
Why curvature costs steps, and why one step collapses to the mean
Goal: quantify the Euler error with a Taylor expansion, show it vanishes for a single straight pair and grows with path curvature for the marginal field, then show that with \(N=1\) every noise sample is mapped to the mean \(\mathbb{E}[a]\).
- \[ \dot a(t) = v\big(a(t),t\big) . \]
The sampling ODE. \(a(t)\) is the exact trajectory, \(h\) below is the step size (\(h=\Delta t\)).
- \[ a(t+h) = a(t) + h\,\dot a(t) + \frac{h^2}{2}\,\ddot a(t) + O(h^3) . \]
Taylor expansion of the exact solution around \(t\), to second order.
- \[ a_{\text{Euler}}(t+h) = a(t) + h\,v\big(a(t),t\big) = a(t) + h\,\dot a(t) . \]
One Euler step uses the velocity at the start of the step. The second equality is step 1.
- \[ e := a(t+h) - a_{\text{Euler}}(t+h) = \frac{h^2}{2}\,\ddot a(t) + O(h^3) . \]
Subtract step 3 from step 2. The \(a(t)\) and \(h\dot a\) terms cancel.
- \[ \|e\| \approx \frac{h^2}{2}\,\|\ddot a(t)\| . \]
Take the norm and drop the \(O(h^3)\) remainder. The local error is quadratic in \(h\) and proportional to the acceleration \(\ddot a\) of the path.
- \[ \ddot a(t) = \frac{d}{dt}\, v\big(a(t),t\big) . \]
Differentiate step 1 in \(t\).
- \[ \frac{d}{dt}\, v\big(a(t),t\big) = \partial_t v + (\nabla_x v)\,\dot a(t) . \]
Multivariable chain rule. \(v\) depends on \(t\) directly and through \(a(t)\). \(\nabla_x v\) is the Jacobian matrix with entries \(\partial v_i/\partial x_j\).
- \[ \ddot a = \partial_t v + (\nabla_x v)\, v . \]
Replace \(\dot a\) by \(v\) using step 1. This is the acceleration of a particle riding the field.
- \[ v(x,t) \equiv u = a - \varepsilon \ \ \text{(one pair, constant)} . \]
Single straight pair: the field is the constant vector \(a-\varepsilon\), the same at every point and time.
- \[ \partial_t v = 0, \qquad \nabla_x v = 0 . \]
The derivative of a constant is zero.
- \[ \ddot a = 0 + 0\cdot v = 0 . \]
Insert step 10 into step 8.
- \[ e = \frac{h^2}{2}\cdot 0 + 0 = 0 \quad \text{for every } h . \]
With \(\ddot a=0\) all higher derivatives vanish too (\(a(t)=\varepsilon+t(a-\varepsilon)\) is a polynomial of degree one), so the Taylor series of step 2 ends after the first-order term. One Euler step, even with \(h=1\), is exact.
- \[ \|e_n\| \le \frac{h^2}{2}\,C, \qquad C := \max_t \|\ddot a(t)\| . \]
For the marginal field \(\ddot a\neq 0\) wherever paths bend. Bound the local error of each step by the largest acceleration \(C\).
- \[ N = \frac1h \ \text{steps} \ \Rightarrow\ \sum_{n=1}^{N}\|e_n\| \le N\,\frac{h^2}{2}\,C = \frac{h}{2}\,C . \]
Add the errors of \(N=1/h\) steps and simplify \(N h^2=h\).
- \[ \|a(1) - a_{\text{Euler}}(1)\| \le \frac{h\,C}{2L}\,\big(e^{L}-1\big) . \]
Earlier errors are also propagated by later steps. If \(v\) is \(L\)-Lipschitz in \(x\), the recursion \(E_{n+1}\le(1+hL)E_n+\tfrac{h^2}{2}C\) sums to this bound (geometric series, \((1+hL)^N\le e^{L}\)). The global error is \(O(h)\), with a constant that grows with curvature \(C\).
- \[ a_0 = (1-0)\,\varepsilon + 0\cdot a = \varepsilon . \]
Now \(N=1\). At \(t=0\) the linear path sits at the noise sample. \(\varepsilon\) is drawn independently of \(a\).
- \[ v(x,0) = \mathbb{E}\big[a-\varepsilon \mid a_0=x\big] = \mathbb{E}[a\mid \varepsilon=x] - \mathbb{E}[\varepsilon\mid \varepsilon=x] . \]
Marginal field at \(t=0\). Use step 16 to replace the conditioning event \(a_0=x\) by \(\varepsilon=x\), and linearity.
- \[ \mathbb{E}[\varepsilon\mid\varepsilon=x]=x, \qquad \mathbb{E}[a\mid\varepsilon=x]=\mathbb{E}[a] . \]
Given \(\varepsilon=x\), the noise equals \(x\) with certainty. Since \(a\) is independent of \(\varepsilon\), conditioning on \(\varepsilon\) does not change the distribution of \(a\).
- \[ v(x,0) = \mathbb{E}[a] - x . \]
Insert step 18 into step 17.
- \[ a_1^{\,N=1} = a_0 + 1\cdot v(a_0, 0) = x + \big(\mathbb{E}[a]-x\big) . \]
One Euler step with \(h=1\), starting at \(x=a_0=\varepsilon\).
- \[ a_1^{\,N=1} = \mathbb{E}[a] \quad \text{for every noise sample } \varepsilon . \]
The \(x\) terms cancel. The output does not depend on the noise at all.
Result: the local Euler error is \(\tfrac{h^2}{2}\|\ddot a\|\) with \(\ddot a=\partial_t v+(\nabla_x v)v\). It is zero for one straight pair and positive for the marginal field wherever paths bend, giving a global error \(O(h)\) scaled by curvature. With a single step, the exact marginal field sends every noise sample to the mean of the action distribution, \(\mathbb{E}[a]\). For a bimodal task (go left or go right around an obstacle) that mean lies between the modes, where no demonstration exists.
Side-by-side code
The snippets below are copied from toy.py, a runnable script that trains a diffusion model and a flow matching model on the same 2-D bimodal action data with the same network. Only the time variable, the noising line and the regression target change. The observation path, the network and the optimizer stay the same.
Diffusion: training step
# DDPM eps-prediction, as in Diffusion Policy
a = sample_actions(B) # clean action chunk
obs = torch.full((B, 4), 0.5) # observation (constant in this toy)
k = torch.randint(1, K + 1, (B, 1)) # k in {1..K}
ab = abar[k] # alpha-bar_k
eps = torch.randn_like(a)
a_k = ab.sqrt() * a + (1 - ab).sqrt() * eps # forward noising
loss = ((net(a_k, k.float(), obs) - eps) ** 2).mean() # predict epsFlow matching: training step
# linear-path flow matching, velocity target
a = sample_actions(B) # clean action chunk
obs = torch.full((B, 4), 0.5) # observation (constant in this toy)
t = torch.rand(B, 1) # t ~ U(0, 1)
eps = torch.randn_like(a)
a_t = (1 - t) * eps + t * a # t = 0 is noise, t = 1 is data
v = net(a_t, TIME_SCALE * t, obs) # TIME_SCALE = 100 so t spans 0..100 like k
loss = ((v - (a - eps)) ** 2).mean() # target a - epsSampling is where the two methods differ most. The DDIM loop below takes ten network calls on a fixed schedule of diffusion times. The Euler loop takes N calls on a uniform grid in t.
Diffusion: DDIM, 10 steps, eta = 0
obs = torch.full((n, 4), 0.5)
x = torch.randn(n, 2) # start from noise
ks = list(range(K, 0, -K // steps)) # steps = 10: 100, 90, ..., 10
for k, k_prev in zip(ks, ks[1:] + [0]):
eps_hat = net(x, torch.full((n, 1), float(k)), obs)
x0_hat = (x - (1 - abar[k]).sqrt() * eps_hat) / abar[k].sqrt()
x = abar[k_prev].sqrt() * x0_hat + (1 - abar[k_prev]).sqrt() * eps_hat # no new noiseFlow matching: Euler, N steps
obs = torch.full((n, 4), 0.5)
x = torch.randn(n, 2) # start at noise (t = 0)
dt = 1.0 / N
for i in range(N):
t = torch.full((n, 1), i * dt)
x = x + dt * net(x, TIME_SCALE * t, obs) # Euler step along vToy results
These numbers come from a 2-D toy run, not a benchmark. There is one seed, 4000 training steps per model, and 2000 samples per sampler. The metric is the fraction of samples within 0.5 of a mode center.
| Sampler | Network calls per sample | Fraction within 0.5 of a mode |
|---|---|---|
| Diffusion, DDPM ancestral | 100 | 0.992 |
| Diffusion, DDIM (eta = 0) | 10 | 0.971 |
| Flow matching, Euler | 1 | 0.000 |
| Flow matching, Euler | 2 | 0.524 |
| Flow matching, Euler | 4 | 0.876 |
| Flow matching, Euler | 10 | 0.964 |
With N = 1, the Euler sample lands at the average of the two modes, near (0, 1). That is why almost no samples are close to either mode. At N = 10, flow matching is close to the 100-step DDPM sampler on this toy. A toy this simple cannot say which method is better.
What changes in a real Diffusion Policy codebase
- Drop the noise scheduler object. In the Diffusion Policy repo this is a
DDPMSchedulerwithadd_noiseandstep. The flow version needs one interpolation line for training and one loop for sampling. - Sample a continuous time
t ~ U(0, 1)for each batch element, instead of an integerkfrom the scheduler's training timesteps. - Replace the target. Regress
vontoa − εinstead ofε. The noising line becomesa_t = (1 − t) ε + t a. - Feed the embedding a float time. If your sinusoidal embedding was tuned for integer
k, scalet(for example100 tor1000 t) so the frequencies see a similar range. A rawtin [0, 1] leaves many of the sinusoidal frequencies nearly constant over the trajectory, so the network gets little time signal. - Sampling becomes a loop of N Euler steps,
x = x + dt * v. There are no β or ᾱ tables, no per-step noise, and noscheduler.stepcall. - Keep these unchanged: action chunking, the observation encoder, EMA of the weights, action normalization, and the conditioning path into the network.
Uniform t is the simplest choice, not a requirement. Logit-normal sampling, used for Stable Diffusion 3, puts more weight on mid-trajectory times. π0 samples from a Beta distribution skewed toward the noisy end, which is small t in this page's convention. Either one is a single line in the training step.
Flow policies in robotics
Robot learning adopted flow matching for three practical reasons. Training is one regression on a velocity target, with no noise schedule to choose. Sampling takes a few network calls, which matters when a policy must emit a new action chunk at control rate. And the same network can serve as an action head on top of a vision-language model, as in π0 [26].
| Method | Year | What flows | Key design choice | Steps at inference |
|---|---|---|---|---|
| Diffusion Policy [25] | 2023 | Action chunks, denoised with DDPM/DDIM (epsilon-prediction) | 100 DDPM training steps; DDIM sampling at inference | 10 DDIM |
| π0 [26] | 2024 | Action chunks (H = 50) from a flow-matching action expert on a VLM | Linear path; Beta-sampled time that favors the noisy end | 10 |
| GR00T N1 [29] | 2025 | Actions from a diffusion-transformer action head | Action head trained with flow matching | 4 |
| FlowPolicy [31] | 2024 (AAAI 2025) | Actions from a flow conditioned on a 3D point cloud | Consistency flow matching; velocity self-consistency in action space | 1 (single-step claimed by authors) |
| ReinFlow [33] | 2025 | Rectified Flow or Shortcut Model policies, fine-tuned with RL | Injects learnable noise so the policy likelihood can be computed | 1 to 4 (as reported) |
| Streaming Flow Policy [30] | 2025 | Action trajectories as flow trajectories, starting near the last action | Actions are streamed to the robot during sampling | — |
| Affordance-based flow matching [32] | 2024 | Random waypoints flowed into target trajectories | Supervised flow matching guided by affordances | — |
The openpi repository ships three VLA models that differ in how they produce actions. π0 is flow-based. π0-FAST is autoregressive: it emits discrete tokens from the FAST action tokenizer [28] and uses no flow. π0.5 [27] is a later model based on π0, and the released code supports only its flow-matching head [35].
Case study: π0's action expert
π0 [26] is a vision-language-action model built on a pre-trained VLM. The paper calls the second set of weights the action expert. It has its own weights, separate from the VLM, and its action tokens use full bidirectional attention among themselves.
Each training example is an action chunk with \(H = 50\) steps. The flow time \(t\) is drawn from a Beta distribution that puts more mass on the noisy end. In the openpi code this is Beta(1.5, 1), rescaled into [0.001, 1] [35]. The network is trained to regress the velocity. At inference the policy starts from Gaussian noise and takes 10 Euler steps.
Take the time convention from the code, not from the paper's notation. The openpi code uses \(t = 1\) for noise, with \(x_t = t\,\varepsilon + (1 - t)\,A\) and target \(\varepsilon - A\). This is the page's path with time reversed. Flipping the time direction also flips the velocity sign, so porting between the two requires changing both.
When to pick which
- Both methods take the same inputs: a noisy action chunk, a time or step index, and the observation. One backbone and one observation encoder can serve either [25] [26].
- Pick flow matching when you want simpler code and few sampling steps. The loss is one regression on a velocity target, and the linear path has no schedule to tune [13].
- Diffusion codebases transfer. Observation encoders, action normalization, and receding-horizon execution carry over unchanged [25].
- Keep a stochastic sampler when diversity matters. A deterministic flow ODE maps each noise draw to one action chunk, so the spread of behaviors comes from the initial noise. Stochastic inference needs extra machinery; ReinFlow [33] injects learnable noise into the flow for RL fine-tuning.
- Evaluate success against the step count, not only at the default. A one-step flow sample can land between modes, so check success at 1, 4, and 10 steps before choosing a setting.
- Check the time convention before porting any code. See the pitfall in the case study.
Cheat sheet and pitfalls
Use this table to translate between the two codebases you read, and to check which parts of a Diffusion Policy implementation need to change.
| Concept | Diffusion Policy (DDPM) | Flow matching policy |
|---|---|---|
| Noise to data | Data at \(k = 0\), noise at \(k = K\). Sampling runs \(k\) from \(K\) down to 0. | Noise at \(t = 0\), data at \(t = 1\). Sampling integrates \(t\) from 0 to 1. |
| Time variable | Integer \(k \in \{1, \dots, K\}\), with \(K = 100\) in Diffusion Policy. | Continuous \(t \in [0, 1]\), drawn uniformly for each example. |
| Corruption | \(a^k = \sqrt{\bar{\alpha}_k}\, a + \sqrt{1 - \bar{\alpha}_k}\, \varepsilon\) | \(a_t = (1 - t)\, \varepsilon + t\, a\) |
| Target | \(\varepsilon\) | \(u = a - \varepsilon\), a velocity |
| Loss | \(\lVert \varepsilon_\theta(a^k, k, o) - \varepsilon \rVert^2\) | \(\lVert v_\theta(a_t, t, o) - (a - \varepsilon) \rVert^2\) |
| Sampler | Ancestral DDPM, or DDIM | Euler, or a higher-order ODE solver |
| Typical steps | 100 ancestral steps. DDIM can use fewer (10 in the toy). | N Euler steps. N = 1 gives the mean. The toy needs about 10. |
| Extra state | β and ᾱ tables computed from the noise schedule. | None. The linear path needs no tables. |
| Stochasticity at inference | Ancestral sampling adds fresh noise at each step. DDIM with η = 0 is deterministic. | Deterministic, given the starting noise. |
Pitfalls
Time conventions flip across papers and code. Lipman et al. use \(x_0\) for noise and \(x_1\) for data, as this page does. The DDPM paper writes \(x_0\) for data. The openpi (π0) code uses \(t = 1\) for noise and the target \(\varepsilon - a\). The sign of time and the sign of the target both change. A mismatch between training and sampling code does not raise an error. The samples come out wrong, and the loss curve gives no warning. Check the convention with a 1-D Gaussian before you train on robot data.
Dividing by a scale that goes to zero. Converting to a score divides by \(\sigma_t\). For the linear path, the score is \(-\hat\varepsilon / \sigma_t\) with \(\sigma_t = 1 - t\), which blows up at \(t = 1\). Converting from \(\hat\varepsilon\) to \(v\) divides by \(t\), which blows up at \(t = 0\). Clamp \(t\) to a small interval such as \([10^{-3}, 1 - 10^{-3}]\) wherever you convert.
Judging flow matching with one step. With the exact field, one Euler step from any noise sample lands at \(E[a]\), the average of the modes. A one-step sample between the modes does not mean the model is broken. Evaluate at N = 4 to 10 before you conclude anything. In the toy, N = 1 puts 0% of samples near a mode, and N = 10 puts 96% there.
Mismatched time scaling in the embedding. A sinusoidal embedding tuned for integer \(k\) in 0 to 99, fed a raw \(t\) in \([0, 1]\), sees almost no change in time for most of its frequencies. The reverse also happens: feeding integer \(k\) into a flow model. The loss can still go down, because \(a_t\) carries some information about time. The bug appears as a weaker model, not as a crash. Scale \(t\) to the range the embedding expects. In toy.py the scale is 100.
Integrating in the wrong direction. The Euler sampler on this page starts at \(t = 0\) and adds \(\Delta t \cdot v\) with \(\Delta t \gt 0\). Under the openpi convention, \(t = 1\) is noise, so you start at \(t = 1\) and step with \(\Delta t \lt 0\). Using the step sign from one convention and the start point from the other sends samples to the wrong end. The samples come out noise-like or in the wrong place. Check that samples match the training distribution, not only that the loss is small.
Normalizing actions. Normalize actions the same way you do for diffusion. Diffusion Policy uses min-max normalization to \([-1, 1]\), with statistics from the training set. Invert the normalization after sampling. The noise term has unit variance. If the actions have a very different scale, the path is mostly data over most of \(t\), and the model learns little about the noise end.
- Pick a straight path from noise to data: \(a_t = (1 - t)\, \varepsilon + t\, a\).
- The network learns the velocity \(u = a - \varepsilon\) that moves a point along that path.
- Training is regression on random \((\varepsilon, a, t)\) triples. Nothing else is learned.
- Sampling starts at noise and takes Euler steps \(a \leftarrow a + \Delta t\, v_\theta\) from \(t = 0\) to \(t = 1\).
- Each point's velocity is an average over every path that passes through it, so few steps blur between modes.
- Diffusion is the same recipe on curved paths with \(\varepsilon\) as the target. Diffusion Policy's chunking, observation encoder and EMA carry over unchanged.
References and further reading
- Sohl-Dickstein et al. Deep Unsupervised Learning using Nonequilibrium Thermodynamics. ICML 2015. arXiv:1503.03585
- Ho et al. Denoising Diffusion Probabilistic Models. NeurIPS 2020. arXiv:2006.11239
- Song, Meng and Ermon. Denoising Diffusion Implicit Models. ICLR 2021. arXiv:2010.02502
- Nichol and Dhariwal. Improved Denoising Diffusion Probabilistic Models. ICML 2021. arXiv:2102.09672
- Song et al. Score-Based Generative Modeling through Stochastic Differential Equations. ICLR 2021. arXiv:2011.13456
- Anderson. Reverse-time diffusion equation models. Stochastic Processes and their Applications 12(3):313–326, 1982. doi:10.1016/0304-4149(82)90051-5
- Vincent. A Connection Between Score Matching and Denoising Autoencoders. Neural Computation 23(7):1661–1674, 2011. doi:10.1162/NECO_a_00142
- Perez et al. FiLM: Visual Reasoning with a General Conditioning Layer. AAAI 2018. arXiv:1709.07871
- Lipman et al. Flow Matching for Generative Modeling. ICLR 2023. arXiv:2210.02747
- Liu et al. Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow. ICLR 2023 (Spotlight). arXiv:2209.03003
- Albergo and Vanden-Eijnden. Building Normalizing Flows with Stochastic Interpolants. ICLR 2023. arXiv:2209.15571
- Tong et al. Improving and generalizing flow-based generative models with minibatch optimal transport. Transactions on Machine Learning Research (TMLR); arXiv 2023. arXiv:2302.00482
- Lipman et al. Flow Matching Guide and Code. arXiv, 2024. arXiv:2412.06264
- Esser et al. Scaling Rectified Flow Transformers for High-Resolution Image Synthesis. arXiv, 2024. arXiv:2403.03206
- Geng et al. Mean Flows for One-step Generative Modeling. arXiv, 2025. arXiv:2505.13447
- Frans et al. One Step Diffusion via Shortcut Models. arXiv, 2024. arXiv:2410.12557
- Chen et al. Neural Ordinary Differential Equations. NeurIPS 2018. arXiv:1806.07366
- Grathwohl et al. FFJORD: Free-form Continuous Dynamics for Scalable Reversible Generative Models. arXiv, 2018. arXiv:1810.01367
- Pooladian et al. Multisample Flow Matching: Straightening Flows with Minibatch Couplings. ICML 2023. arXiv:2304.14772
- Albergo, Boffi and Vanden-Eijnden. Stochastic Interpolants: A Unifying Framework for Flows and Diffusions. arXiv, 2023. arXiv:2303.08797
- Karras et al. Elucidating the Design Space of Diffusion-Based Generative Models. NeurIPS 2022. arXiv:2206.00364
- Song et al. Consistency Models. ICML 2023. arXiv:2303.01469
- Yang et al. Consistency Flow Matching: Defining Straight Flows with Velocity Consistency. arXiv, 2024. arXiv:2407.02398
- Kingma and Gao. Understanding Diffusion Objectives as the ELBO with Simple Data Augmentation. arXiv, 2023. arXiv:2303.00848
- Chi et al. Diffusion Policy: Visuomotor Policy Learning via Action Diffusion. Robotics: Science and Systems (RSS) XIX, 2023. arXiv:2303.04137
- Black et al. π0: A Vision-Language-Action Flow Model for General Robot Control. arXiv, 2024. arXiv:2410.24164
- Black et al. π0.5: a Vision-Language-Action Model with Open-World Generalization. arXiv, 2025. arXiv:2504.16054
- Pertsch et al. FAST: Efficient Action Tokenization for Vision-Language-Action Models. arXiv, 2025. arXiv:2501.09747
- NVIDIA et al. GR00T N1: An Open Foundation Model for Generalist Humanoid Robots. arXiv, 2025. arXiv:2503.14734
- Jiang et al. Streaming Flow Policy: Simplifying diffusion/flow-matching policies by treating action trajectories as flow trajectories. arXiv, 2025. arXiv:2505.21851
- Zhang et al. FlowPolicy: Enabling Fast and Robust 3D Flow-based Policy via Consistency Flow Matching for Robot Manipulation. AAAI 2025. arXiv:2412.04987
- Zhang and Gienger. Affordance-based Robot Manipulation with Flow Matching. arXiv, 2024. arXiv:2409.01083
- Zhang et al. ReinFlow: Fine-tuning Flow Matching Policy with Online Reinforcement Learning. arXiv, 2025. arXiv:2505.22094
- Black, Galliker and Levine. Real-Time Execution of Action Chunking Flow Policies. arXiv, 2025. arXiv:2506.07339
- Physical Intelligence. openpi: open-source models and packages for robotics. Official GitHub repository. github.com/Physical-Intelligence/openpi
Start here
- Ho et al., Denoising Diffusion Probabilistic Models [2], or Chi et al., Diffusion Policy [25]. The DDPM paper for the denoising math; the Diffusion Policy paper for the robot system.
- Lipman et al., Flow Matching Guide and Code [13]. The best entry point for the mechanics and the code.
- Liu et al., Rectified Flow [10]. The straight-path intuition and the reflow idea.
- Black et al., π0 [26]. A flow policy at robot scale, with the action-chunk design used in this part.