Skip to main content

Denoising Diffusion Probabilistic Models (DDPM)

DDPM is the foundation of modern generative AI (like Stable Diffusion and Midjourney). It works by destroying data with noise and then learning to reverse that destruction.

Diffusion Process Visualization

1. The Forward Process (qq)

In the forward process, we take a clean image x0x_0 and slowly add Gaussian noise over TT timesteps.

q(xtxt1)=N(xt;1βtxt1,βtI)q(x_t | x_{t-1}) = \mathcal{N}(x_t; \sqrt{1 - \beta_t} x_{t-1}, \beta_t I)

  • βt\beta_t: The variance schedule. Usually, we increase β\beta as tt increases (linear or cosine schedule).
  • The Result: By the time we reach t=Tt=T, the image is indistinguishable from pure white noise.

2. The Reverse Process (pθp_\theta)

This is where the magic happens. We train a neural network (typically a U-Net) to predict the noise that was added at each step. If the network can predict the noise ϵ\epsilon, we can subtract it to get back to a slightly cleaner image.

The transition is modeled as:

pθ(xt1xt)=N(xt1;μθ(xt,t),Σθ(xt,t))p_\theta(x_{t-1} | x_t) = \mathcal{N}(x_{t-1}; \mu_\theta(x_t, t), \Sigma_\theta(x_t, t))


3. The Training Objective

Surprisingly, the complex math of Diffusion simplifies into a very elegant loss function. Instead of predicting the image directly, we predict the noise ϵ\epsilon that was sampled at timestep tt.

Lsimple=Et,x0,ϵ[ϵϵθ(αˉtx0+1αˉtϵ,t)2]L_{simple} = \mathbb{E}_{t, x_0, \epsilon} \left[ \| \epsilon - \epsilon_\theta(\sqrt{\bar{\alpha}_t} x_0 + \sqrt{1 - \bar{\alpha}_t} \epsilon, t) \|^2 \right]

Intuition: We are telling the network: "Here is a messy, noisy image. Can you guess exactly what the random noise was that made it look this way?"


4. The Architecture: Why U-Net?

Diffusion models almost always use a U-Net architecture with Attention layers.

  1. Downsampling: The network looks at the global structure (the "big picture").
  2. Upsampling: The network reconstructs the fine details (the "texture").
  3. Skip Connections: These are vital. They allow the network to keep the original spatial information while it's trying to figure out what's noise and what's data.
  4. Time Embeddings: Since the network needs to know how much noise to expect, we inject the timestep tt into every layer using sinusoidal embeddings (similar to Transformers).

Summary of the DDPM Recipe

  1. Pick an image from your dataset.
  2. Pick a random timestep tt between 1 and TT.
  3. Add noise ϵ\epsilon to the image to create xtx_t.
  4. Ask the U-Net to guess ϵ\epsilon given xtx_t and tt.
  5. Update the U-Net based on how wrong its guess was.

Pro Tip: Conditioning

To make the model generate specific things (like "a cat in a hat"), we inject Text Embeddings (from a model like CLIP) into the U-Net. This is called Guided Diffusion.