Compression via Pre-trained Transformers: A Study on Byte-Level Multimodal Data

David Heurtel-Depeiges, Anian Ruoss, Joel Veness, Tim Genewein

Introduction

Researchers have identified a "sweet spot" where relatively small transformer models—those with millions, rather than billions, of parameters—can outperform standard compression tools like gzip, LZMA2, and even domain-specific formats like FLAC. By factoring the model's own weight into the compression ratio, this study proves that pre-trained neural networks can serve as highly efficient, general-purpose compressors, provided they have been exposed to the target data modality during training.

The "Model Size Tax" Problem

In information theory, "prediction is compression." If a model can perfectly predict the next byte in a sequence, that sequence can be compressed to nearly zero bits. While massive Large Language Models (LLMs) are incredible predictors, they fail as practical compressors because of the "Model Size Tax."

To decompress a file, the recipient needs the model's weights. If you use a 70-billion-parameter model to compress a 1GB file, the "adjusted" compression ratio is abysmal because you must transmit the massive model alongside the data. Conversely, tiny models often predict too poorly to beat simple algorithms like gzip. This paper investigates whether a middle ground exists: can a "right-sized" transformer, pre-trained on massive datasets, achieve a better total compression ratio (data size + model size) than traditional algorithms?

Methodology and Datasets

The authors employed a "vanilla" decoder-only transformer architecture. To remain domain-general, they eschewed traditional tokenizers (which are often language-specific) and fed raw byte streams directly into the model. They then used the transformer’s probability outputs to drive an arithmetic coder, a standard technique for turning statistical predictions into a lossless bitstream.

The core metric used is the Adjusted Compression Ratio, calculated as: $$ \frac{\text{Size of Compressed Data} + \text{Size of Model Weights}}{\text{Size of Original Data}} $$

Overview of training and evaluation datasets across text, image, and audio modalities.

Models were trained on a massive 165GB corpus and evaluated on 1GB out-of-distribution (OOD) sets:

  • Text: Trained on Wikipedia, Project Gutenberg, and scientific papers; evaluated on Reddit.
  • Images: Trained on ImageNet (flattened RGB bytes); evaluated on CelebA HQ.
  • Audio: Trained on Common Voice (downsampled to 16kHz); evaluated on LibriSpeech.
  • Multimodal Mixtures: Seven different combinations of the above were used to study cross-modal effects.

Key Findings

  • The "Sweet Spot" is Real: There is a specific regime (roughly 5M to 20M parameters) where transformers become "profitable" compressors. At this scale, the predictive gains outweigh the cost of including the model weights.
  • What You See is What You Get: Unlike billion-parameter LLMs, these smaller models show almost zero "zero-shot" transfer. A model trained only on text is terrible at compressing images. To compress a modality well, the model must have encountered it during pre-training.
Audio OOD Evaluation showing that models must be trained on audio to compress it effectively.
  • Multimodal Regularization: Training on multiple modalities (e.g., text + audio + images) only slightly degrades performance on any single modality compared to a specialized model. Interestingly, multimodal training acts as a regularizer, preventing the model from overfitting to the specific statistical quirks of one data type.
  • Scaling Laws for Compression: Compression performance follows scaling laws similar to LLMs, but OOD evaluation makes small models more prone to overfitting than traditional scaling laws suggest.

State-of-the-Art Results

The small transformers achieved state-of-the-art adjusted compression ratios on 1GB OOD samples, often beating long-standing benchmarks:

  • Audio: Achieved a ratio of 0.487, outperforming the domain-specific FLAC (0.538) and gzip (0.813).
  • Text: Achieved 0.217, significantly better than gzip (0.394) and nearly matching the specialized Bellard online transformer (0.204).
  • Images: Achieved 0.285, beating PNG (0.426) and JPEG 2000 (0.390), though narrowly trailing the cutting-edge JPEG-XL (0.260).

Importantly, these results hold even when the model's 16-bit weights are added to the file size, proving that pre-training is a viable strategy for general-purpose lossless compression.

Limitations and Future Work

While the compression ratios are excellent, the speed is not. Neural compression is orders of magnitude slower than gzip, especially during decoding, which must happen token-by-token. Furthermore, the failure of small models to transfer knowledge to unseen modalities suggests we haven't yet found a "universal" small-scale compressor.

Future work could explore applying lossy compression or quantization to the model weights themselves to further improve the adjusted compression ratio. Additionally, moving beyond vanilla transformers to more efficient architectures like Perceivers or MegaByte could help handle even longer sequences or higher-resolution data.

Summary updated

BibTeX
@inproceedings{heurteldepeiges2025compression,
  author = {David Heurtel-Depeiges and Anian Ruoss and Joel Veness and Tim Genewein},
  title = {{Compression via Pre-trained Transformers: A Study on Byte-Level Multimodal Data}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=c5R0lKLIr3},
}
Figure