In a diffusion model:
- The encoder maps the data example through a series of intermediate variables , adding noise.
- The decoder learns a series of probabilistic mappings back from latent variable to , from to , and so on, until we reach the data .
The joint distribution of the observed variable and the latent variables is:
The likelihood of the observed data is found by marginalizing over the latent variables:
To train the model, we maximize the log-likelihood of the training data with respect to parameters :
We can’t maximize this directly because the marginalization in the equation above is intractable. Hence, we use Jensen’s inequality to define a lower bound on the likelihood and optimize the parameters with respect to this bound exactly as we did for the VAE.
Evidence lower bound (ELBO)
To derive the lower bound, we multiply and divide the log-likelihood by the encoder distribution and apply Jensen’s Inequality:
This gives us the evidence lower bound (ELBO):
In the VAE, the encoder approximates the posterior distribution over the latent variables to make the bound tight, and the decoder maximizes this bound. In a diffusion model, the decoder does all the work because the encoder has no parameters. It makes the bound tighter by (i) changing its parameters so that the static encoder does approximate the posterior and (ii) optimizing its own parameters with respect to the bound.

Simplifying ELBO
Let’s manipulate the log term from ELBO into the final form that we will optimize. First, we substitute the joint distributions for and :
Then we expand the denominator of the second term:
where:
- The first equality follows because all of the information about variable is encompassed in , so the extra conditioning on the data is irrelevant.
- The second equality is a straightforward application of Bayes’ rule.
Substituting in this result gives:
where all but two of the terms in the product of the ratios cancel out between lines 2 and 3, leaving only and . The last term in the third line is approximately since the result of the forward process is a standard normal distribution, and so is equal to the prior .
Hence, the simplified ELBO is:
where we have marginalized over the irrelevant variables in between lines 2 and 3 and used the definition of KL divergence.
Analyzing ELBO
The first term in the ELBO was defined previously in the decoder:
and is equivalent to the reconstruction term in the VAE. The ELBO will be larger if the model prediction matches the observed data. Like the VAE, we will approximate the expectation over the log of this quantity using a Monte Carlo estimate, in which we estimate the expectation with a sample from .
The KL divergence in the ELBO measures the distance between and , which were also defined previously in the encoder and decoder:
The KL divergence between two normal distributions has a closed-form expression. Moreover, many of the terms in this expression do not depend on , and the expression simplifies to the squared difference between the means plus a constant :
Diffusion loss function
To fit the model, we maximize the ELBO with respect to the parameters . We recast this as a minimization by multiplying with minus one and approximating the expectations with samples to give the loss function:
where is the -th data point, and is the associated latent variable at diffusion step .
Although this loss function can be used, diffusion models have been found to work better with a reparameterized version.
Training procedure
This loss function can be used to train a network for each diffusion time step. It minimizes the difference between the estimate of the hidden variable at the previous time step and the most likely value that it took given the ground truth de-noised data .
The figures below show the fitted reverse process for a simple 1D example. This model was trained by:
- Taking a large dataset of examples from the original density
- Using the diffusion kernel to predict many corresponding values for the latent variable at each time
- Training the models to minimize the loss function above.

