Minimal Random Code Learning: Getting Bits Back from Compressed Model Parameters

Marton Havasi, Robert Peharz, José Miguel Hernández-Lobato

Deep learning models are notoriously "heavy," often requiring massive amounts of memory and energy. While researchers have spent years pruning and quantizing these models to fit them onto mobile devices, a team from the University of Cambridge and Microsoft Research has introduced a new approach called MIRACLE (Minimal Random Code Learning). By shifting the focus from deterministic weights to probabilistic distributions, they’ve set a new state-of-the-art in neural network compression.

TL;DR

MIRACLE achieves massive neural network compression (up to 1110x) by treating model weights as random samples from a variational distribution rather than fixed values. By leveraging shared randomness between the "sender" and "receiver," the method reaches compression rates near the theoretical information-theoretic lower bound, outperforming traditional pruning and quantization.

What Problem Does This Paper Address?

Traditional model compression follows a standard pipeline: pruning (removing small weights), quantization (reducing the precision of weights), and coding (using schemes like Huffman coding to store the result efficiently).

The authors argue that this pipeline is fundamentally limited because it insists on finding a single, deterministic set of weights. In information theory, the "bits-back" argument suggests that if we view weights as being drawn from a distribution, we can encode them much more efficiently. Previous "Bayesian" compression methods tried to use this logic but ultimately reverted to encoding a single set of deterministic weights, failing to capture the full efficiency promised by the theory.

Methods

The core innovation of MIRACLE is to stop trying to store specific weight values and instead store an index into a sequence of random numbers.

  1. Variational Training: Instead of training fixed weights, the authors train a variational distribution $q_\phi(\mathbf{w})$ (typically a Gaussian) using an objective similar to a $\beta$-VAE. This objective balances the model's performance (negative loss) against its complexity (the KL divergence between the learned distribution and a simple prior).
  2. Shared Randomness: Alice (the compressor) and Bob (the decompressor) share a pseudo-random number generator with a public seed.
  3. Minimal Random Coding: To "send" the model, Alice draws a large number of samples from the prior using the shared seed. She then uses importance sampling to pick the one sample that best matches her trained variational distribution. Instead of sending the weights, she only sends the index of that sample.
  4. The MIRACLE Algorithm: Because drawing enough samples to cover a whole network at once is computationally impossible (the number of samples needed grows exponentially), the authors split the weights into blocks. They encode one block, then update the distribution for the remaining blocks before encoding the next. This "auto-regressive" approach keeps the process tractable.

Key Insights and Ideas

  • Weights as Messages: The paper treats the model parameters themselves as a message to be transmitted. By using the "bits-back" philosophy, they show that the "cost" of a model is essentially the KL divergence between the posterior and the prior.
  • The Power of "Good Enough": Neural networks are highly over-parameterized. There isn't just one "perfect" set of weights; there are many "good" ones. MIRACLE exploits this by searching through a random sea of weights to find one that is "good enough" and easy to point to.
  • Explicit Control: Unlike pruning, which requires tedious hyperparameter tuning to reach a target size, MIRACLE allows users to explicitly control the compression rate by adjusting the $\beta$ penalty on the KL divergence term.

Key Results

MIRACLE demonstrates a "Pareto-optimal" performance, meaning it provides the best accuracy for a given size and the smallest size for a given accuracy level.

Pareto-frontier comparing MIRACLE to other compression methods.

The authors evaluated MIRACLE on two classic computer vision benchmarks: LeNet-5 on MNIST and VGG-16 on CIFAR-10.

Compression results for LeNet-5 and VGG-16.
  • LeNet-5 (MNIST):
    • Achieved a staggering 1110x compression ratio, reducing the model to just 1.52 kB while maintaining a 0.96% error rate.
  • At a lower compression (555x), it achieved a 0.69% error rate, actually outperforming the uncompressed model (0.7%).
  • VGG-16 (CIFAR-10):
    • Achieved 365x compression, bringing a 60 MB model down to 168 kB with a 10.0% error rate.
  • For a fixed error rate of ~6.5%, MIRACLE compressed the model to 417 kB, whereas the nearest competitor (Bayesian Compression) required over 600 kB for a much higher error rate (8.6%).

Limitations and Future Work

While MIRACLE is a breakthrough for storage and transmission, it has a significant hurdle for real-time use: Inference Efficiency.

Currently, to use the model, you must reconstruct the weights using the block indices and the random number generator. The authors suggest that future work could involve designing "inference machines" that use pseudo-random generators as algorithmic lookup tables, potentially bypassing the need to fully reconstruct the weights in memory and further saving energy on memory accesses. Additionally, the block-by-block encoding process adds a computational overhead during the initial compression phase.

Summary updated

BibTeX
@inproceedings{havasi2019minimal,
  author = {Marton Havasi and Robert Peharz and José Miguel Hernández-Lobato},
  title = {{Minimal Random Code Learning: Getting Bits Back from Compressed Model Parameters}},
  booktitle = {International Conference on Learning Representations},
  year = {2019},
  url = {https://openreview.net/forum?id=B1q-1oG-vCg},
}
Figure