[Score Matching] Y. Song and S. Ermon, “Generative modeling by estimating gradients of the data distribution,” in Advances in Neural Information Processing Systems, 2019, pp. 11918–11930.
[GAN] I. Goodfellow, J. Pouget-Abadie, M. Mirza, B. Xu, D. Warde-Farley, S. Ozair, A. Courville, and Y. Bengio, “Generative adversarial nets,” in Advances in Neural Information Processing Systems, 2014, pp. 2672–2680.
[GAN Theory] S. Arora and Y. Zhang, “Do GANs actually learn the distribution? An empirical study,” arXiv preprint arXiv:1706.08224, 2017.
[DCGAN] A. Radford, L. Metz, and S. Chintala, “Unsupervised representation learning with deep convolutional generative adversarial networks,” in International Conference on Learning Representations, 2016.
[WGAN] M. Arjovsky, S. Chintala, and L. Bottou, “Wasserstein generative adversarial networks,” in International Conference on Machine Learning, 2017, pp. 214–223.
[WGAN-GP] I. Gulrajani, F. Ahmed, M. Arjovsky, V. Dumoulin, and A. C. Courville, “Improved training of Wasserstein GANs,” in Advances in Neural Information Processing Systems, 2017, pp. 5767–5777.
[StyleGAN] T. Karras, S. Laine, and T. Aila, “A style-based generator architecture for generative adversarial networks,” in Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2019, pp. 4401–4410.
[Evaluation] T. Kynkäänniemi, T. Karras, S. Laine, J. Lehtinen, and T. Aila, “Improved precision and recall metric for assessing generative models,” in Advances in Neural Information Processing Systems, 2019, pp. 3927–3936.
[VAE]D. P. Kingma and M. Welling, “Auto-encoding variational Bayes,” in International Conference on Learning Representations, 2014.
[VAE Review]D. P. Kingma and M. Welling, “An introduction to variational autoencoders,” Foundations and Trends in Machine Learning, vol. 12, no. 4, pp. 307–392, 2019.
[ELBO] M. D. Hoffman and M. J. Johnson, “ELBO surgery: yet another way to carve up the variational evidence lower bound,” in NIPS Workshop on Advances in Approximate Bayesian Inference, 2016.
[VQ-VAE] A. van den Oord, O. Vinyals, and K. Kavukcuoglu, “Neural discrete representation learning,” in Advances in Neural Information Processing Systems, 2017, pp. 6306–6315.
Generative Adversarial Networks (GANs)
The Objective Leaves the Function Class Open
Fixed by the objective
Objective: a classifier game or a Wasserstein critic - which divergence training follows
Equilibrium: \(p_g = p_{\text{data}}\), \(D = \tfrac{1}{2}\) - a statement in function space
Failures and treatments: saturation, collapse, orbits - each mapped to its fix
Left open
\(G: \mathbb{R}^{100} \to \mathbb{R}^{H \times W \times 3}\) - how a vector becomes an image, and at what resolution
Conditioning - how a label or a second image steers \(G\)
Scale - the objective is the same at every resolution, the training is not
Scoring - a sample set against a sample set, with no likelihood to report
The objective fixes the target - the architecture fixes which distributions \(G\) can reach.
GAN Architectures
Transposed Convolution Upsamples Inside the Network
Shapes
Convolution, stride 1: \(H \times W \to H \times W\)
Transposed, stride 2: \(H \times W \to 2H \times 2W\) - upsampling as a learned layer
Parameters both ways: \(K^2 \cdot C_{\text{in}} \cdot C_{\text{out}}\)
Equivalent form: insert a zero between neighboring inputs, then convolve - the transpose’s sparsity pattern made explicit
Unconditional term: the ordinary discriminator on \(\mathbf{x}\) alone - a network \(\psi(\phi(\mathbf{x}))\)
Class term: how the two class-posteriors disagree at \(\mathbf{x}\) - the only place \(y\) enters
Log-linear class model
Assumption: \(p(y|\mathbf{x}) \propto \exp(\mathbf{v}_y^{p\top} \phi(\mathbf{x}))\), and likewise for \(q\) - both class-posteriors are softmax classifiers on shared features
Class term \(= (\mathbf{v}^p_y - \mathbf{v}^q_y)^\top \phi(\mathbf{x})\) plus terms independent of \(y\)
Collected: \(a^*(\mathbf{x}, y) = \mathbf{y}^\top \mathbf{V}\, \phi(\mathbf{x}) + \psi(\phi(\mathbf{x}))\) - the projection discriminator (Miyato and Koyama 2018)
Projection hard-codes the additive class term - concatenation has to learn it.
Progressive Growing Stabilizes High Resolution
Schedule (Karras et al. 2018)
Train at 4 × 4 for a fixed image budget - add a resolution-doubling block - repeat to 1024 × 1024
Every added block fades in: \(\alpha\) from 0 to 1
Low-resolution stages settle layout - later stages add detail only
Why it stabilizes: each new stage starts from a generator that already matches the coarse statistics - the supports overlap, and the discriminator has no free win
Up to 5.4× faster to a fixed quality at 1024² (Karras et al. 2018)
First 1024 × 1024 face samples (CelebA-HQ)
CelebA-HQ samples at 1024 × 1024 (Karras et al. 2018, Fig. 5)
The high-resolution game never starts from scratch - it inherits the overlap the low-resolution stage established.
StyleGAN Injects One Code at Every Scale
Three changes to the generator (Karras et al. 2019)
Mapping network: \(\mathbf{z} \to \mathbf{w}\) through 8 FC layers - \(\mathbf{w}\)-space less entangled than \(\mathbf{z}\)-space, measured by perceptual path length and linear separability
Style injection: \(\mathbf{w}\) enters every synthesis block through AdaIN - coarse blocks set pose and shape, fine blocks set color and texture
Per-layer noise: fresh randomness at each scale - stochastic detail (hair, freckles) without structural change
Lineage and cost
StyleGAN2: weight demodulation replaces AdaIN - removes the blob artifacts of per-sample normalization - and path-length regularization added
StyleGAN3: alias-free synthesis - texture no longer locked to pixel coordinates
StyleGAN2 at FFHQ 1024²: ~30M generator parameters, ~9 days on 8 V100s (Karras et al. 2020)
FID on FFHQ 1024², one dataset across the lineage: 8.04 (Progressive GAN), 4.40 (StyleGAN), 2.84 (StyleGAN2)
Because every block receives \(\mathbf{w}\) separately, a code can be swapped per band - the basis of style mixing and of truncation in \(\mathbf{w}\).
Coarse Styles Set Pose, Fine Styles Set Color
Style mixing on FFHQ (Karras et al. 2019, Fig. 3; tiles from the paper’s source)
Two latent codes, one image
Top row: source A, four samples - left column: source B, three samples
Each interior image: \(\mathbf{w}_B\) everywhere, with \(\mathbf{w}_A\) substituted in one band of blocks
What each band carries
Row 1, coarse blocks (\(4^2\) to \(8^2\)) from A: pose, face shape, glasses, hair style follow A - colors stay B’s
Row 2, middle blocks (\(16^2\) to \(32^2\)) from A: facial features and eyes follow A - pose stays B’s
Row 3, fine blocks (\(64^2\) to \(1024^2\)) from A: color scheme and micro-texture follow A - identity stays B’s
Read against the synthesis stack
The band a style is applied to is the scale it controls - the synthesis stack’s routing, read off the images
Attributes separate by scale because the code is applied by scale.
Latent Interpolation Stays on the Manifold
Paths in \(\mathbf{z}\) decode to paths on the manifold
Interpolate in \(\mathbf{z}\) (or \(\mathbf{w}\)): \(G\) is continuous, so the decoded path stays on the output manifold - a smooth morph
Straight lines in a Gaussian \(\mathbf{z}\) cut through the low-mass interior - spherical interpolation keeps the path on the typical shell \(\|\mathbf{z}\| \approx \sqrt{d}\) (White 2016)
Interpolate in pixel space: the straight line leaves the data manifold - cross-fades, not intermediates
Interpolation is the standard check that \(G\) generalizes - a memorizing \(G\) would cross-fade between training images.
Latent Arithmetic Works Where Pixel Arithmetic Fails
DCGAN on faces (Radford et al. 2016, Fig. 7)
Procedure (Radford et al. 2016)
Average the \(\mathbf{z}\) of three samples sharing an attribute - one vector per concept
\(\mathbf{z}_{\text{smiling woman}} - \mathbf{z}_{\text{neutral woman}} + \mathbf{z}_{\text{neutral man}}\), decoded: a smiling man
The \(3 \times 3\) block: the result plus small perturbations of \(\mathbf{z}\) - the direction is stable under them
Averaging
One sample’s \(\mathbf{z}\) carries everything about that face - averaging three cancels what they do not share
Same arithmetic in pixel space (bottom rows)
Averaged faces blur, differences of averages ghost - no pixel-space direction corresponds to smiling
What it shows
Linear attribute directions in \(\mathbf{z}\) are observed, not guaranteed - nothing in the objective asks for them, and they appear when attributes vary independently in the data
Arithmetic in \(\mathbf{z}\) works when attributes occupy separable directions - a property \(G\) acquired, not one the objective imposed.
Truncation Trades Diversity for Fidelity in \(\mathbf{w}\)
Two seeds, \(\psi\) = 1, 0.7, 0.5, 0, −0.5, −1 left to right (Karras et al. 2019, Fig. 8)
Definition (Karras et al. 2019)
\(\bar{\mathbf{w}} = \mathbb{E}_{\mathbf{z}}[f(\mathbf{z})]\) - the center of \(\mathbf{w}\)-space, decoding to an average face (\(\psi = 0\))
\(\mathbf{w}' = \bar{\mathbf{w}} + \psi(\mathbf{w} - \bar{\mathbf{w}})\) - every sample pulled toward the center by \(\psi < 1\)
\(\psi < 0\): reflected through the center - every attribute flips
What it trades
\(\psi \to 0\): samples land in the densest region - fewer artifacts, less variety, one face
Applied at generation time - nothing about training changes
Off the typical shell: \(\psi < 1\) moves samples toward the center of \(\mathbf{w}\)-space, where density is high and draws are rare - fidelity gained by leaving the region the prior samples
Truncated samples are atypical by construction - the trade is fidelity for the diversity the prior would have drawn.
Paired Translation Learns from Correspondence
Pix2Pix (Isola et al. 2017) - image in, image out, with aligned pairs
2.7M parameters against 41M for a whole-image \(D\)
The two losses split the work
\(L_1\): gets the low frequencies right - blurry alone
Adversarial: sharpens the texture the \(L_1\) term averages away
Input \(\mathbf{x}\), output \(G(\mathbf{x})\), target \(y\): Cityscapes labels to photo, edges to shoe (Isola et al. 2017, from the paper’s result sets)
Paired data is the constraint - one aligned \((\mathbf{x}, y)\) per training example.
Cycle Consistency Replaces Paired Data
CycleGAN (Zhu et al. 2017) - two domains, no pairs
Two generators: \(G: X \to Y\), \(\;F: Y \to X\) - two discriminators \(D_X\), \(D_Y\)
Cycle consistency replaces correspondence: translate over, translate back, land at the input
Failure modes
Semantic drift: geometry changes when only texture should
Hidden information: \(G\) encodes the input in imperceptible high-frequency detail so that \(F\) can invert it - the cycle check passes without a semantic map (Chu et al. 2017)
Texture bias: color moves, structure resists
Cost
Four networks - 2× the memory of one GAN
Input, \(G(\mathbf{x})\), and \(F(G(\mathbf{x}))\): Monet to photo, horse to zebra (Zhu et al. 2017, Fig. 4)
The cycle check forces \(F \circ G\) toward the identity - which invertible \(G\) satisfies it is left to the adversarial terms.
Adversarial Losses Outlived Standalone GANs
BigGAN (Brock et al. 2019) - class-conditional generation at ImageNet scale
Batch size 2048 against the 256 baseline - the largest single gain in the paper’s ablation
Projection conditioning, spectral norm in both networks, truncation at generation
Self-attention (Zhang et al. 2019)
Attention layers at mid resolutions - long-range structure convolutions miss
Cost: memory \(O(n^2)\) in the number of positions - a \(64 \times 64\) feature map is \(4096^2 \approx 1.7 \times 10^7\) attention entries per head
Inception features (pool3, 2048-d) of both sample sets, a Gaussian fitted to each
FID = the Fréchet distance between the two fits - lower is better, 0 = identical fits
Evaluation as distribution comparison - a sample set against a sample set, in kind with the objective
Against IS
Real data enters the comparison - IS never looks at it
A mode dropped within a class moves \(\boldsymbol{\mu}_g, \boldsymbol{\Sigma}_g\) - FID rises where IS holds still
Assumptions
Features treated as Gaussian - two moments only
Inherits the Inception network’s feature geometry - ImageNet-trained, ImageNet-biased
Real data enters FID and not IS - the two metrics fail on different collapses.
Precision and Recall Separate Fidelity from Diversity
Two manifolds, two fractions (Kynkäänniemi et al. 2019)
\(\text{manifold}(S)\): the union of balls around each feature vector in \(S\), radius = distance to its \(k\)-th nearest neighbor in \(S\) (\(k = 3\))
Precision: generated samples that land on the data - fidelity
Recall: data that the generator covers - diversity
What FID reports as one number
Truncation: precision up, recall down - FID moves one way and hides the trade
Mode dropping: recall falls, precision unchanged
Off-manifold samples: precision falls, recall unchanged
Protocol-bound like FID: same features, same \(N\), same \(k\)
FID reports one number for a trade with two sides - truncation moves the sides in opposite directions.
An FID Is Comparable Only Under One Protocol
Sample size
The estimate is biased upward at small \(N\) - and noisy
Reported numbers: 50k samples standard - 10k for quick checks only
Same \(N\) on both sides - real and generated
Everything else held fixed
Same preprocessing and resizing path
Same Inception weights and implementation
Resizing and compression differences alone shift FID by more than some model differences (Parmar et al. 2022)
Reading a published FID
Dataset, sample count, and pipeline - always stated with the number
A published FID is a statement about a protocol - compare only numbers that share it.
A GAN Has No Likelihood and No Encoder
Dropping the density
One pass per sample, sharp outputs, no partition function, no chain - and no \(\log p_g(\mathbf{x})\)
Every score above is a proxy computed from samples - IS, FID, precision and recall
Three things a sampler cannot do
Score held-out data: no likelihood, so no model comparison from the model itself
Encode: given \(\mathbf{x}\), no \(\mathbf{z}\) - inversion needs optimization or a second network
Report progress: the game’s losses oscillate - stopping falls back on the proxies
Third option
Keep the latent and the sampler - add an encoder and a lower bound on \(\log p(\mathbf{x})\), paying with a bound in place of the likelihood
A sampler without a density can be judged only by its samples - the encoder and the likelihood bound are what the next family adds.
Variational Autoencoders
A Latent Variable Model Has a Density and No \(Z\)
Two families so far
Energy: \(p(\mathbf{x}) = e^{-E(\mathbf{x})}/Z\) - a density, normalized over all of \(\mathbf{x}\)-space, and \(Z\) cannot be computed
Sampler only: \(\mathbf{x} = G(\mathbf{z})\) - no density, so no \(Z\) and nothing to score but samples
Latent variable model
\(p(\mathbf{x}) = \int p(\mathbf{x}|\mathbf{z})\, p(\mathbf{z})\, d\mathbf{z}\) - every factor normalized, no \(Z\), and the integral over \(\mathbf{z}\) remains
A simple prior and a simple conditional give a complex marginal - the shape comes from the decoder’s nonlinearity
A density for training and scoring, a posterior for inference
Cost
The integral has no closed form - training uses a bound on \(\log p(\mathbf{x})\), not \(\log p(\mathbf{x})\) itself
All learned structure is in the decoder - the integral over \(\mathbf{z}\) is what remains intractable.
Latent Variable Models
A Latent Variable Is a Continuous Hidden Unit
From the RBM’s hidden layer
Hidden units \(\mathbf{h} \in \{0,1\}^H\) were never observed - \(p(\mathbf{v})\) summed them out
Continuous version: \(\mathbf{z} \in \mathbb{R}^k\), integrated out instead of summed
\(\mathbf{x} \sim p_{\boldsymbol{\theta}}(\mathbf{x}|\mathbf{z})\) - compute \(\boldsymbol{\mu}_{\boldsymbol{\theta}}(\mathbf{z})\), then draw around it
Gaussian: \(\mathcal{N}(\boldsymbol{\mu}_{\boldsymbol{\theta}}(\mathbf{z}), \sigma^2 \mathbf{I})\), with \(\boldsymbol{\mu}_{\boldsymbol{\theta}}: \mathbb{R}^k \to \mathbb{R}^d\) the decoder network - Bernoulli for binary pixels
Result - \(\mathbf{z}\) discarded, the pair is one draw from \(p_{\boldsymbol{\theta}}(\mathbf{x})\) - the procedure runs at any \(\boldsymbol{\theta}\), and training changes only how much the draws resemble data
The latent for a given \(\mathbf{x}\) - the encoding direction a GAN does not have
Its shape is set by the decoder - non-Gaussian and correlated whenever \(\boldsymbol{\mu}_{\boldsymbol{\theta}}\) is nonlinear
Shared denominator
The marginal is the posterior’s normalizer - both require the same integral
The likelihood and the posterior require the same integral over \(\mathbf{z}\).
The Integral over \(\mathbf{z}\) Is Intractable for a Network Decoder
No closed form
\(\int \mathcal{N}(\mathbf{x}; \boldsymbol{\mu}_{\boldsymbol{\theta}}(\mathbf{z}), \sigma^2 \mathbf{I})\, \mathcal{N}(\mathbf{z}; \mathbf{0}, \mathbf{I})\, d\mathbf{z}\) - no analytic integral for a nonlinear \(\boldsymbol{\mu}_{\boldsymbol{\theta}}\)
Quadrature over \(\mathbf{z}\): exponential in \(k\)
Monte Carlo from the prior fails
\(p_{\boldsymbol{\theta}}(\mathbf{x}) \approx \frac{1}{N}\sum_i p_{\boldsymbol{\theta}}(\mathbf{x}|\mathbf{z}_i)\), \(\;\mathbf{z}_i \sim p(\mathbf{z})\) - unbiased, with variance too large to use
Almost every prior draw decodes far from \(\mathbf{x}\) - \(p_{\boldsymbol{\theta}}(\mathbf{x}|\mathbf{z}_i) \approx 0\) for all but a vanishing fraction
Effective sample size falls exponentially in \(k\) - the same failure as rejection sampling
Requirement
Draws from where \(p_{\boldsymbol{\theta}}(\mathbf{x}|\mathbf{z})\) is large - draws from the posterior
The posterior requires the marginal - the same integral
Training requires the posterior and cannot compute it - variational inference replaces it with an approximation.
Variational Inference
A Tractable Family Stands In for the Posterior
Substitution
\(q_{\boldsymbol{\phi}}(\mathbf{z}|\mathbf{x})\) from a fixed family replaces \(p_{\boldsymbol{\theta}}(\mathbf{z}|\mathbf{x})\) - the standard family is a diagonal Gaussian, \(\mathcal{N}(\boldsymbol{\mu}_{\boldsymbol{\phi}}(\mathbf{x}), \text{diag}\, \boldsymbol{\sigma}^2_{\boldsymbol{\phi}}(\mathbf{x}))\)
\(\boldsymbol{\phi}\) chosen to make \(q\) close to the posterior - the objective must not require \(p_{\boldsymbol{\theta}}(\mathbf{x})\)
Only reverse KL is computable
\(\text{KL}(q \,\|\, p(\mathbf{z}|\mathbf{x}))\): an expectation under \(q\) - samples available
\(\text{KL}(p(\mathbf{z}|\mathbf{x}) \,\|\, q)\): an expectation under the posterior - no samples, so no estimate
Reverse KL, model in the first argument - the direction that concentrates on one mode
What the family cannot represent
The true posterior is non-Gaussian and correlated whenever the decoder is nonlinear
A diagonal Gaussian under reverse KL: one mode, and variances from the posterior’s precision diagonal - narrower than the posterior’s own marginals
The computable direction is reverse KL, and reverse KL fits one mode too narrowly - the approximation error has a known sign.
The ELBO Is \(\log p(\mathbf{x})\) Minus the Posterior Gap
Proof: write \(p(\mathbf{x}, \mathbf{z}) = p(\mathbf{x})\, p(\mathbf{z}|\mathbf{x})\) inside the expectation - \(\log p(\mathbf{x})\) factors out, the remainder is the KL
\(\mathcal{L} \leq \log p_{\boldsymbol{\theta}}(\mathbf{x})\), equality iff \(q\) equals the posterior - the evidence lower bound, ELBO, evidence being the name for \(p_{\boldsymbol{\theta}}(\mathbf{x})\)
Same bound by Jensen
\(\log \mathbb{E}_q[p(\mathbf{x}, \mathbf{z}) / q] \geq \mathbb{E}_q[\log(p(\mathbf{x}, \mathbf{z}) / q)]\) - concavity of \(\log\); the gap is the KL above
Every term computable: \(q\) samples, the decoder likelihood, the prior - no \(p_{\boldsymbol{\theta}}(\mathbf{x})\) anywhere
Maximized over \(\boldsymbol{\phi}\): \(q\) approaches the posterior. Over \(\boldsymbol{\theta}\): the decoder changes the posterior too, so the gap can grow while the bound rises
The bound is exact minus a KL that is never negative - maximizing it over \(q\) is the same problem as fitting the posterior.
Both the Bound and \(\log p_{\boldsymbol{\theta}}(\mathbf{x})\) Move During Training
Two parameter sets, two effects
\(\boldsymbol{\phi}\)-steps: \(q\) moves toward the posterior - the gap \(\text{KL}(q \,\|\, p_{\boldsymbol{\theta}}(\mathbf{z}|\mathbf{x}))\) shrinks, the bound rises toward a fixed \(\log p_{\boldsymbol{\theta}}(\mathbf{x})\)
\(\boldsymbol{\theta}\)-steps: the decoder changes - \(\log p_{\boldsymbol{\theta}}(\mathbf{x})\) itself rises, and the posterior it defines moves, so the gap can widen at the same time
What the training loop sees
Only the bound - \(\log p_{\boldsymbol{\theta}}(\mathbf{x})\) is never computed, so the gap is never observed directly
A rising bound is consistent with a rising likelihood and with a closing gap - the curve alone does not say which
What the number at the end means
The final \(\mathcal{L}\) on held-out data is a lower bound on held-out \(\log p_{\boldsymbol{\theta}}(\mathbf{x})\) - the model’s likelihood is at least this, and the shortfall is the posterior gap
Training reports the bound and never the gap - the bound’s rise is the sum of two movements it cannot tell apart.
One Encoder Serves Every Data Point
Per-datapoint inference
Classical variational inference: one optimization of \((\mathbf{m}_i, \mathbf{s}_i)\) per \(\mathbf{x}_i\) - \(2k\) free parameters per point, restarted for every new \(\mathbf{x}\)
Amortized inference
One network: \(\mathbf{x} \mapsto (\boldsymbol{\mu}_{\boldsymbol{\phi}}(\mathbf{x}), \boldsymbol{\sigma}_{\boldsymbol{\phi}}(\mathbf{x}))\) - the encoder
Shared \(\boldsymbol{\phi}\) across the dataset - inference for a new \(\mathbf{x}\) is one forward pass
The variational autoencoder is this pair: encoder \(q_{\boldsymbol{\phi}}\), decoder \(p_{\boldsymbol{\theta}}\), trained together on \(\mathcal{L}\)
Amortization gap
The encoder’s \(q\) for a given \(\mathbf{x}\) is worse than the best \(q\) in the family for that \(\mathbf{x}\) - a second gap under the bound (Cremer et al. 2018)
\(-\mathcal{L}\) is the variational free energy of statistical physics: an energy term \(\mathbb{E}_q[-\log p(\mathbf{x}, \mathbf{z})]\) minus an entropy
Not the Helmholtz free energy \(F = -\log Z\) of the energy-based unit: that \(F\) normalizes a density, this one bounds a marginal - at \(q\) equal to the posterior, \(-\mathcal{L} = -\log p_{\boldsymbol{\theta}}(\mathbf{x})\), the latent-variable counterpart of \(-\log Z\)
Units
Nats per data point, and \(-\mathcal{L}\) is a code length: the bits to transmit \(\mathbf{x}\) through \(\mathbf{z}\) with \(q\) as the code distribution - the code-length reading of a log-likelihood, now with a latent
Two groupings of one bound - the second names the quantity, the first is what the loss function computes.
The KL Term Is Information Plus Prior Mismatch
Aggregate posterior
\(q_{\boldsymbol{\phi}}(\mathbf{z}) = \frac{1}{N}\sum_i q_{\boldsymbol{\phi}}(\mathbf{z}|\mathbf{x}_i)\) - the code distribution over the whole dataset
The regularizer, averaged (Hoffman and Johnson 2016)
\[\frac{1}{N}\sum_i \text{KL}\!\left(q(\mathbf{z}|\mathbf{x}_i) \,\|\, p(\mathbf{z})\right)
= \underbrace{I_q(\mathbf{x}; \mathbf{z})}_{\text{code carries information}}
+ \underbrace{\text{KL}\!\left(q(\mathbf{z}) \,\|\, p(\mathbf{z})\right)}_{\text{aggregate differs from the prior}}\]
Proof: add and subtract \(\log q(\mathbf{z})\) inside the KL - the mutual information is the average KL of each \(q(\mathbf{z}|\mathbf{x}_i)\) to the aggregate
What the objective penalizes
Information in the code, \(I_q(\mathbf{x};\mathbf{z})\): bounded by \(\log N\), each nat charged at full weight
Mismatch between the aggregate and the prior: regions of \(\mathbf{z}\) the prior samples that no data point encodes to
What follows
A code that carries nothing costs nothing - \(I_q \to 0\) is a valid optimum of the regularizer alone
Reweighting the KL term reweights both, not one - posterior collapse and the β-VAE trade both come from this split
The KL term is two costs, information in the code and mismatch with the prior, with one weight in front of both.
With \(\boldsymbol{\mu}_2 = \mathbf{0}\), \(\boldsymbol{\Sigma}_2 = \mathbf{I}\), \(\boldsymbol{\Sigma}_1\) diagonal: the trace is \(\sum \sigma_j^2\), the quadratic is \(\sum \mu_j^2\), the log-determinant is \(-\sum \log \sigma_j^2\)
Per dimension
\(\mu_j^2\): distance of the code’s mean from the prior’s
\(\sigma_j^2 - \log \sigma_j^2 - 1\): zero at \(\sigma_j = 1\), positive on either side - a variance both larger and smaller than the prior’s costs
Minimum zero at \(\mu_j = 0\), \(\sigma_j = 1\) - a dimension that matches the prior is free
The regularizer is a sum of per-dimension costs, each zero exactly when that dimension matches the prior.
Training a VAE
Two Estimators for the Gradient of an Expectation
Gradient of an expectation
\(\nabla_{\boldsymbol{\phi}}\, \mathbb{E}_{q_{\boldsymbol{\phi}}(\mathbf{z})}[f(\mathbf{z})]\) with \(\boldsymbol{\phi}\) in the distribution, not in \(f\) - the derivative cannot pass inside the expectation as written
The randomness moves to \(\boldsymbol{\epsilon}\), which has no parameters - the derivative passes inside
Uses \(\nabla_{\mathbf{z}} f\) - variance scales with the slope of \(f\), not its magnitude
Which families reparameterize
Location-scale (Gaussian, Laplace, logistic) and any inverse-CDF sampler
Not categorical, not discrete - the cases Gumbel-softmax and the straight-through estimator handle
Both estimators are unbiased - the pathwise one uses the slope of \(f\) and its variance does not grow with the latent dimension.
Reparameterization Makes the ELBO a Standard Backpropagation Problem
One forward pass per data point
mu, log_var = encoder(x) # two heads, k eachz = mu + torch.exp(0.5* log_var) * torch.randn_like(mu)x_logits = decoder(z)recon = F.binary_cross_entropy_with_logits(x_logits, x, reduction='sum')kl =-0.5* torch.sum(1+ log_var - mu**2- log_var.exp())loss = recon + kl # = -ELBO for this x
One sample of \(\boldsymbol{\epsilon}\) per data point - the pathwise variance is low enough
KL in closed form, reconstruction by Monte Carlo with one draw
The log-variance head
A linear head can produce any real number - \(\sigma^2 = e^{\text{head}}\) is positive without a constraint
Clamped to \([-10, 10]\) in practice - \(\sigma^2\) from \(4.5 \times 10^{-5}\) to \(2.2 \times 10^{4}\), wide enough for any encoder and a guard on the \(e^{\log\sigma^2}\) term of the KL
Cost
Encoder pass, decoder pass, and their backward passes - four network evaluations per update, against six for a GAN and about 120 for a truncated EBM
The sampling step sits between two ordinary networks - with the noise drawn outside, the whole graph is differentiable end to end.
The Output Distribution Sets the Reconstruction Loss
Bernoulli - binary data
\(p(\mathbf{x}|\mathbf{z}) = \prod_i \text{Bernoulli}(x_i \,|\, \pi_i(\mathbf{z}))\), decoder outputs logits - the loss is binary cross-entropy with logits
Gaussian with fixed \(\sigma^2\) - continuous data
\(\sigma^2\) is the weight of reconstruction against the KL term - plain mse_loss with reduction='sum' is this loss at \(\sigma^2 = \tfrac{1}{2}\), not at unit variance
Squared error and a single mean: where the conditional has several modes, the optimal \(\boldsymbol{\mu}\) is their average - the blur of Gaussian decoders is this average, not a defect of the network
Gaussian with learned \(\sigma^2\)
Per-pixel \(\sigma_i^2 \to 0\) on any pixel the mean fits exactly: \(-\log p \to -\infty\) - the likelihood is unbounded, and gradient descent moves toward it
Used with a floor on \(\sigma^2\) or one shared \(\sigma^2\) per image (Rybkin et al. 2021)
The likelihood chosen for \(p(\mathbf{x}|\mathbf{z})\) is the reconstruction loss and its scale is the KL weight - two decisions made by one line.
Reconstruction Falls First, Then the KL Term Rises
Setup
600 points on a curve in the plane, Gaussian noise \(\sigma = 0.18\) (left panel)
Encoder and decoder of two hidden layers, latent \(k = 2\) - Gaussian decoder, \(\sigma\) fixed
Four runs differing only in the KL weight \(\beta\) - \(\beta = 1\) is the ELBO
At \(\beta = 1\)
Reconstruction falls first - the KL rises as the code starts to carry information
\(-\mathcal{L}\) decreases throughout - a loss that tracks the objective
A loss that decreases is what the bound provides - the adversarial game had no such curve.
Every Nat in the Code Appears in the KL Term
KL per dimension, four runs
Both dimensions carry information at low \(\beta\) - a curve embedded in the plane uses two coordinates cheaply
Higher \(\beta\) lowers every dimension’s share
At \(\beta = 30\) the first dimension sits at zero - collapsed to the prior, ignored by the decoder
The objective prices information, not dimensions - a dimension the decoder ignores costs nothing.
The Latent Space and Its Failures
Samples Are Good Only Where Encoded Data Is Nearby
Two views of one latent space
Encoded training data: \(\boldsymbol{\mu}_{\boldsymbol{\phi}}(\mathbf{x}_i)\) for every point - where the data lands in \(\mathbf{z}\)
Decoded prior draws: \(\boldsymbol{\mu}_{\boldsymbol{\theta}}(\mathbf{z})\) for \(\mathbf{z} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})\) - what the model generates
A working model
The encoded data fills the prior - no empty region under the bell
Prior draws land on the data - the decoder is trained wherever the prior has mass
Holes
A region of the prior with no encoded data - the decoder was never trained there, and the prior draws from it anyway
The KL term is the only part of the objective that penalizes holes
Sample quality depends on the encoded data filling the prior - nothing but the KL term asks for that.
Posterior Collapse: The Code Carries Nothing
Collapse
\(q_{\boldsymbol{\phi}}(\mathbf{z}|\mathbf{x}) = p(\mathbf{z})\) for every \(\mathbf{x}\) - KL term zero, no information in the code
The decoder ignores \(\mathbf{z}\) and models \(p(\mathbf{x})\) on its own - every input reconstructs to the same output
Why the objective permits it
The KL term alone is minimized by a code that carries nothing
Only reconstruction pays for information - if the decoder fits the data without \(\mathbf{z}\), no information is worth its cost
When: a decoder strong enough on its own (autoregressive decoders), or early training, when the KL gradient outweighs a poor decoder (Bowman et al. 2016)
Treatments
Warm-up: the KL weight raised from 0 to 1 over the first epochs (Bowman et al. 2016)
Free bits: no penalty below a KL floor per dimension (Kingma et al. 2016)
A weaker decoder, or one that cannot reach \(p(\mathbf{x})\) without \(\mathbf{z}\) (Chen et al. 2017)
Watch the KL per dimension - a dimension at zero carries nothing, and collapse is a valid optimum of the KL term alone.
\(\beta\) Reweights Information Against Reconstruction
\(\beta = 1\): the bound - \(\beta > 1\): less information in the code, coarser reconstructions - \(\beta < 1\): more information, closer to a plain autoencoder
\(\beta\) multiplies both parts of the KL term: the information in the code and the mismatch with the prior
With a Gaussian decoder, \(\beta\) and \(\sigma^2\) are one parameter: \(\mathcal{L}_\beta / \beta\) is the bound at noise variance \(\beta \sigma^2\)
The disentanglement claim
Higher \(\beta\) pushes the latent dimensions toward independence - reported as one factor per dimension on synthetic data with known factors
Not guaranteed: without extra assumptions no unsupervised method identifies the factors, and the scores vary more across random seeds than across \(\beta\) (Locatello et al. 2019)
What is guaranteed
A rate-distortion trade: each \(\beta\) picks one point on the curve of reconstruction error against information in the code
\(\beta\) sets a point on the rate-distortion curve - disentanglement is something some data show at some \(\beta\), not a consequence of the objective.
Top layer: coarse structure - lower layers: detail, conditioned on the layer above
One KL term per layer, each against the layer above - only the top layer keeps a fixed prior
Inference top-down (Sønderby et al. 2016)
A bottom-up pass computes features of \(\mathbf{x}\) at every level - a top-down pass forms \(q(\mathbf{z}_l | \mathbf{z}_{l+1}, \mathbf{x})\) from those features and the generative path
\(q\) and \(p\) share the top-down network - each layer’s posterior is a correction to its prior
Every prior but the top one is learned - each layer is generated from the layer above it.
Deep Hierarchies Collapse from the Top
Failure
The upper layers’ KL terms go to zero first and the lower layers carry everything - warm-up and per-layer free bits are the treatments (Sønderby et al. 2016)
At scale (Vahdat and Kautz 2020)
NVAE: dozens of latent groups at several resolutions, with spectral regularization to keep the KL terms stable - 2.91 bits per dimension on CIFAR-10
Same model, fixed encoder
A diffusion model is this hierarchy with \(\mathbf{z}_l\) set to the data at noise level \(l\) and \(q\) fixed to the noising process - each layer’s KL term becomes a denoising regression
With the encoder fixed to added noise, the hierarchy is a diffusion model - the two lines of this unit meet there.
Discrete Latents and Outputs
VQ-VAE Replaces the Gaussian Code with a Code-Book Index
Quantization in the middle (van den Oord et al. 2017)
Encoder output \(\mathbf{z}_e = f_{\boldsymbol{\phi}}(\mathbf{x})\), continuous - snapped to the nearest of \(K\) code-book vectors: \(\mathbf{z}_q = \mathbf{e}_k\), \(k = \arg\min_j \|\mathbf{z}_e - \mathbf{e}_j\|\)
Decoder reads \(\mathbf{z}_q\) - the code for \(\mathbf{x}\) is the index \(k\), \(\log_2 K\) bits per position
Reconstruction; the code-book vector moved toward the encoder output; the encoder output moved toward its code-book vector - \(\text{sg}\) stops the gradient
The argmin has no gradient: the decoder’s gradient at \(\mathbf{z}_q\) is copied to \(\mathbf{z}_e\) unchanged - the straight-through estimator, the discrete counterpart of reparameterization
What the KL term becomes
Uniform prior over \(K\) indices and a deterministic posterior: \(\text{KL} = \log K\), a constant - nothing in the objective moves the code toward the prior
No posterior collapse, but a failure of its own: a few indices used, the rest never assigned and so never updated
Generation needs a second model
Prior draws are uniform indices - samples need a learned \(p(k_1, \dots, k_M)\) over the index grid, trained afterward (an autoregressive model in the paper)
A discrete code replaces the Gaussian KL with a constant and reparameterization with a copied gradient - and fails by leaving codes unused.
Sampling a Token Breaks the Gradient Path
Where the graph breaks
\(G\) emits logits \(\boldsymbol{\ell}\) over a vocabulary - a token is sampled, \(D\) reads tokens (with images, \(D\) read \(G\)’s output directly)
\(\partial\, \text{token} / \partial \boldsymbol{\ell}\): zero almost everywhere (argmax) or undefined (a draw) - nothing reaches \(G\) from \(D\)
Three repairs and their trades
Score-function estimator: \(\nabla_{\boldsymbol{\ell}}\, \mathbb{E}[R] = \mathbb{E}\!\left[R \, \nabla_{\boldsymbol{\ell}} \log p(\text{token})\right]\), \(R\) = \(D\)’s score - unbiased, high variance, reduced with baselines and rollouts (SeqGAN)
Gumbel-softmax: \(\text{softmax}\!\left((\boldsymbol{\ell} + \mathbf{g}) / \tau\right)\)\(\mathbf{g}\) Gumbel noise - differentiable, biased for \(\tau > 0\), and \(D\) trains on soft tokens it never sees at test time
Embedding space: \(D\) scores the embedding \(G\) emits, no token drawn - a different game, the discrete output never judged
The same break appears wherever a categorical variable is sampled inside the graph - Gumbel-softmax is the categorical counterpart of reparameterization.
Comparing the Families
Each Family Trains Against a Different Divergence
Energy-based, maximum likelihood
\(\text{KL}(p_{\text{data}} \,\|\, p_{\boldsymbol{\theta}})\), forward - every data mode must be covered, at any cost in spread
Price: the negative phase, a sampling run inside every gradient
Variational autoencoder
The same forward KL, minus the posterior gap - a bound, tight only where \(q\) matches the posterior
Price: the gap, and averaged outputs wherever one mean must stand for several answers
Adversarial
At optimal \(D\): Jensen-Shannon - bounded, symmetric, and flat once the two distributions stop overlapping
In practice, with the non-saturating loss: reverse-KL behavior - sharp samples, dropped modes tolerated
One model family, three objectives
Forward KL covers both modes at every separation, reverse KL sits on one at every separation
Jensen-Shannon covers when the modes are close and drops one when they are far - a bounded divergence pays at most \(\log 2\) for the drop, and covering keeps costing more as the gap grows
The errors a model makes are set by the divergence its training minimizes - the architecture decides only how well it can minimize it.
Each Family Gives Up Something the Others Keep
Energy-based
Variational autoencoder
Adversarial
Density
known up to \(Z\)
a lower bound on \(\log p(\mathbf{x})\)
none
Inference of \(\mathbf{z}\)
by a Markov chain
one encoder pass
none, or a separately trained encoder
Training cost per update
~120 network passes (60-step Langevin)
4 passes
6 passes
Sampling cost
a chain, 60 steps and more
1 decoder pass
1 generator pass
Training signal
a biased gradient from a short chain
a bound that decreases
a game with no loss to read
Characteristic failure
chains stuck in one mode, spurious modes
posterior collapse, averaged outputs
mode collapse, oscillation
Selection
A number for held-out data, or a code for a given input - the variational autoencoder, and the price is the bound
Sharp samples in one pass with no need for a density - the adversarial family, and the price is a training run without a loss to trust
The score of the data density, or a likelihood at any cost - the energy-based family, and the price is the chain
Every cell in the table is a structural fact about the objective, not a benchmark - the choice follows from what the application has to report.
Diffusion Combines the Score and the Bound
Two lines meet
Score matching across noise levels, from the energy-based family - a learned \(\nabla_{\mathbf{x}} \log p_\sigma(\mathbf{x})\) at every \(\sigma\), no partition function, no chain during training
A hierarchical variational autoencoder with the encoder fixed to added noise - the same objective written as a lower bound, one KL term per noise level
Sampling: Langevin steps on the learned score at decreasing noise - the chain returns, at generation time only
Sampling cost returns
One sample costs \(T\) network passes, \(T\) in the hundreds to thousands - against one pass for a generator or a decoder
Distillation to a few steps is where the adversarial loss survives - the discriminator as a training signal for a fast sampler
Codes as tokens
A code-book index per position, from the VQ-VAE, and a learned model over the index grid - the bridge from images to models over token sequences
The families did not converge on a winner - the score, the bound, the code-book, and the discriminator each survive as a component of the models that followed.