Section 11.5
Diffusion Models

The forward diffusion process (top) generates noise from data, . The reverse diffusion process (bottom) recovers a sample from the data distribution from noise
Figure 136: The forward diffusion process (top) generates noise from data, \(\text{data}, x_0 \in \reals^n \to \text{noise}, x_T \in \reals^n\). The reverse diffusion process (bottom) recovers a sample from the data distribution from noise, \(\text{noise}, x_T \in \reals^n \to \text{data}, x_0 \in \reals^n\).

Diffusion models are generative models that learn to reverse a gradual noise corruption process. Starting from real data \(x_0\), a forward diffusion process progressively adds Gaussian noise over many timesteps until the data becomes nearly pure noise. A denoising diffusion probabilistic model (DDPM) then learns the reverse process: given a noisy sample \(x_t\), a neural network predicts either the original signal or the added noise so that the model can iteratively denoise samples back into realistic data. This is shown in Figure 136 and an example denoising network architecture in Figure 137.

Neural network architecture for producing a sample from . The reparameterization trick is used so that we can back-propagate through and . The model is often si
Figure 137: Neural network architecture for producing a sample \(x_{t-1}\) from \(q(x_{t-1} \mid x_t, t) = \cN(f_\mu(x_t, t; \theta), f_\Sigma(x_t, t; \theta))\). The reparameterization trick is used so that we can back-propagate through \(\mu\) and \(\Sigma\). The model is often simplified to assume spherical covariance, \(\Sigma = \sigma_t^2 I\) with predetermined fixed \(\sigma_t\).

Training is typically performed by minimizing a simple mean-squared error objective on the predicted noise, while generation begins with Gaussian noise and repeatedly applies learned denoising steps. DDPMs are highly stable to train and can generate extremely high-quality samples, although sampling is often computationally expensive because it requires many sequential denoising iterations. Training and sampling algorithms are provided below.

1:procedure LearnDDPM
2:initialize \(\theta\)
3:repeat
4:\(x_0 \sim q(x_0)\)▷ sample data
5:\(t \sim U(1, T)\)▷ sample timestep
6:\(\epsilon \sim {\cal N}(0, I)\)▷ sample noise
7:\(x_t = \sqrt{\bar{\alpha}_t} x_0 + \sqrt{1 - \bar{\alpha}_t} \epsilon\)▷ forward recursion
8:\(\ell(\theta) = \| \epsilon - f_\epsilon(x_t, t; \theta) \|^2\)▷ compute loss
9:\(\theta \gets \theta - \eta \nabla_{\theta} \ell(\theta)\)▷ update parameters
10:until converged
11:return \(\theta\)
12:end procedure
1:procedure SampleDDPM
2:\(x_T \sim {\cal N}(0, I)\)▷ sample noise
3:for \(t = T, \ldots, 1\) do
4:if \(t > 1\) then
5:\(z \sim {\cal N}(0, I)\)
6:else
7:\(z = 0\)
8:end if
9:\(x_{t-1} = \frac{1}{\sqrt{\alpha_t}} \left( x_t - \frac{1 - \alpha_t}{\sqrt{1 - \bar{\alpha}_t}} f_\epsilon(x_t, t; \theta) \right) + \sigma_t z\)▷ denoise
10:end for
11:return \(x_0\)
12:end procedure