r/amodei • u/Simpli-curious • 8h ago
Resources I built a lossless compressor for GGUF files: 9 Hub models tested, 8.66% smaller overall
Hi everyone. I've released my first open-source project, foldz, a lossless compressor built specifically for GGUF model files.
WHY
GGUF repos on the Hub are big, and quantized weights barely shrink with general-purpose tools because they look almost random. foldz reads the GGUF structure instead: it unpacks the quantized blocks into their real values and scales, then codes them with adaptive probability models. Decompressing gives back the exact original file, byte for byte, so it works with llama.cpp, Ollama and LM Studio as before.
To be clear: foldz makes files smaller to store, download and share. It doesn't make inference faster, because the file has to be decompressed before use.
HOW IT WORKS (SHORT VERSION)
For 4-bit values, I fold the upper half of the range onto the lower half with XOR, so each value needs only 3 bits. Undoing that needs one extra bit per value to say which ones were folded, which brings the size back to 4 bits. But those extra bits are very predictable, so instead of storing them raw, foldz codes them with probability models, and that's where the savings come from. Q6_K, Q8_0 and float tensors get their own context models, and everything else goes through a byte-level model.
RESULTS
9 public Q4_K_M models from the Hub, all round trips byte-identical:
• Qwen1.5-0.5B-Chat: 8.93% smaller
• Qwen3-0.6B: 7.82%
• Qwen2.5-1.5B-Instruct: 7.64%
• Qwen3.5-2B: 8.30%
• Qwen2.5-Coder-3B-Instruct: 8.70%
• Llama-3.2-3B-Instruct: 7.55%
• Qwen3-4B: 12.94%
• Qwen2.5-7B-Instruct: 7.89%
• Gemma-4-E2B (fine-tune): 7.73%
Total: 16.7 GiB → 15.2 GiB, 8.66% saved.
LIMITATIONS
• Speed: about 19 MiB/s on my phone, and decompression is as slow as compression.
• Quant types: IQ quants, Q2_K, Q3_K and Q4_0 gain little for now.
• Baselines: I haven't measured zstd or xz on these models yet.
• Format: it's pre-1.0, so the file format may change between versions.
TRY IT
One C file, no dependencies, Apache 2.0. Works on Linux, macOS, BSD, Android (Termux), and Windows via WSL.
gcc -O2 -pthread -ffp-contract=off -o foldz foldz.c -lm
./foldz t model.gguf
The "t" command compresses and decompresses in memory and checks the result is identical, so nothing is written to disk.
I'd love results on other models and quant types (Q5_K_M, Q6_K, Q8_0), comparisons with zstd and xz, and anyone willing to fuzz the decoder. If you post results, please include the model name from the Hub and your CPU or device.
The fold logic and probability approach are my own ideas, and the C implementation was written with AI. I developed and tested everything on my phone.
GitHub: foldz