From KL divergence to the ELBO
During the treatment of entropy, we have met the concept of relative entropy or KL divergence that measures the “distance” between two distributions referenced on one of them. We will use KL divergence to obtain a suitable loss function that will be used in the optimization of this approximation via the network. Ultimately we are trying to minimize the KL divergence between the true posterior and the approximate posterior : Applying Bayes’ rule to replace the posterior : Separating the log of the product: Distributing the sum: Since does not depend on , it can be pulled out of the sum. And since is a valid distribution, : Rearranging: The bracketed quantity is the Evidence Lower Bound (ELBO). It is a function of both the encoder parameters (through ) and the decoder parameters (through the joint ).Why is it a lower bound?
The KL divergence is non-negative, with equality if and only if almost everywhere. Dropping the KL term from the equality above therefore turns it into an inequality: The KL is the gap between the bound and the true marginal log-likelihood. The closer the encoder approximates the true posterior, the tighter the bound.A practical form: reconstruction minus KL
The joint factors as , where is the (fixed, parameter-free) prior, typically . Substituting and expanding the log: This is the form actually computed in code:- The reconstruction term is the expected log-likelihood of the observed data under the decoder when is drawn from the encoder. Maximizing it pushes the decoder to put high probability on real data.
- The KL regularizer pulls the encoder’s posterior toward the prior . This prevents the encoder from collapsing into a different point distribution for every datapoint and is what makes the latent space dense and continuous.
Why is the ELBO useful for optimization?
Re-arrange the identity to put the ELBO on one side: Joint SGD over on the ELBO does two coupled jobs at once:- Encoder step (gradients on ). With fixed, is constant in , so maximizing over is exactly equivalent to minimizing the posterior KL. The encoder learns to track the true posterior, tightening the bound.
- Decoder step (gradients on ). Increasing over raises a lower bound on . It does not guarantee that the marginal itself rises. Because , a step that raises can lower when the gap shrinks by more than grows. The encoder’s quality controls the slack.

The aggregate posterior and posterior collapse
Average the KL regularizer over the data distribution and define the aggregate posterior . Then where is the mutual information under the joint . The identity follows by writing and taking the expectation over the joint. The first term penalizes the information the code carries about . The second penalizes the mismatch between the aggregate posterior and the prior, and it is the term that makes sampling from the prior a good way to generate. Minimizing the regularizer pushes both down. When the decoder is powerful enough to model without help from , the cheapest solution sets for every . Then and the latent code is ignored, which is posterior collapse. This same ELBO reappears as the DDPM training loss when the single latent is replaced by a Markov noise chain and the encoder is fixed in advance: see Training objective: from VAE ELBO to the DDPM loss on the diffusion introduction page for the bridge.Found an error on this page? Report an issue.

