Foundations to Frontier
Tests
H. Generative Models › H3 Variational Autoencoders

Posterior collapse and its fixes

Posterior collapse is when some or all of a VAE's latents carry no information: the encoder's q(z | x) equals the prior for every input, the KL term is zero, and the decoder ignores z. It was first reported for VAEs with LSTM decoders on text (Bowman and colleagues, 2016), where a decoder that can model the data alone has no reason to pay the KL cost of using z. Fixes followed: KL annealing, word dropout, free bits, δ-VAE, aggressive encoder training, cyclical schedules and skip connections. Lucas and colleagues (2019) then showed with linear VAEs that collapse is often not an optimisation failure. A latent whose data variance is below the decoder's noise variance collapses at the exact optimum of the ELBO, and the decoder variance decides how many latents survive. This page explains both views, derives the linear collapse condition, and tests the common fixes. In the exercises you measure per-latent KL, free bits and annealing schedules. You then train linear VAEs on data with four latent directions. With decoder variance 0.1 all four latents stayed active, at 0.6 three, at 1.5 two, exactly as predicted. KL annealing changed nothing: the collapsed latent stayed collapsed. Free bits revived it at a cost of 0.054 nats of ELBO. Learning the decoder variance found 0.213, kept all four latents and gave the best ELBO.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

When the code goes silent

A VAE pays a small fee, the KL term, for every bit of information it puts into its code. If the decoder can do well without the code, for example because it is powerful enough to guess the data on its own, or because the code would only describe what looks like noise, the cheapest solution is to send nothing. The encoder then outputs the prior for every input and that latent goes silent. Sometimes that is the right answer and sometimes it is a training trap. The demo shows which latents survive as you change how much noise the decoder assumes.

VAE lab
σ² = 0.6: active latents 3 of 4, total KL 1.90 nats. A latent collapses when its data variance (4, 2, 1.2, 0.5) is below σ²; free bits keep it at λ nats.
Why engineers care

Collapse silently ruins VAE-based anomaly detectors, controllable generators and latent planners: a collapsed latent cannot represent the factor you wanted to control or monitor, so check per-latent KL before trusting a trained model.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A collapsed latent has…
  2. 2. Collapse makes the decoder…
  3. 3. Collapse is detected by…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Definition: latent j is collapsed if KL(q(z_j | x) ‖ p(z_j)) ≈ 0 for all x; equivalently its posterior mean does not vary over the data (inactive in the active-units sense).
  • Why it can be optimal (linear VAE): with decoder variance σ², a data direction of variance λ is coded only if λ > σ², with KL ½ ln(λ/σ²); otherwise its latent collapses.
    • Variances 4, 2, 1.2, 0.5: σ² = 0.6 keeps 3 latents, σ² = 1.5 keeps 2.
    • λ = 4 at σ² = 0.6: KL ½ ln(6.67) = 0.949 nats.
  • Learned σ²: the maximum-likelihood σ² of probabilistic PCA with d latents is the mean of the discarded eigenvalues; every kept direction is then above it, so none collapses.
  • Fixes and what they change:
    • KL annealing (Bowman et al., 2016): β rises from 0 to 1; changes the path, not the optimum.
    • Cyclical annealing (Fu et al., 2019): repeat the ramp several times.
    • Free bits (Kingma et al., 2016): the KL term is Σ_j max(λ, KL_j), so each latent may use λ nats for free; changes the objective.
    • δ-VAE (Razavi et al., 2019): restrict q and p so the KL can never be below δ.
    • Aggressive inference (He et al., 2019): update the encoder several times per decoder step to stop it lagging behind.
    • Weaker or skip-connected decoders: word dropout, dilated CNN decoders, or skip connections from z to every decoder layer.
📝 Quick check (Level 1)
0/3 answered
  1. 1. A linear VAE keeps a direction of variance λ if…
  2. 2. Free bits change…
  3. 3. KL annealing changes…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Diagnosing and fixing collapse

Exercise 1.

  • Per-latent average KL and the list of collapsed latents.
  • The free-bits KL term.
  • A linear KL warm-up schedule.

Practice.

  • Always log KL per latent (or per group) and the number of active units; a falling total KL can hide individual collapses.
  • Decide first whether collapse is wrong: if the latent would only encode noise, collapse is the ELBO doing its job.
  • Check the decoder variance: a fixed σ_x that is too large (or a β above 1) switches latents off; learn σ_x or lower it.
  • For powerful autoregressive decoders, combine free bits (0.1–0.5 nats per latent or group) with annealing, or weaken the decoder.
  • Report the true ELBO (β = 1, no free bits) alongside the training objective, so the cost of a fix is visible.
def vae_loss(rec, mu, logvar, step, warmup=10_000, free_bits=0.25):
    kl_j = 0.5 * (mu ** 2 + logvar.exp() - 1 - logvar).mean(0)     # per-latent KL, batch average
    beta = min(1.0, step / warmup)                                  # KL annealing
    kl_term = torch.clamp(kl_j, min=free_bits).sum()                # free bits
    true_elbo = -(rec.mean() + kl_j.sum())                          # log this too
    return rec.mean() + beta * kl_term, true_elbo, (kl_j > 0.01).sum()
🐍 Exercise 1: per-latent KL, free bits and warm-up
Compute per-latent KL, list collapsed latents, and implement the free-bits term and a linear warm-up.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Before fixing collapse, ask…
  2. 2. A fixed decoder variance that is too large…
  3. 3. Report alongside the training objective:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Two kinds of collapse.

  • Optimal collapse. The ELBO is maximised with the latent switched off. For a linear VAE, Lucas, Tucker, Grosse and Norouzi (2019) showed the stationary points are those of probabilistic PCA: directions with variance below σ² are not represented. With σ² learned, collapse only removes directions that look like noise. In deep VAEs, a large fixed σ_x (equivalently β > 1) produces the same effect.
  • Collapse from optimisation. Early in training the encoder is poor, so z carries little useful information, while the KL cost is immediate. A powerful decoder (an LSTM over words, a PixelCNN over pixels) learns to model the data without z, after which there is no gradient signal to start using it. He et al. (2019) describe the encoder as lagging behind the true posterior.

The bits-back view (Chen et al., 2017). Encoding data with a VAE costs the KL in extra bits. If the decoder can model x alone with the same quality, any information in z is pure overhead, so a perfect optimiser should collapse. Using z must buy more than it costs.

Proof sketch of the linear condition. For one direction, scaling the loss shows the optimal decoder weight satisfies w² = λ − σ² when positive (H3-4 with β = 1). If λ ≤ σ², w = 0 is optimal, the encoder output is irrelevant, and the KL is minimised by q = p, giving KL = 0.

What fixes do to the objective.

  • Annealing leaves the final objective unchanged, so it can only help with collapse from optimisation.
  • Free bits and δ-VAE change the objective: the model is required to send at least λ nats per latent, even when that lowers the true ELBO.
  • Skip connections and weaker decoders change the model, making z more useful.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Bits-back argues a perfect optimiser collapses z when…
  2. 2. Lazy (lagging) inference networks cause…
  3. 3. Which fix cannot change the optimum?

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Is posterior collapse an optimisation failure, and what do the usual fixes actually do?

History.

  • S. R. Bowman et al., “Generating sentences from a continuous space” (CoNLL 2016): collapse with LSTM decoders, KL annealing and word dropout.
  • X. Chen et al., “Variational lossy autoencoder” (ICLR 2017): the bits-back explanation.
  • J. He et al., “Lagging inference networks and posterior collapse in VAEs” (ICLR 2019); A. Razavi et al., “Preventing posterior collapse with δ-VAEs” (ICLR 2019).
  • J. Lucas, G. Tucker, R. Grosse and M. Norouzi, “Don’t blame the ELBO! A linear VAE perspective on posterior collapse” (NeurIPS 2019).

Exercise 2.

  • Data: 300 points in 6 dimensions with four latent directions of variances 4, 2, 1 and 0.3 plus noise of variance 0.2 (sample eigenvalues 4.02, 1.99, 1.17, 0.52, 0.23, 0.20).
  • Model: a linear VAE with 4 latents, trained with Adam (800 steps, rate 0.05, decayed linearly to 0 over the last 500 so the result is converged) on the exact expected loss.
  • Runs: decoder variance fixed at 0.1, 0.6 or 1.5; learned (starting at 1.5); at 0.6 with KL annealing over the first 400 steps; at 0.6 with 0.25 free bits per latent.
  • Reported: per-latent KL (sorted), active latents (KL above 0.01) and the true ELBO (β = 1, no free bits).
run per-latent KL (nats) active true ELBO
σ² = 0.1 1.844, 1.499, 1.232, 0.825 4 −8.138
σ² = 0.6 0.951, 0.599, 0.335, 0.000 3 −8.156
σ² = 1.5 0.493, 0.141, 0.000, 0.000 2 −9.071
σ² = 0.6 + annealing 0.951, 0.599, 0.335, 0.000 3 −8.156
σ² = 0.6 + free bits 0.25 0.951, 0.599, 0.25, 0.25 4 −8.210
σ² learned (→ 0.213) 1.469, 1.116, 0.852, 0.446 4 −7.762
  • Collapse followed the theory exactly: a latent survived only if its data variance exceeded σ², and the largest KL at σ² = 0.6 was ½ ln(4.02/0.6) = 0.951.
  • KL annealing did nothing here (a null result): the collapsed latent is the optimum, and annealing only changes the path to it.
  • Free bits revived the latent but cost 0.054 nats of true ELBO: the model was forced to encode a direction it judged not worth encoding.
  • Learning σ² was the real fix: it converged to 0.213, the mean of the two discarded eigenvalues (the PPCA optimum), kept all four latents and gave the best ELBO.
  • Seeds 1 and 2: identical patterns; free-bits costs 0.067 and 0.068 nats; learned σ² 0.196 and 0.195 with ELBO −7.681 and −7.676; annealing again matched the unannealed run.
  • Caveat: in deep VAEs with autoregressive decoders, collapse also arises from optimisation, and there annealing and aggressive inference do help; this linear model isolates the optimal kind.
🐍 Exercise 2 (research): is posterior collapse an optimisation failure, and what do the usual fixes actually do?
Train linear VAEs at several decoder variances, with KL annealing, with free bits and with a learned variance, and count the latents that survive.

Posterior collapse in AI, robotics and aerospace

  • Sequence VAEs for telemetry and text: autoregressive decoders over time series are prone to ignoring z; free bits, KL annealing and skip connections are standard defences.
  • Latent world models: DreamerV3 uses free bits (1 nat) and KL balancing on its latent dynamics for stable training across domains.
  • Diagnostics before deployment: per-latent KL and active-unit counts belong in model cards for VAE-based anomaly detectors.

References

  1. S. R. Bowman et al. (2016). “Generating sentences from a continuous space.” CoNLL.
  2. D. P. Kingma et al. (2016). “Improved variational inference with inverse autoregressive flow.” NeurIPS (free bits).
  3. X. Chen et al. (2017). “Variational lossy autoencoder.” ICLR.
  4. J. He, D. Spokoyny, G. Neubig and T. Berg-Kirkpatrick (2019). “Lagging inference networks and posterior collapse in variational autoencoders.” ICLR.
  5. A. Razavi, A. van den Oord, B. Poole and O. Vinyals (2019). “Preventing posterior collapse with δ-VAEs.” ICLR.
  6. H. Fu et al. (2019). “Cyclical annealing schedule: a simple approach to mitigating KL vanishing.” NAACL.
  7. J. Lucas, G. Tucker, R. Grosse and M. Norouzi (2019). “Don’t blame the ELBO! A linear VAE perspective on posterior collapse.” NeurIPS.