Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI and machine learning / Language models / Remembering context efficiently

KV cache quantisation: storing keys and values in fewer bits

Every cached number takes 16 bits. How many could we drop before the model stops noticing?

A cached key holds 128 numbers, and each number is written with 16 bits.

Does it need all 16?

Fewer bits, a smaller cache

The same cache stored in 16, 8, 4 and 2 bits per numberFour rows show 16, 8, 4 and 2 bits per cached value and their combined storage at the selected model's maximum context.KV cache at its longest context16 bits8 bits4 bits2 bits
What to notice: Halve the bits per value and halve their storage. These sizes count the selected model’s cache values, including shared, compressed and sliding-window caches.

At 2 bits the cache is an eighth of the size. What would we lose?

Can a number survive in 2 bits?

Two bits can only name four values. So we pick four levels, evenly spaced, and round each number to the nearest one.

Store a two-bit code, then rebuild its valueFour levels are -3, -1, 1 and 3. The number 0.6 rounds to 1, stored as code 10, or level 2. Store starting point -3 and spacing 2 once for the group. Rebuild the value as -3 plus 2 times 2, which is 1.Four codes, four levels-300-101110311spacing: 2start: −30.6 → 1What we keepOnce for this groupstart −3 · spacing 2For this number: just 2 bits10 (level 2)Read it back−3 + 2 × 2 = 1start + level × spacing
The two bits choose a level. The starting point and spacing give that level its value; both are stored once for the group.

We get 1 back, rather than 0.6. The orange gap is the rounding error.

One big number spoils the group

Numbers that share a spacing form a group. If one number is huge, the levels stretch to reach it, and the ordinary numbers pile onto the same few levels.

The cache is a grid: a row for each token, a column for each channel. We can group by row or by column.

Grouping numbers for quantisation: per token or per channelTwo eight by eight grids of numbers with tokens as rows and channels as columns, two of them large. On the left a whole row shares one scale; on the right a whole column shares one scale.One scale per tokenone row shares a scale: the largechannels set the range for the small onesOne scale per channelone column shares a scale: all itsnumbers are of a similar size
What to notice: Dark channels contain large values in this constructed example. Compare row and column groupings: which gives the smaller values room between the rounding levels?

Keys and values break differently

Some key channels are large for every token, so a column holds the trouble. Value sizes change from token to token, so a row does.

Would rows or columns make better groups? Compare the originals with their rounded copies below, then switch the grouping.

Same numbers, different rounding

Interactive

The originals stay fixed. Watch what rounding keeps—and what it loses.

Keys

A few channels hold large numbers across tokens.

Original
After rounding

Average rounding error:

Values

Some tokens hold larger numbers across channels.

Original
After rounding

Average rounding error:

Blue: positive. Orange: negative. Brighter: larger. Each pair uses the same colour scale. The outline shows one group sharing its starting point and spacing.

Rounding changes what attention sees. Always compare the quantised model’s answers with the original’s.

We have made each entry cheaper to store. But how much memory sits wasted around them? That is PagedAttention.

Sources and assumptions
  • KIVI (2024, Zirui Liu and colleagues), a tuning-free asymmetric 2-bit method with keys grouped per channel and values per token. It reported little quality change on its tested Llama, Falcon and Mistral workloads and about 2.6 times less peak memory, including weights.
  • KVQuant (2024, Coleman Hooper and colleagues), a different design with per-channel keys, pre-RoPE key quantisation, non-uniform levels and outlier handling.
  • Serving support: vLLM’s FP8 cache and TensorRT-LLM’s INT8 and FP8 caches, checked on 14 October 2026. Support changes between releases; use the backend’s current documentation for your model and hardware.

Cache sizes for the selected model are ideal payload storage at its longest context: tokens, attention layers and cached numbers per token, times the bytes per number. Models that cache a compressed latent use that. Real schemes also store a scale and an offset per group, which adds about a quarter of a bit per number for groups of 128 (two 16-bit values per 128 numbers). They also keep a recent full-precision buffer and padding. The 2.6 times figure is a whole-system result and differs from the ideal eightfold shrinkage of a 2-bit payload.

The rounding is uniform integer rounding: a group’s smallest and largest values set the spacing, `s = (max - min) / (2^b - 1)`, a number is stored as the nearest level index, and `level × s + min` rebuilds it. Other schemes use an integer zero point. FP8 uses uneven floating-point spacing; the widget does not simulate it. The cache in the widget is generated with a fixed seed, 16 tokens by 16 channels, with a few large key channels as in real keys. KIVI’s streaming method also uses finite groups and a recent full-precision buffer. Whether a real model’s answers stay acceptable needs testing on its actual tasks. FP8 quality depends on calibration, scales and backend support.

← Browse all subjectsBack to the beginning ↑