Recommended resources
The freely available resources this lesson will direct you to.
Introduction
In our journey through generative models, we have explored two distinct philosophies. First, we examined Variational Autoencoders (VAEs), which learn an explicit probabilistic mapping from a structured latent space to the data space. Then, we delved into Generative Adversarial Networks (GANs), which reframe generation as a game-theoretic contest between a generator and a discriminator. Today, we turn our attention to the latest and arguably most powerful class of generative models: Diffusion Models.
This lesson will introduce the core principles of diffusion models. Instead of learning a direct, one-shot transformation from noise to data like GANs, or through a compact latent code like VAEs, diffusion models operate via a process of iterative refinement. You will learn about the two fundamental components of this framework: a fixed forward process that systematically corrupts data with noise, and a learned reverse process that meticulously reverses this corruption to generate new data. We will unpack the theoretical underpinnings of this method, which are rooted in thermodynamics and stochastic processes, and derive the elegant and surprisingly simple training objective that has enabled these models to achieve state-of-the-art results.
The Core Idea: Destroy and Reconstruct
The concept behind diffusion models is both intuitive and deeply rooted in physics. Imagine taking a clear photograph and gradually adding small amounts of noise over many steps until the original image is completely indistinguishable from random static. This is the forward (diffusion) process. Now, what if we could learn to precisely reverse each of these small steps? If we could, we could start with a new image of pure random static and, by applying our learned "denoising" function repeatedly, reconstruct a clear, novel photograph. This is the reverse (denoising) process.
The following video from 3Blue1Brown's guest channel provides a superb high-level visualization of this idea, showing how pure noise is iteratively transformed into a coherent video.
But how do AI images and videos actually work? | Guest video by Welch Labs
This video by Welch Labs provides an excellent intuitive and visual introduction to the core concept of diffusion models.
Watch the first segment from "If we dig into our WAN model's source code" to see the iterative generation process in action. Then, watch the conceptual explanation of the process from "The core idea behind diffusion models".
This destroy-and-reconstruct paradigm is formalized using a pair of Markov chains.

The Forward Diffusion Process
The forward process, denoted by , is a fixed procedure that does not involve any learning. It's defined as a Markov chain that gradually adds Gaussian noise to an image over discrete timesteps, according to a predefined variance schedule .
At each step , the new, noisier image is sampled from a Gaussian distribution whose mean is a scaled version of the previous image and whose variance is determined by .
A crucial property of this process is that we can sample at any arbitrary timestep directly from the original image , without having to iterate through all the intermediate steps. This is possible due to the properties of Gaussian distributions and is analogous to the reparameterization trick you saw with VAEs. This makes the training process highly efficient.
The following reading from Lilian Weng's highly-regarded blog post provides the mathematical derivation for this closed-form solution.
This article is a comprehensive technical introduction to diffusion models. We will use it to understand the mathematical formulation of the forward and reverse processes.
Please read the section "Forward diffusion process", which introduces the core formula. Then, focus on the derivation in the paragraph that begins "A nice property". This will show you how the direct sampling equation is derived: \mathbf{x}_t = \sqrt{\bar{\alpha}_t}\mathbf{x}_0 + \sqrt{1 - \bar{\alpha}_t}\boldsymbol{\epsilon} where \alpha_t = 1 - \beta_t, \bar{\alpha}_t = \prod_{i=1}^t \alpha_i, and \boldsymbol{\epsilon} \sim \mathcal{N}(\mathbf{0}, \mathbf{I}). Pay close attention to how the sum of two Gaussians is used recursively to arrive at this result.
As approaches , the term approaches zero, meaning the final state is almost entirely determined by the noise term , effectively becoming a sample from a standard isotropic Gaussian distribution.
The Reverse Process and the Training Objective
The generative part of the model is the reverse process, , which must learn to undo the noising steps. The goal is to learn the distribution to approximate the true but intractable reverse distribution . We use a neural network, parameterized by , for this task.
To train this network, we can frame the problem, much like with VAEs, as maximizing the log-likelihood of the data, which we can optimize using the variational lower bound (ELBO). The derivation is mathematically involved, but the conceptual path is what matters for your foundational understanding.
The video from the "Outlier" channel provides a clear, step-by-step walkthrough of this derivation, starting from the negative log-likelihood and arriving at the final, simplified objective function. Given your background, this detailed derivation will provide the theoretical rigor you appreciate.
Diffusion Models | Paper Explanation | Math Explained
This video offers a deep dive into the mathematics behind diffusion models, focusing on deriving the objective function from first principles.
Please watch the section from "so now let's move to the reverse diffusion process". This is the core mathematical part of the lesson. Follow the derivation closely: Starting Point: The derivation begins with the negative log-likelihood and introduces the variational lower bound (VLB or ELBO). Reformulation: Witness the series of reformulations using Bayes' rule and properties of logarithms to make the VLB tractable. The key step, as the video notes, is conditioning the reverse process q on \mathbf{x}_0, which makes it computable. Simplification: The objective is broken down into a sum of KL-divergence terms. The crucial insight is how this complex objective simplifies. Predicting the Noise: The derivation shows that predicting the mean of the less-noisy image, \tilde{\boldsymbol{\mu}}_t, is equivalent to predicting the noise \boldsymbol{\epsilon} that was added at that step. Final Objective: The process culminates in the simplified Mean Squared Error (MSE) objective: the model is trained to minimize the difference between the actual noise added and the noise predicted by the network.
As the video masterfully explains, after a long chain of theoretical derivations, we arrive at a remarkably simple and elegant training objective. Instead of predicting the denoised image directly, the model is trained to predict the noise that was added to the original image to create the noisy image .
The simplified loss function is:
Here, is the noisy image created using the closed-form forward process: . This means the training algorithm is as follows:
- Pick a random image from your dataset, .
- Pick a random timestep, .
- Generate a random noise vector, .
- Create the noisy image using the formula above.
- Feed and to the neural network .
- Calculate the MSE between the network's output and the original noise .
- Update the network's weights using gradient descent.
This objective, proposed in the Denoising Diffusion Probabilistic Models (DDPM) paper by Ho et al. (2020), was a landmark result that made diffusion models practical and powerful.
Architecture and Sampling
The final pieces of the puzzle are the model architecture and the procedure for generating new images (sampling).
Architecture
The neural network used to predict the noise, , needs to take a noisy image and a timestep as input and output a tensor of the same shape as the input image (the predicted noise). A U-Net architecture is a natural fit for this task. U-Nets were originally developed for biomedical image segmentation and excel at image-to-image tasks. They use a series of downsampling blocks to capture context and a series of upsampling blocks with skip connections to reconstruct the image while preserving high-resolution details. The timestep is typically encoded using sinusoidal positional embeddings (the same technique from the Transformer architecture) and fed into each residual block of the U-Net.

Sampling
To generate a new image, we reverse the diffusion process:
- Start with a tensor of pure Gaussian noise, .
- Iterate backwards from down to .
- In each step, feed the current noisy image and the timestep to the trained network to get a prediction of the noise.
- Use this predicted noise to calculate the denoised image . An interesting detail of the original DDPM algorithm is that a small amount of stochastic noise is added back in this step, which was found to improve sample quality.
- After steps, you are left with , a novel, clean image.
The Outlier video concludes with a concise summary of these two algorithms.
Diffusion Models | Paper Explanation | Math Explained
This final segment of the video summarizes the complete training and sampling procedures.
Please watch from "so now let's take a look at the algorithms" to see the two algorithms laid out clearly. This will consolidate your understanding of how the model is trained and how it is used to generate new data.
Conclusion
In this lesson, we have explored the fundamental principles of diffusion models, a powerful and modern approach to generative modeling. You have learned how these models elegantly combine a fixed forward process of noise injection with a learned reverse process of iterative denoising.
Here are the key theoretical takeaways:
- Core Concept: Diffusion models generate data by learning to reverse a multi-step process that gradually destroys a data sample with Gaussian noise.
- Forward Process: A fixed, non-learned Markov chain adds noise according to a predefined variance schedule. A key property is the ability to sample a noisy image at any timestep in a single, closed-form step.
- Reverse Process: A neural network (typically a U-Net) is trained to approximate the reverse (denoising) steps.
- Training Objective: Through a derivation based on the variational lower bound, the complex problem of learning the reverse distribution is simplified to an intuitive objective: training the network to predict the noise that was added at each step, using a simple Mean Squared Error loss.
- Sampling: Generation starts with pure noise and iteratively applies the trained denoising network to produce a clean sample.
This completes our survey of the three major families of generative models: VAEs, GANs, and now Diffusion Models. Each represents a unique theoretical perspective on the problem of data generation.
In the next module, we will pivot from generative modeling to a new domain of artificial intelligence: Reinforcement Learning (RL). Our first lesson will introduce the foundational concepts of RL, defining the interactive loop between an agent and its environment, and the core components of states, actions, and rewards that govern the agent's learning process.