NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Bit-Swap: Recursive Bits-Back Coding for Lossless Compression with Hierarchical Latent Variables

Friso H. Kingma, Pieter Abbeel, Jonathan Ho

Introduction

In the realm of lossless compression, there exists a profound theoretical link between generative modeling and coding: if a model can perfectly predict the probability distribution of your data, you can use "entropy coding" to compress that data down to its theoretical limit, known as the Shannon entropy.

The "Bits-Back" argument is a classic technique that leverages Latent Variable Models (LVMs), such as Variational Autoencoders (VAEs), for this exact purpose. However, practical implementations like BB-ANS (Bits-Back with Asymmetric Numeral Systems) have historically hit a major bottleneck. They require a large "bank" of random initial bits to kickstart the decoding process. As researchers have moved toward "hierarchical" models—deep models with many layers of latent variables that excel at capturing complex data like high-resolution images—this "initial bits" cost has exploded. Essentially, the startup cost of the compressor becomes so high that it negates the benefits of using a more expressive model.

Bit-Swap is a novel lossless compression algorithm designed to make deep, hierarchical latent variable models practical for data storage. By cleverly interleaving the encoding and decoding steps, it eliminates the massive initial bits overhead that previously made multi-layered models too inefficient for compression.

Methodology: The Bit-Swap Algorithm

Bit-Swap introduces a recursive generalization of the standard bits-back coding scheme. To understand how it works, it is crucial to recognize that ANS (the underlying coding mechanism) operates as a stack, following a Last-In, First-Out (LIFO) structure.

In Standard BB-ANS, the sender first decodes all latent layers ($z_1, z_2, \dots, z_L$) from the bitstream, then encodes the data $x$, and finally encodes the latents back onto the bitstream. For deep models, this requires a massive pile of bits to be present on the stack before the process can even begin.

Hierarchical latent variable model with a Markov chain structure.

Bit-Swap fundamentally changes this order. Instead of executing all decodes followed by all encodes, Bit-Swap interleaves them. The sender decodes the first latent $z_1$ and immediately encodes the data $x$. Because ANS is a stack, the bits generated by encoding $x$ are now sitting at the top of the stack. Bit-Swap then uses those newly generated bits to decode the next latent layer $z_2$.

This recursive process allows the algorithm to effectively "pay for itself" as it progresses. It reuses bits generated from lower layers to satisfy the requirements of higher layers in the hierarchy. By recognizing that the LIFO nature of ANS is a feature rather than a constraint, Bit-Swap keeps the initial bits overhead nearly constant, regardless of how deep the model is.

Key Results and Performance

The authors evaluated Bit-Swap on three standard image benchmarks: MNIST (28x28 grayscale digits), CIFAR-10 (32x32 color images), and a downsampled 32x32 version of ImageNet.

Previously, researchers faced a strict trade-off: use a shallow model (which is efficient to code but yields poor compression) or a deep model (which offers great density estimation but highly inefficient coding overhead). Bit-Swap breaks this trade-off, allowing the use of highly expressive, deep hierarchical models.

Compression rates on the ImageNet 32x32 dataset.

Bit-Swap consistently outperformed both standard compression utilities and the previous BB-ANS state-of-the-art:

  • State-of-the-Art Compression: On the complex ImageNet (32x32) dataset, Bit-Swap achieved a compression rate of 3.51 bits per dimension, outperforming WebP (3.66), BB-ANS (3.62), PNG (4.71), and Gzip (5.96).
  • Massive Overhead Reduction: On an 8-layer MNIST model, standard BB-ANS required approximately 21.93 initial bits per dimension just to function. Bit-Swap required only 3.34 initial bits. This dramatic reduction makes the algorithm viable for small files or short sequences.
  • Faster Amortization: While the initial bits cost in standard methods is eventually amortized when compressing many images sequentially, Bit-Swap reaches the optimal compression rate much faster (requiring fewer images) than BB-ANS.

Limitations and Future Work

While Bit-Swap represents a significant leap forward for neural compression, it does have a few limitations:

  • Markov Chain Constraint: The current algorithm is specifically optimized for hierarchical models with a linear Markov chain structure ($z_L \to z_{L-1} \dots \to z_1 \to x$). While other topologies are possible, the primary method is specialized for this specific hierarchy.
  • Discretization Noise: Because VAEs typically utilize continuous latent variables, these variables must be discretized into "bins" to allow for lossless compression. This discretization introduces a small amount of noise, creating a slight gap between the theoretical Evidence Lower Bound (ELBO) and the actual achieved bitrate.
  • Computational Complexity: Although it is faster than autoregressive models like PixelCNN, Bit-Swap still requires multiple forward and backward passes through a neural network for every single image. Without dedicated hardware acceleration, this may be too slow for real-time applications.

Summary updated

BibTeX
@inproceedings{kingma2019bit,
  author = {Friso H. Kingma and Pieter Abbeel and Jonathan Ho},
  title = {{Bit-Swap: Recursive Bits-Back Coding for Lossless Compression with Hierarchical Latent Variables}},
  booktitle = {International Conference on Machine Learning},
  year = {2019},
}
Figure