Very Deep Hierarchical VAEs
Latent hierarchies, NVAE and why very deep VAEs rival autoregressive models.
A VAE with one layer of latents blurs. Stack dozens of latent layers, let each be generated from the ones above it, and the same objective produces sharp faces at and likelihoods better than PixelCNN's. A short argument shows why depth matters, a handful of stability tricks show what it costs, and diffusion models turn out to be the same idea with the encoder frozen.
What you’ll learn
- Write the generative and inference models of a hierarchical VAE, and prove that its ELBO splits into one KL term per layer.
- Explain top-down inference, the residual parameterization of NVAE and the stabilizers deep hierarchies need: spectral regularization, gradient skipping, KL warm-up, KL balancing and free bits.
- Prove that a VAE with one latent layer per data dimension can represent any autoregressive model, and assess what VDVAE's results show and do not show.
- Map a diffusion model onto a hierarchical VAE with a fixed encoder, and state what the continuous-time limit implies for the noise schedule.
Hierarchies of latents
The log-ratio of the two factorizations is a sum over layers:
Take the expectation under . Term depends only on , so the groups below it integrate out, and sampling first and then turns the inner expectation into a KL:
Summing gives the total KL of the ELBO, , layer by layer: the chain rule for KL divergence. Had been factored bottom-up (first from , then from , and so on), the orders would disagree and no such layerwise Gaussian KLs would exist; the bound would have to be estimated entirely by sampling.
The top-down order has a second benefit: the posterior over really does depend on the groups above it, because they define its prior. Top-down inference lets reuse the generative model's own computation. A single deterministic bottom-up pass extracts features of at every resolution; then a top-down pass samples the groups in generative order, and at each layer the encoder combines the prior's state with the bottom-up features of the same resolution. The Ladder VAE (Sønderby et al., 2016) combined them by precision weighting, the product of a Gaussian "likelihood" from the bottom-up pass, , with the prior :
The ResNet VAE of Kingma et al. (2016) used the same bidirectional scheme with inverse autoregressive flows on each layer's posterior, and every deep hierarchical VAE since has kept it.
A hierarchical VAE for color images has four latent groups at each of three resolutions, , and , each group with 20 channels. How many latent dimensions does it have in total?
Show the answer
107520 dimensions
, almost nine times the numbers in the image. Deep hierarchical VAEs are not bottlenecks: compression comes from the KL terms, which charge for every nat a layer carries, so most dimensions end up close to their priors.
Making depth trainable: NVAE
Deep hierarchies were long unstable: KL terms blew up, groups collapsed onto their priors, and gradients spiked. NVAE (Vahdat & Kautz, 2020) put together a recipe that made dozens of groups train reliably on natural images, and was the first VAE reported to work well at . Its central change is to parameterize each posterior relative to its prior:
The rest of the recipe targets the instabilities one at a time:
- Spectral regularization, a penalty on the largest singular value of every layer (estimated with one power-iteration step per update), limits how sharply the encoder's outputs, and so the KL terms, can change with the input. Vahdat & Kautz found it key to stable training.
- Batch normalization with care: its running statistics at evaluation time differ from the batch statistics used in training, and deep stacks amplify the mismatch, so NVAE adjusts the momentum and regularizes the norm of the BN scale parameters.
- Cheap, wide generative cells: depthwise-separable convolutions with an expansion factor of 6, Swish activations and squeeze-and-excitation give large receptive fields at low cost in the top-down path.
- KL warm-up and balancing: the KL weight ramps from 0 to 1 over the first 30% of training, and during warm-up each group's KL is reweighted in proportion to its size times its average KL, so that no group is starved into collapse.
With these, NVAE reached 2.91 bits per dimension on CIFAR-10, the best reported among non-autoregressive likelihood models at the time, against 2.98 before it.
Why depth: VAEs that contain autoregressive models
Under the latents copy the data, , so the reconstruction term is .
Each posterior is a point mass, so at the sample, and by the layerwise decomposition each KL is minus the prior's log-probability of the copied value:
Hence . The bound is tight because the point-mass posterior is the true posterior of this model.
The construction is degenerate on purpose: the prior does all the work, one pixel per layer, and the decoder only copies. Its lesson is that an autoregressive model is a VAE with a very particular, very long hierarchy. Child's argument is that images should admit far shorter hierarchies (layout, then parts, then texture, with many dimensions generated in parallel at each layer), which a VAE can learn and a pixel-by-pixel model cannot exploit. The theorem guarantees expressivity, not that gradient descent will find a good hierarchy.
VDVAE (Child, 2021) tested this with hierarchies of up to 78 stochastic layers, at resolutions from up to the image's, built from bottom-up and top-down residual blocks. Two stabilizers mattered. Gradient skipping discards any update whose gradient norm exceeds a threshold set so that fewer than 0.01% of updates are skipped; without it, rare spikes with norms as large as about derailed training. And the last convolution of each residual block is initialized scaled by for network depth , so the residual stream does not grow with depth. Child reports that with this architecture he needed neither free bits nor KL warm-up.
| Bits per dimension (lower is better) | CIFAR-10 | ImageNet | ImageNet |
|---|---|---|---|
| VDVAE (Child, 2021) | 2.87 | 3.80 | 3.52 |
| PixelCNN family (PixelCNN++ on CIFAR-10, gated PixelCNN on ImageNet) | 2.92 | 3.83 | 3.57 |
| Best autoregressive transformer listed in the paper | 2.80 | 3.77 | 3.44 |
In the construction that turns any autoregressive model into an -layer VAE, which part of the VAE plays the autoregressive model's role?
- The decoder
- The posterior
- The prior over the latent layers
- The KL weight
Show the answer
C. The prior over the latent layers
The latents copy the data, so the prior over latents must assign them exactly the autoregressive model's probabilities; the ELBO's KL terms then sum to .
Diffusion models as hierarchical VAEs
A DDPM (Ho, Jain & Abbeel, 2020) is a hierarchical VAE whose encoder is frozen. Its latents are the noisy images (here counts discrete diffusion steps, running from the data toward nearly pure noise ), produced by a fixed Markov encoder , and its generative model is the top-down chain . The encoder runs bottom-up, but Bayes' rule rewrites it in generative order, , and the layerwise ELBO of the first step appears term for term:
| Aspect | Learned hierarchical VAE | Diffusion model |
|---|---|---|
| Encoder | learned, top-down, can collapse | fixed noise injection: every layer always carries information |
| Latents | tens of groups, multi-resolution, can compress | copies of data-sized noisy images |
| Generative layers | separate weights per layer | one network shared across steps, told the step |
| Per-layer task | generate a whole group of features | remove a small amount of noise |
| Sampling | one pass | one pass per step |
Variational diffusion models (Kingma, Salimans, Poole & Ho, 2021) took the hierarchy to its continuous-time limit, . Their latents are for , and time runs as in DDPM, from nearly clean data at to nearly pure noise at : the reverse of the flow-matching convention of Continuous Flows & Flow Matching, where noise sits at . With signal-to-noise ratio , decreasing in , the diffusion part of the bound becomes
and the change of variables shows that it depends on the noise schedule only through its endpoints and . The schedule in between affects only the variance of the Monte Carlo estimate of the bound, so VDM learned it to minimize that variance, and reported state-of-the-art likelihoods on standard image benchmarks at the time. An infinitely deep hierarchy, then, is not a liability when every layer is a small, shared denoising step.
Key takeaways
- A hierarchical VAE generates latent groups top-down and infers them in the same order; its ELBO then splits into one closed-form Gaussian KL per group, averaged over the groups above.
- Top-down inference combines one bottom-up feature pass with the generative pass; NVAE adds posteriors relative to their priors, spectral regularization, careful batch normalization, KL warm-up and KL balancing.
- Groups that the decoder can do without collapse to their priors; warm-up and free bits, which charge each group at least nats, , keep them in use.
- A VAE with one latent layer per dimension and copying posteriors contains every autoregressive model (Child, 2021); VDVAE's 78-layer hierarchies beat PixelCNN likelihoods with one-pass sampling, stabilized by gradient skipping and depth-scaled initialization.
- A diffusion model is a hierarchical VAE with a fixed encoder and a shared denoiser; in continuous time its bound depends on the noise schedule only through the endpoint SNRs (Kingma et al., 2021).
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In a hierarchical VAE whose prior and posterior are both factored top-down, what does the KL part of the ELBO become?
- , one standard-normal KL per group
- Only the KL of the top group,
- It has no closed form at any layer and must be estimated by sampling every group
Show the answer
B.
By the chain rule for KL divergence, the joint KL is a sum of conditional KLs, each averaged over the groups above. Given those groups, each conditional KL is between two Gaussians and has a closed form.
NVAE writes a posterior as relative to the prior . If the encoder outputs and , what is that group's KL?
- : the posterior equals the prior, so the group carries no information about
- It depends on through and
Show the answer
C. : the posterior equals the prior, so the group carries no information about
. The relative parameterization makes "say nothing about " the encoder's neutral output, whatever the prior currently is.
Viewed as a hierarchical VAE, how does a DDPM differ from NVAE or VDVAE?
- Its latents are lower-dimensional than the data, so it compresses more
- Its encoder is a fixed noise-adding process, so only the generative steps are learned and no layer can collapse to its prior
- It infers its latents bottom-up, so its ELBO has no layerwise KL terms
- It uses a separate network for every layer
Show the answer
B. Its encoder is a fixed noise-adding process, so only the generative steps are learned and no layer can collapse to its prior
The forward process has no parameters: every noisy image necessarily carries information about , and training fits only the reverse steps, with one network shared across . Bayes' rule rewrites the encoder in top-down order, so the ELBO still splits into one Gaussian KL per step.
Further reading
- C. K. Sønderby, T. Raiko, L. Maaløe, S. K. Sønderby & O. Winther, "Ladder variational autoencoders," NeurIPS (2016).
- D. P. Kingma, T. Salimans, R. Jozefowicz, X. Chen, I. Sutskever & M. Welling, "Improved variational inference with inverse autoregressive flow," NeurIPS (2016).
- A. Vahdat & J. Kautz, "NVAE: A deep hierarchical variational autoencoder," NeurIPS (2020).
- R. Child, "Very deep VAEs generalize autoregressive models and can outperform them on images," ICLR (2021).
- D. P. Kingma, T. Salimans, B. Poole & J. Ho, "Variational diffusion models," NeurIPS (2021).