Simple Algorithm
Artificial Intelligence · Deep Layer · 30 min

Diffusion Models

Learning to reverse a noising process.

A diffusion model is trained by a one-line regression: predict the noise. Behind it sit a variational bound, denoising score matching, a stochastic and an ordinary differential equation that share every marginal, and a family of samplers that trade steps for error. This lesson derives them, and uses a sampler with the exact score to separate sampling error from learning error.

What you’ll learn

  • Derive the DDPM bound as a sum of Gaussian KL terms and prove that noise prediction is weighted denoising score matching.
  • Prove that an exact-score DDPM step has exactly the right mean, and locate its error in the step's variance.
  • Derive the probability-flow ODE from the Fokker–Planck equation, and show that deterministic DDIM is Euler's method on it.
  • Express classifier-free guidance as a tilted density, compute latent diffusion's savings, and state a convergence guarantee for score-based sampling.

DDPM as a hierarchical VAE

It is a hierarchical VAE whose encoder, the forward chain, is fixed. Because that encoder is Gaussian, so is its posterior given x0\mathbf x_0, by standard Gaussian conditioning:

q(xt−1∣xt,x0)=N(μ~t,β~tI),μ~t=αˉt−1 βt1−αˉt⏟ctx0+αt (1−αˉt−1)1−αˉt⏟dtxt,β~t=1−αˉt−11−αˉt βtq(\mathbf x_{t-1}\mid\mathbf x_t,\mathbf x_0)=\mathcal N\big(\tilde{\boldsymbol\mu}_t,\tilde\beta_tI\big),\quad \tilde{\boldsymbol\mu}_t=\underbrace{\frac{\sqrt{\bar\alpha_{t-1}}\,\beta_t}{1-\bar\alpha_t}}_{c_t}\mathbf x_0+\underbrace{\frac{\sqrt{\alpha_t}\,(1-\bar\alpha_{t-1})}{1-\bar\alpha_t}}_{d_t}\mathbf x_t,\quad \tilde\beta_t=\frac{1-\bar\alpha_{t-1}}{1-\bar\alpha_t}\,\beta_t
DerivationThe bound, term by term (Sohl-Dickstein et al., 2015; Ho, Jain & Abbeel, 2020)
  1. −log⁡pθ(x0)≤Eq[DKL(q(xT∣x0) ∥ p(xT))⏟LT+∑t=2TDKL(q(xt−1∣xt,x0) ∥ pθ(xt−1∣xt))⏟Lt−1−log⁡pθ(x0∣x1)⏟L0]-\log p_\theta(\mathbf x_0)\le\E_q\Big[\underbrace{\KL\big(q(\mathbf x_T\mid\mathbf x_0)\,\|\,p(\mathbf x_T)\big)}_{L_T}+\sum_{t=2}^T\underbrace{\KL\big(q(\mathbf x_{t-1}\mid\mathbf x_t,\mathbf x_0)\,\|\,p_\theta(\mathbf x_{t-1}\mid\mathbf x_t)\big)}_{L_{t-1}}\underbrace{-\log p_\theta(\mathbf x_0\mid\mathbf x_1)}_{L_0}\Big]

    Take the ELBO with the forward chain as encoder. Rewriting each q(xt∣xt−1)q(\mathbf x_t\mid\mathbf x_{t-1}) with Bayes' rule as q(xt−1∣xt,x0) q(xt∣x0)/q(xt−1∣x0)q(\mathbf x_{t-1}\mid\mathbf x_t,\mathbf x_0)\,q(\mathbf x_t\mid\mathbf x_0)/q(\mathbf x_{t-1}\mid\mathbf x_0) makes the marginals telescope:

  2. Lt−1=Eq[12σt2∥μ~t(xt,x0)−μθ(xt,t)∥2]+CL_{t-1}=\E_q\Big[\frac{1}{2\sigma_t^2}\norm{\tilde{\boldsymbol\mu}_t(\mathbf x_t,\mathbf x_0)-\boldsymbol\mu_\theta(\mathbf x_t,t)}^2\Big]+C

    LTL_T has no parameters. Each Lt−1L_{t-1} is a KL between Gaussians with fixed covariances β~tI\tilde\beta_tI and σt2I\sigma_t^2I, so only the means matter:

  3. μ~t=1αt(xt−βt1−αˉtε),μθ=1αt(xt−βt1−αˉtεθ(xt,t))\tilde{\boldsymbol\mu}_t=\frac{1}{\sqrt{\alpha_t}}\Big(\mathbf x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\boldsymbol\varepsilon\Big),\qquad \boldsymbol\mu_\theta=\frac{1}{\sqrt{\alpha_t}}\Big(\mathbf x_t-\frac{\beta_t}{\sqrt{1-\bar\alpha_t}}\boldsymbol\varepsilon_\theta(\mathbf x_t,t)\Big)

    Substitute x0=(xt−1−αˉt ε)/αˉt\mathbf x_0=(\mathbf x_t-\sqrt{1-\bar\alpha_t}\,\boldsymbol\varepsilon)/\sqrt{\bar\alpha_t} into μ~t\tilde{\boldsymbol\mu}_t, and give μθ\boldsymbol\mu_\theta the same form with a predicted noise:

  4. Lt−1=βt22σt2 αt (1−αˉt) E∥ε−εθ(αˉt x0+1−αˉt ε, t)∥2+CL_{t-1}=\frac{\beta_t^2}{2\sigma_t^2\,\alpha_t\,(1-\bar\alpha_t)}\,\E\norm{\boldsymbol\varepsilon-\boldsymbol\varepsilon_\theta\big(\sqrt{\bar\alpha_t}\,\mathbf x_0+\sqrt{1-\bar\alpha_t}\,\boldsymbol\varepsilon,\ t\big)}^2+C

    The difference is proportional to ε−εθ\boldsymbol\varepsilon-\boldsymbol\varepsilon_\theta. Ho et al.'s LsimpleL_{\text{simple}} drops the weight, which relative to the bound emphasizes the noisier steps, and gave better samples. In continuous time the bound depends on the schedule only through the SNR at its two endpoints (Kingma et al., 2021).

DerivationProof
  1. ∇xtlog⁡q(xt∣x0)=−xt−αˉt x01−αˉt=−ε1−αˉt\nabla_{\mathbf x_t}\log q(\mathbf x_t\mid\mathbf x_0)=-\frac{\mathbf x_t-\sqrt{\bar\alpha_t}\,\mathbf x_0}{1-\bar\alpha_t}=-\frac{\boldsymbol\varepsilon}{\sqrt{1-\bar\alpha_t}}

    The conditional score is explicit, and it is the noise up to scale:

  2. E[s(xt)⋅∇log⁡q(xt∣x0)]=∬s(xt)⋅∇xtq(xt∣x0) q(x0) dx0 dxt=∫s⋅∇qt dxt=Eqt[s⋅∇log⁡qt]\E\big[\mathbf s(\mathbf x_t)\cdot\nabla\log q(\mathbf x_t\mid\mathbf x_0)\big]=\iint\mathbf s(\mathbf x_t)\cdot\nabla_{\mathbf x_t}q(\mathbf x_t\mid\mathbf x_0)\,q(\mathbf x_0)\,d\mathbf x_0\,d\mathbf x_t=\int\mathbf s\cdot\nabla q_t\,d\mathbf x_t=\E_{q_t}\big[\mathbf s\cdot\nabla\log q_t\big]

    Expand both squares. The ∥s∥2\norm{\mathbf s}^2 terms agree, and so do the cross terms, because averaging the conditional density's gradient over x0\mathbf x_0 gives the marginal's gradient:

  3. E[x0∣xt]=xt+(1−αˉt)∇log⁡qt(xt)αˉt\E[\mathbf x_0\mid\mathbf x_t]=\frac{\mathbf x_t+(1-\bar\alpha_t)\nabla\log q_t(\mathbf x_t)}{\sqrt{\bar\alpha_t}}

    The remaining terms do not involve s\mathbf s. ■\blacksquare Read as a statement about E[x0∣xt]\E[\mathbf x_0\mid\mathbf x_t], this is Tweedie's formula, proved in Autoencoders & Latent Spaces:

Check your understanding

Suppose εθ\boldsymbol\varepsilon_\theta could be any function of (xt,t)(\mathbf x_t,t). How does replacing the bound's weights by LsimpleL_{\text{simple}}'s uniform weights change the optimal εθ\boldsymbol\varepsilon_\theta?

  1. It shifts the optimum toward accuracy at the noisiest steps
  2. It turns εθ\boldsymbol\varepsilon_\theta into a predictor of x0\mathbf x_0
  3. It changes the optimum only at t=1t=1
  4. Not at all: each tt has its own term, minimized by −1−αˉt ∇log⁡qt-\sqrt{1-\bar\alpha_t}\,\nabla\log q_t for any positive weight
Show the answer

D. Not at all: each tt has its own term, minimized by −1−αˉt ∇log⁡qt-\sqrt{1-\bar\alpha_t}\,\nabla\log q_t for any positive weight

With unlimited capacity the objective decouples across tt, and a positive weight does not move a term's minimizer. Weights matter only because one finite network is shared across all tt and trained by SGD: they decide where its errors go.

What a sampler gets wrong

A sampler's output carries two errors: the network's score error and the error of taking finitely many steps. The widget below has no network. Its data are a mixture of 320 small Gaussians (standard deviation 0.045) along a shape, so every noised marginal qtq_t is a known mixture and its score is computed exactly. Whatever is wrong with its samples is the sampler's doing, and a lemma says where to look.

DerivationProof
  1. E[xt−1∣xt]=ct E[x0∣xt]+dt xt\E[\mathbf x_{t-1}\mid\mathbf x_t]=c_t\,\E[\mathbf x_0\mid\mathbf x_t]+d_t\,\mathbf x_t

    Given (xt,x0)(\mathbf x_t,\mathbf x_0), xt−1∼N(μ~t,β~tI)\mathbf x_{t-1}\sim\mathcal N(\tilde{\boldsymbol\mu}_t,\tilde\beta_tI) with μ~t=ctx0+dtxt\tilde{\boldsymbol\mu}_t=c_t\mathbf x_0+d_t\mathbf x_t affine in x0\mathbf x_0. The tower property gives:

  2. E[xt−1∣xt]=βt(xt+(1−αˉt)∇log⁡qt)αt (1−αˉt)+αt(1−αˉt−1)αt (1−αˉt)xt=xt+βt∇log⁡qt(xt)αt\E[\mathbf x_{t-1}\mid\mathbf x_t]=\frac{\beta_t\big(\mathbf x_t+(1-\bar\alpha_t)\nabla\log q_t\big)}{\sqrt{\alpha_t}\,(1-\bar\alpha_t)}+\frac{\alpha_t(1-\bar\alpha_{t-1})}{\sqrt{\alpha_t}\,(1-\bar\alpha_t)}\mathbf x_t=\frac{\mathbf x_t+\beta_t\nabla\log q_t(\mathbf x_t)}{\sqrt{\alpha_t}}

    Insert Tweedie's formula and simplify with αˉt−1/αˉt=1/αt\sqrt{\bar\alpha_{t-1}/\bar\alpha_t}=1/\sqrt{\alpha_t} and βt+αt(1−αˉt−1)=1−αˉt\beta_t+\alpha_t(1-\bar\alpha_{t-1})=1-\bar\alpha_t:

  3. Cov⁡(xt−1∣xt)=E[β~tI∣xt]+Cov⁡(ctx0+dtxt∣xt)=β~tI+ct2Cov⁡(x0∣xt)\Cov(\mathbf x_{t-1}\mid\mathbf x_t)=\E\big[\tilde\beta_tI\mid\mathbf x_t\big]+\Cov\big(c_t\mathbf x_0+d_t\mathbf x_t\mid\mathbf x_t\big)=\tilde\beta_tI+c_t^2\Cov(\mathbf x_0\mid\mathbf x_t)

    The law of total covariance adds the spread of the posterior mean to the posterior covariance. ■\blacksquare

Away from t=0t=0, ctc_t is proportional to βt\beta_t, so the deficit per step is O(βt2)\order{\beta_t^2}, negligible for fine steps. With few, large steps every step is too narrow, and the cloud of samples contracts toward the data's center of mass. At the last step αˉ0=1\bar\alpha_0=1 makes c1=1c_1=1 and σ1=0\sigma_1=0: the sampler outputs the posterior mean E[x0∣x1]\E[\mathbf x_0\mid\mathbf x_1] itself, missing all of Cov⁡(x0∣x1)\Cov(\mathbf x_0\mid\mathbf x_1). Learned variances (Nichol & Dhariwal, 2021) and analytically optimal ones (Bao et al., 2022) target exactly this deficit.

Score SDEs, the probability-flow ODE and DDIM

Let T→∞T\to\infty with βt=β(t/T)/T\beta_t=\beta(t/T)/T. The DDPM chain becomes the variance-preserving SDE dx=−12β(t)x dt+β(t) dwd\mathbf x=-\tfrac12\beta(t)\mathbf x\,dt+\sqrt{\beta(t)}\,d\mathbf w on t∈[0,1]t\in[0,1], whose marginals have αˉ(t)=exp⁡(−∫0tβ)\bar\alpha(t)=\exp\big(-\int_0^t\beta\big) (Song et al., 2021). The widget's schedule is exactly this SDE with β\beta rising linearly from 0.1 to 20, the continuum limit of DDPM's 1,000-step linear schedule. In general, take dx=f(x,t) dt+g(t) dwd\mathbf x=\mathbf f(\mathbf x,t)\,dt+g(t)\,d\mathbf w with marginals ptp_t.

DerivationProof sketch of (ii)
  1. ∂tpt=−∇⋅(f pt)+12g2 Δpt\partial_tp_t=-\nabla\cdot(\mathbf f\,p_t)+\tfrac12g^2\,\Delta p_t

    The SDE's marginals obey the Fokker–Planck equation:

  2. ∂tpt=−∇⋅[(f−12g2∇log⁡pt) pt]\partial_tp_t=-\nabla\cdot\Big[\big(\mathbf f-\tfrac12g^2\nabla\log p_t\big)\,p_t\Big]

    Use Δp=∇⋅∇p=∇⋅(p ∇log⁡p)\Delta p=\nabla\cdot\nabla p=\nabla\cdot(p\,\nabla\log p) to fold the diffusion term into the drift:

  3. ddtlog⁡pt(xt)=−∇⋅vt(xt)\frac{d}{dt}\log p_t(\mathbf x_t)=-\nabla\cdot\mathbf v_t(\mathbf x_t)

    This is the continuity equation of the velocity field vt=f−12g2∇log⁡pt\mathbf v_t=\mathbf f-\tfrac12g^2\nabla\log p_t, so particles moving by x˙=vt(x)\dot{\mathbf x}=\mathbf v_t(\mathbf x) have marginals ptp_t (given uniqueness for the continuity equation). The flow is invertible, so the instantaneous change of variables gives exact likelihoods, with the divergence estimated by Hutchinson's trace estimator:

DDIM (Song, Meng & Ermon, 2021) starts from the observation that the DDPM loss involves only the marginals q(xt∣x0)q(\mathbf x_t\mid\mathbf x_0), so every process with the same marginals can reuse the trained network. A family of non-Markovian forward processes indexed by η\eta yields the update

xt−1=αˉt−1 x^0+1−αˉt−1−σt2  εθ(xt,t)+σtz,x^0=xt−1−αˉt εθ(xt,t)αˉt,σt=ηβ~t\mathbf x_{t-1}=\sqrt{\bar\alpha_{t-1}}\,\hat{\mathbf x}_0+\sqrt{1-\bar\alpha_{t-1}-\sigma_t^2}\;\boldsymbol\varepsilon_\theta(\mathbf x_t,t)+\sigma_t\mathbf z,\qquad \hat{\mathbf x}_0=\frac{\mathbf x_t-\sqrt{1-\bar\alpha_t}\,\boldsymbol\varepsilon_\theta(\mathbf x_t,t)}{\sqrt{\bar\alpha_t}},\qquad \sigma_t=\eta\sqrt{\tilde\beta_t}
η=1\eta=1 recovers DDPM (σt2=β~t\sigma_t^2=\tilde\beta_t); η=0\eta=0 is deterministic. The update works on any subsequence of the training timesteps, so a model trained with T=1000T=1000 can sample in 50 steps or fewer.

Why η=0\eta=0 tolerates large steps: in the variables xˉ=x/αˉ\bar{\mathbf x}=\mathbf x/\sqrt{\bar\alpha} and σ=(1−αˉ)/αˉ\sigma=\sqrt{(1-\bar\alpha)/\bar\alpha}, the probability-flow ODE of the VP-SDE reads dxˉ/dσ=ε(xˉ/1+σ2,σ)d\bar{\mathbf x}/d\sigma=\boldsymbol\varepsilon\big(\bar{\mathbf x}/\sqrt{1+\sigma^2},\sigma\big), and deterministic DDIM is exactly Euler's method on it:

xˉt−1=xˉt+(σt−1−σt) εθ(xt,t).\bar{\mathbf x}_{t-1}=\bar{\mathbf x}_t+(\sigma_{t-1}-\sigma_t)\,\boldsymbol\varepsilon_\theta(\mathbf x_t,t).

Euler's global error is O(h)\order{h}. Higher-order solvers that exploit the ODE's semilinear structure (Karras et al., 2022; Lu et al., 2022) reach good samples in tens of evaluations.

Distillation removes most of the rest: progressive distillation halves the step count repeatedly (Salimans & Ho, 2022), consistency models learn to map any point of an ODE trajectory to its endpoint (Song et al., 2023), and adversarial distillation adds a GAN loss (Generative Adversarial Networks). Flow matching and rectified flows (Lipman et al., 2023; Liu, Gong & Liu, 2023) skip the SDE and regress a velocity field along straight paths xt=(1−t)x0+tε\mathbf x_t=(1-t)\mathbf x_0+t\boldsymbol\varepsilon; as of the mid-2020s they are a common choice for large image and video generators.

Check your understanding

You sample a model trained as a 1,000-step DDPM with DDIM at η=0\eta=0, using 20 of its timesteps, twice from the same xT\mathbf x_T. What happens?

  1. Two different images, because each step injects fresh noise
  2. Two identical images: the map from xT\mathbf x_T to x0\mathbf x_0 is deterministic, and approximately invertible
  3. An error: DDIM requires a network retrained for 20 steps
  4. Samples from a different target distribution, because DDIM's forward process differs from DDPM's
Show the answer

B. Two identical images: the map from xT\mathbf x_T to x0\mathbf x_0 is deterministic, and approximately invertible

With η=0\eta=0, σt=0\sigma_t=0 and each step is a deterministic function of xt\mathbf x_t. It discretizes the probability-flow ODE, so running it backward encodes a real image into an xT\mathbf x_T, which is used for editing and interpolation.

Guidance, latent diffusion and the frontier

Conditioning needs ∇log⁡pt(x∣c)=∇log⁡pt(x)+∇log⁡pt(c∣x)\nabla\log p_t(\mathbf x\mid c)=\nabla\log p_t(\mathbf x)+\nabla\log p_t(c\mid\mathbf x). Classifier guidance (Dhariwal & Nichol, 2021) trains a classifier on noisy inputs and adds ww times its gradient. Classifier-free guidance (Ho & Salimans, 2022) trains a single network in which the condition is replaced by a null token ∅\varnothing for a random 10–20% of examples, then extrapolates from the unconditional prediction toward the conditional one:

ε~=(1+w) εθ(xt,c)−w εθ(xt,∅)⟺s~=∇log⁡pt(x∣c)+w ∇log⁡pt(c∣x)=∇log⁡[pt(x∣c) pt(c∣x)w]\tilde{\boldsymbol\varepsilon}=(1+w)\,\boldsymbol\varepsilon_\theta(\mathbf x_t,c)-w\,\boldsymbol\varepsilon_\theta(\mathbf x_t,\varnothing)\quad\Longleftrightarrow\quad\tilde{\mathbf s}=\nabla\log p_t(\mathbf x\mid c)+w\,\nabla\log p_t(c\mid\mathbf x)=\nabla\log\Big[p_t(\mathbf x\mid c)\,p_t(c\mid\mathbf x)^w\Big]
The guided score tilts the conditional density toward points that the implicit classifier pt(c∣x)∝pt(x∣c)/pt(x)p_t(c\mid\mathbf x)\propto p_t(\mathbf x\mid c)/p_t(\mathbf x) finds unambiguous. Raising ww trades diversity for fidelity and prompt adherence: in Ho & Salimans' experiments, FID first improves and then worsens as ww grows, while Inception Score keeps rising. The tilted densities at different tt are not the noised versions of one distribution, so guided sampling does not exactly sample p0(x∣c) p0(c∣x)wp_0(\mathbf x\mid c)\,p_0(c\mid\mathbf x)^w; it is a heuristic, if a remarkably effective one.

Pixel-space diffusion spends much of its capacity on imperceptible detail. Latent diffusion (Rombach et al., 2022) first trains an autoencoder, with perceptual and patch-adversarial losses and light KL or VQ regularization (Variational Autoencoders & the ELBO), that downsamples by a factor ff, then runs diffusion on the latents. Text enters through cross-attention to a text encoder's outputs. Stable Diffusion, released in 2022, used f=8f=8 with 4 latent channels. Diffusion Transformers (Peebles & Xie, 2023) replaced the U-Net with a transformer over latent patches.

Predict before you look

Stable Diffusion's autoencoder maps a 512×512512\times512 RGB image to a 64×64×464\times64\times4 latent. By what factor does this cut the number of values the diffusion model must process?

Show the answer

48

512⋅512⋅3=786,432512\cdot512\cdot3=786{,}432 values versus 64⋅64⋅4=16,38464\cdot64\cdot4=16{,}384: a factor of 4848. Attention costs grow faster than linearly in the number of positions, and spatial positions fall by 82=648^2=64, so the compute saving per step is larger still.

Key takeaways

  • DDPM's bound is a sum of Gaussian KL terms. With the mean parameterized like the posterior mean, each term is a weighted ∥ε−εθ∥2\norm{\boldsymbol\varepsilon-\boldsymbol\varepsilon_\theta}^2, and LsimpleL_{\text{simple}} drops the weights, which leaves a perfect model unchanged.
  • Noise prediction is weighted denoising score matching, with optimum ε∗=−1−αˉt ∇log⁡qt\boldsymbol\varepsilon^*=-\sqrt{1-\bar\alpha_t}\,\nabla\log q_t; in continuous time the bound depends on the schedule only through its endpoints.
  • With the exact score, a DDPM step's mean is exactly E[xt−1∣xt]\E[\mathbf x_{t-1}\mid\mathbf x_t], and its error is the missing covariance ct2Cov⁡(x0∣xt)c_t^2\Cov(\mathbf x_0\mid\mathbf x_t). That deficit contracts samples when steps are few and makes the last step output E[x0∣x1]\E[\mathbf x_0\mid\mathbf x_1]. Given an accurate score, O~(L2d/ε2)\tilde{\mathcal O}(L^2d/\varepsilon^2) steps reach TV error ε\varepsilon.
  • The reverse SDE and the probability-flow ODE, with drift f−12g2∇log⁡pt\mathbf f-\tfrac12g^2\nabla\log p_t, share every marginal. Deterministic DDIM is Euler's method on that ODE, and higher-order solvers, distillation and flow matching cut the number of steps further.
  • Classifier-free guidance follows the score of pt(x∣c) pt(c∣x)wp_t(\mathbf x\mid c)\,p_t(c\mid\mathbf x)^w, trading diversity for fidelity; latent diffusion runs the whole process in an autoencoder's latent space, 48 times smaller for Stable Diffusion.

Check yourself

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

Question 1

A DDPM sampler with the exact score uses 5 steps, and its samples are too tightly clustered toward the middle of the data. Which part of each step is at fault?

  1. The step's variance: the Gaussian step uses β~t\tilde\beta_t and omits ct2Cov⁡(x0∣xt)c_t^2\Cov(\mathbf x_0\mid\mathbf x_t)
  2. The step's mean, which is biased toward the data's center of mass
  3. Tweedie's formula, which fails for large steps
  4. The score is evaluated at the wrong noise level
Show the answer

A. The step's variance: the Gaussian step uses β~t\tilde\beta_t and omits ct2Cov⁡(x0∣xt)c_t^2\Cov(\mathbf x_0\mid\mathbf x_t)

With the exact score, (xt+βt∇log⁡qt)/αt=E[xt−1∣xt](\mathbf x_t+\beta_t\nabla\log q_t)/\sqrt{\alpha_t}=\E[\mathbf x_{t-1}\mid\mathbf x_t] for any step size. The true conditional also has covariance ct2Cov⁡(x0∣xt)c_t^2\Cov(\mathbf x_0\mid\mathbf x_t) beyond β~tI\tilde\beta_tI, which is large when steps are large, so every step is too narrow and the cloud contracts.

Question 2

What does the probability-flow ODE share with the reverse-time SDE?

  1. The same sample paths
  2. It is the reverse SDE with its noise term deleted
  3. The same marginal distribution ptp_t at every time tt
  4. Nothing: it targets a different distribution, with exact likelihoods as compensation
Show the answer

C. The same marginal distribution ptp_t at every time tt

Both have the marginals ptp_t of the forward SDE, as the Fokker–Planck computation shows. The ODE's drift is f−12g2∇log⁡pt\mathbf f-\tfrac12g^2\nabla\log p_t, half the score term of the reverse SDE's f−g2∇log⁡pt\mathbf f-g^2\nabla\log p_t.

Question 3

With guidance weight ww, the classifier-free guided score at noise level tt is the score of which (unnormalized) density?

  1. pt(x∣c)1+wp_t(\mathbf x\mid c)^{1+w}
  2. pt(x)w pt(x∣c)p_t(\mathbf x)^w\,p_t(\mathbf x\mid c)
  3. pt(c∣x)p_t(c\mid\mathbf x)
  4. pt(x∣c) pt(c∣x)wp_t(\mathbf x\mid c)\,p_t(c\mid\mathbf x)^w
Show the answer

D. pt(x∣c) pt(c∣x)wp_t(\mathbf x\mid c)\,p_t(c\mid\mathbf x)^w

s~=(1+w)∇log⁡pt(x∣c)−w∇log⁡pt(x)=∇log⁡[pt(x∣c)(pt(x∣c)pt(x))w]\tilde{\mathbf s}=(1+w)\nabla\log p_t(\mathbf x\mid c)-w\nabla\log p_t(\mathbf x)=\nabla\log\Big[p_t(\mathbf x\mid c)\big(\tfrac{p_t(\mathbf x\mid c)}{p_t(\mathbf x)}\big)^w\Big], and pt(x∣c)pt(x)∝pt(c∣x)\tfrac{p_t(\mathbf x\mid c)}{p_t(\mathbf x)}\propto p_t(c\mid\mathbf x) by Bayes' rule.

Question 4

A noise predictor is trained to optimality with E∥ε−εθ(xt,t)∥2\E\norm{\boldsymbol\varepsilon-\boldsymbol\varepsilon_\theta(\mathbf x_t,t)}^2. What is εθ(x,t)\boldsymbol\varepsilon_\theta(\mathbf x,t)?

  1. The noise that was actually added to produce x\mathbf x
  2. x/1−αˉt\mathbf x/\sqrt{1-\bar\alpha_t}
  3. −1−αˉt ∇log⁡qt(x)-\sqrt{1-\bar\alpha_t}\,\nabla\log q_t(\mathbf x)
  4. ∇log⁡qt(x)\nabla\log q_t(\mathbf x)
Show the answer

C. −1−αˉt ∇log⁡qt(x)-\sqrt{1-\bar\alpha_t}\,\nabla\log q_t(\mathbf x)

Squared error is minimized by E[ε∣xt]\E[\boldsymbol\varepsilon\mid\mathbf x_t], and denoising score matching (equivalently Tweedie's formula) gives E[ε∣xt]=−1−αˉt ∇log⁡qt(xt)\E[\boldsymbol\varepsilon\mid\mathbf x_t]=-\sqrt{1-\bar\alpha_t}\,\nabla\log q_t(\mathbf x_t).

Further reading

  • J. Ho, A. Jain & P. Abbeel, "Denoising diffusion probabilistic models," NeurIPS (2020).
  • Y. Song, J. Sohl-Dickstein, D. P. Kingma, A. Kumar, S. Ermon & B. Poole, "Score-based generative modeling through stochastic differential equations," ICLR (2021).
  • J. Ho & T. Salimans, "Classifier-free diffusion guidance," arXiv:2207.12598 (2022).
  • R. Rombach, A. Blattmann, D. Lorenz, P. Esser & B. Ommer, "High-resolution image synthesis with latent diffusion models," CVPR (2022).
  • K. P. Murphy, Probabilistic Machine Learning: Advanced Topics, ch. "Diffusion models" (MIT Press, 2023).