Recommended resources
The freely available resources this lesson will direct you to.
In our previous lesson, we established the fundamental mechanics of Denoising Diffusion Probabilistic Models (DDPMs). We explored the fixed forward process that systematically corrupts an image with Gaussian noise, and the learned reverse process where a neural network, , is trained to predict and remove that noise step-by-step. You now understand what the model is trained to do.
Today, we will connect this intuitive goal of "predicting the noise" to its rigorous mathematical foundation. We will derive the training objective for a DDPM, starting from the principled objective for any generative model: maximizing the log-likelihood of the data. You will see how, through a series of elegant mathematical steps, this complex probabilistic objective is transformed into a simple, practical Mean Squared Error loss. This lesson bridges the gap between high-level theory and the code you would actually write to train such a model.
From Maximum Likelihood to a Sum of KL Divergences
The ultimate goal of training a generative model is to make it produce samples that are indistinguishable from the real data distribution . The standard way to achieve this is by maximizing the log-likelihood of the training data under the model. However, for a DDPM, the likelihood of a given image involves integrating over all possible noise-addition paths, making it intractable:
where represents the entire chain.
This is a familiar problem, similar to what we encountered with Variational Autoencoders (VAEs). The solution is also similar: we optimize a lower bound on the log-likelihood, known as the Evidence Lower Bound (ELBO). By applying Jensen's inequality, we can derive this bound, often called the Variational Lower Bound .
The full derivation is quite involved, but it relies on rewriting the bound and leveraging the Markov property of both the forward process () and our learned reverse process (). This allows us to decompose the total ELBO into a sum of terms, each corresponding to a single timestep in the diffusion process.
The result of this decomposition is:
Let's interpret these terms:
- : This term measures the KL divergence between the distribution of the fully noised image and a standard Gaussian prior . Since the forward process is designed to converge to this prior, and there are no trainable parameters () in this term, we can ignore it during optimization.
- : This is a reconstruction term, representing the log-likelihood of the final denoising step that produces the clean image from .
- : This is the heart of the training objective. For each timestep from down to 2, it's a KL divergence that measures the "distance" between our learned reverse step and the true, but conditional, reverse posterior . Our goal is to train the network to minimize this divergence at every step.
The following video provides an excellent visual walkthrough of this derivation, from the initial log-likelihood objective to this decomposed sum of KL divergences.
Diffusion Models: DDPM | Generative AI Animated
The video "Diffusion Models: DDPM | Generative AI Animated" by Deepia provides a clear, step-by-step derivation.
Please watch the segments covering the negative log-likelihood objective, the application of Jensen's inequality to get the ELBO, and its final simplification into a sum of KL divergences. Pay close attention to the intuitive explanation of each term in the final ELBO expression.
Simplifying the KL Divergence to a Difference of Means
Our objective is now to minimize .
As we established in the last lesson, both of these distributions are Gaussian:
- The true posterior is .
- Our learned approximation is .
The DDPM paper makes a key simplifying choice: the variance of the learned reverse step is fixed and not learned. It's set to a constant, , typically or . This means our neural network only needs to learn the mean .
Now for a crucial question from your probability studies.
Socratic Question: The KL divergence between two multivariate Gaussian distributions and has a general, rather complex form. What happens to this formula if we set their covariance matrices to be equal, ? How does the expression for simplify?
...
If the covariance matrices are identical, the terms involving the determinant and trace of the matrices cancel out, and the KL divergence reduces to a simple (scaled) L2 norm, or squared Euclidean distance, between their means:
Applying this to our loss term , we see that minimizing the KL divergence is equivalent to minimizing the squared distance between the predicted mean and the true posterior mean .
So, our objective simplifies to training the network to predict the correct mean for the denoising step:
The Final Step: The Noise Prediction Objective
We've made great progress, boiling the problem down to matching the means of two Gaussian distributions. But as we discussed last lesson, directly predicting the mean is not the most effective strategy. The final insight is to re-parameterize this objective in terms of noise.
Recall the forward process "shortcut" equation: .
We can invert this to express in terms of and the noise :
The full expression for the true posterior mean is a weighted sum of and . If we substitute the equation for above into the formula for , a remarkable simplification occurs. After some algebra, can be rewritten as a function of and the true noise .
The key idea is to parameterize our network's predicted mean, , using the exact same functional form, but with the network's predicted noise, :
Now, when we compute the difference , the complex terms involving cancel each other out perfectly. The entire expression simplifies to a scaled squared difference between the true noise and the predicted noise.
The authors of the DDPM paper found that ignoring the complex scaling factors in front of this term and simply minimizing the direct Mean Squared Error (MSE) between the noises worked best in practice. This leads to the final, simplified training objective:
This beautifully simple loss function underpins the training of modern diffusion models.
The following resources walk through this final crucial step, showing how the reparameterization leads to the noise prediction objective.
Diffusion Models: DDPM | Generative AI Animated
Let's finish the Deepia video.
Watch the section that explains simplifying the KL divergence to a distance between means. Then, watch the most important part, which shows the reparameterization and final noise loss. The flowchart at the end of this segment provides a fantastic summary of the entire derivation.
Denoising Diffusion Probabilistic Models (DDPM)
This resource from labml.ai provides a concise, code-oriented summary of the loss derivation.
Read the section titled "Loss", which sets up the ELBO. Then, focus on the subsection re-parameterizing to predict noise and the final simplified loss. This directly shows the math leading to the L_simple objective.
This simplified objective translates into a very direct training algorithm, illustrated by the diagram below.

Conclusion
In this lesson, we have completed the theoretical journey of DDPMs, connecting the high-level goal of generative modeling to a simple and effective training objective.
Key Takeaways:
- From Likelihood to ELBO: Training starts with the goal of maximizing data log-likelihood, which is made tractable by optimizing its Evidence Lower Bound (ELBO).
- ELBO as a Sum of KL Terms: The ELBO for a DDPM can be decomposed into a sum of KL divergences, where each term measures how well the learned reverse step matches the true posterior at a given timestep.
- KL Simplifies to MSE of Means: By fixing the variance of the reverse process, the KL divergence objective simplifies to minimizing the Mean Squared Error between the predicted mean () and the true posterior mean ().
- Reparameterization Yields Noise Prediction: The final and most crucial step is to re-parameterize both means in terms of noise ( and ). This elegantly reduces the objective to a simple MSE loss between the true and predicted noise, .
This simplification is not just a mathematical convenience; it provides a much more stable and effective learning target for the neural network, which is a major reason for the success of DDPMs.
Preview of the Next Module:
Having covered the foundational principles of modern generative models—VAEs, GANs, and now DDPMs—we are fully equipped to venture into the domain of neural rendering. In our next module, we will explore Neural Radiance Fields (NeRF), a groundbreaking technique that uses a simple MLP not just to generate 2D images, but to represent and render complex 3D scenes from any viewpoint.