All glossary terms

Model architecture

Grouped-query attention

An attention variant that shares each key-value head across several query heads, shrinking the KV cache per token and raising how many users one card holds.

In plain multi-head attention, every query head carries its own key and value states, so the per-token cache is one key-value entry per head per layer. Grouped-query attention assigns several query heads to one shared key-value head, so the cache entry count per layer - the number of KV heads - drops. Multi-query attention is the limit case of one shared head. The quality cost is usually small because queries vary more than keys and values do, and the concurrency gain is direct.

The cache bytes per token fall in exact proportion to the KV head count: bytes per token = 2 (keys plus values) x layers x KV heads x head dimension x bytes per value. Halve the KV heads and the cache budget halves - no quantization of the cache itself, no precision change, purely an architecture choice made before training. That is why serving teams ask which attention variant a candidate model uses before sizing a fleet: it is a multiplier on every downstream memory number.

The trade is breadth against depth: with fewer KV heads the card holds more users per card, but attention has less state to distinguish contexts, which can show up as quality loss on tasks that genuinely need many distinguishable positions. The measured comparison is a concurrency-per-card figure against an eval pass rate, and the answer one model at a time - which is why two models of comparable quality at different KV head counts can price serving very differently.

A worked example

Two variants of the same 70B-class model at 40 layers, 128 head dimension, fp16: one with 32 KV heads, one trained with grouped-query attention at 8 KV heads. A card has 9 GiB free for the cache after its weights.

  1. Multi-head, 32 KV heads: 2 x 40 x 32 x 128 x 2 = 655,360 bytes, about 640 KiB per token, and one 4k-token user holds 4,096 x 640 KiB = 2,560 MiB.
  2. Grouped-query, 8 KV heads: one quarter of the state, 160 KiB per token and 640 MiB per 4k user.
  3. Concurrency: 9 GiB holds 9 / 2.5 = about 3 users under multi-head and 9 / 0.625 = about 14 under grouped-query - the same card, the same quality class, 4x the seats.

Dropping KV heads from 32 to 8 quarters the per-token cache, 2,560 MiB down to 640 MiB per 4k user - about 3 users per card becomes about 14 without touching precision.

Where this shows up

Related terms