Diffusion Models Overview


Diffusion Models Overview

Anna
Michael, I always thought diffusion models were a recent breakthrough, but it turns out the original idea goes back to 2015—a paper called 'Deep Unsupervised Learning using Nonequilibrium Thermodynamics' by Sohl-Dickstein and colleagues.

Michael
Right, but that early work didn't get much attention because GANs were dominating image generation back then. It wasn't until the 2020 DDPM paper—Denoising Diffusion Probabilistic Models by Ho et al.—that diffusion models really took off. That paper made the method practical and is now the most cited in the field.

Anna
Exactly. And the core idea is fascinating: start with clean images, gradually add Gaussian noise until they become pure noise, then train a neural network to reverse that process. If it learns well, you can generate new images by starting from random noise and denoising step by step.

Michael
But here's the tricky part: the way you add noise matters. If you just keep adding noise without scaling, the mean stays fixed and variance explodes. That's called a variance-exploding process, and it never converges to a standard normal distribution, which is what we want for generation.

Anna
So the DDPM authors introduced a variance-preserving diffusion. They multiply the mean by sqrt(1 - beta_t) at each step. With the right choice of beta_t, the mean goes to zero and variance goes to one as t increases—so the process converges to standard Gaussian noise.

Michael
Right, and they use a reparameterization trick to go directly from clean image x_0 to any noisy version x_t in one step: x_t = sqrt(alpha_bar_t) * x_0 + sqrt(1 - alpha_bar_t) * epsilon, where alpha_bar_t is the product of (1 - beta) up to step t.

Anna
And beta_t can vary per step—that's the noise schedule. Common choices are linear or cosine schedules. Now, once we have this forward process, we need to learn the reverse. The reverse process is also a Markov chain, but with learned parameters theta—usually a neural network.

Michael
Training that network involves maximizing the log-likelihood of generating real images. But that's intractable because it would require summing over all possible noise paths. So we use a trick: the evidence lower bound, or ELBO. By applying Jensen's inequality, we get a tractable upper bound on the negative log-likelihood.

Anna
And after a lot of algebra, the ELBO simplifies to a sum of KL divergences between the true posterior q(x_{t-1}|x_t, x_0) and the approximate posterior p_theta(x_{t-1}|x_t). Since both are Gaussian, the KL boils down to an L2 distance between their means.

Michael
But the true posterior mean depends on x_0 and x_t. Using the reparameterization trick again, we can rewrite it in terms of x_t and the noise epsilon. Then the network predicts the noise epsilon_theta instead of the mean. The loss becomes simple: mean squared error between the true noise and the predicted noise.

Anna
And to make training efficient, instead of summing over all timesteps, we randomly sample a single timestep per batch. The final training loop is straightforward: sample a batch of images, pick random t, add noise according to the schedule, feed the noisy image and t into the network, compute MSE against the noise, and update weights.

Michael
In the DDPM paper, they actually drop the time-dependent weighting in the loss and use uniform weights—that often works better. The network architecture is a U-Net with self-attention, and they train on datasets like MNIST or FFHQ. After training, we can generate new images by starting from pure noise and iteratively denoising.

Anna
During inference, we start with x_T ~ N(0, I). For t from T down to 1, we predict epsilon_theta, compute the estimated mean, and then sample x_{t-1} from p_theta. We repeat for all timesteps. The result is a fully generated image that looks like it came from the training distribution.

Michael
The code is surprisingly compact—the sampling loop fits in fewer than thirty lines. And you can swap in pretrained weights for different datasets to generate faces or digits. The quality is much higher than VAEs, but it comes at a cost: you need hundreds or thousands of network evaluations per image.

Anna
That trade-off between quality and speed led to follow-up work on faster sampling, but that's another story. For now, we've covered the key ideas: forward process, variance preserving, ELBO, KL divergence, reparameterization, simple MSE loss, and the training/inference loop. It's amazing how a denoiser can generate entirely new data from noise.

Michael
And there's a deeper connection: this discrete-time framework can be generalized to continuous-time stochastic differential equations, known as score-based diffusion models. That'll be our next topic. But for now, I think we've given a solid foundation on DDPMs.

Ask anything
We've read this whole study set, so questions about it get the best answers.