The target distribution
Same three-cluster MoG as the EM tutorial: 100 points each from three anisotropic Gaussians with random seed 42. To DDPM, this is just a tensor of 300 points in , it has no idea three Gaussians produced it.Code
Code
The forward (noising) process
DDPM defines a fixed Markov chain that gradually adds Gaussian noise to a data point until, after steps, it is indistinguishable from pure noise: is the variance schedule. With and , the chain has a closed-form jump from any directly to : This shortcut is what makes DDPM training cheap: you never simulate the chain step by step during training, you sample , jump straight to , and learn from there.Code
Code
The reverse (denoising) process
Generation is the forward process run backwards. We learn a Gaussian transition Ho, Jain and Abbeel (Ho et al., 2020) reparameterize the mean by training a network to predict the noise that was added when producing from . The mean is then and the entire variational lower bound collapses to a simple denoising objective: No KL divergence to manage, no encoder, no posterior approximation, pure regression on noise.The noise predictor
For 2D data, is a small MLP. The only non-obvious piece is the time embedding: the network must condition on which timestep we are denoising. The conventional trick is sinusoidal positional features (same idea as transformers).Code
Code
Training
The training loop is one of the simplest in modern generative modeling:- Sample a batch from .
- Sample a random timestep for each example.
- Sample noise and form via the closed-form forward jump.
- Predict .
- Minimize .
Code
Code
Sampling: the reverse process in action
Now run the chain backwards. Start with and, for , take a step: with for and at the final step. The standard variance choice is .Code
Code
Did it work?
Compare the generated samples to the original training data. The model never learned that there are three components, that they are Gaussian, or where their centers are, it only saw 300 data points and a noise-prediction objective. If the three clusters reappear in the generated cloud, the diffusion model has captured the data distribution.Connections to other concepts
- Black-box density modeling. DDPM treats as opaque. Compare with EM, which assumes a parametric mixture form and fits its parameters.
- Same recipe, bigger backbone. Replace the 4-layer MLP with a U-Net and the same noise-prediction objective generates 256×256 images. The schedule, the closed-form forward jump, and the training loop do not change.
- Conditional and guided generation. Condition on a label, prompt, or class to obtain conditional models, and combine with classifier-free guidance to trade diversity for fidelity.
- Latent diffusion. Run the entire chain inside a learned latent space (encode → diffuse in latents → decode) for orders-of-magnitude faster image generation.
- Score-based unification. The score mixture example trains a score network on the same mixture under the variance-preserving Ornstein-Uhlenbeck process. DDPM’s noise predictor gives a score through with . The two networks estimate the same quantity with different output scalings.
- Faster, deterministic sampling. The DDIM tutorial reuses this same trained model with a different sampler that takes a fraction of the steps and is deterministic, opening the door to latent interpolation and editing.
Further reading
DDPM grew out of an earlier diffusion model built on nonequilibrium thermodynamics (Sohl-Dickstein et al., 2015). Nichol and Dhariwal improved the noise schedule and learned the reverse variances in Improved Denoising Diffusion Probabilistic Models (ICML 2021, arxiv.org/abs/2102.09672).PyTorch reference
References
- Ho, J., Jain, A., Abbeel, P. (2020). Denoising Diffusion Probabilistic Models. arXiv [cs.LG]. DOI
- Sohl-Dickstein, J., Weiss, E., Maheswaranathan, N., Ganguli, S. (2015). Deep Unsupervised Learning using Nonequilibrium Thermodynamics. arXiv [cs.LG]. Link
Found an error on this page? Report an issue.

