Repository navigation
TurboQuant
🏠 Home · 🧭 Choose a method · 🚀 Quickstart · 🧰 Help
On this page
TurboQuant compresses the key/value cache that grows with context during standard softmax attention. Enable it per loaded model for generation with dense or quantized weights. The policy lives in memory for the current session. Saved weights and checkpoint metadata are unchanged.
from gptqmodel import GPTQModel, TurboQuantConfig
policy = TurboQuantConfig(key_bits=4, value_bits=3)
model = GPTQModel.load("Qwen/Qwen3-0.6B", kv_quant=policy)
output = model.generate("Explain grouped-query attention.", max_new_tokens=64)TurboQuant is off by default. Call model.enable_kv_quant(policy) to enable it after loading or model.enable_kv_quant(None) to use the ordinary cache for new generations. Set the policy before creating the cache. If you manage past_key_values yourself, create a TurboQuantDynamicCache with gptqmodel.utils.turboquant.make_turboquant_cache(model.config, policy) before the first call and reuse it with the same policy.
| Field | Default | Behavior |
|---|---|---|
key_bits |
4 |
Total key bit budget. Accepts 2, 3, or 4. With QJL enabled, one bit is reserved for the residual sketch. |
value_bits |
4 |
Value codebook bit budget. Accepts 2, 3, or 4. |
use_qjl |
True |
Use a one-bit QJL residual sketch for keys. Set False to use the full key budget for the ordinary codebook. |
seed |
0 |
Integer seed for the randomized Hadamard sign patterns. |
codebook |
"beta" |
Use the spherical-coordinate density with "beta" or the Gaussian alternative with "gaussian". |
center_keys |
True |
Subtract a frozen per-channel key mean before packing and add it back when reconstructing keys for attention. |
center_min_tokens |
16 |
Minimum length of the first non-empty key chunk used to estimate the mean. Accepts integers of at least 1. A shorter first chunk disables centering for that cache layer until reset. |
When centering applies, each cache layer averages the first non-empty chunk across its tokens and stores one FP16 vector per batch item and KV head. Later chunks reuse the same mean. Centering reduces the effect of large, consistent key offsets such as those measured in Qwen2.5. Each layer uses an additional batch_size * kv_heads * head_dim * 2 bytes, about 2 KiB for one batch item with 8 KV heads and a head dimension of 128.
- Use a decoder-only model with at least one standard full-attention dynamic cache layer and a power-of-two attention head dimension of at least eight. Llama 3.1, Llama 3.2, Qwen2.5, and full-attention Qwen3 ports are examples.
- Sliding-window, chunked, and hybrid attention, as well as MLA and compressed or indexed cache layouts, are unsupported. TurboQuant and LeapQuant cannot be enabled together.
- Use eager generation with the default cache implementation or
cache_implementation="dynamic". Generation rejects static or offloaded caches, compile requests, assistant decoding, prompt lookup, early-exit decoding, multi-token prediction, and custom generation callbacks. For an eager call, leavecompile_configunset and usedisable_compile=Trueif needed. - The wrapper reads generation keywords first, then the supplied
generation_config, then the model defaults. An effectiveuse_cache=Falsebypasses packed cache creation. With caching enabled, any suppliedpast_key_valuesmust be aTurboQuantDynamicCachewith the same policy as the model. - Cache keys and values must have matching shapes, devices, and FP16, BF16, or FP32 dtypes. Beam reorder, batch selection, and explicit batch repeats operate on packed data and the frozen key mean. Cache cropping, offloading, and conversion from a prepopulated dense cache are unsupported.
The cache stores packed codes and FP32 per-vector RMS values between attention calls. With QJL enabled, it also stores an FP16 key residual norm and a packed one-bit residual sketch. Each attention layer materializes its keys and values transiently in the activation dtype. If readout fails, the cache restores the sequence length, packed chunks, and centering state from the last successful update.
For Llama-3.1-8B at 8K context, the reported peak allocation above the pre-forward baseline was 3,100 MiB with the dense cache and 2,320 MiB with 4-bit keys and 3-bit values. The cache payload fell from 1,024 MiB to 244 MiB in that run.
In the reported 32K-token benchmark on Qwen2.5-0.5B with 4-bit keys and values, key centering lowered prefill perplexity from 253.93 to 33.74 with the default QJL key quantizer and from 154.90 to 20.27 with use_qjl=False. The dense cache scored 13.77. On Llama-3.1-8B at 4/3 with QJL, prefill perplexity was 7.7089 without centering and 7.7113 with it. Benchmark protocol and results
Documentation home · Quickstart · Troubleshooting · Repository · PyPI
Public source 780f1bbfc declares package version 7.15.0. Individual pages identify their source revisions. Choose a method · Dtypes and formats. Maintained by ModelCloud.ai.
🧭 1 · Choose and understand
🚀 2 · Use it
- Installation and Quickstart
- Loading and Inference
- LeapQuant recurrent-state quantization
- Evaluation
- Serving
- Troubleshooting and FAQ
- Memory, Offload, Multi-GPU
- MLX / Apple Silicon
- Tenstorrent / Block Floats
- Hugging Face Integration
- Multimodal and MoE Models
🎛️ Methods and representations
Each guide: choose → examples → math / advanced
- GPTQ / GPTAQ / G2PTQ / ADMM-Q / RTN
- SINQ
- JointQ
- AWQ
- QQQ
- MACaQ / MXFP4
- EXL3
- CPTC
- VPTQ
- Tetra
- TWLA
- Paro
- FP8 and NVFP4
- NF12: lossless BF16 storage
- GGUF families
- BitsAndBytes: NF4 / FP4 / INT8
🧰 Refinement and execution
- GSQ refinement / allocation
- EoRA adapters
- Rotation, Smoothing, Norm Tuning
- Projection Fusion
- TurboQuant KV cache
🧠 3 · Theory and advanced reference