What multi-head latent attention is
MQA and GQA shrink the KV cache by having fewer key and value heads. Multi-head latent attention (MLA), introduced with DeepSeek-V2, keeps a full set of heads but caches something smaller than any of them: each token is compressed into one latent vector , from which every head rebuilds its own keys and values when it needs them.
This page shows layer 3 of 27 of DeepSeek-V2-Lite (16B parameters, 2.4B active), taken from a full-model recording of the prompt “The capital of France is”, with 16 heads. The toolbar counts what the cache keeps per token in this layer: 576 numbers, a 512-dimensional latent plus a 64-dimensional rotary key, where multi-head attention with these heads would keep 5,120.
The latent cache
A down-projection maps each token's 2,048-dimensional input to the latent, followed by an RMSNorm; two up-projections per head, and , expand it to a 128-dimensional content key and a 128-dimensional value:
The KV cache column holds for every token; the W↑K box on the head card and the W↑V note under the values are the up-projections, 512 → 128 for each of the 16 heads. In the recorded checkpoint they are one matrix of weights, rows. The queries do not go through a latent in this model: one projection gives each head a 192-dimensional query.
The page expands the keys and values so that each head's can be seen. At inference they need not exist: since , DeepSeek-V2 folds into the query and into the output projection, and attends directly over the cached latents.
Decoupled RoPE
Rotary position embeddings (see the GQA tab) would break that folding: a rotation that depends on the key's position would sit between and the latent, and could not be moved into the query. MLA therefore carries position separately. Each head's query has 128 content dimensions and 64 rotary ones; each token has one 64-dimensional rotary key , rotated by RoPE and shared by all 16 heads, like MQA's single key. The score adds the two parts:
The cache keeps next to the latent, which is where the 512 + 64 comes from. Clicking the W↑K box opens a row's content part and the RoPE box its rotary part; the matrix shows the softmax of their sum. In head 5, “ is” puts 0.84 of its weight on “ France”.
The scale
A plain head would scale its 192-dimensional dot products by . DeepSeek-V2 extends its context with YaRN, which stretches the low RoPE frequencies by a factor of 40 beyond the original 4,096 positions and corrects the attention temperature, so the recorded scale is
as the toolbar shows.
What it saves
Per token and layer, multi-head attention with 16 heads of 192-dimensional keys and 128-dimensional values would cache numbers; MLA caches 576, about a ninth. Unlike MQA, every head still has its own keys and values, rebuilt from the latent. The DeepSeek-V2 paper reports that against DeepSeek 67B the model cut the KV cache by 93.3 % and raised the maximum generation throughput 5.76 times.
Where it came from
MLA appeared in DeepSeek-V2 (2024) and was kept in DeepSeek-V3. It continues the line of MQA (2019) and GQA (2023), which shrink the cache by sharing heads, while the rotary key it shares is MQA's idea applied to position alone. The Transformer Explainer's MLA tab shows a whole DeepSeek block; the DP attention tab of the Efficiency Explainer shows how serving systems split MLA's small cache across GPUs.
Papers
- DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model Introduces multi-head latent attention with decoupled RoPE; DeepSeek-V2-Lite, recorded here, is described in its appendix.
- DeepSeek-V3 Technical Report The next DeepSeek model, which keeps MLA at a larger scale.
- YaRN: Efficient Context Window Extension of Large Language Models The RoPE scaling and attention temperature behind this page's rotary key and its scale.
- RoFormer: Enhanced Transformer with Rotary Position Embedding Rotary position embeddings, applied here to a 64-dimensional slice only.
- Fast Transformer Decoding: One Write-Head is All You Need Multi-query attention: the first way to shrink the KV cache by sharing keys and values.
- GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints Grouped-query attention, the head-sharing method MLA is compared against.