A story: the cloakroom that runs out of space
Picture a large theater. At every show, the audience arrives with coats, bags, umbrellas. The cloakroom has to hold everything for the whole performance, and the fuller the house, the more it overflows. At some point there's simply no room left: it's the cloakroom, not the hall, that caps how many people you can admit.
A language model generating text lives exactly this problem. With every new word it produces, it must remember everything it has already read and written. That working memory is called the KV cache, and it (not raw compute) is what saturates first on long contexts.
Multi-head Latent Attention (MLA) is a clever way to tidy that cloakroom: instead of keeping each coat separately, you compress them into a small shared locker, then reconstruct them only when needed. The cloakroom becomes tiny, the show stays just as good.
Refresher: what the KV cache is, and why it hurts
When a Transformer reads text, each token produces three vectors per attention head: a query (Q, "what I'm looking for"), a key (K, "what I offer") and a value (V, "the information I carry"). Attention compares the current token's query against the keys of all previous tokens, then blends in their values.
The key point: to generate the next word, you don't recompute the K and V of tokens already processed, you cache them. That's the KV cache. The query is never stored: the current token's query is used once and never again, while the keys and values of the whole past are re-read at every step, you cache what gets re-read, not what is written once (the full explanation). The catch: the cache's size grows linearly with context length and with the number of heads. Over 100,000 tokens and dozens of layers, that's tens of gigabytes of GPU memory. It is the real bottleneck of inference.
Three families of attention have tried to attack this cost:
- MHA (Multi-Head Attention), every head has its own K and V: maximum quality, huge cache.
- MQA (Multi-Query Attention), all heads share a single K/V pair: tiny cache, but quality can suffer.
- GQA (Grouped Query Attention), a middle ground: a few K/V groups (typically 8) shared across heads.
MQA and GQA shrink the cache by cutting the number of K/V heads: you keep fewer copies. It works, but it's a head-on trade-off, fewer K/V heads means potentially less nuance. MLA takes a different road: keep the equivalent of all heads, but in compressed form.
The MLA idea: compress, then decompress
MLA was introduced with DeepSeek-V2 (2024) and carried over into DeepSeek-V3. The intuition fits in one sentence: don't cache the full K and V, cache a small latent vector that summarizes them, and rebuild K and V on the fly when you compute attention.
DeepSeek-V2The underlying observation is the same as in image compression: the K and V across all heads carry a lot of redundancy. You can project them into a low-dimensional ("latent") subspace without losing much. This is a low-rank compression: replace one large matrix with the product of two small ones.
Rather than writing down every word spoken in a meeting (the full K and V), you take a compact summary (the latent vector). When you need a specific detail, you expand just the useful part of the summary. The notebook stays thin, yet the information is recoverable.
How it works, step by step
1. The "down" projection: compress
For each token, instead of computing keys and values directly, you first compute a single compressed latent vector , of dimension far smaller than the combined K/V size across all heads:
where is the representation of token (the vector entering the attention layer) and is the compression matrix (down-projection), a learned parameter, fixed at training time, the same for all texts. The latent vector , on the other hand, is a result, recomputed for each token of the current text. It is this vector , and only this one, that gets cached.
2. The "up" projection: decompress
When it's time to compute attention, you reconstruct each head's keys and values from the latent, via decompression matrices (up-projection):
You thus recover full-dimensional K and V, head by head (just like MHA) but without ever having stored them. Only the small takes up memory.

3. What is actually cached
The contrast is striking:
- MHA caches, per token and per layer, the K and V of all heads.
- MLA caches only (plus a small position component, see below).
Because is much smaller than the heads' combined dimension, the cache shrinks dramatically, typically in proportions comparable to, or better than, an aggressive GQA, while keeping quality close to full MHA.

MLA's up-projections can be mathematically absorbed into the query and output matrices. In practice you often don't have to explicitly decompress K and V at every step: you can reorganize the computation to work directly on the latent. This prevents decompression from eating up the memory savings in compute time.
The subtle point: RoPE breaks compression
Here is the technical wrinkle that makes MLA non-trivial. Modern LLMs encode word position with RoPE (Rotary Position Embedding, dedicated lesson): queries and keys are given a rotation whose angle depends on the token's position.
The problem: if a key is meant to be rebuilt on the fly via , but must then receive a rotation that is different for every position, then you can no longer cleanly pre-fold the matrices, nor cache an already-"positioned" latent. The position-dependent rotation interferes with the low-rank compression.
The fix: decoupled RoPE
DeepSeek solves this by splitting the dimensions into two sets:
- A position-free part: most dimensions, compressed into the latent and rebuilt by up-projection. They carry no position information.
- A small position-dedicated part: a few extra key dimensions that do receive RoPE. These are computed and cached separately.
Reading the formula: token 's final key is two pieces laid end to end. The first, , is the content, rebuilt from the compressed latent. The second is the position: a small dedicated learned matrix, , produces a few key dimensions from , and RoPE's rotation is applied to those alone. At attention time you concatenate the two. Result: compression stays intact for most of the vector, while position lives in a small dedicated channel that supports RoPE without breaking the rest. The extra cache for this positional part is minimal.

Without decoupled RoPE, MLA would either be incompatible with standard positional encoding, or be forced to give up the matrix-absorption trick (and thus lose part of its advantage). Decoupling is precisely the ingredient that makes MLA both RoPE-compatible and memory-efficient.
A forward-looking variant: NoPE
Since position causes so much trouble, an obvious question arises: what if we did without it? That's the idea behind NoPE (No Positional Encoding).
The observation, surprising at first: a causal decoder (one that can only look at past tokens, never the future) already holds implicit position information. The mere fact that token 5 "sees" 5 tokens while token 50 sees 50 is enough for the network to infer an order, no explicit position injection required. Some work shows causal decoders can run without explicit positional encoding, sometimes with better generalization to lengths never seen during training (explicit encodings tend to "break down" outside their training range).
The link to MLA: since RoPE is exactly the part that complicates compression and generalizes poorly at very long context, one research direction is to use less RoPE, or none at all, leaning on implicit position. Recent architectures thus mix layers with no positional encoding and layers with a bit of RoPE, to combine long-context robustness with the ability to model precise positions.
NoPE doesn't mean "no notion of position whatsoever", it's the idea that the causal mask already carries part of that information, so you can lighten (or drop) explicit positional encoding, especially to generalize better to very long contexts.
Comparison table: MHA / MQA / GQA / MLA
| Mechanism | What is cached | Cache size | Quality |
|---|---|---|---|
| MHA | K and V of all heads | Largest (baseline) | Maximum (baseline) |
| MQA | A single shared K/V pair | Smallest | Good, but can lag on demanding tasks |
| GQA | A few K/V groups (often 8) | Reduced (roughly ÷8 vs MHA) | Near-MHA |
| MLA | A compressed latent vector (+ small RoPE channel) | Strongly reduced, comparable to or better than GQA | Close to full MHA, often above GQA at equal cache |
DeepSeek's argument is precisely this: at a memory budget comparable to GQA, MLA tends to preserve quality better, because it doesn't throw heads away, it compresses the information of all heads and reconstructs it.
Why it matters
The KV cache is the factor that decides how many users you can serve in parallel, and up to what context length, on a given piece of hardware. Cutting that cache directly cuts inference cost and unlocks longer contexts without changing GPUs. MLA is one of the first techniques to deliver that reduction without the usual quality trade-off of "fewer heads" approaches, which explains its adoption in frontier models and the interest it draws, including from an intellectual-property standpoint (it is a clearly identifiable, differentiating architectural optimization).
Key takeaways
- The KV cache is the model's working memory at inference; it grows with context and becomes the main memory bottleneck.
- MLA compresses the keys and values of all heads into a small latent vector (down-projection), then rebuilds them at compute time (up-projection); only the latent is cached.
- Unlike MQA/GQA, which reduce the number of K/V heads, MLA keeps the information of all heads but in compressed form, hence quality close to MHA at a strongly reduced cache.
- RoPE breaks compression: the position-dependent rotation prevents pre-folding and caching a "positioned" latent. Decoupled RoPE isolates position in a small dedicated channel, leaving the rest compressed.
- NoPE reminds us that a causal decoder holds implicit position; one can therefore lighten or drop RoPE, notably to generalize better to long context, hence MLA + less-RoPE combinations.
- Introduced with DeepSeek-V2, reused in DeepSeek-V3, MLA offers an excellent memory/quality trade-off and illustrates a deeper trend: optimize inference by compression rather than by removal.
1. During generation, what does MLA actually cache for each token?
2. In the formula c_t = W_DKV h_t, what is the difference in nature between the matrix W_DKV and the vector c_t?
3. How does MLA's strategy differ from MQA's and GQA's?
4. Why does RoPE cause trouble for MLA, and how does DeepSeek solve it?
5. What does the NoPE (No Positional Encoding) idea actually mean?