Diffusion Models Overview
Diffusion Models and DDPM: Comprehensive Study Notes
History and Context
Diffusion models have become a powerful generative modeling technique, applied to images, videos, music, 3D models, and molecular discovery. The key breakthrough paper is "Denoising Diffusion Probabilistic Models" (DDPM) by Jonathan Ho et al., published in 2020. However, DDPM did not invent diffusion models.
The first diffusion model formulation appeared in "Deep Unsupervised Learning using Nonequilibrium Thermodynamics" (Jascha Sohl-Dickstein et al., 2015). At that time, GANs were state-of-the-art for image generation, and diffusion models received little attention.
The 2020 DDPM paper transformed diffusion models from a theoretical concept (limited to toy datasets) into a state-of-the-art technique for image generation. Its main contribution was a much simpler training objective and highlighting connections to earlier denoising models.
Core Idea of Diffusion Models
Given a complex data distribution p(x) (e.g., all natural images), the goal is to generate new samples from this distribution without an explicit formula.
Diffusion models approach this by removing Gaussian noise from images:
Forward process (diffusion): Gradually corrupt an image by adding small amounts of Gaussian noise over many steps. After enough steps, the image becomes pure noise.
Reverse process (denoising): Train a neural network to reverse the corruption steps — starting from random noise and progressively removing noise until a meaningful image emerges.
If the reverse model is effective, sampling from pure noise yields realistic data.
Mathematical Formulation of the Forward Process
Let x0 be the original clean image. The forward process adds Gaussian noise at each step.
Variance Exploding Formulation (initial naive approach)
A simple forward step:
where βt controls the noise variance. After t steps:
Problem: The mean stays fixed at x0 and variance grows indefinitely — the process does not converge to a standard normal distribution. This is called a variance exploding diffusion.
Variance Preserving Formulation (used in DDPM)
To make the process converge to N(0,I), two conditions are needed:
Mean must converge to 0
Variance must converge to 1
The DDPM paper modifies each forward step:
where βt∈(0,1). This choice leads to a convenient closed-form expression for any timestep t directly from x0:
Define:
αt=1−βt
αˉt=∏s=1tαs
Then:
As t→∞, αˉt→0, so the mean goes to 0 and variance goes to 1 — a variance preserving diffusion.
Key point: The forward process is fixed — no learnable parameters. It transforms any data distribution into a standard normal.
Noise Schedules
In the original DDPM, a linear schedule is used: βt linearly interpolates from βstart to βend over T steps.
Other schedules (e.g., cosine) are possible, as long as each βt∈(0,1).
Reverse Process and Training Objective
Setting Up the Reverse Process
Define the reverse process with learnable parameters θ (neural network weights):
Typically, the variance Σθ is fixed to a constant σt2I (not learned). The network predicts the mean μθ.
The true posterior q(xt−1∣xt,x0) (conditioned on the clean image x0) has a closed-form Gaussian expression:
where μ~t and β~t depend on xt, x0, and the noise schedule.
Deriving the Training Objective
The goal is to maximize the log-likelihood logpθ(x0). Since this is intractable (requires summing over all possible reverse paths), a variational lower bound (ELBO) is used:
Evidence Lower Bound (ELBO): An upper bound on the negative log-likelihood, equivalent to a lower bound on the likelihood itself.
Starting with:
After algebraic manipulation and using the Markov property, the ELBO can be expressed as a sum of KL divergences:
Where:
The KL divergence DKL(P∥Q) measures how much distribution Q diverges from P (zero when identical).
The first term involves no learnable parameters and is ignored.
The last term (reconstruction from x1 to x0) is negligible in practice and often dropped.
Simplifying to a Noise Prediction Objective
Since both the true posterior q(xt−1∣xt,x0) and the approximate posterior pθ(xt−1∣xt) are Gaussian with fixed variances, the KL divergence simplifies to a squared distance between their means:
Using the reparameterization trick:
xt=αˉtx0+1−αˉtϵ, where ϵ∼N(0,I)
The true posterior mean μ~t can be written as a function of xt and ϵ
The network's predicted mean μθ is similarly parameterized to predict ϵθ(xt,t)
After substitution and cancellation, the loss simplifies to:
Final training objective: The neural network predicts the noise ϵ that was added to the clean image x0 to produce xt. Minimize the mean squared error (MSE) between the true noise and the predicted noise.
In practice, the sum over all timesteps is replaced by sampling a random t for each batch element, which converges to the same objective.
The DDPM paper uses uniform weights (no time-dependent weighting), which often produces better results than the theoretically derived weights.
Implementation Overview
Training
Tools: PyTorch + DeepInverse (provides pre-built Diffusion UNet architecture and pretrained weights).
Steps:
Load dataset (e.g., MNIST, 32×32 grayscale).
Instantiate a
DiffusionUNetwith appropriate input/output channels.Define a noise schedule: linear interpolation from βstart to βend over T=1000 timesteps.
Compute αt, αˉt, αˉt, 1−αˉt.
Training loop for each batch:
Sample random t∼Uniform(0,T) and noise ϵ∼N(0,I).
Compute noisy image: xt=αˉtx0+1−αˉtϵ
Network predicts ϵθ(xt,t).
Loss = MSE(ϵ, ϵθ).
Update network weights (e.g., Adam optimizer).
During training, the model gradually learns to denoise at all noise levels.
Inference (Sampling)
Steps:
Start with pure Gaussian noise xT∼N(0,I).
for t=T down to 1:
Predict noise ϵθ(xt,t).
Compute posterior mean: μθ(xt,t)=αt1(xt−1−αˉtβtϵθ)
Sample xt−1∼N(μθ,σt2I), where σt2=β~t (or a fixed schedule).
Output x0 as the final generated sample.
The sampling loop is concise (~30 lines of code), running the network T times (typically 1000).
Properties and Trade-offs
Quality: DDPM generates images of extremely high fidelity — often indistinguishable from real data.
Comparison to VAEs: DDPMs produce much sharper images than VAEs, but at the cost of many inference steps (1000 forward passes vs. one for a VAE). This is a compute-quality trade-off.
Flexibility: The same sampling code works across different datasets by swapping pretrained weights (e.g., MNIST → FFHQ portraits).
Extensions and Next Steps
Faster sampling was achieved shortly after DDPM by reducing the number of steps (e.g., using denoising diffusion implicit models, DDIM).
A more general formulation replaces discrete Markov chains with continuous-time stochastic differential equations (score-based diffusion models), which unify and extend the theory.
Summary of Mathematical Pipeline
Step | Operation | Expression |
|---|---|---|
Forward process | q(xt∣xt−1) | N(1−βtxt−1,βtI) |
Direct to xt | q(xt∣x0) | N(αˉtx0,(1−αˉt)I) |
True posterior | q(xt−1∣xt,x0) | Gaussian with closed-form mean μ~t |
Approx. posterior | pθ(xt−1∣xt) | N(μθ(xt,t),σt2I) |
Training loss | Lsimple | E[∣ϵ−ϵθ(xt,t)∣2] |
Sampling (one step) | xt−1 from pθ | μθ+σt⋅N(0,I) |
The central insight: training a denoiser to predict the noise enables generating new data by running the reverse process from pure noise.

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