Skip to content
scaleapiPublic

About

Per-File Models for Lossless Compression (cmxc)

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

cmx

General data, averaged over 7 benchmarks: compressed size relative to gzip -9 against the time to compress 1 GB, one thread, strongest setting of each codec. cmx (58.9% of gzip, 1.3 hours per GB) lies on the Pareto frontier between zpaq -m5 (63.1%, 24 minutes per GB) and paq8px -11 (50.1%, 16 hours per GB); cmx is 13 times faster than paq8px. Qwen3-14B on one H100: decode speed against archive size. cmx --gpu decodes at 571 GB/s at 66.27% of the original, DFloat11 at 529 GB/s at 68.17%, cmx given its base at 275 GB/s at 43.84%, and ZipNN on 192 CPU cores at 4.0 GB/s at 66.75%.

State-of-the-art lossless compression for LLM weights, on CPU and GPU, and a context-mixing compressor for everything else, in one program.

On bfloat16 model weights, cmx writes the smallest archives of every lossless coder we compared (ZipNN, DFloat11, FM-Delta, BitX), on all 12 models and 5 fine-tune pairs we tested from 0.8B to 72B parameters, and it is also the fastest of them on the CPU, so it is both smaller and faster than each of them in every comparison. On the GPU it decodes faster than DFloat11, with smaller archives.

cmx prior codecs
A model alone, 12 models (0.8B–72B), % of original 65.21–66.11% 66.32–66.75% (best of ZipNN and DFloat11)
A fine-tune given its base, 5 pairs (up to 72B), % of original 30.37–43.71% 35.04–48.81% (FM-Delta)
Compression speed, weights, 16 CPU threads 4.2–4.9× faster ZipNN
Qwen2.5-72B-Instruct given its base (145 GB), 16 x86 threads 66 s 362 s (BitX)
GPU decode, Qwen3-14B on one H100 571 GB/s at 66.27% 529 GB/s at 68.17% (DFloat11)
Silesia (general data), bits per byte 1.353 1.476 (zpaq -m5), 1.829 (xz -9e); paq8px and precomp + cmix are smaller (1.045, 1.067)
  • Fine-tunes shrink to 30–44% of their size. Given its base model, a fine-tune is 4.7–5.1 percentage points smaller than with FM-Delta and 10–13 smaller than with the XOR coders (ZipNN, BitX), on every pair. That matters for model hubs, where most checkpoints are fine-tunes of a public base.
  • Faster than DFloat11 on the GPU. With 64 KiB sub-streams, the GPU kernels decode at 1.08× the speed of DFloat11's own kernel, with archives 1.9 percentage points smaller. With the base resident on the GPU, a whole Qwen3-14B fine-tune kept compressed (12.9 GB) decodes in 0.13 s; DFloat11 has no given-the-base mode, and given the base cmx decodes at 275 GB/s. The GPU pays off when weights stay on the GPU: for file-to-file use, the CPU path is faster end to end.
  • Pareto-optimal on general data. Averaged over the 7 benchmarks on which paq8px was also run (geometric mean, strongest setting of each codec, one thread), no codec is both smaller and faster than cmx: paq8px is 15% smaller but 13× slower, and zpaq -m5 is 3× faster but 7% larger. On Silesia and the AIT corpus, timed against about 30 settings of seven codecs, cmx is on the size–time frontier in every timing round. On ten benchmarks (text, binaries, images, speech), it is smaller than gzip, bzip2, zstd, xz, brotli, bsc and zpaq on every one. Among general-purpose codecs, only paq8px and cmix, which are much slower, compress smaller; on images and speech, JPEG XL and FLAC also do.
  • One program. cmx c picks the codec from the input and cmx d from the archive. The CPU is the default; --gpu is optional. MIT licensed, plain C (and CUDA for the GPU path), no dependencies.

Every cmx result is verified by a byte-exact round trip. Full tables, timings, ablations and the hardware used are in Results.

What is inside

  • bf16ref (bf16ref.c): a static-table rANS coder for bfloat16 model weights in safetensors files. It codes each weight as one 11-bit symbol (the exponent plus the 3 most informative other bits, chosen per block), and, given a base model, the difference of magnitudes in units in the last place, with the base weight's exponent as context. It codes a model alone, or a fine-tuned model given its base model. Archives start with BFR8 (the sub-stream layout below, the default) or BFR7; BFR6 archives still decode.
  • cmxc (cmxc.c): context mixing, for text and general data. It accompanies the paper Per-File Models for Lossless Compression (2026). Archives start with CMXC.

cmx (cmx.c) chooses the codec from the input when compressing and from the archive when decompressing. Both codecs are compiled into it unchanged, with their main functions renamed (-DCMX_UNIFIED).

Build

make            # builds ./cmx
make test       # tests/roundtrip.sh and tests/cmx.sh

This uses clang -O3 -march=native ... -lm -lpthread; use make CC=gcc for another compiler. The code has no dependencies. tests/cmx.sh needs python3 to write its safetensors inputs.

  • The text codec (cmxc) has been built and tested only on Apple silicon (arm64, NEON); other platforms fall back to a portable scalar mixing path that has not been tested. An archive records whether NEON mixing was used, and a decoder built the other way refuses it rather than decoding it incorrectly.
  • The weights codec (bf16ref) has also been built and tested with gcc on x86-64 (AMD EPYC, Ubuntu 24.04).

tests/roundtrip.sh tests the text codec: it round-trips empty, text, random and E8/E9-heavy inputs, including multi-block and primed archives, and checks that the decoder refuses truncated and malformed archives.

tests/cmx.sh checks several things:

  • round trips of text and of a synthetic safetensors pair, alone and given the base;
  • options give the same archive as the settings they stand for, and weights archives do not depend on -t;
  • the choice of codec;
  • the BFR8 layouts, and a damaged index;
  • the output: never the input or the reference, and kept when a run fails;
  • refusals.

Each text-codec run maps about 3.4 GiB of model tables.

Use

./cmx c <input> <archive> [--ref BASE] [-t N] [--max] [--codec text|weights] [-b MiB] [-s KiB] [-l lanes] [--gpu]
./cmx d <archive> <output> [--ref BASE] [-t N] [--gpu]

Compressing. cmx c uses bf16ref for a safetensors file with at least one BF16 tensor, and cmxc for anything else. Within a safetensors file, bf16ref codes the BF16 tensors; it stores the header and the tensors of other dtypes raw.

Decompressing. cmx d chooses the decoder from the archive's first four bytes.

The output. cmx writes to a temporary file next to the output and renames it over the output only when the run succeeds, so a failed run (a wrong reference, a damaged archive) leaves an existing output as it was. It refuses an output that is the same file as the input or the reference. If the output is a symbolic link to a file, the file it points to is replaced and the link is kept; a device such as /dev/null is written directly.

Option Effect
--ref BASE Compress a fine-tuned model given its base model (bf16ref). Tensors are paired by name. Give the same BASE to decompress.
-t N Threads. For cmxc this sets CMXC_THREADS, which also sets the number of blocks when compressing. bf16ref's archives do not depend on it.
--max cmxc's max-compression mode (CMX_NIBO=0).
--codec text|weights Force cmxc (text) or bf16ref (weights).
-b MiB bf16ref block size (default 64).
-s KiB, -l lanes bf16ref's layout (below): sub-streams of -s KiB with -l lanes. The default is -s 256 -l 32 (BFR8); -s 0 -l 16 writes BFR7.
--gpu bf16ref on the GPU: BFR8 with 32 lanes (a build with make CUDA=1).

BFR8: the sub-stream layout

A BFR7 block is one rANS stream with 16 interleaved states. That gives far too few independent streams for a GPU. BFR8 keeps everything else in BFR7's blocks: the symbols, the choice of the 3 coded bits, the tables and the raw bits. It changes three things:

  • Sub-streams: each block's words are cut into sub-streams of -s KiB of weights.
  • Lanes: each sub-stream has its own -l interleaved states, 16 or 32.
  • Index: an index of the sub-streams' word offsets follows the tables. Given the base, the index also holds each sub-stream's raw-bit offset.

The archive header records the sub-stream size and the lane count. With one sub-stream per block and 16 lanes, a BFR8 block is byte for byte a BFR7 block, and the decoder handles both.

Default. The default layout has 256 KiB sub-streams with 32 lanes.

  • Size: it costs about 0.04 percentage points of the original size against BFR7, on Qwen3.5 and Qwen3-14B, alone and given the base.
  • Speed at 16 threads: on an Apple M5 Pro, BFR8 decoded Qwen3-14B and Llama-3.1-8B-Instruct shards as fast as BFR7 or faster: 0% to −26% time, median of 5 repeats.
  • Speed on one thread: it is within 2% of BFR7 on Qwen3-14B, and 13% slower on the Llama shard.

Choice of the 3 coded bits. The encoder now makes this choice in integer arithmetic, with a fixed rule for exact ties. So any CPU, compiler or GPU encoder writes the same bytes. Floating-point entropies could round exact ties differently on different math libraries.

GPU

make CUDA=1 builds cmx with a GPU path for the weights codec, compiled with nvcc (default CUDA_ARCH=sm_90, H100). The CPU stays the default: for file-to-file use, 16 CPU threads are faster end to end than one H100, because of CUDA start-up and host copies.

Writing. --gpu codes every bfloat16 segment on the GPU. Checks and file I/O stay on the CPU. It writes BFR8 with 32 lanes, the same bytes the CPU encoder writes for that layout.

Reading. cmx d --gpu decodes a BFR8 archive with 32 lanes on the GPU, whichever encoder wrote it. Any other archive is decoded without --gpu.

Sources.

  • bf16ref_gpu.cu: the host side.
  • gpu/kernels.cuh: the kernels.
  • gpu/cuemu.h: a CPU emulator of the kernels. make cmx_emu builds a test-only cmx with the GPU path on it, so the GPU path can be tested without a GPU. It is slow, so use small inputs only.

Tests. make test-gpu-emu (emulator) and make CUDA=1 test-gpu (GPU) run tests/gpu.sh. It checks four things:

  • the GPU archives equal the CPU's;
  • each decodes the other's archives, alone and given the base;
  • archives the GPU path cannot decode are refused;
  • damaged archives fail with an error.

Text-codec settings (environment variables, read when compressing)

-t and --max set the first two.

Variable Effect
CMXC_THREADS=n Split the input into n independent blocks, compressed in parallel (default 8). CMXC_THREADS=1 gives the best compression and is the setting used in the paper.
CMX_NIBO=0 Max-compression mode: about 0.2% smaller on Silesia, about 1.25× the time.
CMXC_VERBOSE=1 Print the settings written to the header.

At one thread the compressor needs about 3.4 GiB of memory (3.6 GiB in max-compression mode). On the Silesia corpus (211.9 MB) at one thread on an Apple M5 Pro, compression takes about 860 s and decompression about 1,040 s.

Untrusted input

The cmxc decoder checks every header field and the block table against the values the encoder can write, and refuses an archive that fails those checks. A build with AddressSanitizer and UndefinedBehaviorSanitizer decoded or refused about 11,600 corrupted archives (damaged headers, damaged streams, truncations) without a memory error. It is still a research codec, not a hardened one: a crafted archive can make it run for a long time or allocate a lot of memory (about 3.4 GiB of model tables plus the declared output size). Do not decompress archives from untrusted sources.

The cmxc archive format has no checksum. A decoder built with a different compiler or optimization level from the encoder can, in principle, reproduce the encoder's floating-point arithmetic inexactly and write wrong bytes without reporting an error, so compare the decompressed output with the original (for example with cmp) before deleting the original.

bf16ref archives carry a 64-bit check of each segment's original bytes, and bf16ref refuses to decode with a reference other than the one used to compress.

Please report security problems as described in SECURITY.md.

License

MIT; see LICENSE.

Results

Runs are on an Apple M5 Pro (6 performance + 12 efficiency cores, macOS) unless a table says otherwise: the x86 timings and the GPU runs used a cloud GPU node (AMD EPYC 7R13 host CPUs, one H100). Every result was checked by a byte-exact round trip unless marked ‡ (compressed size only) or described as computed.

Text and general data (cmxc)

Silesia (211,938,580 bytes), single-threaded (-t 1). Times are compression plus decompression, median (min–max) of 3 interleaved rounds.

codec bytes bits/byte ratio total s
paq8px v217 -12L (published) 27,682,006 1.0449 7.656× —
precomp 0.4.7 + cmix v21 (published) 28,261,094 1.0668 7.499× —
paq8px v216 -11 ‡ 28,570,370 1.0784 7.418× —
cmx 35,838,365 1.3528 5.914× 1897.3 (1896.3–1899.9)
cmx --max 35,773,030 1.3503 5.925× 2371.8 (2366.5–2376.7)
zpaq -m5 39,113,381 1.4764 5.419× 631.9 (627.3–634.1)
zpaq -m4 42,628,623 1.6091 4.972× 183.2 (181.5–183.3)
bsc -e2 46,536,916 1.7566 4.554× 11.7 (11.7–12.0)
xz -9e 48,456,004 1.8291 4.374× 57.5 (57.2–57.6)
brotli -11 49,564,563 1.8709 4.276× 217.7 (217.3–218.7)
zstd -22 52,369,178 1.9768 4.047× 52.6 (52.5–52.7)
zstd -19 52,895,350 1.9966 4.007× 40.4 (40.3–40.4)

Ten benchmarks, every codec single-threaded at its strongest setting. Units: bits per byte (b/B), per 8-bit RGB sub-pixel (b/sp) or per 16-bit PCM sample (b/smp); lower is better. paq8px -11 was not run on the three largest benchmarks (—). The last column is the best domain-specific codec (J = JPEG XL lossless, F = FLAC -8).

benchmark unit gzip bzip2 zstd xz brotli bsc zpaq paq8px cmx cmx --max domain
Calgary b/B 2.608 2.132 2.266 2.174 2.108 1.983 1.776 1.490 1.632 1.630
Canterbury b/B 2.072 1.545 1.469 1.403 1.397 1.302 1.036 0.869 0.948 0.947
Canterbury (large) b/B 2.293 1.854 1.826 1.833 1.794 1.619 1.544 1.402 1.470 1.468
Silesia b/B 2.553 2.057 1.977 1.829 1.871 1.757 1.476 1.078 ‡ 1.353 1.350
AIT 2026 b/B 5.314 5.005 5.076 4.939 4.869 4.812 4.603 4.087 4.540 4.540
enwik8 b/B 2.918 2.321 2.022 1.987 2.059 1.718 1.570 1.287 ‡ 1.451 1.446
enwik9 b/B 2.582 2.032 1.710 1.694 1.787 1.484 1.349 — 1.192 1.187
Kodak b/sp 4.998 3.856 4.292 4.090 4.275 3.619 3.205 1.880 2.982 2.973 2.828 J
DIV2K valid b/sp 5.979 4.663 5.400 4.814 4.845 4.248 3.724 — 3.497 3.493 2.816 J
LibriSpeech dev-clean b/smp 12.977 10.839 11.843 10.970 10.620 9.845 9.356 — 8.861 8.862 8.632 F

cmx is the smallest of the general-purpose codecs other than paq8px on all ten benchmarks; paq8px is smaller on every benchmark it was run on.

Model weights with the text codec. On the 1 GB slice from the middle of Llama-3.1-8B-Instruct that ZipNN uses, cmxc (--codec text) reaches 65.10%, against 66.38% for ZipNN, 65.14% for zpaq -m5, 69.73% for xz -9e and 77.60% for zstd -3; the order-0 entropy of the 16-bit values is 65.44%. On the first 16 MiB, paq8px -11 reaches 65.06% (cmxc: 65.15%) at 28× cmxc's time (2,396 s vs 86 s) and 12.4 GiB of memory (cmxc: 3.2 GiB). The weights carry almost no sequential context beyond the distribution of their values, which is why bf16ref, a static coder several thousand times faster, reaches about the same size on the whole model (65.21%).

From the paper (Per-File Models for Lossless Compression):

  • Of twenty pre-registered changes to the 83-expert context-mixing model, each tested against a bit-exact off-switch and a held-out set, fifteen fail, and in four of nine controlled additions a matched control that adds the same machinery but no information does as well or better.
  • Giving each file the best of four candidate models reduces held-out code length by 0.702%, against 0.361% for the best single model (1.95×); a deterministic 64 KB probe recovers 99.6% of this oracle without a learned selector.
  • Searching invertible transforms per file found an exact lagged recurrence that takes one file from 7.95 to 0.058 bits per byte.

Model weights (bf16ref)

Whole models in bfloat16 safetensors, as a percentage of the original size (lower is better). Times are the median of 5 repeats in seconds, compression / decompression. These runs used the BFR7 layout (-s 0 -l 16); the default BFR8 layout is about 0.04 percentage points larger, and decodes as fast at 16 threads.

A model alone

model size cmx ZipNN DFloat11 order-0 cmx, 16 threads ZipNN, 16 threads cmx, 1 thread
Llama-3.1-8B-Instruct 16.1 GB 65.21% 66.39% 67.84% 65.38% 1.65 / 2.22 7.76 / 7.44 12.95 / 6.93
Llama-3.1-8B 16.1 GB 65.74% 66.39% 66.57%† 65.93% 1.65 / 2.21 7.51 / 7.39 12.96 / 7.04
Qwen3-14B 29.5 GB 66.11% 66.75% 68.17% 66.57% 3.07 / 4.05 13.90 / 13.47 23.79 / 12.75
Qwen3-14B-Base 29.5 GB 66.09% 66.75% 67.31%† 66.53% 3.10 / 4.12 14.50 / 13.62 23.91 / 12.96
Qwen3.5-0.8B-Base 1.7 GB 66.03% 66.66% 67.36%† 66.66% 0.25 / 0.24 1.11 / 1.10 1.24 / 0.88
Qwen3.5-4B 9.3 GB 65.84% 66.47% 66.76%† 66.11% 1.00 / 1.10 4.27 / 4.11 7.40 / 3.86
Qwen3.5-4B-Base 9.3 GB 65.81% 66.47% 66.77%† 66.07% 1.00 / 1.07 4.19 / 4.08 7.00 / 3.88
Qwen3.5-9B-Base 19.3 GB 65.70% 66.41% 66.53%† 65.86% 1.89 / 2.02 9.25 / 9.15 14.78 / 8.06
Qwen3-30B-A3B (MoE) 61.1 GB 65.64% 66.35% 66.34%† 65.65% x86 below
Qwen3-30B-A3B-Base (MoE) 61.1 GB 65.53% 66.34% 66.33%† 65.51%
Qwen2.5-72B-Instruct 145.4 GB 65.69% 66.32% 66.49%† 65.82% x86 below
Qwen2.5-72B 145.4 GB 65.59% 66.32% 66.49%† 65.71%
  • DFloat11: the size of its published checkpoint (Llama-3.1-8B-Instruct, Qwen3-14B), or the computed size of its format where no checkpoint is published (†). The published checkpoints are 0.9–1.3 pp larger than the computed format, because they also store what the GPU decoder needs to start many threads within a tensor, so † is a lower bound.
  • order-0: the entropy of the 16-bit values over the whole model, the limit for a coder with one fixed distribution per model. bf16ref codes each 64 MiB block with its own tables, so it can go below it, and does on every model except Qwen3-30B-A3B-Base (0.02 pp above), whose many small expert tensors each carry their own tables.
  • Models used during design: Llama-3.1-8B(-Instruct) and Qwen3-14B(-Base). The Qwen3.5 models and the two larger pairs were not used during design.

A fine-tuned model given its base (--ref)

model, given cmx --ref FM-Delta ZipNN (XOR) BitX (XOR + zstd) cmx, 16 threads ZipNN, 16 threads
Llama-3.1-8B-Instruct, given Llama-3.1-8B 38.41% 43.22% 49.82% 51.71% 2.09 / 2.96 12.87 / 15.81
Qwen3-14B, given Qwen3-14B-Base 43.68% 48.68% 53.57% 56.48% 3.76 / 5.42 18.64 / 19.02
Qwen3.5-4B, given Qwen3.5-4B-Base § 38.82% 43.48% 48.75% 51.18% 1.29 / 1.31 9.50 / 10.19
Qwen3-30B-A3B, given Qwen3-30B-A3B-Base 43.71% 48.81% 53.62% 56.59% x86 below
Qwen2.5-72B-Instruct, given Qwen2.5-72B § 30.37% 35.04% 43.42% 43.01% x86 below

FM-Delta was run single-threaded, once (66–224 s to compress, 102–343 s to decompress). § These fine-tunes place their tensors in their shards differently from their base, so every codec was given a tensor-aligned copy of the base: the base tensors of the same names, in the same order and at the same offsets as in each fine-tuned shard.

Speed: every codec. Whole-model time in seconds, compress / decompress. Apple M5 Pro: median of 5 repeats. Both machines were shared and carried background load from other processes, so absolute times are upper bounds on an idle machine; the codecs ran interleaved under the same load. FM-Delta ran once, single-threaded.

Apple M5 Pro Llama-3.1-8B-Instruct, 1 thread 16 threads Qwen3-14B, 1 thread 16 threads Qwen3.5-4B, 1 thread 16 threads
cmx 12.95 / 6.93 1.65 / 2.22 23.79 / 12.75 3.07 / 4.05 7.40 / 3.86 1.00 / 1.10
ZipNN 16.01 / 10.55 7.76 / 7.44 28.09 / 19.55 13.90 / 13.47 8.64 / 5.98 4.27 / 4.11
cmx --ref 17.99 / 12.53 2.09 / 2.96 32.54 / 22.86 3.76 / 5.42 9.83 / 6.92 1.29 / 1.31
ZipNN (XOR) 24.81 / 19.69 12.87 / 15.81 40.21 / 34.83 18.64 / 19.02 17.24 / 13.49 9.50 / 10.19
BitX 40.55 / 29.74 7.15 / 11.18 78.09 / 54.69 13.76 / 20.33 23.97 / 16.93 5.68 / 6.84
FM-Delta 119.33 / 182.52 224.20 / 342.98 66.45 / 102.32

The same protocol on x86 (the host CPUs of a cloud GPU node: AMD EPYC 7R13, Ubuntu 24.04, gcc; the GPU was not used). Qwen2.5-72B-Instruct ran once.

AMD EPYC 7R13 Qwen3-14B, 1 thread 16 threads Qwen3-30B-A3B, 1 thread 16 threads Qwen2.5-72B-Instruct, 1 thread 16 threads
cmx 74.97 / 52.86 13.37 / 16.03 158.84 / 110.18 27.84 / 36.29 376.48 / 264.16 70.87 / 83.62
ZipNN 114.17 / 101.83 83.01 / 82.63 256.43 / 227.09 198.41 / 200.31 648.77 / 524.75 437.90 / 424.74
cmx --ref 130.31 / 90.72 13.16 / 17.16 268.36 / 189.84 25.47 / 35.05 652.61 / 463.15 66.35 / 96.64
ZipNN (XOR) 169.91 / 157.58 125.75 / 126.57 386.26 / 365.81 303.33 / 300.41 1032.40 / 857.04 714.90 / 701.81
BitX 205.12 / 144.78 60.29 / 71.40 446.86 / 322.78 142.56 / 168.34 1183.08 / 765.28 362.25 / 392.10
FM-Delta 569.89 / 670.48 1199.96 / 1410.57 2750.53 / 3112.25

cmx is the fastest codec in every column, in both directions.

Ablations: what each part of the weights codec is worth (click to expand)

Each row changes one design element; values are percentage points of the original size against cmx (lower is better). Slices are 1 GB from the middle of each design model; the held-out columns are whole models.

A model alone

change Llama-8B-Instruct slice Qwen3-14B slice Llama-8B slice Qwen3-14B-Base slice Qwen3.5-4B 4B-Base 0.8B-Base 9B-Base
A0 cmx (% of original) 65.45 65.77 65.96 65.75 65.83 65.81 66.02 65.70
A1 top 3 mantissa bits, fixed +0.52 0.00 0.00 +0.02 0.00 +0.01 +0.01 +0.01
A2 exponent only, 8 bits raw (the ZipNN/DFloat11 split) +0.89 +0.39 +0.38 +0.42 +0.40 +0.42 +0.41 +0.43
A3 whole 16-bit value, 16-bit table precision +1.61 +1.56 +1.52 +1.33 +1.39 +1.11 +1.08 +1.10
A4 one table for the file +0.09 +0.04 +0.10 +0.02 +0.31 +0.31 +0.74 +0.19
A5 per-tensor tables, no 64 MiB split +0.09 +0.04 +0.10 +0.02 0.00 0.00 0.00 +0.01
A6 4 MiB blocks −0.21 −0.01 −0.21 −0.01 −0.03 −0.03 −0.01 0.00
A7 table precision 12 bits +0.26 +0.33 +0.31 +0.25 +0.26 +0.20 +0.17 +0.20

Given the base

change Llama slice Qwen3 slice Qwen3.5-4B (whole)
R0 cmx --ref (% of original) 38.98 44.48 38.82
R1 no base-exponent context +4.16 +4.05 +3.80
R2 coarser magnitude buckets (120 symbols) +0.10 +0.09 +0.08
R3 finer magnitude buckets (416 symbols) −0.01 0.00 0.00
R4 previous symbol as context, escape above 255 +0.75 +1.33 +1.01
R5 XOR with the base, standalone symbol +7.78 +6.81 +8.87
R6 XOR with the base, base-exponent context +4.57 +3.08 +5.63
R7 one table per context, per file +0.02 +0.02 +1.65
R8 no reference +26.47 +21.29 +27.01

Speed of the CPU kernels (in memory, one thread, compress / decompress in GB/s, on Qwen3-14B; Llama-3.1-8B-Instruct and Qwen3.5-4B are within 0.02 GB/s)

change alone given the base
K0 cmx kernels 1.97 / 3.90 1.36 / 1.84
K1 8 interleaved states instead of 16 1.92 / 3.04 1.39 / 1.80
K2 refill with a mask select in C 1.97 / 3.89 1.36 / 1.83
K3 refill with a C conditional (a branch) 1.97 / 0.83 1.36 / 0.52
K4 decode table with two lookups 1.94 / 3.13
K5 no base-exponent context 1.56 / 2.47
K6 coarser magnitude buckets 1.39 / 1.85
K7 table precision 12 bits 1.40 / 1.84
K8 table precision 14 bits 1.40 / 1.79

float32 (computed, not implemented in cmx). cmx stores float32 tensors raw. On OLMo-2-1B, a float32 extension of the same design would reach 82.90% alone (ZipNN: 83.25%) and 53.41% given the checkpoint 852 steps earlier (FM-Delta: 55.70%; ZipNN on the XOR: 61.05%). These are computed code lengths, not runs.

GPU (--gpu, one H100 with an AMD EPYC 7R13 host), per 3.8 GB Qwen3-14B shard, against the CPU path of the same host at 16 threads. The GPU archives equal the CPU's byte for byte.

GPU kernels GPU end to end CPU end to end
compress 0.04–0.07 s 1.9–3.7 s 1.0–1.9 s
decompress 0.007–0.016 s 1.8–4.3 s 0.5–0.9 s

The kernels are about 100× faster than the CPU coder, but copying between host and GPU memory and about 2 s of CUDA start-up per process make the CPU faster for file-to-file use. That is why the CPU stays the default.

GPU against DFloat11 and ZipNN (Qwen3-14B, the same 29,536,665,640 bytes for every codec, one H100 host; weights and archive in GPU memory for the GPU decoders; every decode checked against the original). These were measured with the kernels in gpu/kernels.cuh, run from a test harness before they were built into cmx, with 64 KiB sub-streams (-s 64; the default is 256 KiB).

size decode load from host memory
DFloat11 0.5.0 (published archive, its own kernel) 68.17% 529 GB/s 20.5 GB/s, measured
ZipNN 0.5.4 (CPU, 192 cores; no GPU decoder released) 66.75% 4.0 GB/s 3.1 GB/s, measured
BFR8, 64 KiB sub-streams, alone 66.27% 571 GB/s ~20 GB/s, estimated
BFR8, 64 KiB sub-streams, given Qwen3-14B-Base 43.84% 275 GB/s ~29 GB/s, estimated
BFR7 layout on the GPU, alone 66.11% 4.4 GB/s
  • Encode on the GPU: 137 GB/s alone and 68 GB/s given the base.
  • Load estimates: the archive copied at the measured 14.3 GB/s host-to-device rate, plus the decode. With 256 KiB sub-streams (cmx's default), measured end to end: 19.6 GB/s alone and 28.6 GB/s given the base, against 14.3 GB/s for copying the bf16 weights themselves.
  • Hot swap: with the base resident on the GPU, a whole Qwen3-14B fine-tune kept compressed (12.9 GB) decodes in 0.13 s.
  • Why BFR8: a BFR7 block is one rANS stream, which leaves a GPU about as fast as 16 CPU threads.
  • What limits the decoder: instructions issued per weight, not memory. With every memory access removed from a decode step, it still caps at 1,123 GB/s alone and 834 GB/s given the base.

Larger models on one H100 (the same kernels and harness, 256 KiB sub-streams with 32 lanes, the default; seconds for the whole model, sum over shards of the best of 3; every decode checked).

model GB size vs BFR7 GPU encode GPU decode copy + decode copy of the bf16 weights
Qwen3-1.7B 4.1 alone 65.92% +0.038 pp 0.033 0.022 0.21 0.28
given base 48.01% +0.039 pp 0.061 0.022 0.16
Qwen3-8B 16.4 alone 66.11% +0.038 pp 0.122 0.079 0.83 1.13
given base 43.76% +0.040 pp 0.255 0.078 0.57
Qwen3-14B 29.5 alone 66.15% +0.038 pp 0.216 0.140 1.49 2.05
given base 43.72% +0.040 pp 0.453 0.128 1.02
Qwen3-30B-A3B (MoE) 61.1 alone 65.68% +0.037 pp 0.476 0.362 3.17 4.28
given base 43.75% +0.038 pp 0.968 0.444 2.32
Qwen2.5-32B-Instruct 65.5 alone 66.08% +0.038 pp 0.480 0.314 3.30 4.53
given base 26.31% +0.040 pp 0.951 0.279 1.47
Qwen2.5-72B-Instruct 145.4 alone 65.72% +0.038 pp 1.056 0.678 7.28 10.04
given base 30.41% +0.040 pp 2.128 0.608 3.66

Time grows in proportion to model size: on the dense models, decode runs at 189–239 GB/s and encode at 123–138 GB/s alone and 64–69 GB/s given the base. The mixture-of-experts model decodes more slowly (169 and 138 GB/s), because its many small expert tensors leave sub-streams partly filled. For comparison, 16 CPU threads decoded Qwen2.5-72B-Instruct in about 82 s.

Size cost of the sub-streams (Qwen3-14B, against BFR7): +0.038 pp alone and +0.040 pp given the base at 256 KiB (the default), and about +0.15 pp at 64 KiB.

About

Per-File Models for Lossless Compression (cmxc)

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages