Equations · Ho, Jain and Abbeel, “Denoising Diffusion Probabilistic Models” (2020)
The DDPM training loss (predict the noise), explained
How a diffusion model is trained: take a clean example, add a known amount of noise in one jump, and ask the network to say what noise was added. The loss is the squared error. The paper derives it from a variational bound and finds that dropping the bound's weights trains better.
Term by term
Average over a random step (uniform on ), a training example and a noise draw . Each training step samples one of each per example.
The noised input , made in one step with the forward process's closed form.
The network (usually a U-Net or Transformer) with parameters : given the noisy input and the step number, it predicts the noise. Here is a noise vector, not a small constant.
Epsilon · Theta · Subscript (index or label) · Bold lowercase (vector)
The squared Euclidean norm: the sum of squared errors over all pixels. Code usually takes the mean instead, which only changes the scale.
The subscript is a label: the "simple" version, without the weighting terms of the full bound.
A small worked example
Two-pixel image, drawn noise , network prediction . Loss: . Sampling then runs the network backward from pure noise, removing a little predicted noise at each of the steps.
In code
import torch
import torch.nn.functional as F
def ddpm_loss(model, x0, alpha_bar):
# x0: (B, C, H, W); alpha_bar: (T,)
t = torch.randint(0, len(alpha_bar), (x0.shape[0],))
eps = torch.randn_like(x0)
ab = alpha_bar[t].view(-1, 1, 1, 1)
x_t = ab.sqrt() * x0 + (1 - ab).sqrt() * eps
return F.mse_loss(model(x_t, t), eps)Every symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- Backpropagation through one layer
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)