Skip to content

Module 20

Anurag Prasad edited this page Nov 7, 2026 · 9 revisions

Module 20: Diffusion Models and DDPM

Level: Advanced
Status: Planned — navigation and lesson specifications

Module purpose

This module is a self-contained learning unit within the larger Deep Learning curriculum. Its purpose is to build understanding from motivation and prerequisites through mathematical reasoning, implementation and critical evaluation.

Introduction and conceptual foundation

Diffusion models learn to reverse a gradual corruption process. A forward Markov chain adds noise to data; a neural denoiser learns to predict noise or another parameterization at different timesteps. Sampling iteratively transforms noise into a structured sample.

How the ideas develop

Study the forward transition and closed-form noisy sample, then derive the reverse denoising objective. Understand beta schedules, timestep embeddings and U-Net conditioning. Separate training-time noising from inference-time sampling.

What the reader should be able to explain

By the end of this module, a reader should be able to define its central objects, explain the motivation behind its main methods, interpret the governing equations, work through a small example, and identify assumptions and limitations. The goal is understanding the mechanism—not memorizing a list of terms.

Learning outcomes

  • Derive the forward marginal.
  • Explain noise prediction objective.
  • Distinguish training noising from reverse sampling.

Navigation

Topic-wise lessons

  1. Module-20-Lesson-01
  2. Module-20-Lesson-02
  3. Module-20-Lesson-03
  4. Module-20-Lesson-04
  5. Module-20-Lesson-05
  6. Module-20-Lesson-06
  7. Module-20-Lesson-07
  8. Module-20-Lesson-08
  9. Module-20-Lesson-09
  10. Module-20-Lesson-10
  11. Module-20-Lesson-11
  12. Module-20-Lesson-12
  13. Module-20-Lesson-13

How to complete this module

  1. Study the lessons in prerequisite order.
  2. Write a notation sheet and derive central equations.
  3. Solve at least one hand-worked example per major mechanism.
  4. Implement core operations where appropriate.
  5. Verify outputs and gradients.
  6. Complete conceptual and coding exercises.
  7. Record limitations and research extensions.

Completion status

  • Conceptual understanding
  • Mathematical derivations
  • Worked numerical examples
  • NumPy implementation (where applicable)
  • PyTorch implementation (where applicable)
  • Tests and numerical verification
  • Experiments and interpretation
  • Revision and self-assessment

Focused process reference

Technical chapter

1. Why this area matters

Diffusion models define a forward process that gradually corrupts data with noise and learn a reverse process that denoises. DDPM training can be reduced to predicting the noise added at a randomly selected timestep. Sampling iteratively applies learned reverse transitions.

2. Core mathematical formulation

Let $\alpha_t=1-\beta_t$ and $\bar\alpha_t=\prod_{s=1}^{t}\alpha_s$. The forward marginal is $$ q(x_t\mid x_0)= \mathcal N(\sqrt{\bar\alpha_t}x_0,(1-\bar\alpha_t)I), $$ or $$ x_t=\sqrt{\bar\alpha_t}x_0+ \sqrt{1-\bar\alpha_t}\epsilon,\quad \epsilon\sim\mathcal N(0,I). $$

Noise-prediction objective: $$ L_{simple}=\mathbb E_{x_0,t,\epsilon} \left[|\epsilon-\epsilon_\theta(x_t,t)|_2^2\right]. $$

3. Worked reasoning example

Given x0=0.8, alpha_bar=0.396 and epsilon=-0.5, x_t=sqrt(0.396)0.8+sqrt(0.604)(-0.5) approximately 0.115. If the model predicts -0.3, squared noise-prediction error is (-0.5+0.3)^2=0.04.

4. Conceptual flow

flowchart TD
  A[Clean sample x0] --> B[Forward noising q]
  B --> C[Noisy sample xt]
  C --> D[Noise predictor epsilon-theta]
  E[Timestep t] --> D
  D --> F[Compare predicted and true noise]
  F --> G[Update denoiser]
  H[Random Gaussian xT] --> I[Reverse sampling]
  I --> J[Generated sample x0]
Loading

5. Implementation and verification

Implement the forward marginal first and verify empirical mean/variance across timesteps. Then train a timestep-conditioned denoiser and implement reverse sampling with a fixed noise schedule.

6. Common failure modes and misconceptions

Training and sampling are different algorithms. The network receives noisy samples and timestep, not the original clean sample at inference. Schedule conventions and variance parameterizations differ between implementations.

7. Advanced and research directions

Study improved DDPM, DDIM, score matching, classifier-free guidance, latent diffusion, consistency models and accelerated samplers.

8. Suggested practical assignment

  1. Reproduce the smallest mathematical example by hand.
  2. Implement the central operation using NumPy.
  3. Implement the same operation using PyTorch.
  4. Compare outputs and gradients with numerical tolerances.
  5. Change one assumption or hyperparameter and document what changes.
  6. Record environment, random seed, data split, compute budget and limitations.

9. Completion criteria

  • Explain the motivation and assumptions without notes.
  • Derive the principal equations and define every symbol.
  • Complete at least one worked numerical example.
  • Trace tensor shapes through the computation.
  • Implement and test the central mechanism.
  • Explain at least two failure modes.
  • Read one primary paper and summarize its contribution and limitations.

Content status: This page now contains a technical chapter and a practical learning specification. The linked lesson pages provide focused subtopic treatment; experiments are not claimed complete until their result logs are added.

🎓 Deep Learning Hub

🏠 Home · 🗺️ Curriculum · 🧭 Learning paths

❓ Question bank · 📖 Glossary · 📚 References

Jump to module:

01 02 03 04 05 06 07 08 09 10 11 12

13 14 15 16 17 18 19 20 21 22 23 24

Part 1 · Mathematical foundations
Part 2 · Neural network fundamentals
Part 3 · Training deep networks
Part 4 · Core architectures
Part 5 · Representation and generative learning
Part 6 · Specialised, modern and responsible deep learning
Reference and meta

Clone this wiki locally