What is key-value (KV) cache quantisation?

KV cache quantisation is a method that stores the key and value tensors built up during inference at lower precision, such as 8, 4 or 2 bits instead of 16, cutting GPU memory needs for long contexts.

It is also spelt KV cache quantization. Unlike weight quantisation, which shrinks the model's fixed parameters, it shrinks only the cache built up for each request at run time.

Topic
Inference and performance
Also known as
KV cache quantization, KV cache compression

How key-value (KV) cache quantisation works

  1. Scales are computed for the key and value tensors produced in each layer.
  2. Tensors are converted to low bit width and cached; methods such as KIVI quantise keys per channel and values per token.
  3. In attention the cached values are dequantised or used directly at low precision.
  4. Quality is measured on long-context tasks against an unquantised cache.

In more detail

FP8 hardware support and on-the-fly dequantisation cost

Hardware support dictates which precision is fastest in production: FP8 (E4M3/E5M2) KV caches can be read and processed natively by Hopper and Blackwell tensor cores (e.g., via FlashAttention-3), often improving decoding throughput with negligible quality loss. By contrast, INT4 and INT2 caches generally require on-the-fly dequantisation inside fused attention kernels, trading extra compute or kernel complexity for larger memory savings.

Outliers, attention sinks and the residual window

Keys and values have distinct outlier patterns: keys frequently exhibit persistent outlier channels across tokens, whereas values vary more smoothly by channel but can spike per token. Quantising keys per channel and values per token, often keeping the initial attention-sink tokens and a small recent residual buffer in 16-bit precision, prevents severe accuracy collapse at 4 or 2 bits.

The KV cache size formula and the effect of GQA and MLA

KV cache memory per token is roughly 2 × layers × KV heads × head size × bytes per element. Models using grouped-query attention (GQA) or multi-head latent attention (MLA) already shrink KV footprints sharply compared with classic multi-head attention (MHA), so quantisation gives its largest absolute gains when long contexts and high concurrency come together.

Commonly confused terms

TermHow it differs
KV cache eviction and pruningKV cache eviction drops less important tokens (keeping attention sinks and recent windows) to cap memory at a fixed budget, whereas KV cache quantisation retains all tokens in the context window at reduced numerical precision.
Activation quantisationActivation quantisation quantises intermediate tensors in linear layers (such as W8A8 GEMMs) to accelerate compute, whereas KV cache quantisation specifically targets cached attention K/V tensors to save VRAM capacity and memory bandwidth across decoding steps.

Why key-value (KV) cache quantisation matters for on-premises AI

With long contexts the KV cache can take more memory than the model weights. In the long-context model example, a cache of about 16 GB for 128 thousand tokens drops to about 8 GB at 8 bits and about 4 GB at 4 bits. The memory saved goes to longer contexts or more concurrent requests on the same GPU. The price is a risk of quality loss, mostly on detailed questions over long documents, so it is validated on the organisation's own tests.

ON-PREMISES EXAMPLE

An audit firm quantises the KV cache of its in-house assistant for long financial reports to 8 bits, letting more analysts work at once on the same GPU after checking results against the original setup on its own test set.

Common questions

Does KV cache quantisation also quantise model weights?

No. It compresses only the key and value cache built up at run time; weight quantisation is a separate step and the two can be combined.

How many bits are safe?

8 bits works with small loss on most models; at 4 bits and below results depend on method and model. Decide by measuring on the organisation's own long-context tasks.

Sources

In the glossary: Glossary, E to L

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.