TurboQuant compresses LLM KV caches 4-7x at inference time using random rotation + optimal scalar quantization, with near-zero quality loss. No training, no calibration data, fully data-oblivious. Drop-in replacement for HuggingFace Transformers cache.
Key Results
Benchmarked across 5 model families, 6 models (7B to 70B) on NVIDIA H100 NVL (96GB):
Model
Architecture
KV Heads
head_dim
Outlier Layers
Prefill Fidelity
Saved @8K
Qwen2.5-7B
28L, qwen2
4
128
layers 0, 27
exact
380 MB
Llama-3.1-8B
32L, llama
8
128
none
exact
890 MB
Gemma-2-9B
42L, gemma2
8
256
none
exact
2,323 MB
Phi-4-14B
40L, phi3
10
128
none
exact
1,392 MB
Qwen2.5-32B
64L, qwen2
8
128
none
exact
1,791 MB
Llama-3.3-70B
80L, llama
8
128
none
exact
501 MB (@2K)
Prefill logits are bit-identical (0.0 difference) across all 6 tested models. Output quality is coherent and semantically correct — divergence from uncompressed output is purely greedy-decoding drift, not quality degradation.
Needle-in-a-Haystack: 100% Recall
Tested on Qwen2.5-7B across 5 context lengths (1K-16K) and 3 needle positions (25%, 50%, 75%):
Llama-3.1-8B: Max/median ratio = 1.18x. No outliers at all.
Gemma-2-9B: Max/median ratio = 1.19x. No outliers.
Phi-4-14B: Max/median ratio = 1.38x. No outliers.
Finding: Smaller Qwen models have severe outlier layers. Larger models and non-Qwen architectures are well-balanced. Our calibrate_skip_layers() auto-detects outliers and keeps them in full precision.
head_dim Compatibility
The paper only tested head_dim=128 (Llama, Mistral). We verified TurboQuant works with head_dim=256 (Gemma-2) — the Lloyd-Max codebook adapts to any dimension since it's computed from the Beta distribution parameterized by d.
Architecture Coverage
Architecture
Paper Tested
We Tested
Works
Llama
Llama-3.1-8B
Llama-3.1-8B, 3.3-70B
Yes
Mistral
Ministral-7B
—
—
Qwen
—
Qwen2.5-7B, 32B
Yes (with outlier handling)
Gemma
—
Gemma-2-9B
Yes (head_dim=256)
Phi
—
Phi-4-14B
Yes
Files
turboquant/
├── __init__.py # Public API
├── codebook.py # Lloyd-Max solver for Beta distribution
├── quantizer.py # Core TurboQuantizer: rotate → quantize → pack
├── packing.py # uint4/uint2 bit packing
├── cache.py # TurboQuantCache for HF Transformers
scripts/
├── verify.py # Unit tests (MSE bounds, packing, fixed-point)
├── test_cache.py # Cache API integration tests
├── benchmark_models.py # Multi-model benchmark suite
├── run_inference.py # Interactive inference demo
benchmark_results.json # Raw benchmark data (all 5 models)
Verified Against Paper
Metric
Paper
Ours
MSE at 4-bit (unit vectors)
≤ 0.009
0.0093
MSE at 2-bit (unit vectors)
≤ 0.117
0.116
Compression ratio (per-vector)
~4x
3.88x
System compression @8K+
4-7x
7.2x
Prefill fidelity
"quality neutral"
exact (0.0 logit diff)
Double quantization
fixed point
verified (indices identical)
Requirements
Python 3.10+
PyTorch 2.7+ (CUDA 12.8 compatible)
HuggingFace Transformers 5.0+
scipy (for codebook computation)
bitsandbytes (optional, for 4-bit model loading)
Citation
If you use this implementation, please cite the original paper:
bibtex
1@article{zandieh2025turboquant,
2 title={TurboQuant: Online Vector Quantization with Near-optimal Distortion Rate},
3 author={Zandieh, Amir and Daliri, Majid and Hadian, Majid and Mirrokni, Vahab},
4 journal={arXiv preprint arXiv:2504.19874},
5 year={2025}
6}
License
This implementation is released under MIT License. The TurboQuant algorithm is described in the paper above.