Featured image headed Latent Attention, Smaller KV Cache, with three takeaways: KV cache not FLOPs limits long context; MLA caches one latent instead of all K and V; RoPE must be decoupled from the cached latent.

Multi-Head Latent Attention: Compressing the KV Cache in the Architecture

Most discussions of attention cost start with the quadratic term: every token attends to every other token, so compute grows with the square of sequence length. In practice, teams running models in production hit a different wall first. Long before the matrix multiplications become unaffordable, the key-value cache fills the card. The cache is the model’s working memory during generation — the keys and values of every token processed so far, held for every layer — and it grows linearly with context, batch size and depth until there is no room left for anything else.

There is a well-known set of serving-side responses to this: paging the cache, quantising it, evicting parts of it. Multi-head latent attention (MLA), introduced by DeepSeek in DeepSeek-V2 (2024) and used up to DeepSeek-V3.2, takes a different route; in DeepSeek-V4 (April 2026) DeepSeek replaced it with a hybrid of Compressed Sparse Attention and Heavily Compressed Attention, and its DeepSeek-V4.1-Flash report (September 2026) moves to pure Compressed Sparse Attention 2 with FP4 KV caching. It changes what the model stores in the first place, by compressing keys and values into a small latent vector and regenerating the detailed ones on demand. That makes it an architecture decision rather than a deployment decision — which is exactly why it is worth understanding before you commit to a base model or a pre-training run.

Why the cache, not the FLOPs, is the binding constraint

A worked example makes the scale concrete. Take a dense model with 32 layers and 32 attention heads of dimension 128, serving in 16-bit precision. Per layer, each token contributes 32 × 128 = 4,096 key values and the same number of value values, so 8,192 numbers. Across 32 layers that is 262,144 numbers, and at two bytes each, 524,288 bytes — half a mebibyte of cache per token.

A single 8,192-token conversation therefore costs exactly 4 GiB. Thirty-two concurrent conversations cost 128 GiB, which is more than most single accelerators hold, before the model weights are loaded. The arithmetic has three uncomfortable properties:

  • It scales linearly with context length, so doubling the window doubles the cache.
  • It scales linearly with batch size, so throughput and context trade directly against each other.
  • It scales with depth and head count, so the better models are usually the hungrier ones.

During decoding the cache is also read in full for every single token generated, which makes attention memory-bandwidth bound rather than compute bound. A smaller cache is therefore not only a capacity win but a latency win.

What MQA and GQA trade away

The first generation of fixes attacked head count. Multi-query attention (Shazeer, 2019) keeps one set of keys and values shared by all query heads, collapsing the cache by a factor equal to the number of heads. Grouped-query attention (Ainslie et al., 2023) sits in between: query heads are divided into groups, and each group shares one set of keys and values. With 32 heads and 8 groups, the cache in the example above drops from 512 KiB to 128 KiB per token.

Both work, and GQA is now the default in most open-weight families. But both buy memory by removing representational capacity: heads that used to look at different projections of the context are now forced to look at the same one. The quality cost is usually small and usually recoverable with uptraining, yet it is a cost, and it is paid in the part of the model that does the most interesting work.

The MLA idea: cache a latent, not the keys

MLA keeps every head distinct and compresses along a different axis. Instead of sharing keys and values between heads, it projects the hidden state down into a single low-rank latent vector per token per layer, and caches only that. When attention runs, per-head keys and values are reconstructed from the latent by up-projection matrices learned during training.

The structure is deliberately unexciting from the model’s point of view. You still have queries, keys, values and a softmax; you have simply inserted a bottleneck on the path that gets stored. The bet is that the key and value spaces are effectively low rank — that the thousands of numbers cached per token per layer carry far less independent information than their dimensionality suggests, and that a few hundred latent directions capture what matters. DeepSeek reports in its DeepSeek-V2 technical report that DeepSeek-V2, whose attention is built on MLA, reduces the KV cache by 93.3% relative to the company’s earlier dense 67B model while achieving stronger benchmark results.

There is a further trick that makes the scheme cheap at inference time. Because the up-projection from latent to keys is a fixed linear map, it can be folded into the query projection: rather than expanding the latent back into full keys for every step, you push the query into the latent space and score there. The expansion largely disappears into weights that were already being multiplied.

The RoPE problem, and why positions are decoupled

Compression collides with rotary position embeddings (Su et al., 2021). RoPE applies a position-dependent rotation to queries and keys, so a cached key is not a neutral piece of content — it has a position baked into it. If positions were applied before compression, the cached latent would no longer be position free, and the absorption trick above would break, because the matrix between query and key would change at every offset.

MLA resolves this by splitting the head dimension in two:

  • A content part, carried by the compressed latent, with no positional rotation applied to it.
  • A positional part, a small number of extra dimensions that do carry RoPE and are computed and cached separately.

Attention scores are the sum of the two contributions. The cache stays dominated by a compact, position-agnostic latent, while position sensitivity is preserved through a narrow dedicated channel. It is a good example of a recurring pattern in efficient attention design: when a constraint blocks an optimisation, isolate the part of the computation that creates the constraint rather than abandoning the optimisation.

How it relates to serving-side techniques

MLA does not replace the work done at the serving layer; it changes the starting number. Paging, prefix reuse and cache quantisation all operate on whatever the architecture produces, so a model that produces an order of magnitude less cache per token makes every one of them go further. The relationship is multiplicative, not competitive. The same applies to kernel-level work: a compressed latent still has to be read efficiently, and the memory-bound character of decode attention does not change, as discussed in our pieces on serving LLMs on your own GPUs and on hybrid attention in long-context models.

The important asymmetry is timing. Serving-side changes can be adopted after the fact, on a model you already have. MLA has to be chosen before pre-training, or inherited by selecting a base model that already uses it. Converting an existing GQA model to MLA is an active research area rather than a routine operation, and it involves retraining effort that most teams will weigh carefully.

What this means for organisations training and running their own models

For anyone sizing a deployment on owned hardware, the practical consequences are straightforward:

  • Model selection is a memory decision. Two models with identical parameter counts can differ by an order of magnitude in cache per token. Compare cache arithmetic, not just weights, when deciding what fits on the cards you have.
  • Measure at your real context length. Benchmarks at 2k tokens hide the problem entirely. Load tests should use the prompt and conversation lengths your application actually produces.
  • Cache savings convert into whichever currency you need — longer context, larger batches, or headroom for a bigger model — but you have to decide which one, because you cannot bank all three.
  • Treat architecture as part of the cost model. If a fine-tune or a domain-specific pre-training run is on the table, the attention variant you inherit will constrain unit economics for the life of the model.

AMD Telecom has run machine learning in production since 2017 and trains and fine-tunes deep-learning models and large language models on its own in-house GPUs, so these trade-offs are operational rather than theoretical.

If you are weighing architecture choices for a model that has to run on hardware you control, our AI Model Development and AI Model Training services cover the path from design decisions through training and evaluation. Contact us to discuss what your workload needs.