IntermediateEnglish19 lectures · 2h 16m

DDPM and DDIM from Scratch

Derive and implement DDPM and fast DDIM sampling in PyTorch — from the paper to working code on MNIST

Watch 3 lectures free

What you'll learn

  • Explain the forward and reverse diffusion processes and derive the closed-form noising formula
  • Derive the ELBO for diffusion models and simplify it to the DDPM noise-prediction loss
  • Implement a noise scheduler, a time-conditioned U-Net, training and sampling loops in PyTorch
  • Train a DDPM on MNIST and generate digits from pure noise
  • Understand why DDIM sampling is non-Markovian and implement deterministic 50-step sampling
  • Read a diffusion paper and map its equations to code

About this course

Diffusion models power Stable Diffusion, DALL-E and Midjourney — but most tutorials stop at "it adds noise and removes it". This course goes all the way: we read the DDPM paper (Ho et al., 2020) and the DDIM paper (Song et al., 2020) line by line, derive every equation on screen in plain language, and turn each one into PyTorch code that trains on MNIST in minutes.

You will build the forward diffusion process and its closed form, derive the reverse process and the evidence lower bound (ELBO) through Jensen's inequality, simplify it to the noise-prediction loss, implement the noise scheduler, a time-conditioned U-Net, the training loop and the sampling loop. Then you will add DDIM: the non-Markovian view of diffusion that turns 1000 sampling steps into 50 with the same trained model.

Every lecture shows the notebook on screen while the narration explains what each cell does and why. Failure modes, trade-offs and "what to try if this breaks" are part of the lesson. By the end you can read a diffusion paper, explain it to a colleague, and implement it.

This is the first of two courses. The sequel, *Latent Diffusion to SANA*, continues with Stable Diffusion, Diffusion Transformers, PixArt-α and SANA.

Curriculum3 sections · 19 lectures · 2h 16m

Section 0. Welcome

Free preview

Section 1. DDPM

Free preview
  • section 1 intro0:18
  • DDPM chapter intro2:00
  • 🔒Environment setup2:42
  • 🔒Notation6:24
  • 🔒Forward process7:18
  • 🔒Reverse process8:42
  • 🔒Jensen inequality6:00
  • 🔒ELBO4:00
  • 🔒From ELBO to the loss10:24
  • 🔒Noise scheduler10:42
  • 🔒Diffusion class14:18
  • 🔒UNet17:48
  • 🔒Training and sampling12:24
  • 🔒DDPM wrap up3:06

Section 2. DDIM

  • 🔒section 2 intro0:18
  • 🔒DDIM intro and differences6:18
  • 🔒DDIM sampling9:42
  • 🔒DDIM implementation11:48

Requirements

  • · A computer with Python 3.10+ (a free Google Colab account is enough for most sessions)
  • · Comfort reading Python code; you do not need to be an expert
  • · Basic PyTorch (tensors, autograd, nn.Module, a training loop)
  • · Basic probability: Gaussian distributions, expectation, Bayes' rule; a little calculus

Who this is for

  • · ML engineers and data scientists who use diffusion models and want to understand them
  • · Graduate students and researchers preparing to read or write diffusion papers
  • · Developers who can run Stable Diffusion but cannot modify or train it
  • · Anyone who prefers derivations and code over hand-waving

Read alongside the course

The voice-over in this course is synthesized with a text-to-speech model from scripts written and reviewed by the instructor, and the on-screen material (notebooks, code, slides) is the instructor's own work.

DDPM and DDIM from Scratch | SOTAAZ Blog