1 of 36

Lecture 16:

Diffusion Models

Spring 2026

2 of 36

Taxonomy of Generative Models

Diffusion

Generative models

Explicit density

Implicit density

Tractable density

Approximate density

Variational

Stochastic

Direct

Stochastic

Generative Adversarial Networks (GAN)

Variational Autoencoders (VAE)

Boltzmann Machine

Fully Visible Belief Nets

PixelRNN/CNN

Today

Spring 2025

2

3 of 36

Score-based Generative Modeling

Spring 2025

3

4 of 36

Score-based Generative Modeling

  • Dataset consists of i.i.d. samples from unknown data distribution:

  • Define score of probability density as:
    • “the gradient of the log probability density of the data”

  • A score network sθ is trained to approximate the score:

Spring 2025

4

5 of 36

Score-based Generative Modeling

  • Score-based generative modeling in a nutshell:

Spring 2025

5

6 of 36

Score-based Generative Modeling

  • Score estimation
    • Directly train a score network sθ(x) to estimate score, eventually the data distribution.
    • The objective is to minimize

This part is constant�(independent of the score function sθ).

    • Thus, the overall objective is equivalent to

xRD

sθ(x) : RDRD

xsθ(x) ∈ RD×D

We don’t know this distribution. 😅

Spring 2025

6

7 of 36

Challenge 1: Limited Support

In the low data density regions, the score estimation becomes inaccurate.�→ Due to the lack of data samples, there is no sufficient evidence to estimate score functions accurately in these regions.

Spring 2025

7

8 of 36

Proposed Solution: Denoising Score Matching

  • Employs score matching to estimate the score of the perturbed data distribution qσ(| x).
    • The objective function is changed:�����
    • If the noise is small enough, .

A similar idea to the denoising autoencoders.

Spring 2025

8

9 of 36

Proposed Solution: Denoising Score Matching

  • qσ(| x) is a perturbed distribution of data point x with a pre-specified noise.�����
  • The score direction, moving back to x, is given by

Because qσ(| x) = 𝓝(; x, σ2)!

A density function that is added with a pre-specified Gaussian noise (𝝈)

qσ(| x) = 𝓝(; x, σ2).�That is, = x + σε, where ε~𝓝(0, σ2).

Spring 2025

9

10 of 36

Sampling with Langevin Dynamics

  • Langevin dynamics:
    • Def. A mathematical modeling of the dynamics of molecular systems, characterized by the use of simplified models while accounting for omitted degrees of freedom by the use of stochastic differential equations. -- Wikipedia
    • ���
  • Sampling with Langevin dynamics
    • Produce samples from a probability density using only the score function.�→ We train a score network, then obtain samples using Langevin dynamics!
    • Langevin method recursively computes the following:

Gradient of the force calculated from the particle interaction potentials

A zero-mean stationary Gaussian process

Score function sθ(x)

zt ~ 𝓝(0, I): to avoid local minimum

Spring 2025

10

11 of 36

Challenge 2: Incorrect Relative Density

When two modes of the data distribution are separated by low density regions, it is not able to correctly recover the relative weights of these two modes in reasonable time.�→ Langevin dynamics have incorrect relative density between the two modes.

Spring 2025

11

12 of 36

Proposed Solution: Multiple Noise Levels

  • Recall that perturbing data with random Gaussian noise makes the data distribution more amenable to score-based generative modeling.
    • The perturbed data will not be confined to a low dimensional manifold any more.
    • Being free from the low-dimensional manifold issue, the score estimation is well-defined anywhere now. 😊�
  • To resolve the Challenge 2, a sequence of perturbed distributions with multiple noise levels are used to converge to the true data distribution.
    • A single conditional score network is trained to estimate scores corresponding to all noise levels simultaneously.
    • A large Gaussian noise has the effect of filling low density regions in the original unperturbed data distribution.

Spring 2025

12

13 of 36

Annealed Langevin Dynamics

  • Distributions perturbed by multi-level Gaussian noises:
    • Initially use scores corresponding to large noise (σ3): providing support for the entire regions.
    • Gradually anneal down the noise level to σ2 and σ1.
    • Smoothly transfer the benefits of large noise levels to low noise levels where the perturbed data are almost indistinguishable from the original ones.

Spring 2025

13

14 of 36

Noise Conditional Score Networks: Training

  • Training NCSN via denoising score matching
    • Choose noise distribution to be:

    • Denoising score matching objective is to minimize:���
    • Thus, the loss function is given by

    • For all noise level :

Spring 2025

14

15 of 36

Noise Conditional Score Networks: Inference

  • NCSN inference via annealed Langevin dynamics
    • After NCSN is trained, sampling with annealed Langevin dynamics.
    • Start by initializing the samples from some fixed prior distribution (e.g., Uniform noise).
    • Continually run Langevin dynamics to sample with reducing step size.

Spring 2025

15

16 of 36

Noise Conditional Score Networks: Examples

  • NCSN inference via annealed Langevin dynamics

Spring 2025

16

17 of 36

  • 6/4, 6/8 Class
  • 6/11 Final review
  • 6/18 Final Exam

Spring 2025

17

18 of 36

Denoising Diffusion Probabilistic Models (DDPM)

Spring 2025

18

19 of 36

Forward Diffusion Process

Spring 2025

19

20 of 36

Forward Diffusion Process

Reverse Diffusion Process

Spring 2025

20

21 of 36

Introduction

  • A diffusion model is a parameterized Markov chain trained using variational inference to produce samples matching the data after finite time.

Reverse process

Forward process

Spring 2025

21

22 of 36

Forward (Diffusion) Process

  • Sample a data point from a real data distribution:
  • Add small Gaussian noise to the sample for T steps, producing a sequence of noisy samples .���
    • βt indicates the degree of added noise. (With βt = 0, xt = xt-1; with βt → 1, xt gets independent of xt-1.)

Spring 2025

22

23 of 36

Forward (Diffusion) Process

Reparameterization trick: let αt = 1 - βt, .

    • From ,������

.�

When we merge two Gaussians with different variance, 𝓝(0, σ12I) and 𝓝(0, σ22I), the new distribution is 𝓝(0, (σ12+σ22)I).�

Spring 2025

23

24 of 36

Forward (Diffusion) Process

  • Reparameterization trick: let αt = 1 - βt, .
    • From ,������
    • Thus, .�
  • Through this reparameterization trick, we can noise the data by arbitrary time step in a closed form.
    • Here, is called diffusion kernel.
    • t can be any arbitrary time step, 1, …, T.

When we merge two Gaussians with different variance, 𝓝(0, σ12I) and 𝓝(0, σ22I), the new distribution is 𝓝(0, (σ12+σ22)I).�

Spring 2025

24

25 of 36

Reverse (Denoising) Process

  • If we can reverse the forward process and sample from q(xt-1 | xt), we will be able to recreate the true sample from a Gaussian noise input, xT ~ 𝓝(0, I).
    • This is counter-intuitive, contradicting to the second law of thermodynamics.
    • However, we can approximate q(xt-1 | xt) by a normal distribution if βt is small enough!�
  • Let’s model pθ to approximate q(xt-1 | xt):�
    • With this,

In short, our goal is to learn this conditional distribution.

Chain rule hold: iid, Markovian assumption

Spring 2025

25

26 of 36

Reverse (Denoising) Process

  • Our goal is to learn pθ by maximizing likelihood of real images x0.
    • Equivalently, we minimize the negative log-likelihood, -log pθ(x0).
    • We apply variational lower bound (VLB) of this:

The blue term enforces pq.

Now, in order to minimize our desired negative log-likelihood -log pθ(x0), we minimize this variational bound term.

Spring 2025

26

27 of 36

Reverse (Denoising) Process

Reverse conditional probability becomes tractable when conditioned on x0 ,(still mathematically equivalent due to Markovian assumption) and using Bayes’ rule, can be expressed as Gaussian distribution.

Spring 2025

27

28 of 36

Reverse (Denoising) Process

  • To sum up, we would like to minimize

Prior matching term.

LT is constant, since q has no learnable parameters and xT is the input.

Reconstruction term.

This is modeled with a separate discrete decoder derived from

Consistency term.

KLD compares two Gaussian distributions, so we have a closed form solution.

For this, we will first find the single-Gaussian expression of the true distribution q(xt-1 | xt, x0), and will model pθ(xt-1 | xt) to approximate it.

Spring 2025

28

29 of 36

Reverse (Denoising) Process

  • Let’s represent the consistency term as a single Gaussian:

From the reparameterization trick in page page 21:

Spring 2025

29

30 of 36

Reverse (Denoising) Process

  • Let’s represent the consistency term as a single Gaussian (cont’d):

From the diffusion kernel in page 21:

Exercise!

Middle school math:

Find the μ and β to make this a perfect square.

Spring 2025

30

31 of 36

Reverse (Denoising) Process

  • Coming back to our objective function LVLB,
  • Now, we model , so that it approximates the true distribution q(xt-1 | xt, x0) by

For this part, we got

Spring 2025

31

32 of 36

Reverse (Denoising) Process

Constant terms ignored.

Reparametrize the Gaussian noise term to make it predict ε from the input xt.

This is often very large for small t and very small for large t.�Empirically, simply removing this improves the sample quality.

Spring 2025

32

33 of 36

DDPM: Model Architecture

  • The U-Net architecture with ResNet blocks and self-attention layers are adopted.
  • Time representations (sinusoidal positional embeddings) are fed to the residual blocks.

Spring 2025

33

34 of 36

DDPM: Summary

Spring 2025

34

35 of 36

DDPM: Examples

Spring 2025

35

36 of 36

DDPM: Limitations

  • Slow sampling due to the iterative T steps.
    • Takes around 20 hours to sample 50k images of size 32 × 32.
    • cf. A GAN model takes less than 1 minute for the same task.
  • The training process spends too much capacity and time on modeling unimportant details.

Spring 2025

36