Very Deep VAEs Generalize Autoregressive Models and Can Outperform Them on Images
- Publication
- ICLR 2021Conference
- First submitted to arXiv
- arXiv:2011.10650
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{imagegenerationvdvae2020,
title = {{Very Deep VAEs Generalize Autoregressive Models and Can Outperform Them on Images}},
author = {Rewon Child},
year = {2020},
eprint = {2011.10650},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2011.10650}
}
A color image is 3,072 numbers. An autoregressive model like PixelCNN generates it one number after another, so the network has to run 3,072 times; a VAE decodes the whole image from its latent variables in one go, so the network runs just once.
Intuitively, a model with latent variables ought to be closer to how images actually come about. Behind a photo there are a scene, objects, poses and lighting, and the pixels are merely their result; an autoregressive model only builds dependencies between pixels and has to lean on a very strong network to piece together long-range relationships. Yet ever since PixelCNN in 2016, autoregressive models had stayed at the top of the log-likelihood leaderboard.
This paper has a single author, Rewon Child of OpenAI. Child wanted to know whether the autoregressive assumption really suits images better, or whether VAEs simply weren't deep enough.
This note first looks at how the paper proves that "a deep enough VAE contains autoregressive models," then at the stabilization techniques an architecture needs to stack 78 stochastic layers, and finally reads the numbers, along with how far they are from the title.
Defining the problem
Autoregressive models are VAEs too
An autoregressive model breaks the probability of an image into a chain of conditional probabilities, each pixel conditioned on all the pixels before it:
A hierarchical VAE instead arranges its latent variables in several layers. The paper uses a top-down VAE, in which both the prior and the approximate posterior start from the top layer and generate layer by layer in the same order:
Here sits at the top, a small number of low-resolution latent variables; sits at the bottom, at the highest resolution. The paper says this structure was introduced by Sønderby et al., that is, Ladder VAE. On top of that, VDVAE requires the decoder to be independent across pixels, so that generation time doesn't grow with the number of pixels.
The paper's Proposition 1 says that when the number of stochastic layers equals the data dimension , a VAE like this can represent any autoregressive model. Let's walk through it with an image of only 4 pixels, .
Prepare 4 layers of latent variables, each holding a single number . The encoder learns nothing and just copies the pixels, ; the decoder copies them straight back, . Pixel values are discrete, from 0 to 255, so these are legitimate probabilities.
Plug this setup into the ELBO:
- , since the decoder is guaranteed to copy correctly.
- , since the encoder is guaranteed to copy correctly too.
- What remains is . Since , this is exactly .
The approximate posterior puts all its probability on , and so does the true posterior; the two are equal, so the ELBO's inequality becomes an equality. The log-likelihood of the whole VAE is exactly the log-likelihood that the prior, an autoregressive model, assigns to the pixels. In other words, a 3,072-layer VAE whose encoder can do nothing but copy is a PixelCNN.

The left figure is the construction we just built. The latent variables are identical to the pixels, and all the autoregressive work is handed to the prior .
The right figure is what the author really hopes for. The encoder learns a more compact set of latent variables (the black squares); if the three at the bottom are conditionally independent of one another given the one on top, they can be generated in parallel within the same layer, and the whole generation process takes only two layers.
So the VAE family already contains autoregressive models; it's just that representing one in the dumbest possible way takes a stack as deep as the data dimension. Proposition 2 adds that an -layer VAE can approximate any -dimensional latent distribution, because the layer-by-layer prior and posterior form an autoregressive flow along the depth direction. The author also admits that every layer uses a Gaussian, which limits the distributions it can actually express.
Not deep enough?
From these two propositions, the author draws an explanation. Autoregressive models win because they are deeper, in the sense of statistical dependence: a 32×32 image takes 3,072 steps. If there really are latent variables of dimensions that describe images more efficiently, a -layer VAE is enough; but nobody knows what is, and it may be far deeper than past VAEs.
Hierarchical VAEs at the time mostly had no more than 3 layers. BIVA used 15, IAF-VAE 12, and NVAE, a few months earlier, 30.
So this paper sets out to test two things. Does adding only stochastic layers, with no extra parameters, improve log-likelihood? And once stacked past 70 layers, can a VAE beat PixelCNN? Answering them first requires an architecture that trains stably with more than 70 layers.
Solving the problem
Architecture

The author says no existing VAE implementation could hold up under that many stochastic layers, so the author rewrote a minimal VAE from scratch, with nothing but convolutions, nonlinearities and Gaussian stochastic layers, for a single purpose: letting stochastic layers keep piling on.
The left side shows the whole. The bottom-up path is a chain of res blocks, with average pooling at each change of resolution; the top-down path is a chain of topdown blocks, with nearest-neighbor upsampling at each change of resolution. The res block is ResNet's bottleneck structure, four convolutions of , , and , each preceded by a GELU.
At the lower right is the topdown block, and each topdown block is one stochastic layer. Take the ImageNet-32 setting through it: the trunk is 512 channels wide, the bottleneck 128, and each layer's latent variables have 16 channels. Say we are at a layer and the decoder trunk's current state is a feature map, which we'll call .
- Approximate posterior. Concatenate with the bottom-up path's features at (also 512 channels) into 1,024 channels, pass them through a four-convolution bottleneck, and output 32 channels, the first 16 being the mean and the last 16 . This is , with shape .
- Prior. Pass alone through another bottleneck that outputs channels: the prior's mean, its , and a feature map to add back to the trunk. The last convolution of this branch is initialized to 0, so at the start of training the prior is a standard normal and what gets added back to the trunk is 0.
- Sample. During training is sampled from the approximate posterior; during generation, from the prior. Both are diagonal Gaussians, so this layer's KL is computed directly in closed form.
- Write back to the trunk. goes through a convolution back to 512 channels and is added to , which passes through one more res block before going to the next layer.
In the official code, only one copy of the bottom-up features is kept per resolution, and all the topdown blocks at that resolution share it; that is what the left side of Figure 3 draws, with a single arrow per resolution heading right and splitting among several topdown blocks.
Set against the two generations before it, where Ladder VAE merges the prior and the evidence from the data with precision weighting and NVAE has the approximate posterior predict a shift relative to the prior, VDVAE simply concatenates the trunk state with the bottom-up features and computes the approximate posterior's parameters with convolutions.
Of ImageNet-32's 78 layers, 2 are at , 5 at , 10 at , 20 at and 41 at . With 16 channels per layer, there are about 765,000 latent variables in all, 250 times the image's dimension, 88% of them at the level. The top of the trunk starts from a learnable constant tensor.
The main text of the paper doesn't say what distribution the decoder uses. The official code uses PixelCNN++'s discretized logistic mixture, with 10 components per pixel and pixels independent given .
No warm-up needed
Ladder VAE and NVAE both use KL warm-up, and NVAE adds KL balancing on top. VDVAE uses neither, and no free bits either. The author says that with nearest-neighbor upsampling as the unpool, combined with the residual structure, no posterior collapse was observed.

This is a 73-layer network on ImageNet-32, trained for 80k steps. The horizontal axis is the layer index, starting from the low-resolution layers at the top; the vertical axis is the KL accumulated from layer 0 up to that layer, in bits/dim. Wherever a stretch of the curve is flat, those layers encode no information, which means they have collapsed to the prior.
- The green line removes the residual connections from the res blocks in the top-down path. The first 45 layers all collapse, and its ELBO is the worst, 3.42.
- The orange line replaces the upsampling with a learnable transposed convolution. The first 13 layers collapse, ELBO 3.30.
- The blue line is the official setting, nearest-neighbor upsampling. Information comes in from the very first layer, and its ELBO is the best, 3.27.
What the caption leaves out is that the blue line goes flat too after about layer 55, so at this point in training the last dozen or so layers also encode no information. The collapse has moved from the top to the bottom.
Residual initialization
Once you stack dozens of layers, the first problem is that values grow as they keep adding up. Every res block adds its output back to the trunk; if each block's output has variance , then after blocks the trunk's variance accumulates to roughly .
The author's fix is to multiply the weights of the last convolution in each bottleneck by , where is the depth. The output shrinks by a factor of and the variance by , so blocks added together still come to about . The official code does this for the res blocks of both the bottom-up and top-down paths, and for the projection of .
The appendix compares training with and without this scaling, at various depths, giving the loss and the number of skipped updates after 80k steps:
| Depth | Unscaled | Skipped | Scaled | Skipped |
|---|---|---|---|---|
| 15 | 2.50 | 13 | 2.51 | 0 |
| 30 | 2.36 | 41 | 2.38 | 1 |
| 45 | 2.31 | 48 | 2.30 | 0 |
| 60 | 2.30 | 76 | 2.29 | 1 |
| 75 | Diverged | − | 2.28 | 0 |
Compiled from Table 3 of the paper.
For shallow networks, adding the scaling actually makes things slightly worse; from 45 layers up, the scaled version is better, and almost no updates get skipped. The unscaled 75-layer network simply diverges.
Gradient skipping
The author writes that VAEs have notorious "optimization difficulties," which are "not frequently discussed in the literature but nevertheless well-known by practitioners." Partway through training, a huge reconstruction loss or KL suddenly appears, the gradient norm can reach as high as , and a single update wrecks the network.
VDVAE's countermeasure is blunt. At every step it first computes the gradient norm, and if the norm exceeds a threshold, the whole step is skipped without any update. The thresholds are set high, so fewer than one in ten thousand updates get skipped, yet this almost eliminates divergence. The threshold per dataset is 400 for CIFAR-10, 300 for ImageNet-32, 380 for ImageNet-64, 180 for FFHQ-256 and 500 for FFHQ-1024.
Here is the official code's training step, excerpted and simplified (with the multi-GPU statistics synchronization left out):
stats = vae.forward(x, x_target) # elbo = distortion + rate, in nats/dim
stats['elbo'].backward()
# returns the total norm before clipping; also clips the gradients to grad_clip
grad_norm = torch.nn.utils.clip_grad_norm_(vae.parameters(), H.grad_clip).item()
has_nan = torch.isnan(stats['distortion']).any() or torch.isnan(stats['rate']).any()
if not has_nan and grad_norm < H.skip_threshold:
optimizer.step()
update_ema(vae, ema_vae, H.ema_rate) # EMA weights move only when an update really happens
Two things here aren't in the paper. First, besides skipping, the code also clips gradients. A step whose gradient norm falls between grad_clip (200 for CIFAR-10) and skip_threshold (400) is first clipped to 200 and then applied. Second, a step is also skipped whole whenever the loss contains NaN.
Other settings
- Optimizer. The paper says Adam; the official code uses FusedAdam in its AdamW form, with and a linear warm-up over the first 100 steps. CIFAR-10 uses a learning rate of and weight decay 0.01; ImageNet and FFHQ-256 use , and FFHQ-1024 .
- EMA. Evaluation and sampling use an exponential moving average of the weights. The author said on GitHub that late in training, EMA helps both log-likelihood and sample quality noticeably.
- Compute. CIFAR-10 trains for 6 days on 2 V100s; every other dataset trains for about 2.5 weeks on 32 V100s.
| Dataset | Layers | Params | Batch |
|---|---|---|---|
| CIFAR-10 | 45 | 39M | 32 |
| ImageNet-32 | 78 | 119M | 256 |
| ImageNet-64 | 75 | 125M | 128 |
| FFHQ-256 | 62 | 115M | 32 |
| FFHQ-1024 | 72 | 115M | 32 |
Compiled from Table 4 of the paper.
Discussion
Does depth alone help?
The first experiment pulls "depth" and "parameter count" apart. On ImageNet-32, the author fixes a network of 48 blocks and 41 million parameters, and uses a trick to reduce the number of stochastic layers.
Normally the -th topdown block takes input and outputs , and the next block's latent variables are conditioned on this block's sample. If consecutive blocks are all given the same input , they see exactly the same thing and their latent variables no longer condition on one another, so they effectively merge into one stochastic layer with times as many latent variables. Not a single parameter is lost, but the statistical depth drops to of what it was.
| Stochastic depth | Test loss |
|---|---|
| 3 | 4.30 |
| 6 | 4.18 |
| 12 | 4.06 |
| 24 | 3.98 |
| 48 | 3.95 |
Compiled from the left half of Table 1 of the paper, ImageNet-32, 600k training steps.
With the same parameter count and only the number of stochastic layers changing, the loss falls all the way from 4.30 to 3.95. The gain from 24 to 48 layers is smaller, but it is still a gain, and 48 layers was already deeper than anything the literature had tried at the time.
The right half of the same table spreads the 48 layers over five resolutions, , , , and , in different proportions. The more of them go to high resolutions, the better, from 3.98 for 10, 10, 10, 10, 8 to 3.95 for 16, 16, 10, 4, 2. The author's reading is that global features may take up less information than local details and textures, so high resolutions need lots of latent variables.
Main results
| Model | Type | Params | bits/dim |
|---|---|---|---|
| CIFAR-10 | |||
| PixelCNN++ | AR | 53M | 2.92 |
| PixelSNAIL | AR | 2.85 | |
| Sparse Transformer | AR | 59M | 2.80 |
| BIVA | VAE | 103M | ≤ 3.08 |
| NVAE | VAE | 131M | ≤ 2.91 |
| VDVAE | VAE | 39M | ≤ 2.87 |
| ImageNet-32 | |||
| Gated PixelCNN | AR | 177M | 3.83 |
| Image Transformer | AR | 3.77 | |
| Flow++ | Flow | 169M | ≤ 3.86 |
| NVAE | VAE | 268M | ≤ 3.92 |
| VDVAE | VAE | 119M | ≤ 3.80 |
| ImageNet-64 | |||
| Gated PixelCNN | AR | 177M | 3.57 |
| SPN | AR | 150M | 3.52 |
| Sparse Transformer | AR | 152M | 3.44 |
| Flow++ | Flow | 73M | ≤ 3.69 |
| VDVAE | VAE | 125M | ≤ 3.52 |
Compiled from Table 2 of the paper. AR is an autoregressive model, whose sampling runs the network times; VAE and Flow need only one run. The parameter counts of PixelCNN++ and Gated PixelCNN are the author's estimates.
First, against VAEs. VDVAE gets 2.87 on CIFAR-10, better than NVAE's 2.91, with only 30% of its parameters; on ImageNet-32 it gets 3.80 to NVAE's 3.92, with less than half the parameters.
Next, against the PixelCNN branch. On CIFAR-10, PixelCNN++ has 2.92, and on ImageNet, Gated PixelCNN has 3.83 and 3.57; VDVAE beats all three, with roughly 30% fewer parameters. The abstract's claim that it "outperforms the PixelCNN in log-likelihood on all natural image benchmarks" holds up on the table.
But the same table has other autoregressive models too. On CIFAR-10, PixelSNAIL has 2.85 and Sparse Transformer 2.80; on ImageNet-32, Image Transformer has 3.77; on ImageNet-64, Sparse Transformer has 3.44, and SPN ties VDVAE at 3.52. VDVAE beats none of these (so the "Them" in the title's "Can Outperform Them" turns out to mean the PixelCNN branch). The paper honestly lists all of these stronger models in its table, and the main text limits its claims to PixelCNN-type models and non-autoregressive models; only the title is written more broadly.
At high resolution, VDVAE gets 0.61 on FFHQ-256 (5-bit), where the NVAE paper itself reports 0.69. FFHQ-1024 is full 8-bit color, and VDVAE gets 2.42 there, with no other model in the table to compare against. The author says the same network can go from to just by adding a few upsampling layers, training for about the same number of steps with about the same resources (32 GPUs, roughly 2.5 weeks); for an autoregressive model to generate a megapixel image, the network has to run more than a million times.
The "thousands of times faster" sampling is counted by the paper in network evaluations, against 1; actual sampling time isn't measured separately.
The learned hierarchy

This figure answers the question from the beginning, whether VDVAE really learns a representation more compact than pixels. Each row corresponds to one FFHQ image. The latent variables up to a given resolution are taken from the approximate posterior, meaning they really are encoded from this image; the rest are sampled from the prior at low temperature. Above are the resolutions; below, the latent variables up to that resolution as a cumulative fraction of all latent variables.
Using only the latent variables (less than one in a hundred thousand), you get an average face with little connection to the original. Add , still only 0.03% cumulatively, and the hairstyle, glasses, clothing color and overall composition are settled. By , at 1.1% cumulatively, the outline of the face and the positions of the features are fixed; at , 9.5% cumulatively, details like age and expression finally appear, and this is where the second row turns from a young face into an older one. The remaining ninety percent or so of the latent variables, at and above, take care of strands of hair, skin texture and background details.
This is exactly what the right side of Figure 2 was hoping for. The latent variables that decide global structure are few; the high-resolution latent variables, which make up the vast majority, look spatially independent of one another and can be generated in parallel within a few layers. The author believes this learned, parallel, multiscale way of generating may be why VDVAE can beat PixelCNN on log-likelihood with fewer parameters and faster sampling. This is the author's conjecture; the paper makes only a qualitative observation with this figure.
Official code and reproduction
The official code is released under the MIT license, with checkpoints for every dataset, and the README lists what each checkpoint should score, for example 2.6364 nats/dim for ImageNet-32, which is 3.80 bits/dim. CIFAR-10 comes with models from four seeds, at 2.879, 2.842, 2.898 and 2.864, averaging 2.87. Work it out, and the four seeds differ by as much as 0.056, more than the 0.04 between VDVAE and NVAE, so keep that in mind when comparing the two models.
There are a few discrepancies between the paper and the code. The output distribution, the gradient clipping and mentioned earlier exist only in the code. Counting the decoder settings in the official hps.py gives 43 layers for CIFAR-10 and 66 for FFHQ-256, which don't match the 45 and 62 in the paper's table; the authors of the later Efficient-VDVAE also note in a footnote that the official code's parameters sometimes differ from the paper, and that they went with the code.
People training from scratch had a rougher time.
- Single GPU. In issue #8, a user training CIFAR-10 on a single GPU with batch 16 was stuck for a long time on a plateau around 4.7 nats/dim; another user, training on Omniglot, ran into it too, with a KL of almost 0, which is posterior collapse. That user also found that switching the output distribution from the logistic mixture to a Gaussian broke training entirely, and it only ran after turning off gradient clipping and adding instance norm, while the logistic mixture itself often brought very large gradient norms and NaN. The author replied that the model is sensitive to batch size and learning rate, and that when the batch shrinks by a factor of 4, the learning rate may need to come down by more than half; the author had tried adjusting the KL weight and found it didn't help.
- The skip threshold. In the same issue, the author added that the skip threshold depends on the learning rate and batch size: if your configuration produces generally higher gradient norms, updates may keep getting skipped and training stops, so the threshold should be set where only very few updates get skipped. Four years later, someone in issue #25 (June 2025) trained CIFAR-10 from scratch with the default threshold of 400; after a few steps the gradient norm reached about 450, and from then on every batch sat around 420, every step was skipped, and the model never updated again. Nobody replied to the issue, and the repo was archived afterward (the fuse installed against divergence sometimes just cuts the power to the whole run).
- NaN. In 2021, Dehaene and Brossard trained CIFAR-10 with the official code and the provided hyperparameters, and both the KL and the reconstruction term hit NaN several times, silently skipped by the code. After they switched the variance of every Gaussian to a bounded parameterization, none of their three seeds showed high gradients or NaN again, and performance didn't get any worse.
- Units. Several people took the
distortionthe code logs for the paper's number and couldn't match 2.87. The author has explained that the paper reports the ELBO, that is,rateplusdistortion, and that the code logs in nats/dim; divide by to get bits/dim.
In 2022, a team at Cash App Labs published Efficient-VDVAE, going back over what VDVAE costs to train. They report convergence up to 2.6 times faster and up to 20 times less training memory, with comparable or better negative log-likelihood. Their changes include producing the standard deviation with a gentler softplus, so that the gradient of is less spiky, which sharply cuts the number of skipped updates, and replacing Adam with AdaMax, because the large gradients from the logistic mixture output blow up Adam's second moment. In their table, the original VDVAE's total training memory on ImageNet and FFHQ is 512 GB.
Conclusion
VDVAE's case splits into one proof and one set of experiments. The proof says that a deep enough top-down VAE can represent any autoregressive model; the experiments say that at a fixed parameter count, more stochastic layers give better log-likelihood, and VDVAE, stacked to 78 layers, reaches 3.80 bits/dim on ImageNet-32, beating the PixelCNN branch and every non-autoregressive model with 30% fewer parameters. What holds that depth up is the residual initialization, nearest-neighbor upsampling, and gradient skipping, which throws a broken step away whole.
Before using the official code, know that the log records nats/dim, which you divide by to compare with the paper. During training, watch the number of skipped updates in the log, which should be almost 0; once every step is being skipped, lower the learning rate or reset the threshold rather than waiting for it to recover by itself. Sample with the EMA weights, with the temperature at 0.8 to 0.9 as the author recommends; and when comparing models, check how many seeds you have.
Of the "Them" in the title, the one still sitting above VDVAE in the CIFAR-10 and ImageNet-64 rows is the author's own Sparse Transformer from the year before.