Interactive Explainer
A diffusion model learns to reverse a noising process. Drag the timestep slider — watch a 2D shape dissolve into Gaussian. Press "reverse" — watch noise reassemble back into the shape. Every modern image generator rides this idea.
The forward process is fixed: repeatedly add small Gaussian noise until the data becomes indistinguishable from N(0, I). The reverse process is learned: a neural network predicts how much noise was added at each step, so you can subtract it and work your way back.
x_t = √(α̅_t) · x_0 + √(1 − α̅_t) · ε ε ~ N(0, I)
Because Gaussians compose under noise-addition, you can sample x_t directly from x_0 without stepping through — huge training speedup. α̅_t is a cumulative product of noise-retention factors; it goes from ~1 at t=0 to ~0 at t=T.
L = E_{t, x_0, ε} [ ∥ε − ε_θ(x_t, t)∥² ]
Sample a random clean image, a random timestep, and a random noise ε. Compute x_t. Ask the network to predict ε. That's the entire loss. Simple, stable, and works better than everything else.
Reversing diffusion means: given $x_t$ (noisy) and the timestep $t$, predict $x_{t-1}$ (slightly less noisy). The exact reverse is intractable, but Ho et al. (2020) show that for small enough noise steps it's well-approximated by a Gaussian:
p_θ(x_{t-1} | x_t) = N(x_{t-1}; μ_θ(x_t, t), Σ_θ(x_t, t))
And — the algebraic punchline — once you have $\epsilon_\theta$, the predicted noise, the mean of that Gaussian has a closed form:
μ_θ(x_t, t) = (1/√α_t) [ x_t − (β_t / √(1−α̅_t)) · ε_θ(x_t, t) ]
That's why DDPM's loss is just "predict the noise" — once $\epsilon_\theta$ is good, the reverse mean is automatic. The variance $\Sigma_\theta$ is either fixed to $\beta_t$ (DDPM) or learned (Nichol & Dhariwal 2021).
DDPM sampling is $T$ network calls (typically 1000) per image. DDIM (Song et al., 2020) shows that a non-Markovian reverse process can take just 25–50 steps with the same trained model:
x_{t−Δ} = √(α̅_{t−Δ}) · x̂_0 + √(1 − α̅_{t−Δ}) · ε_θ(x_t, t)
where $\hat x_0 = (x_t - \sqrt{1 - \bar\alpha_t}\,\epsilon_\theta) / \sqrt{\bar\alpha_t}$ is the model's current estimate of the clean image. Set $\Delta = T/N$; you get $N$-step sampling. Quality survives well even at $N = 25$. The successors (DPM-Solver, UniPC) push the floor below 10 steps.
How do diffusion models know what to generate? They train on $(x, c)$ pairs where $c$ is a class label or text embedding, and the noise predictor takes $c$ as an extra input. At inference, the famous trick (Ho & Salimans, 2021):
ε̂(x_t, t, c) = (1 + w) · ε_θ(x_t, t, c) − w · ε_θ(x_t, t, ∅)
Compute the noise prediction with the condition $c$ and without (an empty / "null" condition the model also saw during training). Extrapolate beyond the conditional prediction by $w$. Large $w$ → strongly on-prompt but less diverse; $w \approx 7$ is the Stable-Diffusion default. The CFG scale visualiser shows this on a 2D toy.
Companion: CFG scale visualiser · text diffusion · U-Net inside diffusion.