Variational Autoencoders
Volume II, Chapter 9 — Part I. VAE objective from the ELBO, reparameterization trick proof, Gaussian KL closed form, posterior collapse, β-VAE, and connection to latent diffusion models.
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- The Generative Model
- The ELBO for VAEs
- The Encoder and Amortized Inference
- Closed-Form KL Divergence
- The Reparameterization Trick
- The Complete VAE Objective
- Posterior Collapse
- β-VAE and Disentanglement
- VQ-VAE and Discrete Latents
- Connection to Diffusion Models
- Worked Examples
- Connection to the Broader Curriculum
- Common Pitfalls and Misconceptions
- Research Perspective
- Summary of Takeaways
- Exercises
Learning Objectives
After reading this chapter, you should be able to:
- Specify the VAE generative model and explain why is intractable.
- Derive the VAE objective as the ELBO from Variational Inference.
- Prove the closed-form KL between diagonal Gaussian and standard normal prior.
- Apply the reparameterization trick and explain why it enables Backpropagation through stochastic nodes.
- Analyze posterior collapse and mitigation strategies.
- State the -VAE objective and VQ-VAE discrete latent formulation.
Prerequisites
- Variational Inference — ELBO, mean-field, reparameterization
- Multivariate Gaussian — KL between Gaussians
- Backpropagation — gradient computation
Notation
- — Observed data and latent variables
- — Encoder (approximate posterior)
- — Decoder (likelihood)
- — Prior (typically )
- — Variational lower bound
Core Intuition
A Variational Autoencoder (VAE) learns a generative model: sample latent code , decode to data . It simultaneously learns an encoder that maps to a distribution over — amortized approximate inference.
Training maximizes a lower bound on (the ELBO) because the true marginal is intractable. The VAE unites deep learning with Bayesian inference: neural networks parameterize both (decoder) and (encoder).
VAEs underpin latent diffusion models (Stable Diffusion operates in a VAE latent space) and remain foundational for representation learning.
Series context. Chapter 9 (Generative Models), Volume II.
VAE Latent Space
The Generative Model
Definition 1 (VAE Generative Process).
Definition 2 (Marginal Likelihood).
Proposition 1. For neural network decoder , integral (2) is intractable — no closed form for or its gradient.
The ELBO for VAEs
From Variational Inference, introduce :
Theorem 1 (VAE ELBO).
Identity (ELBO Gap).
Maximizing (3) minimizes the gap — tightest when .
The Encoder and Amortized Inference
Definition 3 (Amortized Encoder).
where are neural network outputs.
Definition 4 (Amortization). One network serves all data points — vs. per-example variational optimization in classical VI.
Closed-Form KL Divergence
Theorem 2 (Gaussian KL). For , :
Proof. Apply multivariate Gaussian KL formula with , , :
Since : (6) follows.
The Reparameterization Trick
Problem: — distribution depends on .
Theorem 3 (Reparameterization).
Proof. See Variational Inference, Theorem 5.
Monte Carlo estimate with sample enables Backpropagation.
The Complete VAE Objective
Definition 5 (VAE Loss).
Decoder likelihoods:
- Bernoulli (images): reconstruction = binary cross-entropy
- Gaussian: reconstruction = MSE (equivalent to up to constants)
Posterior Collapse
Definition 6 (Posterior Collapse). Encoder learns — latents carry no information about .
Cause: Powerful autoregressive decoder models without ; KL term pushes .
Mitigations:
- KL annealing: ramp from 0 to 1
- Free bits:
- -VAE with
β-VAE and Disentanglement
Definition 7 (-VAE).
- : standard ELBO
- : stronger regularization, more disentangled latents
- : better reconstruction, risk of collapse
VQ-VAE and Discrete Latents
Definition 8 (Vector Quantization). Codebook . Encoder output quantized:
Loss:
Foundation of latent diffusion (Forward Diffusion in VAE latent space).
Connection to Diffusion Models
Stable Diffusion: VQ-VAE encoder maps images to latent ; diffusion process operates on rather than pixels — reducing dimensionality and compute. See Reverse Process.
Worked Examples
Example 1: KL for ,
— encoder matches prior.
Example 2: Single-Dimensional
, : .
Connection to the Broader Curriculum
- ELBO derivation — Variational Inference
- Gradients — Backpropagation
- Diffusion — Forward Diffusion
- Low-rank latents — SVD
Common Pitfalls and Misconceptions
Pitfall 1: Confusing ELBO with true log-likelihood.
Pitfall 2: Ignoring posterior collapse with powerful decoders.
Pitfall 3: Using Monte Carlo without noting variance.
Pitfall 4: invalidates ELBO as lower bound (still useful).
Research Perspective
VAE (Kingma & Welling, 2014; Rezende et al., 2014). -VAE (Higgins et al., 2017). VQ-VAE (van den Oord et al., 2017). Modern: hierarchical VAEs, NVAE, connection to diffusion and flow matching.
Summary of Takeaways
- Encoder — Amortized posterior
- Decoder — Generative model
- KL term (6) — Regularize toward prior
- Reparameterization (8) — Differentiable sampling
- ELBO gap (4) — Approximation quality
Next: Forward Diffusion
Exercises
Exercise 1. Derive (6) from scratch.
Exercise 2. Prove (9) for scalar .
Exercise 3. Explain posterior collapse with a autoregressive decoder.
Exercise 4. How does -VAE affect the ELBO as a valid bound?
Exercise 5. Derive VQ-VAE gradient through straight-through estimator.
Exercise 6. Compare VAE latent dimension to LoRA rank.
Exercise 7. When is Monte Carlo sufficient?
Exercise 8. Connect VAE to Bayesian Linear Regression with linear decoder.