Back to paper library
Paper notesarXiv 2017AISTATS 2018

VampPrior

Borrowing the Posterior's Blood

Original paper

VAE with a VampPrior

Paper authors

Jakub M. Tomczak · Max Welling

Publication
AISTATS 2018Conference
First submitted to arXiv
arXiv:1705.07120
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{imagegenerationvampprior2017,
  title = {{VAE with a VampPrior}},
  author = {Jakub M. Tomczak and Max Welling},
  year = {2017},
  eprint = {1705.07120},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1705.07120}
}
On this page

Train a VAE, draw a zz from N(0,I)\mathcal N(0,I), hand it to the decoder, and quite often you get back a blurry blob that doesn't look like anything.

The decoder has only learned to draw in the regions the encoder actually used. The standard normal is a prior we picked for the latent space because it is convenient to compute with, and the region it covers can be very different from the region the encoder really uses.

The authors of this paper are Jakub Tomczak and Max Welling of the University of Amsterdam; Welling is also one of the two authors of the original VAE paper. They replaced the prior with the Variational Mixture of Posteriors prior, VampPrior for short, which sounds like "vampire." The method really is a bit vampiric. The prior has no Gaussian parameters of its own; each of its components is an approximate posterior borrowed by feeding a "fake input" into the encoder.

This note first takes the KL term of the ELBO apart to find out what the prior is really being asked to do; then looks at how the authors approximate the best prior with K learnable fake images, along with the two-layer version; and finally at how far the evidence goes, and which parts need a discount.

Defining the Problem

What the prior governs in the ELBO

First, the notation. The training data is {x1,…,xN}\{x_1,\dots,x_N\}, and q(x)=1N∑nδ(x−xn)q(x)=\frac1N\sum_n\delta(x-x_n) is the empirical distribution, i.e., "draw an image uniformly from the training set." qϕ(z∣x)q_\phi(z|x) is the encoder (approximate posterior), pθ(x∣z)p_\theta(x|z) is the decoder, pλ(z)p_\lambda(z) is the prior, and ϕ,θ,λ\phi,\theta,\lambda are their respective parameters. Eq. (1) of the paper is the ELBO averaged over the whole training set:

L(ϕ,θ,λ) =Eq(x) Eqϕ(z∣x)[ln⁡pθ(x∣z)+ln⁡pλ(z)−ln⁡qϕ(z∣x)]\begin{aligned} &\mathcal L(\phi,\theta,\lambda)\\ &\ =\mathbb E_{q(x)}\,\mathbb E_{q_\phi(z|x)}\big[\ln p_\theta(x|z)\\ &\qquad+\ln p_\lambda(z)-\ln q_\phi(z|x)\big] \end{aligned}

The first term is the reconstruction term, and the last two together are −KL(qϕ(z∣x) ∥ pλ(z))-\mathrm{KL}\big(q_\phi(z|x)\,\|\,p_\lambda(z)\big).

The standard VAE fixes the prior to N(0,I)\mathcal N(0,I), with no λ\lambda to learn. The gradient of ln⁡N(z∣0,I)\ln\mathcal N(z|0,I) with respect to zz is −z-z, so whether the input is a 3 or a 7, the prior pulls zz toward the origin. The paper says this causes over-regularization, with worse latent representations and fewer useful dimensions.

Splitting the KL term in two

The authors follow the decomposition from Hoffman and Johnson's 2016 "ELBO surgery." Average the KL term over all the training data and first split it into two expectations:

Eq(x)[−KL(qϕ(z∣x) ∥ pλ(z))]=Eq(x) Eqϕ(z∣x)[−ln⁡qϕ(z∣x)]+Eq(x) Eqϕ(z∣x)[ln⁡pλ(z)]\begin{aligned} &\mathbb E_{q(x)}\big[-\mathrm{KL}(q_\phi(z|x)\,\|\,p_\lambda(z))\big]\\ &\quad=\mathbb E_{q(x)}\,\mathbb E_{q_\phi(z|x)}\big[-\ln q_\phi(z|x)\big]\\ &\qquad+\mathbb E_{q(x)}\,\mathbb E_{q_\phi(z|x)}\big[\ln p_\lambda(z)\big] \end{aligned}

The first expectation is the average entropy H[qϕ(z∣x)]H[q_\phi(z|x)] of the individual posteriors. It has nothing to do with the prior and simply encourages each image's posterior to be a little wider.

Only the second expectation involves the prior. Note that the integrand ln⁡pλ(z)\ln p_\lambda(z) doesn't depend on "which image" it is, so the NN posteriors can be summed first and integrated afterward:

1N∑n=1N∫qϕ(z∣xn)ln⁡pλ(z) dz=∫[1N∑n=1Nqϕ(z∣xn)]ln⁡pλ(z) dz=∫q(z)ln⁡pλ(z) dz\begin{aligned} &\frac1N\sum_{n=1}^N\int q_\phi(z|x_n)\ln p_\lambda(z)\,dz\\ &\quad=\int\Big[\frac1N\sum_{n=1}^N q_\phi(z|x_n)\Big]\ln p_\lambda(z)\,dz\\ &\quad=\int q(z)\ln p_\lambda(z)\,dz \end{aligned} q(z)=1N∑n=1Nqϕ(z∣xn)q(z)=\frac1N\sum_{n=1}^N q_\phi(z|x_n)

q(z)q(z) is called the aggregated posterior. Feed the whole training set into the encoder, and each image leaves a blob of posterior in latent space; add up all the blobs and divide by NN, and you get the region the encoder actually occupies.

At this point the prior has a single job left in the ELBO, which is to keep its cross-entropy with the aggregated posterior, Eq(z)[−ln⁡pλ(z)]\mathbb E_{q(z)}[-\ln p_\lambda(z)], as small as possible (Eqs. (4)–(6) of the paper).

The best prior

The cross-entropy can be split once more:

Eq(z)[−ln⁡pλ(z)]=H[q(z)]+KL(q(z) ∥ pλ(z))\begin{aligned} \mathbb E_{q(z)}\big[-\ln p_\lambda(z)\big]={}&H[q(z)]\\ &+\mathrm{KL}\big(q(z)\,\|\,p_\lambda(z)\big) \end{aligned}

H[q(z)]H[q(z)] doesn't depend on the prior; the KL divergence is greater than or equal to 0, and equals 0 only when the two distributions are identical. So with the encoder fixed, the prior that maximizes the ELBO is the aggregated posterior itself:

pλ∗(z)=1N∑n=1Nqϕ(z∣xn)p^*_\lambda(z)=\frac1N\sum_{n=1}^N q_\phi(z|x_n)

The paper solves for it with a Lagrange multiplier (Eqs. (7) and (8)) and gets the same result.

An example with two images

A small example shows how big the gap can be. Suppose the latent space is 2-dimensional, the training set has only two images, and the encoder sends them to N((−2,0), 0.12I)\mathcal N\big((-2,0),\,0.1^2 I\big) and N((2,0), 0.12I)\mathcal N\big((2,0),\,0.1^2 I\big) respectively.

Start with the standard normal prior. The KL between two Gaussians has a closed form, 12(σ2+μ2−1−ln⁡σ2)\frac12(\sigma^2+\mu^2-1-\ln\sigma^2) per dimension. Summed over the two dimensions:

12[(0.01+4−1+4.605)+(0.01+0−1+4.605)]≈5.615 nats\begin{aligned} &\tfrac12\big[(0.01+4-1+4.605)\\ &\quad+(0.01+0-1+4.605)\big]\\ &\approx 5.615\ \text{nats} \end{aligned}

Each image's KL is 5.615 nats.

Now use the aggregated posterior as the prior, that is, a mixture with half the weight on each of the two Gaussian blobs. For the first image, q(z)q(z) near its posterior is almost exactly 12qϕ(z∣x1)\frac12 q_\phi(z|x_1), so the KL drops to just ln⁡2≈0.693\ln 2\approx 0.693 nats. Those 0.693 nats are exactly the information needed to tell "which of the two" images it is.

The extra 5.615−0.693=4.9225.615-0.693=4.922 nats are KL(q(z) ∥ N(0,I))\mathrm{KL}(q(z)\,\|\,\mathcal N(0,I)). In general, when the prior equals the aggregated posterior, what remains of the KL term is the mutual information between zz and "which training image," at most ln⁡N\ln N.

The problem at generation time shows up here too. Sampling from N(0,I)\mathcal N(0,I), only about 1.2% of samples land within three standard deviations (radius 0.3) of either posterior blob; the rest land where the aggregated posterior is nearly zero, and at the origin, for instance, q(z)q(z) is about 10−8610^{-86}. The decoder was never trained in those places, and what it draws there is the blurry blob from the start of this note. Tomczak's blog later called such regions, where the prior assigns plenty of probability but the aggregated posterior is nearly zero, holes.

So why not just use the aggregated posterior?

The paper gives two reasons.

The first is computation. Every evaluation of ln⁡pλ∗(z)\ln p^*_\lambda(z) means computing the posteriors of all NN training images. Static MNIST has 50,000 training images, so every step would run the encoder 50,000 times.

The second is overfitting. The paper only says it "may potentially lead to overfitting," but the analysis above makes it more concrete. When the prior equals the aggregated posterior, the KL never exceeds ln⁡N\ln N however sharp each posterior blob gets, about 10.8 nats at N=50,000N=50{,}000; under a standard normal prior, the sharper the posterior, the larger the KL. So the model can safely put each training image on a spike of its own and let the decoder memorize every one. The ELBO on the training set looks great, but the model's distribution sits entirely on the training images, and test images get no probability.

The standard normal is too simple, and the aggregated posterior is too expensive and memorizes the answers. A common compromise is to make the prior a mixture of KK Gaussians (MoG), each component with its own learnable mean and variance. The authors include it in the experiments as a baseline, but what they propose is a different compromise.

Solving the Problem

K fake images

VampPrior replaces the NN training images with KK learnable pseudo-inputs (Eq. (9)):

pλ(z)=1K∑k=1Kqϕ(z∣uk)p_\lambda(z)=\frac1K\sum_{k=1}^K q_\phi(z|u_k)

uku_k is a DD-dimensional vector with the same shape as an input image; on MNIST it is a 28×2828\times28 fake image. The pseudo-inputs are trained by backpropagation along with the network weights, and the prior's parameters are λ={u1,…,uK,ϕ}\lambda=\{u_1,\dots,u_K,\phi\}, where ϕ\phi is shared with the encoder.

This formula looks exactly like the aggregated posterior, except that the sum runs over KK learned images instead of the real training images. The experiments use K=500K=500 (1,000 for OMNIGLOT), two orders of magnitude fewer than the 50,000 training images. With a limited number of components, the prior can't keep a spike for every training image; with enough components, it can still grow a multimodal shape and won't pull every posterior toward the same point.

In the two-image example, if K=2K=2 and u1,u2u_1,u_2 happen to be learned as those two images, VampPrior is exactly the aggregated posterior.

Putting the pseudo-inputs in image space has its costs. At every step, besides the batch of training images, the encoder has to run on KK more fake images; with batch 100 and K=500K=500, the encoder processes 600 images at a time. The parameters live in image space too. On MNIST, 500 fake images of 784 dimensions are 392,000 numbers, while a MoG prior with the same 500 components in a 40-dimensional latent space needs only 500×80=40,000500\times80=40{,}000 means and variances. In the wall-clock times measured in the supplementary material, compared with the standard normal prior, the MLP version is about 1.4 times slower, the convolutional version 1.9 times (K=500K=500) to 2.1 times (K=1000K=1000) slower, and the PixelCNN version 1.4 to 1.7 times slower.

What the implementation looks like

The official code writes the pseudo-inputs as a linear layer without bias whose input is the K×KK\times K identity matrix, with the output passed through a Hardtanh clamped to [0,1][0,1]. Multiplying the identity matrix by the weights just pulls out the weights themselves, so "learning pseudo-inputs" becomes "learning the weights of a linear layer," which any ordinary optimizer can update directly; Hardtanh keeps the fake images' pixel values within the range of real images.

ln⁡pλ(z)\ln p_\lambda(z) is the log of a mixture of KK Gaussians and needs logsumexp to avoid numerical underflow. Below is a version compiled from the official models/Model.py and models/VAE.py, rewritten for current PyTorch:

python
import math
import torch
import torch.nn as nn

class VampPrior(nn.Module):
    def __init__(self, encoder, K=500, D=784):
        super().__init__()
        self.encoder = encoder                    # the same encoder as q(z|x)
        self.pseudo = nn.Linear(K, D, bias=False) # column k of the weight is u_k
        nn.init.normal_(self.pseudo.weight, 0.05, 0.01)
        self.register_buffer("eye", torch.eye(K))

    def log_prob(self, z):                        # z: [B, M]
        u = torch.clamp(self.pseudo(self.eye), 0.0, 1.0)   # [K, D]
        mu, logvar = self.encoder(u)              # [K, M]
        # log density of a diagonal Gaussian; the official code drops -M/2·ln(2π), which cancels with ln q(z|x) in the KL
        log_comp = -0.5 * (logvar + (z[:, None] - mu) ** 2 / logvar.exp()).sum(-1)  # [B, K]
        return torch.logsumexp(log_comp, dim=1) - math.log(log_comp.shape[1])

# during training: z is one reparameterized sample from q(z|x)
# kl = log_normal_diag(z, mu_q, logvar_q) - prior.log_prob(z)

The KL term can only be estimated by sampling. A standard VAE can use the Gaussian-to-Gaussian closed form, but here the prior is a mixture, and the KL from a Gaussian to a Gaussian mixture has no closed form, so the official code computes ln⁡qϕ(z∣x)−ln⁡pλ(z)\ln q_\phi(z|x)-\ln p_\lambda(z) directly on the reparameterized zz. In 2021, someone asked in issue #5 whether the closed-form KL could be used instead; nobody has replied to this day.

To generate, pick a uku_k uniformly from the KK pseudo-inputs, feed it into the encoder to get qϕ(z∣uk)q_\phi(z|u_k), sample zz from that, and hand it to the decoder. The official generate_x simply takes the first NN pseudo-inputs and samples once from each; in 2019, someone asked in issue #3 how to sample from the prior itself, and in the end it was another user who answered: "uniformly sample one of the pseudo inputs u and then pass it through the encoder."

How it differs from a Gaussian mixture prior

A MoG prior is also multimodal and can also approximate the aggregated posterior. The difference is that VampPrior's components are produced by the encoder, which ties the prior to the posterior.

First, look at how the prior pulls on zz. The log-gradient of a mixture is a weighted average of the components' gradients:

∇zln⁡pλ(z)=∑k=1Krk(z) ∇zln⁡qϕ(z∣uk)\nabla_z\ln p_\lambda(z)=\sum_{k=1}^K r_k(z)\,\nabla_z\ln q_\phi(z|u_k) rk(z)=qϕ(z∣uk)∑j=1Kqϕ(z∣uj)r_k(z)=\frac{q_\phi(z|u_k)}{\sum_{j=1}^K q_\phi(z|u_j)}

rk(z)r_k(z) is the "responsibility" of component kk for zz; whichever component zz is close to gets the larger weight. Each component is a diagonal Gaussian, with ∇zln⁡qϕ(z∣uk)=−(z−μk)/σk2\nabla_z\ln q_\phi(z|u_k)=-(z-\mu_k)/\sigma_k^2 (element-wise), where μk,σk2\mu_k,\sigma_k^2 are the encoder's outputs on uku_k. So the prior pulls zz toward nearby component centers, unlike the standard normal prior's −z-z, which always pulls toward the origin. Back in the two-image example, a zz near (2,0)(2,0) gets pulled toward (2,0)(2,0), not toward the origin.

A MoG prior can do this too. What VampPrior adds is a gradient with respect to the encoder parameters ϕ\phi. Eq. (25) of the supplementary material expands the gradient of the KL term with respect to a single weight ϕi\phi_i, and every component carries a difference of the form qϕ(z∣x) ∂qϕ(z∣uk)−qϕ(z∣uk) ∂qϕ(z∣x)q_\phi(z|x)\,\partial q_\phi(z|u_k)-q_\phi(z|u_k)\,\partial q_\phi(z|x). If some uku_k closely resembles xx, the two posteriors are computed by the same encoder, so when ϕ\phi changes they move together, and this difference is close to 0. What gradient remains comes mainly from the pseudo-inputs that don't resemble xx.

The authors' reading is that under the standard normal prior the gradient always pulls the posterior toward 0 (supplementary Eq. (26)); under VampPrior, the components that resemble the input exert no pressure, so the encoder tends to assign different data to different regions of the latent space. The paper also views the pseudo-inputs as hyperparameters of the prior, learned by maximizing the ELBO, the same idea as empirical Bayes (type-II maximum likelihood).

The two-layer version

The prior's problems are worse in multilayer VAEs. The IWAE paper measured a statistic, the "activity" of latent dimension uu, Au=Covx(Eu∼q(u∣x)[u])A_u=\mathrm{Cov}_x\big(\mathbb E_{u\sim q(u|x)}[u]\big), i.e., how much the posterior mean varies with the input; a unit counts as active only if Au>0.01A_u>0.01. They found that the second layer of two-layer models was barely used, with fewer than 10 of its 50 dimensions active.

The paper's explanation is that generation runs top-down while inference runs bottom-up, so the deeper a latent layer sits, the less information from the real data it receives, and the more easily the KL term squashes it into the prior.

Two sets of probabilistic graphical models. (a) Single-layer VAE: the generative part is a solid arrow from z to x, and the inference part is a dashed arrow from x to z. (b) Two-layer model: in the generative part, z2 points to z1 and z1 points to x, with another solid line curving from z2 directly to x; in the inference part, x points to z1, x points directly to z2 along a curved dashed line, and a dashed arrow runs from z2 to z1.
Original Figure 1, Tomczak and Welling, from PDF page 4, arXiv license, scholarly quotation.

On the right, (b) is the authors' two-layer model; solid lines are generation and dashed lines are inference (Eqs. (10)–(15)):

  • Inference first computes the top layer qψ(z2∣x)q_\psi(z_2|x) directly from xx, then computes qϕ(z1∣x,z2)q_\phi(z_1|x,z_2) from xx and z2z_2 together.
  • Generation starts from p(z2)p(z_2), goes through pλ(z1∣z2)p_\lambda(z_1|z_2), and the final decoder pθ(x∣z1,z2)p_\theta(x|z_1,z_2) takes both z1z_1 and z2z_2.
  • VampPrior sits only at the top layer, p(z2)=1K∑kqψ(z2∣uk)p(z_2)=\frac1K\sum_k q_\psi(z_2|u_k).

All conditional distributions are diagonal Gaussians. The structure makes two deliberate choices. The top-layer posterior looks only at xx, so feeding uku_k straight into the z2z_2 encoder gives the prior's components, with no need to sample a z1z_1 for the fake image first. The decoder also takes z2z_2 directly (the curved solid line in the figure), so z2z_2 has a direct path to xx and is more than just a prior for z1z_1.

The ELBO of the whole model is:

L=Eq[ln⁡pθ(x∣z1,z2)+ln⁡pλ(z1∣z2)+ln⁡p(z2)−ln⁡qϕ(z1∣x,z2)−ln⁡qψ(z2∣x)]\begin{aligned} \mathcal L=\mathbb E_{q}\big[&\ln p_\theta(x|z_1,z_2)\\ &+\ln p_\lambda(z_1|z_2)+\ln p(z_2)\\ &-\ln q_\phi(z_1|x,z_2)-\ln q_\psi(z_2|x)\big] \end{aligned}

Inside the expectation, first sample z2∼qψ(z2∣x)z_2\sim q_\psi(z_2|x), then z1∼qϕ(z1∣x,z2)z_1\sim q_\phi(z_1|x,z_2). The official code draws a single set of samples per image and simply adds up the five log densities.

Experimental setup

All six datasets are small images. Static MNIST uses a fixed binarization and dynamic MNIST is re-binarized every time during training; the rest are OMNIGLOT (50 alphabets, 1,623 handwritten characters), Caltech 101 Silhouettes (black silhouettes of objects from 101 classes, with only 4,100 training images), Frey Faces (one person's face, about 2,000 images, 28×2028\times20) and Histopathology (grayscale patches of tissue sections). The first four use Bernoulli decoders and the last two a discretized logistic distribution.

The main architecture is an MLP, with two gated fully connected layers of 300 units for each distribution and 40 dimensions each for z1z_1 and z2z_2, a permutation-invariant setting that doesn't exploit the spatial structure of images. Two other versions replace the MLP with gated convolutions (convHVAE), and additionally replace the decoder with a PixelCNN (PixelHVAE).

Training uses Adam with learning rate 10−410^{-4} or 5×10−45\times10^{-4} and batch size 100. Warm-up runs over the first 100 epochs, with the weight of the KL term rising linearly from 0 to 1; early stopping uses a look-ahead window of 50 epochs.

Evaluation uses the marginal log-likelihood on the test set, estimated by importance sampling with 5,000 samples, in nats, where closer to 0 is better. Frey Faces and Histopathology report bits/dim instead, where lower is better.

Discussion

Swapping the prior, once for each architecture

Table 1 trains each of the four architectures once with the standard normal prior and once with VampPrior. The original table has eight columns; here it is split into two, with each cell reading "standard normal / VampPrior."

DataVAEHVAE
static MNIST−88.56 / −85.57−86.05 / −83.19
dynamic MNIST−84.50 / −82.38−82.42 / −81.24
OMNIGLOT−108.50 / −104.75−103.52 / −101.18
Caltech 101−123.43 / −114.55−112.08 / −108.28
Frey Faces4.63 / 4.574.61 / 4.51
Histopathology6.07 / 6.045.82 / 5.75
DataconvHVAEPixelHVAE
static MNIST−82.41 / −81.09−80.58 / −79.78
dynamic MNIST−80.40 / −79.75−79.70 / −78.45
OMNIGLOT−97.65 / −97.56−90.11 / −89.76
Caltech 101−106.35 / −104.22−85.51 / −86.22
Frey Faces4.49 / 4.454.43 / 4.38
Histopathology5.59 / 5.584.84 / 4.82

Compiled from Table 1 of the paper. The first four rows are log-likelihoods (nats), the last two bits/dim.

The two MLP columns show the clearest gains. The single-layer VAE improves by about 3 nats on static MNIST and about 8.9 nats on Caltech 101; the two-layer HVAE also gains 1.2 to 3.8 nats.

The stronger the decoder, the less swapping the prior does. convHVAE differs by only 0.09 nats on OMNIGLOT; PixelHVAE's gains fall between 0.35 and 1.25 nats, and Caltech 101 is the only cell in the whole table that goes backward, from −85.51 to −86.22. The supplementary material mentions that PixelHVAE's reconstructions sometimes show "fantasizing," strokes that aren't in the original image, which the authors put down to the decoder being too strong and ignoring part of the latent information. When the decoder can draw the image well on its own, there was never much room for the latent prior to improve things.

There's one more thing to watch for in this table. The paper only says that the standard deviation on Frey Faces is no more than 0.03 (over 3 repeats); the other datasets have no error ranges at all. For convHVAE's gaps of less than 0.1 on OMNIGLOT and Histopathology, it's hard to tell whether they are anything more than random variation.

Controls for the prior

If VampPrior works, is it because it is multimodal, because it is tied to the posterior, or because the pseudo-inputs are learnable? Table 2, on static MNIST, swaps four different priors into the top layer of the two-layer HVAE:

ModelLog-likelihood
Two-layer VAE (from the IWAE paper)−87.86
Two-layer IWAE (from the IWAE paper)−85.32
HVAE + standard normal−85.89
HVAE + MoG−85.07
HVAE + VampPrior data−85.71
HVAE + VampPrior−83.19

Compiled from Table 2 of the paper.

VampPrior data uses a random batch of real training images as fixed, non-trainable pseudo-inputs. The four HVAE rows can be read like this:

  1. The structure itself contributes. With the same standard normal prior, the authors' HVAE (−85.89) beats the two-layer VAE from the IWAE paper (−87.86) by nearly 2 nats. The two differ in dimensions and networks, so these 2 nats can't be credited to the prior.
  2. Multiple modes help. MoG beats the standard normal by 0.82 nats.
  3. Real images as components help very little. VampPrior data beats the standard normal by only 0.18 nats, and loses to MoG.
  4. Learnable pseudo-inputs are the main source. VampPrior beats the standard normal by 2.70 nats and MoG by 1.88 nats.

Point 3 is a bit surprising. Randomly picked real images look like they should be a decent approximation of the aggregated posterior, yet they turn out to be almost useless; the pseudo-inputs have to be learned together with the encoder to end up in the right places.

Line chart with the number of pseudo-inputs or mixture components K, from 0 to 1000, on the horizontal axis and the ELBO, from −94.5 to −90.5, on the vertical axis. The blue horizontal line is HVAE with the standard normal prior, at about −94.4. The red line is the MoG prior, roughly flat around −92.4, slowly dropping to about −92.8 once K passes 500. The green line is VampPrior: about −92.6 at very small K, rising to −91.25 by K of about 100, peaking at about −90.6 at K equal to 500, then falling to about −90.9 at K equal to 1000.
Original Figure 2, Tomczak and Welling, from PDF page 5, arXiv license, scholarly quotation.

This figure sweeps over KK, with the test-set ELBO on the vertical axis. The ELBO is a lower bound, several nats below the importance-sampled log-likelihoods in Table 2, but the three lines can be compared with one another.

The blue line is the standard normal prior, which has no KK to tune, at about −94.4. The red MoG line is flat around −92.4 from very small KK onward, and drops past 500. The green VampPrior line is about level with MoG at very small KK, climbs as KK grows to −90.6 at 500, and then slips back to −90.9 as more are added. The authors themselves say they were somewhat surprised that more pseudo-inputs didn't help. This sweep was run only on static MNIST, and the paper doesn't answer whether the number 500 carries over to other datasets.

Latent dimensions woken up

Line chart with the number of pseudo-inputs K, from 0 to 1000, on the horizontal axis and the number of active units (A_z ≥ 0.01), from 5 to 40, on the vertical axis. The solid blue line is the VAE's z1, fixed at 17; the dashed blue line is the VAE's z2, fixed at 6. The solid red line is IWAE's z1, fixed at 24; the dashed red line is IWAE's z2, fixed at 7. The solid green line is VampPrior's z1, about 36 to 37; the dashed green line is VampPrior's z2, about 19 at the smallest K, peaking at about 29 at K equal to 500, and about 26 at K equal to 1000.
Original Figure 3, Tomczak and Welling, from PDF page 7, arXiv license, scholarly quotation.

This figure counts active units. Solid lines are the first layer z1z_1, closest to xx, and dashed lines are the top layer z2z_2; blue and red are the VAE and IWAE, and green is HVAE with VampPrior.

VampPrior's z1z_1 has 36 to 37 active units, and its z2z_2 has 29 at K=500K=500. The VAE's two layers have 17 and 6, IWAE's 24 and 7. According to the paper, the top layer's active units quadruple and the first layer's grow about 1.5 times; even with a single component, the top layer has nearly three times as many.

This comparison needs a discount. The blue and red lines are horizontal lines taken from the appendix of the IWAE paper (fixed-binarization MNIST), whose models had latent layers of 100 and 50 dimensions and a different network altogether; the green line is the authors' own 40 + 40-dimensional HVAE, with both the inference and the generative structure changed. The figure has no line for HVAE with a standard normal prior (exactly the one line that most needed to be there), so how much of the "quadrupling" comes from the prior and how much from the structure can't be read off this figure.

The K=1K=1 point makes this even clearer. With only one component, VampPrior is just a diagonal Gaussian with a learnable mean and variance; the shift and scale of such a prior can be absorbed by the first linear layer of the network that follows, so the models it can express are roughly the same as with a standard normal prior. In this setting the top layer already has around 19 active units, and the excess over IWAE's 7 more likely comes from the authors' two-layer structure and from differences in latent dimensions and training settings between the two.

Against the strongest models of the time

In the permutation-invariant MLP setting, HVAE with VampPrior is the best in the table on all four datasets; in parentheses is the best of the other papers' methods in the table. Static MNIST −83.19 (VAE + NF −85.10), dynamic MNIST −81.24 (VAE + VGP −81.32), OMNIGLOT −101.18 (Ladder VAE −102.11), Caltech 101 −108.28 (VR-max −117.10).

With convolutional and PixelCNN decoders, the comparison shifts to models that also use convolutional or autoregressive decoders, such as VLAE, IAF and PixelVAE. PixelHVAE reaches −78.45 on dynamic MNIST, slightly better than VLAE's −78.53 and PixelVAE's −78.96; on OMNIGLOT it is −89.76 against VLAE's −89.83, a 0.07-nat difference that amounts to a tie. On static MNIST, VLAE's −79.03 beats PixelHVAE's −79.78, and the paper explains in a footnote that VLAE used a different training procedure on this dataset.

What the fake images look like

Two rows of image grids for five datasets, from left to right MNIST, Omniglot, Caltech 101 Silhouettes, Frey Faces and Histopathology. The top row shows 5×5 samples generated by PixelHVAE with VampPrior from one pseudo-input, with the chosen pseudo-input in the top-left cell: the MNIST set is all 8s with different stroke widths and slants, and the Frey Faces set is the same face with different expressions. The bottom row shows the trained pseudo-inputs: MNIST and Omniglot show blurry stroke outlines, while most cells for Caltech 101 Silhouettes, Frey Faces and Histopathology look like gray noise.
Original Figure 4, Tomczak and Welling, from PDF page 8, arXiv license, scholarly quotation.

Each set in the top row is 24 images generated from the same pseudo-input (the top-left cell). The MNIST set is all 8s, but with different thicknesses, slants and loop sizes; the Frey Faces set is the same face with different expressions. There is enough variation under a single component that the model is not just copying out some training image.

The bottom row is the trained pseudo-inputs. The paper calls them "prototypical objects (digits, characters, silhouettes)." MNIST and Omniglot do show blurry strokes, while the Caltech 101 Silhouettes column looks like TV static (so where are the silhouettes?). In the main text the authors admit that the Frey Faces pseudo-inputs are noisy, and say that pseudo-inputs are hard to train when the sample is small or the decoder too flexible. Caltech 101 has only 4,100 training images, and it is also exactly the dataset on which PixelHVAE went backward in Table 1 after switching to VampPrior. Whether the two share a cause, the paper ran no experiment to check.

Tomczak also wrote later, in the blog post "VAE priors," that the main drawback of the VampPrior lies in initializing the pseudo-inputs. On MNIST, the official code by default starts from nearly black images drawn from N(0.05, 0.012)\mathcal N(0.05,\,0.01^2), with a separate option to initialize from training images.

Later fixes

The paper closes by mentioning that Alemi et al. replaced the uniform weights 1K\frac1K with learnable wkw_k (Eq. (16) of the paper), letting the model decide which pseudo-inputs are useful. The 2020 Exemplar VAE went the other way and simply used the whole training set as mixture components, computing only a few nearby components via approximate nearest-neighbor search and using leave-one-out to keep the model from memorizing the training images; this is exactly the aggregated posterior that VampPrior had rejected as too expensive and prone to overfitting.

In October 2026, "VampPrior Unleashed" (Stirn et al.) went after the very advantage this paper emphasized back then, the tying of prior and posterior. Each VampPrior component uses the variance output by the encoder directly, so the same set of parameters has to produce two kinds of distributions with opposite requirements. The posterior has to be sharp (low entropy) for reconstruction to be accurate; the prior's components have to be wide (high entropy) to cover the whole aggregated posterior. They split each component's covariance off into an independently learnable Σk\Sigma_k, with the mean still computed by the encoder on uku_k. Across 36 settings covering MNIST and FashionMNIST, three initialization schemes and K≥10K\ge10, the decoupled version was better on average in every one, with gains in log marginal likelihood of up to 3.6 nats.

Conclusion

The best prior is the aggregated posterior, which you can see just by taking the ELBO apart; VampPrior turns it into an approximation that can actually be trained, passing KK learnable fake images through the encoder once each and mixing the results into the prior. On MLP architectures it brings gains of 1 to 9 nats on four binary-image datasets and lowers bits/dim on both grayscale datasets; combined with the authors' two-layer structure, it posted the best numbers in the table for the permutation-invariant setting of the time. Once the decoder becomes a PixelCNN, the gains shrink to around 1 nat, and Caltech 101 even goes backward; and the quadrupling of active units has differences in structure and setup mixed into it.

To try it on your own VAE, the only thing to change is the prior function; neither the encoder nor the decoder needs touching. Compute ln⁡p(z)\ln p(z) with logsumexp and switch the KL to a sampled estimate; initialize the pseudo-inputs from training images, and after training plot them and take a look, because if all you see is noise, they didn't learn anything. Leave room for longer training too, since at K=500K=500 the encoder processes 500 extra images at every step.

In November of the same year, DeepMind's VQ-VAE went the opposite way, training with a uniform discrete prior and only fitting a PixelCNN to learn the real prior after the encoder was done training.