Skip to main content

Diffusion Models and Flow Matching

Generating by gradual denoising: the DDPM forward and reverse processes, the variational bound and noise-prediction loss, score matching and denoising score matching, annealed Langevin dynamics, score SDEs and probability-flow ODEs, fast solvers and guidance, flow matching and rectified flow, and applications to images, video, and protein structure.

A GAN or VAE generates an image in one big step from noise. A diffusion model takes hundreds of small ones. A fixed forward process destroys the data by adding a little Gaussian noise at a time, until nothing but noise remains, and a network learns to undo one small step at a time. Each step is a simple regression problem, so training is as stable as supervised learning, and the result has become the dominant generative model for images, video, and more. The same model can be read in three ways, tying together the earlier chapters: a hierarchical VAE (Ch. 6), a learned score for Langevin sampling (Ch. 4), and a continuous normalizing flow (Ch. 6).

7.1 Denoising Diffusion Probabilistic Models

Definition 7.1 (Denoising Diffusion Probabilistic Model) Fix a noise schedule \(\beta_1,\dots,\beta_T\in(0,1)\) and set \(\alpha_t=1-\beta_t\), \(\bar\alpha_t=\prod_{s=1}^t\alpha_s\). A DDPM (Ho et al., 2020) consists of:

  • a fixed forward process that adds noise, \[ q(x_t\mid x_{t-1})=\mathcal N\bigl(\sqrt{1-\beta_t}\,x_{t-1},\;\beta_tI\bigr), \qquad\text{i.e.}\quad x_t=\sqrt{\alpha_t}\,x_{t-1}+\sqrt{\beta_t}\,\epsilon_t; \]
  • a learned reverse process that denoises, starting from \(p(x_T)=\mathcal N(0,I)\): \[ p_\theta(x_{t-1}\mid x_t)=\mathcal N\bigl(\mu_\theta(x_t,t),\;\sigma_t^2I\bigr). \]

Proposition 7.1 (Jumping to Any Noise Level) \[ q(x_t\mid x_0)=\mathcal N\bigl(\sqrt{\bar\alpha_t}\,x_0,\;(1-\bar\alpha_t)I\bigr), \qquad\text{i.e.}\quad x_t=\sqrt{\bar\alpha_t}\,x_0+\sqrt{1-\bar\alpha_t}\,\epsilon,\quad\epsilon\sim\mathcal N(0,I). \]

With \(\bar\alpha_T\approx0\), \(x_T\) is essentially pure noise \(\mathcal N(0,I)\), whatever the data.

By induction on \(t\). If \(x_{t-1}=\sqrt{\bar\alpha_{t-1}}\,x_0+\sqrt{1-\bar\alpha_{t-1}}\,\epsilon'\), then

\[ x_t=\sqrt{\alpha_t}\,x_{t-1}+\sqrt{1-\alpha_t}\,\epsilon_t=\sqrt{\bar\alpha_t}\,x_0+\Bigl(\sqrt{\alpha_t(1-\bar\alpha_{t-1})}\,\epsilon'+\sqrt{1-\alpha_t}\,\epsilon_t\Bigr). \]

The bracket is a sum of independent zero-mean Gaussians, with variance \(\alpha_t(1-\bar\alpha_{t-1})+1-\alpha_t=1-\bar\alpha_t\).

Proposition 7.2 (Forward Posterior) Given the clean data \(x_0\), one denoising step of the forward process is Gaussian:

\[ q(x_{t-1}\mid x_t,x_0)=\mathcal N\bigl(\tilde\mu_t(x_t,x_0),\;\tilde\beta_tI\bigr), \qquad \tilde\beta_t=\frac{1-\bar\alpha_{t-1}}{1-\bar\alpha_t}\,\beta_t, \]

\[ \tilde\mu_t=\frac{\sqrt{\bar\alpha_{t-1}}\,\beta_t}{1-\bar\alpha_t}\,x_0+\frac{\sqrt{\alpha_t}\,(1-\bar\alpha_{t-1})}{1-\bar\alpha_t}\,x_t =\frac1{\sqrt{\alpha_t}}\Bigl(x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\,\epsilon\Bigr), \]

where \(\epsilon\) is the noise in \(x_t=\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\,\epsilon\).

By Bayes, \(q(x_{t-1}\mid x_t,x_0)\propto q(x_t\mid x_{t-1})\,q(x_{t-1}\mid x_0)\), and the exponent is

\[ -\frac12\Bigl[\frac{\|x_t-\sqrt{\alpha_t}x_{t-1}\|^2}{\beta_t}+\frac{\|x_{t-1}-\sqrt{\bar\alpha_{t-1}}x_0\|^2}{1-\bar\alpha_{t-1}}\Bigr], \]

quadratic in \(x_{t-1}\). The precision is \(\frac{\alpha_t}{\beta_t}+\frac1{1-\bar\alpha_{t-1}}=\frac{1-\bar\alpha_t}{\beta_t(1-\bar\alpha_{t-1})}\) (using \(\alpha_t-\bar\alpha_t+\beta_t=1-\bar\alpha_t\)), which gives \(\tilde\beta_t\). The mean is \(\tilde\beta_t\bigl(\frac{\sqrt{\alpha_t}}{\beta_t}x_t+\frac{\sqrt{\bar\alpha_{t-1}}}{1-\bar\alpha_{t-1}}x_0\bigr)\), which is the first form of \(\tilde\mu_t\).

For the second form, substitute \(x_0=\bigl(x_t-\sqrt{1-\bar\alpha_t}\,\epsilon\bigr)/\sqrt{\bar\alpha_t}\) and use \(\sqrt{\bar\alpha_{t-1}}/\sqrt{\bar\alpha_t}=1/\sqrt{\alpha_t}\). The coefficient of \(x_t\) becomes \(\frac{\alpha_t(1-\bar\alpha_{t-1})+\beta_t}{(1-\bar\alpha_t)\sqrt{\alpha_t}}=\frac1{\sqrt{\alpha_t}}\), and the coefficient of \(\epsilon\) becomes \(-\frac{\beta_t}{\sqrt{\alpha_t}\sqrt{1-\bar\alpha_t}}\).

Theorem 7.1 (Variational Bound of a Diffusion Model) Treat \(x_{1:T}\) as latent variables with the forward process as a fixed encoder. Then

\[ \mathbb E\bigl[-\log p_\theta(x_0)\bigr]\le\mathbb E_q\Bigl[\underbrace{\mathrm{KL}\bigl(q(x_T\mid x_0)\,\|\,p(x_T)\bigr)}_{L_T}+\sum_{t=2}^T\underbrace{\mathrm{KL}\bigl(q(x_{t-1}\mid x_t,x_0)\,\|\,p_\theta(x_{t-1}\mid x_t)\bigr)}_{L_{t-1}}\underbrace{-\log p_\theta(x_0\mid x_1)}_{L_0}\Bigr]. \]

The ELBO (Thm. 6.2) with \(z=x_{1:T}\) gives \(-\log p_\theta(x_0)\le\mathbb E_{q(x_{1:T}\mid x_0)}\Bigl[\log\frac{q(x_{1:T}\mid x_0)}{p_\theta(x_{0:T})}\Bigr]\). The forward chain is Markov, so by Bayes it can be reversed given \(x_0\):

\[ q(x_{1:T}\mid x_0)=q(x_T\mid x_0)\prod_{t=2}^Tq(x_{t-1}\mid x_t,x_0), \qquad p_\theta(x_{0:T})=p(x_T)\prod_{t=2}^Tp_\theta(x_{t-1}\mid x_t)\cdot p_\theta(x_0\mid x_1). \]

The log-ratio splits into \(\log\frac{q(x_T|x_0)}{p(x_T)}+\sum_{t\ge2}\log\frac{q(x_{t-1}|x_t,x_0)}{p_\theta(x_{t-1}|x_t)}-\log p_\theta(x_0|x_1)\), and each expectation of a log-ratio is a KL divergence. Writing the forward process in this reversed form is what makes every term a KL between two Gaussians.

Proposition 7.3 (Noise-Prediction Loss) \(L_T\) has no parameters. Parameterize the reverse mean in the form of Proposition 7.2, with a network \(\epsilon_\theta\) that predicts the noise:

\[ \mu_\theta(x_t,t)=\frac1{\sqrt{\alpha_t}}\Bigl(x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\,\epsilon_\theta(x_t,t)\Bigr). \]

Then, up to a constant,

\[ L_{t-1}=\mathbb E_{x_0,\epsilon}\Bigl[\frac{\beta_t^2}{2\sigma_t^2\,\alpha_t(1-\bar\alpha_t)}\bigl\|\epsilon-\epsilon_\theta\bigl(\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\,\epsilon,\;t\bigr)\bigr\|^2\Bigr]. \]

DDPM drops the weights and trains on the simple loss

\[ L_{\text{simple}}=\mathbb E_{t\sim\mathrm{Unif}\{1..T\},\,x_0,\,\epsilon}\Bigl[\bigl\|\epsilon-\epsilon_\theta\bigl(\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\,\epsilon,\;t\bigr)\bigr\|^2\Bigr]. \]

For two Gaussians with the same fixed covariance \(\sigma_t^2I\), Prop. 6.3 gives \(\mathrm{KL}=\frac1{2\sigma_t^2}\|\tilde\mu_t-\mu_\theta\|^2+\text{const}\). Both means have the form \(\frac1{\sqrt{\alpha_t}}\bigl(x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\,\cdot\,\bigr)\), so their difference is \(\frac{\beta_t}{\sqrt{\alpha_t}\sqrt{1-\bar\alpha_t}}(\epsilon_\theta-\epsilon)\). Squaring gives the stated weight.

TipDDPM in Two Loops

Training (parallel over \(t\)): repeat

  1. take \(x_0\) from the data, \(t\sim\mathrm{Unif}\{1,\dots,T\}\), \(\epsilon\sim\mathcal N(0,I)\);
  2. take a gradient step on \(\bigl\|\epsilon-\epsilon_\theta\bigl(\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\,\epsilon,t\bigr)\bigr\|^2\).

Sampling (sequential): \(x_T\sim\mathcal N(0,I)\); for \(t=T,\dots,1\),

\[ x_{t-1}=\frac1{\sqrt{\alpha_t}}\Bigl(x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\,\epsilon_\theta(x_t,t)\Bigr)+\sigma_tz,\qquad z\sim\mathcal N(0,I)\ (z=0\text{ at }t=1). \]

  • Schedules. \(\beta_t\) grows over time, linearly or by a cosine schedule. The reverse variance \(\sigma_t^2\) can be fixed to \(\beta_t\) or \(\tilde\beta_t\), or learned (Nichol and Dhariwal, 2021). The network can equivalently predict \(x_0\) or a velocity \(v\) instead of \(\epsilon\).
  • Architecture. \(\epsilon_\theta(x_t,t)\) is a U-Net (Ch. 3) with self-attention layers, receiving \(t\) through sinusoidal or random Fourier embeddings; later models use transformers (DiT, below).
  • DDPM versus VAE. A DDPM is a hierarchical VAE, but
    • its encoder is fixed, so there is no posterior collapse and training is stable;
    • its latents have the same dimension as the data, with no compression;
    • one denoising network is shared across all time steps;
    • training samples time steps in parallel, but sampling is sequential and slow (\(10^3\) steps originally);
    • it is trained on a reweighted variational bound, which gives better samples than the bound itself.

7.2 Score-Based Models

Definition 7.2 (Score Matching) The score of a density is \(\nabla_x\log p(x)\), a vector field pointing toward higher density. A score model \(s_\theta(x)\) approximates it by minimizing the Fisher divergence

\[ F(\theta)=\frac12\,\mathbb E_{x\sim p}\bigl\|s_\theta(x)-\nabla_x\log p(x)\bigr\|^2. \]

  • For an EBM \(p_\theta=e^{-E_\theta}/Z\), \(\nabla_x\log p_\theta=-\nabla_xE_\theta\): the partition function disappears. The score is all Langevin dynamics needs (Def. 4.6): \(x_{k+1}=x_k+\delta\,s_\theta(x_k)+\sqrt{2\delta}\,z_k\).
  • The difficulty is that \(\nabla_x\log p\) of the data is unknown. Two identities remove it.

Theorem 7.2 (Implicit Score Matching) If \(p\,s_\theta\to0\) at infinity, then

\[ F(\theta)=\mathbb E_{x\sim p}\Bigl[\frac12\|s_\theta(x)\|^2+\nabla\cdot s_\theta(x)\Bigr]+\text{const}, \]

where \(\nabla\cdot s_\theta=\mathrm{tr}(\nabla_xs_\theta)\), which for \(s_\theta=\nabla\log p_\theta\) is the trace of the Hessian of \(\log p_\theta\).

Expand: \(F=\mathbb E_p\bigl[\frac12\|s_\theta\|^2\bigr]-\mathbb E_p\bigl[\nabla\log p\cdot s_\theta\bigr]+\frac12\mathbb E_p\|\nabla\log p\|^2\). The last term does not depend on \(\theta\). For the cross term, \(p\nabla\log p=\nabla p\), and integration by parts (the boundary term vanishes) gives

\[ \mathbb E_p\bigl[\nabla\log p\cdot s_\theta\bigr]=\int\nabla p\cdot s_\theta\,\mathrm dx=-\int p\,\nabla\cdot s_\theta\,\mathrm dx=-\mathbb E_p\bigl[\nabla\cdot s_\theta\bigr]. \]

  • The divergence costs \(d\) backward passes in \(d\) dimensions. Sliced score matching estimates it with random projections: \(\nabla\cdot s_\theta=\mathbb E_{v\sim\mathcal N(0,I)}\bigl[v^\top(\nabla_xs_\theta)v\bigr]\).

Theorem 7.3 (Denoising Score Matching) Corrupt the data with a known kernel, \(\tilde x\sim q_\sigma(\tilde x\mid x)\), \(x\sim p_{\text{data}}\), with marginal \(q_\sigma(\tilde x)\). Then

\[ \mathbb E_{q_\sigma(\tilde x)}\bigl\|s_\theta(\tilde x)-\nabla_{\tilde x}\log q_\sigma(\tilde x)\bigr\|^2 =\mathbb E_{x,\tilde x}\bigl\|s_\theta(\tilde x)-\nabla_{\tilde x}\log q_\sigma(\tilde x\mid x)\bigr\|^2+\text{const}. \]

For Gaussian noise \(q_\sigma(\tilde x\mid x)=\mathcal N(x,\sigma^2I)\), the target is simply \(\nabla_{\tilde x}\log q_\sigma(\tilde x\mid x)=-\dfrac{\tilde x-x}{\sigma^2}\): point from the noisy sample back to the clean one.

The \(\|s_\theta\|^2\) terms agree, and the remaining squared terms do not involve \(\theta\), so it suffices to match the cross terms. Using \(q\nabla\log q=\nabla q\), the definition of the marginal, and swapping the gradient and integrals:

\[ \begin{aligned} \int q_\sigma(\tilde x)\,\nabla_{\tilde x}\log q_\sigma(\tilde x)^\top s_\theta(\tilde x)\,\mathrm d\tilde x &=\int\nabla_{\tilde x}\Bigl(\int p_{\text{data}}(x)\,q_\sigma(\tilde x\mid x)\,\mathrm dx\Bigr)^\top s_\theta(\tilde x)\,\mathrm d\tilde x\\ &=\iint p_{\text{data}}(x)\,q_\sigma(\tilde x\mid x)\,\nabla_{\tilde x}\log q_\sigma(\tilde x\mid x)^\top s_\theta(\tilde x)\,\mathrm dx\,\mathrm d\tilde x\\ &=\mathbb E_{x,\tilde x}\bigl[\nabla_{\tilde x}\log q_\sigma(\tilde x\mid x)^\top s_\theta(\tilde x)\bigr]. \end{aligned} \]

Proposition 7.4 (Noise Prediction Is Score Estimation) For the DDPM corruption \(q(x_t\mid x_0)\) of Proposition 7.1, \(\nabla_{x_t}\log q(x_t\mid x_0)=-\epsilon/\sqrt{1-\bar\alpha_t}\). Hence the DDPM loss is denoising score matching at every noise level, and the trained noise predictor gives the score of the noisy marginal:

\[ s_\theta(x_t,t)=-\frac{\epsilon_\theta(x_t,t)}{\sqrt{1-\bar\alpha_t}}\approx\nabla_{x_t}\log q_t(x_t). \]

7.2.1 Annealed Langevin Dynamics

  • Pitfall. The Fisher divergence weights errors by \(p(x)\), so the learned score is accurate only where data is dense. Langevin chains start in low-density regions where the score is wrong, and they mix poorly between separated modes.
  • Fix: perturb the data with noise. Large noise fills the low-density regions and connects the modes, but distorts the data; small noise is faithful but leaves the gaps. So use many scales \(\sigma_1>\sigma_2>\dots>\sigma_L\) and train one noise-conditional score network \(s_\theta(x,\sigma)\) on all of them by denoising score matching (NCSN, Song and Ermon, 2019).
  • Annealed Langevin dynamics. Run a few Langevin steps at \(\sigma_1\), use the result to start the chain at \(\sigma_2\), and so on down to \(\sigma_L\). Starting with large noise gives mode coverage and faster mixing. The schedule of decreasing noise mirrors the reverse DDPM chain, and Proposition 7.4 shows the two learn the same objects.

7.2.2 Score SDEs and the Probability-Flow ODE

In the limit of infinitely many small steps, the forward process becomes a stochastic differential equation (Song et al., 2021):

\[ \mathrm dx=f(x,t)\,\mathrm dt+g(t)\,\mathrm dw. \]

  • Variance preserving (VP): \(f=-\frac12\beta(t)x\), \(g=\sqrt{\beta(t)}\), the continuum limit of DDPM.
  • Variance exploding (VE): \(f=0\), \(g=\sqrt{\mathrm d\sigma^2(t)/\mathrm dt}\), the continuum limit of NCSN.

Theorem 7.4 (Reverse SDE and Probability-Flow ODE) Let \(p_t\) be the marginals of the forward SDE. The reverse-time SDE

\[ \mathrm dx=\bigl[f(x,t)-g(t)^2\,\nabla_x\log p_t(x)\bigr]\mathrm dt+g(t)\,\mathrm d\bar w \]

and the deterministic probability-flow ODE

\[ \frac{\mathrm dx}{\mathrm dt}=f(x,t)-\frac12g(t)^2\,\nabla_x\log p_t(x) \]

both have the same marginals \(p_t\) at every time. Replacing \(\nabla_x\log p_t\) by \(s_\theta(x,t)\) turns either one into a sampler.

  • The ODE is a continuous normalizing flow (Ch. 6): it gives exact likelihoods by the instantaneous change of variables (with the Skilling–Hutchinson trace estimator), and a deterministic, invertible map from noise to data in which smooth changes of the latent give semantically smooth changes of the image.
  • Fast solvers. The ODE can be integrated with far fewer steps than the \(10^3\) of ancestral sampling. DPM-Solver notes that the linear part of the ODE can be solved exactly (an exponential integrator): multiply by the integrating factor, change the time variable to the log signal-to-noise ratio, and approximate only the integral of the network output. Its first-order version is DDIM; second- and third-order versions cost more per step but reach good samples in about \(10\)–\(20\) steps.

7.3 Conditional Generation

  • Conditioning the network. Feed the condition \(y\) (a class, a caption, a low-resolution image) into \(\epsilon_\theta(x_t,t,y)\), typically through cross-attention.
  • Classifier guidance. By Bayes, \(\nabla_x\log p_t(x\mid y)=\nabla_x\log p_t(x)+\nabla_x\log p_t(y\mid x)\): add the gradient of a classifier trained on noisy inputs, scaled up to strengthen the condition.

Definition 7.3 (Classifier-Free Guidance) Train one network both with the condition \(c\) and without it (replace \(c\) by a null token \(\emptyset\) at random, e.g. 10% of the time). At sampling time use

\[ \hat\epsilon=(1+w)\,\epsilon_\theta(x_t,t,c)-w\,\epsilon_\theta(x_t,t,\emptyset), \]

with guidance strength \(w>0\).

  • In score terms, \(\hat s=s(x\mid c)+w\bigl(s(x\mid c)-s(x)\bigr)\), and \(s(x\mid c)-s(x)=\nabla\log p(c\mid x)\) is an implicit classifier. Sampling follows \(p(x\mid c)\,p(c\mid x)^w\): larger \(w\) gives images that match the prompt more closely, at the cost of diversity.
  • Latent diffusion (Stable Diffusion; Rombach et al., 2022). Train an autoencoder once, then run the diffusion in its compact latent space. This cuts the cost of high-resolution generation by an order of magnitude.
  • Editing. SDEdit adds noise to a rough guide image (a sketch, or an image to restyle) up to some time \(t_0\) and runs the reverse process from there: small \(t_0\) stays faithful to the guide, large \(t_0\) gives realism. ControlNet attaches a trainable copy of the encoder to a frozen text-to-image model to condition on edges, depth, or pose.

7.4 Flow Matching

A continuous normalizing flow \(\mathrm dx_t/\mathrm dt=v_\theta(t,x_t)\) (Ch. 6) is expressive, but maximum-likelihood training must simulate the ODE at every step and estimate divergences in high dimension. Flow matching trains the same vector field without simulation, by regression, in the same way denoising score matching trains a score.

Definition 7.4 (Flow Matching) Let \(p_t\), \(t\in[0,1]\), be a probability path from \(p_0=\mathcal N(0,I)\) to \(p_1=p_{\text{data}}\), generated by a vector field \(u_t\), meaning the continuity equation \(\partial_tp_t+\nabla\cdot(p_tu_t)=0\) holds. Flow matching regresses a network onto this field:

\[ \mathcal L_{\text{FM}}(\theta)=\mathbb E_{t\sim\mathrm{Unif}[0,1],\,x\sim p_t}\bigl\|v_\theta(t,x)-u_t(x)\bigr\|^2. \]

Samples are generated by integrating \(\dot x=v_\theta(t,x)\) from \(x_0\sim\mathcal N(0,I)\) to \(t=1\).

  • Many vector fields connect the same two endpoints, and \(u_t\) is unknown for any of them. The fix is to build the path out of simple per-example paths.

Theorem 7.5 (Conditional Flow Matching) Choose, for each data point \(x_1\), a conditional path \(p_t(x\mid x_1)\) generated by a field \(u_t(x\mid x_1)\), with \(p_0(\cdot\mid x_1)=\mathcal N(0,I)\) and \(p_1(\cdot\mid x_1)\) concentrated at \(x_1\). Then:

  1. the marginal path \(p_t(x)=\int p_t(x\mid x_1)\,p_{\text{data}}(x_1)\,\mathrm dx_1\) is generated by the posterior-averaged field \[ u_t(x)=\mathbb E\bigl[u_t(x\mid x_1)\,\big|\,x_t=x\bigr]=\int u_t(x\mid x_1)\frac{p_t(x\mid x_1)\,p_{\text{data}}(x_1)}{p_t(x)}\,\mathrm dx_1; \]
  2. the conditional flow matching loss \[ \mathcal L_{\text{CFM}}(\theta)=\mathbb E_{t,\,x_1\sim p_{\text{data}},\,x\sim p_t(\cdot\mid x_1)}\bigl\|v_\theta(t,x)-u_t(x\mid x_1)\bigr\|^2 \] satisfies \(\mathcal L_{\text{CFM}}=\mathcal L_{\text{FM}}+\text{const}\), so it has the same gradients.

1. Each conditional path satisfies its own continuity equation. Integrate over \(x_1\):

\[ \partial_tp_t(x)=\int\partial_tp_t(x\mid x_1)\,p_{\text{data}}(x_1)\,\mathrm dx_1=-\nabla\cdot\int u_t(x\mid x_1)\,p_t(x\mid x_1)\,p_{\text{data}}(x_1)\,\mathrm dx_1=-\nabla\cdot\bigl(p_t\,u_t\bigr). \]

2. Expand both squares. The \(\|v_\theta\|^2\) terms are equal, since \(x\sim p_t\) either way, and \(\|u_t\|^2\) terms do not involve \(\theta\). For the cross term, by the formula for \(u_t\) in part 1,

\[ \mathbb E_{x\sim p_t}\bigl\langle v_\theta,u_t(x)\bigr\rangle=\int\Bigl\langle v_\theta(t,x),\int u_t(x\mid x_1)\,p_t(x\mid x_1)\,p_{\text{data}}(x_1)\,\mathrm dx_1\Bigr\rangle\mathrm dx=\mathbb E_{x_1,\,x\sim p_t(\cdot|x_1)}\bigl\langle v_\theta,u_t(x\mid x_1)\bigr\rangle. \]

This mirrors the proof of Theorem 7.3.

  • Gaussian conditional paths. Take \(x_t=\mu_t(x_1)+\sigma_t(x_1)\,x_0\) with \(x_0\sim\mathcal N(0,I)\). Then \(u_t(x\mid x_1)=\frac{\dot\sigma_t}{\sigma_t}\bigl(x-\mu_t\bigr)+\dot\mu_t\).
  • Optimal-transport path. \(\mu_t=tx_1\) and \(\sigma_t=1-(1-\sigma_{\min})t\) move every point in a straight line at constant speed: \(x_t=tx_1+(1-(1-\sigma_{\min})t)\,x_0\) and \(u_t=x_1-(1-\sigma_{\min})x_0\). With \(\sigma_{\min}=0\) this is rectified flow: interpolate \(x_t=(1-t)x_0+tx_1\) and regress \(v_\theta(t,x_t)\) onto \(x_1-x_0\). Diffusion paths are another choice of \(\mu_t,\sigma_t\), with curved trajectories.
  • Unlike a likelihood-trained CNF, which puts no preference on the vector field, CFM chooses a field through the conditional paths.

In one dimension, let \(p_{\text{data}}\) put mass \(\frac12\) on each of \(\pm a\), and use rectified flow, \(x_t=(1-t)x_0+tx_1\). Each conditional path is a straight line, with \(u_t(x\mid x_1)=\frac{x_1-x}{1-t}\). Given \(x_1=\pm a\), \(x_t\sim\mathcal N\bigl(\pm ta,(1-t)^2\bigr)\), so the posterior of the endpoint is a logistic function and

\[ \mathbb E[x_1\mid x_t=x]=a\tanh\Bigl(\frac{tax}{(1-t)^2}\Bigr), \qquad u_t(x)=\frac{a\tanh\bigl(tax/(1-t)^2\bigr)-x}{1-t}. \]

At \(t=0\) the marginal field is \(u_0(x)=-x\): before the endpoint can be guessed, the samples first contract toward the middle; later the tanh sharpens and they split toward \(\pm a\). The conditional lines cross each other, but the marginal trajectories cannot cross (ODE solutions are unique), so they bend. That curvature is what forces many integration steps at sampling time.

  • The cost of crossing paths. The conditional target \(u_t(x\mid x_1)\) can differ greatly from the marginal \(u_t(x)\), which gives high-variance gradients and slow training. Curved marginal paths are hard to integrate and need many steps.
  • Better couplings. Pairing \(x_0\) and \(x_1\) independently is only one choice. Coupling them by (minibatch) optimal transport makes paths cross less: lower training variance and straighter, faster sampling. Rectified flow’s reflow step retrains on (noise, generated sample) pairs from the current model to straighten the paths further.

7.5 Applications

  • Diffusion transformers (DiT, Peebles and Xie, 2023): replace the U-Net by a transformer on patches of the latent. Sample quality improves steadily with compute, a scaling law. Stable Diffusion 3 (2024) combines a multimodal DiT with rectified flow, reweighting time steps with a logit-normal distribution.
  • Video. Video is \(T\times C\times H\times W\): slower to sample, and it must stay coherent over time. Imagen Video (2022) cascades 7 models (a base model plus 3 spatial and 3 temporal super-resolution models) with space-time separable blocks, generating whole blocks of frames together. Sora (2024) compresses video into a latent space, cuts it into spacetime patches, and treats them as tokens of a DiT; quality improves markedly with compute, but basic physical interactions and long-video coherence are still often wrong.
  • Text-to-image with CLIP. DALL·E 2 (2022) uses CLIP’s joint image–text embedding (contrastive learning, Ch. 9): a prior generates an image embedding from the caption (autoregressively or by diffusion), then cascaded diffusion decoders generate a \(64^2\) image and upsample it to \(1024^2\). DALL·E 3 recaptions its training set with a captioner fine-tuned to write long, descriptive synthetic captions, which greatly improves prompt following.
  • Discrete data. Diffusion also generates text, for example by adding noise to word embeddings and denoising the whole sequence jointly.
  • Protein structure. AlphaFold (2020) predicts distributions of distances and torsion angles between residues from multiple sequence alignments; AlphaFold2 (2021) is end-to-end, with “triangle” updates that respect \(d(a,b)+d(b,c)\ge d(a,c)\); AlphaFold3 (2024) drops the hand-built geometry and generates 3D atom coordinates with a diffusion model, like generating an image.

7.6 Supplementary Notes

7.6.1 Key Results

  • Proposition 7.1: \(x_t=\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\,\epsilon\).
  • Proposition 7.2: \(\tilde\mu_t=\frac1{\sqrt{\alpha_t}}\bigl(x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\epsilon\bigr)\), \(\tilde\beta_t=\frac{1-\bar\alpha_{t-1}}{1-\bar\alpha_t}\beta_t\).
  • Theorem 7.1: bound \(L_T+\sum_tL_{t-1}+L_0\), each a Gaussian KL.
  • Proposition 7.3: \(L_{\text{simple}}=\mathbb E\|\epsilon-\epsilon_\theta(\sqrt{\bar\alpha_t}x_0+\sqrt{1-\bar\alpha_t}\epsilon,t)\|^2\).
  • Theorem 7.2: \(F=\mathbb E_p[\frac12\|s_\theta\|^2+\nabla\cdot s_\theta]+C\).
  • Theorem 7.3: denoising score matching target \(-(\tilde x-x)/\sigma^2\); Proposition 7.4: \(s_\theta=-\epsilon_\theta/\sqrt{1-\bar\alpha_t}\).
  • Theorem 7.4: probability-flow ODE \(\dot x=f-\frac12g^2\nabla\log p_t\).
  • Definition 7.3: \(\hat\epsilon=(1+w)\epsilon_\theta(x,t,c)-w\epsilon_\theta(x,t,\emptyset)\).
  • Theorem 7.5: \(\mathcal L_{\text{CFM}}=\mathcal L_{\text{FM}}+C\); rectified flow regresses \(v_\theta((1-t)x_0+tx_1,t)\) onto \(x_1-x_0\).