---
title: "The Annotated Diffusion Model"
description: "Denoising Diffusion Probabilistic Models (Ho et al., 2020) work by pairing a fixed forward process that gradually adds Gaussian noise to an image under a variance schedule with a learned reverse process that denoises step by step from pure noise."
url: "https://swe.quest/articles/the-annotated-diffusion-model-62697ee4beb56b3a"
canonical: "https://huggingface.co/blog/annotated-diffusion"
source: "Hugging Face"
published: "2022-06-07"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 24
tags: ["computer-vision","model-training","machine-learning","python"]
---

# The Annotated Diffusion Model

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-06-07, 24 min read, Deep dive. Original: [https://huggingface.co/blog/annotated-diffusion](https://huggingface.co/blog/annotated-diffusion)

## Summary

Denoising Diffusion Probabilistic Models (Ho et al., 2020) work by pairing a fixed forward process that gradually adds Gaussian noise to an image under a variance schedule with a learned reverse process that denoises step by step from pure noise. A closed-form property lets x\_t be sampled directly from x\_0, and a reparametrization of the mean turns training into a simple MSE loss on predicting the added noise at a randomly sampled timestep. The walkthrough derives this objective and then implements the model step by step in PyTorch: a U-Net with residual connections, sinusoidal timestep embeddings and weight-standardized ResNet blocks with group normalization, following Phil Wang's implementation.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch
- probability and Gaussian distributions
- variational autoencoders
- convolutional neural networks ([easy posts on Machine learning](https://swe.quest/tags/machine-learning.md?difficulty=easy))

## Keywords

DDPM, diffusion models, PyTorch, U-Net, ELBO, sinusoidal position embeddings

## Related posts

- [PRX Part 3 — Training a Text-to-Image Model in 24h!](https://swe.quest/articles/prx-part-3-training-a-text-to-image-model-in-24h-e27e27a7f3c7dc41.md): Hugging Face · 2026-03-03 · Hard · 9 min read · Model training, Computer vision, Machine learning
  A 24-hour, ~$1500 speedrun on 32 H200s combines the most effective diffusion training tricks into a single text-to-image recipe.
- [How Diffusion Controller unifies and simplifies AI image generation](https://swe.quest/articles/how-diffusion-controller-unifies-and-simplifies-ai-image-generation-261f5c78987e6b2e.md): Google Research · 2026-09-29 · Hard · 7 min read · Model training, Computer vision, Machine learning
  Diffusion Controller reframes diffusion denoising as a continuous control problem, unifying inference-time guidance and fine-tuning methods such as LoRA, reward-weighted regression and policy gradients under one framework.
- [Finetune Stable Diffusion Models with DDPO via TRL](https://swe.quest/articles/finetune-stable-diffusion-models-with-ddpo-via-trl-08d1757d4cd09bc2.md): Hugging Face · 2023-09-29 · Hard · 9 min read · Model training, Computer vision, Machine learning, Python
  Denoising Diffusion Policy Optimization (DDPO) fine-tunes diffusion models with reinforcement learning by treating the full denoising process as a multistep MDP.
- [VQ-Diffusion](https://swe.quest/articles/vq-diffusion-60af6753b8809ca3.md): Hugging Face · 2022-11-30 · Hard · 7 min read · Computer vision, Machine learning, Python
  VQ-Diffusion is a conditional latent diffusion model whose noising and denoising run over a discrete VQ-VAE codebook rather than Gaussian noise.
- [Towards demystifying the creativity of diffusion models](https://swe.quest/articles/towards-demystifying-the-creativity-of-diffusion-models-b65392995a4ab4c2.md): Google Research · 2026-07-15 · Hard · 7 min read · Machine learning, Model training
  Diffusion models generalize beyond their training data because neural networks learn a smoothed version of the score function rather than the exact empirical one, which would only reproduce training samples.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
