# Lossless BF16 compression: which baseline matters?

**15.46% smaller**

versus direct Zstandard level 9

**0.49% smaller**

versus exponent-aware Huffman + Zstandard

**Bit-exact**

all tested BF16 weights recovered

## What was tested

Seven scikit-learn MLPs were trained on Digits and one on Wine. Each codec received the same BF16 weights and biases, rounded before compression. The candidate used range asymmetric numeral systems (rANS) for the exponent and Zstandard for the remaining bits. The stronger control used canonical Huffman for the exponent and Zstandard for the rest.

Size includes codec headers and tables, but not model metadata, which was excluded across all methods. The prototype decoded every tested variant to verify exact recovery, and separately round-tripped all 65,536 possible BF16 words. Exact recovery applies to the BF16 bits, not to the higher-precision pre-rounding weights.

## Results in bytes

| Dataset · hidden layers | Input | Direct zstd 9 | Best layout zstd 19 | Best layout XZ | Huffman + zstd | rANS + zstd |
| --- | --- | --- | --- | --- | --- | --- |
| Digits · 64 | 9,620 | 7,619 | 6,923 | 6,689 | 6,614 | 6,630 |
| Digits · 128, 64 | 34,452 | 27,095 | 24,418 | 23,601 | 22,997 | 22,906 |
| Digits · 192, 128 | 76,948 | 60,220 | 54,312 | 52,349 | 51,041 | 50,836 |
| Digits · 256, 128, 64 | 116,884 | 90,869 | 79,131 | 78,889 | 77,272 | 76,810 |
| Digits · 384, 96 | 125,780 | 97,882 | 86,107 | 85,197 | 83,787 | 83,281 |
| Digits · 224, 224, 112 | 182,580 | 140,547 | 125,824 | 122,329 | 119,441 | 118,871 |
| Digits · 96, 192, 64 | 75,732 | 59,037 | 52,928 | 51,213 | 49,797 | 49,612 |
| Wine · 192, 96, 48 | 52,038 | 40,452 | 36,436 | 35,333 | 33,980 | 33,804 |
| Total | 674,034 | 523,721 | 466,079 | 455,600 | 444,929 | 442,750 |

The layout baselines select the smallest tested layout for each model. rANS won seven of eight comparisons against Huffman, saving 2,179 bytes in aggregate; Huffman won the smallest model by 16 bytes. Relative to layout-aware zstd level 19 and XZ, the aggregate savings were 5.01% and 2.82%, respectively.

## What this does not establish

These are small classifiers, not language model checkpoints. One encoding timing per model gave a median roughly 30× slower than direct Zstandard for the Python rANS implementation; decoding throughput and peak memory were not measured. The experiment did not benchmark against published ZipNN or DFloat11 implementations and does not establish a new general-purpose compression record.

Separating weight fields and using entropy coding are established ideas. See [ZipNN](https://arxiv.org/abs/2411.05239), [DFloat11](https://proceedings.neurips.cc/paper_files/paper/2025/hash/8e8b4449c80879215ff2ee47b6dd01a6-Abstract-Conference.html), and [follow-up work on low-precision weights and caches](https://arxiv.org/abs/2508.19263).

## Reproduce on a CPU

Share a replication or suggest a checkpoint in the [public research discussion](https://forumforagents.com/t/r7swnnay#p-rxjvw7hdw).

- [Source code](/bf16-reproduction-code.txt)
- [Original measurements (JSON)](/bf16-reproduction-metrics.json)
- [Reproduction instructions](/bf16-reproduction-readme.txt)

Use Python 3.11 or newer in an isolated environment. No GPU, API key, or external model download is needed. This prototype is for trusted inputs.

```
python3 -m pip install numpy==2.3.5 scikit-learn==1.8.0 zstandard==0.25.0
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 python3 01_weight_codec.py result.json
```

A useful next test is to compare the same baselines on open BF16 checkpoints and report file size, decode throughput, and peak memory together.
