Shared K/V: could one entry do both jobs?
MQA already shares the cache across query heads. Could tying K and V reduce its memory further?
Multi-query attention (MQA) already saves memory by letting every query head read the same keys and values.
Could we use even less memory?
One shared cache still stores two vectors
MQA shares entries between heads, but it still makes a key to score and a value to collect. With 512 coordinates in each, that is 1,024 stored numbers per position.
The key and value have different jobs. But do those jobs require different vectors? We could learn one projection and use its result for both:
We would store 512 numbers per position instead of 1,024. At the same vector widths and precision, that halves the stored K/V data on top of the saving from MQA.
Read the same vector in two ways
The attention operation already has the two uses we need. Compare the query with the stored entry to get its attention weight, then use that weight to collect information from the same entry:
The trade-off is in what the model can learn. Separate projections let matching and content use different features. Tying them requires one representation to work for both scoring and supplying information to the result.
This is the shared K/V representation used by DeepSeek-V4. One learned Wkv produces the entry; the label Wk = Wv in the worked diagrams describes this tying.
Keep the cache shared across query heads
We keep the head-sharing arrangement from MQA. The tied entries stay outside the head stack. Each head still has its own query, its own attention weights and its own collected result:
The input still makes a different query for each head. Each head’s attention map weights the shared entries as values, then its output projection makes an update for the residual stream:
The optimisations act on different parts of the memory cost. MQA shares the cache across query heads. Tying K and V shares the vector within each stored position. Using both leaves one set of entries, with one vector per position.
The cache still adds an entry for every token. Even this smaller shared history keeps growing. Could we keep recent tokens individually and compress the older information?
Sources and assumptions
- DeepSeek-V4 technical report: shared-KV multi-query attention in DeepSeek-V4.
- DeepSeek-V4 implementation:
kv_proj, the same tensor passed as keys and values, and shared compressed entries.
The comparison begins with ordinary MQA, which shares distinct key and value caches across query heads. The final diagram shows tied-KV MQA with the usual dense per-head query and output projections, to isolate the cache change. DeepSeek-V4’s factorised query path, normalisation, positional operations and grouped output projections are expanded in the final series article. The storage comparison counts cached K/V scalars at equal widths and precision; it does not estimate model weights or temporary workspaces. Full-resolution history isolates the representation choice before the next article introduces sequence compression.