Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 3

ELBO and DDPM Training

Recommended resources

Hello! In our last lesson, we explored the reverse diffusion process through the lens of score matching and stochastic differential equations. We saw that the simple objective of training a network to predict the added noise has a strong theoretical foundation in learning the score function of the data distribution.

Today, we'll arrive at the very same training objective, but from a completely different theoretical starting point: variational inference. This lesson will fulfill our current learning outcome: to analyze the variational lower bound (ELBO) objective to understand the DDPM training process.

By the end of this lesson, you'll see how the DDPM authors derived their simple loss function by starting with the goal of maximizing the data log-likelihood, a classic approach in generative modeling. This dual justification from both score-matching and variational inference is a cornerstone of modern diffusion model theory.

1. The Goal: Maximizing Log-Likelihood

As with many generative models, our ultimate goal is to train a model that assigns high probability to samples from the true data distribution. We want to maximize the log-likelihood of our training data, .

However, calculating is intractable. It requires marginalizing over all possible latent paths from pure noise back to the image :

This integral is over a very high-dimensional space, making direct optimization impossible.


2. The Solution: The Evidence Lower Bound (ELBO)

When a likelihood is intractable, a standard approach in machine learning is to optimize a tractable lower bound on it instead. For this, we use the Evidence Lower Bound (ELBO), also known as the Variational Lower Bound (VLB). You may recall this concept from your work with Variational Autoencoders (VAEs).

The core idea is to introduce the forward process distribution, , and use Jensen's inequality to construct a lower bound on the log-likelihood.

Variational Lower Bound (ELBO) in Diffusion Models
This image shows the relationship for the negative log-likelihood (NLL). Maximizing the ELBO, L, is equivalent to minimizing this upper bound on the NLL. The expectation is taken over samples from the data distribution and the forward process.

The following short video provides a clear, animated derivation of how we arrive at the ELBO.

Diffusion Models: DDPM | Generative AI Animated

The video 'Diffusion Models: DDPM' by Deepia provides an excellent animated walkthrough of how the intractable log-likelihood is transformed into the ELBO using Jensen's inequality.

Watch the segment from 12:59 to 13:50. Focus on the core 'trick' of multiplying and dividing by the forward process distribution q and applying Jensen's inequality to move the logarithm inside the expectation.

By maximizing this lower bound, L_VLB, we push up the true log-likelihood log p_theta(x_0).


3. Deconstructing the ELBO

The raw form of the ELBO isn't very practical for training. The key insight in the DDPM paper is to rewrite it as a sum of more interpretable terms. After applying Bayes' theorem and exploiting the Markov property of the forward and reverse chains, the ELBO can be expressed as:

This can be re-written as a sum of KL divergences, which gives us a clearer picture of what the model is learning at each stage.

7. Diffusion Models - ELBO of DDPM

The document '7. Diffusion Models' from the JIEGroup GenAI course materials provides a very clear breakdown of the ELBO into three distinct components. This is one of the most common ways to analyze the objective.

Read the section '2.1 ELBO of DDPM'. Pay close attention to the second formulation (Equation 2) which breaks the ELBO into a Reconstruction Term, a Prior Matching Term, and a Denoising Matching Term. This view is more computationally stable and intuitive.

Let's summarize the three key components from that reading:

  1. Reconstruction Term (): . This is like the decoder in a VAE, measuring how well the model can reconstruct the original image from the first-step latent .
  2. Prior Matching Term (): . This measures how well the distribution of the final noisy latent (from the forward process) matches our chosen prior, which is typically a standard normal distribution. Since the forward process is designed to produce a standard normal distribution at time , this term is close to zero and has no trainable parameters, so it's often ignored during training.
  3. Denoising Matching Term ( for ): . This is the heart of the training process. For each step, it forces our learned reverse transition to match the true reverse transition .
Forward and Reverse Diffusion Processes in DDPMs
This diagram helps visualize the key distributions. Our goal is to make our learned reverse step `p` (green arrow) match the true posterior `q(x_{t-1}|x_t, x_0)` (pink arrow). Notice that the true posterior is conditioned on both the noisy image `x_t` and the original image `x_0`, which is why it's a tractable target during training.

4. Simplifying the Denoising Term

The Denoising Matching Term looks problematic because our model doesn't get to see the original image , while the target distribution does. This is not a problem; in fact, it's the core of the supervision. We are training the model to approximate this "cheating" posterior, but without cheating.

The true posterior is a Gaussian whose parameters (mean and variance ) can be calculated in closed form because we know everything about the forward process.

Our model's reverse transition, , is also parameterized as a Gaussian, with a learned mean and a variance .

The DDPM paper makes a crucial simplification: they fix the variance to be a non-learned constant (e.g., ). The KL divergence between two Gaussians with the same variance simplifies to the squared L2 distance between their means, scaled by the variance.

This transforms the problem: the neural network's only job is to predict the correct mean for the denoising step.


5. From Predicting the Mean to Predicting the Noise

We're almost there. The final step is a reparameterization that makes the objective even simpler. The true mean is a somewhat complex function of and . The key idea is to express both the true mean and the predicted mean in terms of the noise that was added at step .

The following video shows this final, elegant step.

Diffusion Models: DDPM | Generative AI Animated

The Deepia video continues its excellent explanation, showing how the mean-matching objective is transformed into a noise-prediction objective using the reparameterization trick.

Watch from 16:06 to 21:50. This is the punchline. Follow how they first define the true posterior mean (μ-tilde), then parameterize the model's mean (μ-theta) to predict noise (ε-theta). See how substituting these into the L2 loss beautifully cancels out terms, leaving a simple squared error between the true noise (ε) and the predicted noise (ε-theta).

As the video explains, by parameterizing our model to predict the noise , the loss term becomes:

This is exactly the simple Mean Squared Error objective we arrived at from the score-matching perspective! The authors of the DDPM paper found that ignoring the weighting factors and using this simple loss worked best in practice.

Test your understanding!

The full ELBO contains terms for all timesteps . In practice, the training loop for DDPMs doesn't compute a loss for every timestep for a given image. How is the full ELBO objective approximated during training?

Show answer

Instead of summing the loss over all timesteps for each training sample, the training algorithm approximates the expectation over . For each image in a batch, a single, random timestep is sampled uniformly from . The loss is then calculated only for that specific timestep. Over many training iterations and many samples, this stochastic approximation effectively optimizes the sum over all timesteps.


The Complete Training Algorithm

This derivation leads directly to the training algorithm outlined in the DDPM paper. The resource we looked at earlier provides a concise summary.

7. Diffusion Models - Training a DDPM

Let's revisit the '7. Diffusion Models' document to see how this simplified loss translates into a practical training loop.

Briefly review the section '2.3 Two equivalent ways of modeling' to see the final loss function for both predicting the image and predicting the noise. Then, read the short 'Training a Denoising Diffusion Probabilistic Model' section, which outlines the algorithm we just derived.

This simple loop is the foundation of DDPM training and is what you would have implemented in your prior experience. You now have a complete theoretical picture of its justification from a variational inference standpoint.


Conclusion

In this lesson, we dug into the theoretical underpinnings of the DDPM training objective from a variational inference perspective.

Key Takeaways:

  • The DDPM training objective is derived by maximizing the Evidence Lower Bound (ELBO) on the data log-likelihood.
  • The ELBO can be decomposed into terms representing reconstruction, prior matching, and denoising matching.
  • The crucial denoising matching term minimizes the KL divergence between the model's reverse transition and the true (but "cheating") posterior, .
  • By fixing the variance of the reverse process, this objective simplifies to minimizing the L2 distance between the true and predicted means of the denoising steps.
  • A final reparameterization trick elegantly transforms the mean-matching objective into a simple Mean Squared Error between the true noise and the predicted noise .
  • This result provides a powerful, alternative justification for the same simple loss function we derived from score-matching, solidifying its theoretical grounding.

In our next lesson, we will wrap up our foundational theory module by analyzing and comparing different formulations of this training objective. We'll discuss the practical differences between the simplified MSE loss and the full variational bound, and briefly introduce alternative prediction targets like predicting directly.