Multi-Head Latent Attention (MLA): How DeepSeek Cuts KV Cache Memory

Multi-head latent attention caches one latent vector per token instead of per-head keys and values.

Multi-Head Latent Attention (MLA): How DeepSeek Cuts KV Cache Memory
Written by TechnoLynx Published on 30 Aug 2026

Multi-head latent attention (MLA) shrinks the KV cache by storing one compressed latent vector per token per layer, shared by every attention head, in place of a separate key and value for each head. DeepSeek introduced it in DeepSeek-V2, and the V2 paper reports a KV cache 93.3% smaller than that of DeepSeek 67B. In DeepSeek-V3 the cached state comes to about 70 KB per token, compared with 516 KB for LLaMA-3.1 405B and 327 KB for Qwen-2.5 72B, according to DeepSeek’s 2025 hardware paper. The less obvious effect shows up on the GPU. Because a single latent serves all heads, decode attention can move from the usual memory-bound regime into a compute-bound one, and whether it actually does depends on how many query heads each GPU runs.

What Multi-Head Latent Attention Caches Instead of Keys and Values

Standard multi-head attention (MHA) caches a key and a value for every head, which comes to 2·n_h·d_h·l elements per token (n_h heads of dimension d_h across l layers), and the DeepSeek-V2 paper names this cache as the bottleneck that limits maximum batch size and sequence length in deployment. MLA replaces that with a low-rank joint compression: a projection matrix, trained with the model, maps each token’s hidden state to a small latent vector c_KV, and at inference time only that latent is cached. Keys and values for every head are reconstructed from the same latent, so one joint representation covers both.

During decoding, the key up-projection W_UK is folded into the query projection W_Q and the value up-projection W_UV into the output projection W_O, so full keys and values never materialise and each query attends straight to the latent. vLLM’s engineers call this “matrix absorption” and describe it as the core of MLA’s advantage, because the model computes directly on cached latent values. MLA also compresses the queries, but only to save activation memory during training; query compression does nothing for the KV cache.

Why Rotary Position Encoding Needed Its Own Path

Rotary position encoding (RoPE) is incompatible with this low-rank compression. If RoPE is applied to keys reconstructed from the latent, a position-dependent rotation for the current token sits between W_Q and W_UK. Matrix multiplication is not commutative, so W_UK can no longer be absorbed, and the keys for every prefix token would have to be recomputed on each step. DeepSeek’s fix, decoupled RoPE, adds a separate set of multi-head queries and a single shared key that carry the rotation outside the compression path. The decoupled key must be cached as well, so the per-token cache is (d_c + d_h^R)·l elements, where d_c is the latent dimension and d_h^R is the RoPE key dimension.

Query-Key Normalisation (QK-Norm), one fix for growing attention logits, cannot be applied to MLA because its key matrices are not fully materialised during inference. Moonshot’s Kimi K2 team built a separate weight-clipping method, QK-Clip, for that reason. In our view, anyone changing an MLA model’s attention block (normalisation, positional scheme, logit control) should first check whether the change assumes explicit keys, since the inference path does not have them.

What Sits in a DeepSeek-V3 Cache Entry

DeepSeek-V3 sets the KV compression dimension d_c to 512, with 128 heads of dimension 128. The GLA authors’ MLA configuration pairs this 512-dimensional latent with a 64-dimensional decoupled RoPE key, which is consistent with the 576-element-wide K blocks that DeepSeek’s FlashMLA decode kernel loads. On that basis each token stores one 576-element vector per layer, shared across all 128 heads, with nothing stored per head.

How Much Memory Does the MLA KV Cache Save Against MHA, GQA and MQA?

The comparison is easiest to read from the per-token formulas the DeepSeek-V2 paper gives for each mechanism:

Mechanism KV cache per token (elements) What is cached Capability
Multi-head attention (MHA) 2·n_h·d_h·l One K/V pair per head Strong
Grouped-query attention (GQA) 2·n_g·d_h·l One K/V pair per group of n_g groups Moderate
Multi-query attention (MQA) 2·d_h·l One K/V pair for all heads Weak
Multi-head latent attention (MLA) (d_c + d_h^R)·l, about 4.5·d_h·l in DeepSeek-V2 One latent for both K and V, all heads Stronger than MHA, equal in cache to GQA with 2.25 groups

One property of these formulas matters more than any single percentage. The MLA cache size contains no n_h term, so adding query heads costs no extra cache, while MHA’s cache grows linearly with head count. That is why the savings figure you see quoted depends heavily on how wide the baseline model is.

Worked Example: Where the 70 KB per Token Comes From

Assume the DeepSeek-V3 configuration above and BF16 storage (2 bytes per element).

  1. MLA per layer: 512 latent + 64 RoPE = 576 elements.
  2. Layers: assume 61, the layer count vLLM uses for its DeepSeek V3.2-style estimate.
  3. Per token: 576 × 61 × 2 bytes = 70,272 bytes, about 70 KB, consistent with the 70 KB DeepSeek publishes.
  4. A hypothetical MHA layer with the same heads would cache 2 × 128 × 128 = 32,768 elements, so MLA stores 576 / 32,768 ≈ 1.8% of that per layer.

The MHA comparison describes a hypothetical model, so read it as the effect of the architecture choice and not as a measured comparison between products.

Reading the Headline Percentages Correctly

The 93.3% figure compares DeepSeek-V2 against DeepSeek 67B, which is a different model, and the deployed V2 also quantises each cache element to 6 bits on average. The paper’s like-for-like ablation is cleaner. MLA needs 14% of the MHA cache for small MoE models (15.6K against 110.6K elements per token) and 4% for large ones (34.6K against 860.2K). Against GQA, the GTA/GLA authors note that a GQA-8 model allocates roughly 4× more KV cache bytes than MLA, although under four-way tensor parallelism the two occupy about the same per device.

A 2025 study of small language models measured a 45% KV cache reduction with the latent set to half the model dimension and a 0.3% rise in validation loss, and found that MLA without RoPE underperformed vanilla attention by 3-5%. How much MLA saves is a property of the latent rank against the model’s width and head count, not a fixed constant.

Does MLA Make Decode Attention Compute-Bound on GPUs?

It can: in DeepSeek’s own decode instances, the FlashMLA attention kernel is compute-bound. Standard decoding with a KV cache turns attention into matrix-vector work (GEMV) with a low compute-to-memory ratio, which is why it is normally memory-bound. MLA changes the ratio because one latent head is loaded once from HBM into on-chip SRAM and reused as both key and value for every query head. The GTA/GLA authors calculate that this doubles arithmetic intensity compared with even the most aggressive MQA designs, and that MLA’s intensity during decoding comes down to the number of query heads.

DeepSeek’s FlashMLA deep-dive gives the arithmetic. FLOPs are roughly 2·h_q·s_q·s_k·(d_k + d_v), and memory traffic is about 2·s_k·d_k bytes, where h_q is query heads, s_q query tokens per step and s_k cached tokens. On an H800 SXM5, with 3.35 TB/s of bandwidth and about 865 TFlops of practical peak after clock throttling, the kernel becomes compute-bound once h_q·s_q ≥ 128. DeepSeek runs decode instances without tensor parallelism, so h_q is 128 and the kernel is compute-bound, which is why FlashMLA was tuned for that regime and reached up to 660 TFlops.

An independent hardware-centric analysis reaches a similar conclusion from modelling. MLA can shift attention toward the compute-bound regime, while MHA variants stay memory-bound and are much more sensitive to cache length and hardware configuration. The same analysis finds MLA’s performance far more stable across cache sizes, which makes consistent quality of service across sequence lengths easier to deliver. The authors also distinguish two execution variants of MLA with different compute and memory trade-offs, one better on typical hardware and one better where compute is limited.

Checklist: Is Your MLA Decode Compute-Bound?

  • Query heads per GPU. Divide the model’s query heads by the tensor-parallel degree; that number, not the model total, goes into h_q.
  • Query tokens per step. Plain decoding has s_q = 1, and speculative decoding with two query tokens doubles h_q·s_q.
  • Your GPU’s FLOPs-to-bandwidth ratio. The threshold of 128 comes from H800 figures; a GPU with less compute per byte of bandwidth reaches it sooner, and one with more reaches it later.
  • Load pattern. In vLLM’s measurements MHA gave better time-to-first-token at low queries per second, while MLA delivered better time per output token under sustained load.

When the Compute-Bound Picture Breaks Down

Tensor parallelism is one exception. Because every head shares one latent, MLA cannot be partitioned by head the way MHA or GQA can, so the latent is replicated on every device and the per-device memory saving from head-level parallelism shrinks. Under the FlashMLA formula, an assumed TP degree of 8 on a 128-head model leaves 128 / 8 = 16 heads per GPU, so single-token decoding gives h_q·s_q = 16 against the H800 threshold of 128. The GLA authors report their grouped-latent variant at TP=8 delivering up to 2.7× the serving throughput of MLA run with TP=2 and DP=4, though those are the proposing authors’ own benchmarks. The same paper also found MLA ahead at 128 concurrent requests when it used hybrid TP and DP against GLA under pure TP, so the result depends on how the model is sharded.

Head count is a design lever that cuts both ways. Kimi K2 report that DeepSeek-V3 set its head count at roughly twice its layer count to make better use of memory bandwidth, and that they halved it to 64 heads because doubled heads add significant inference overhead at long context.

Smaller accelerators expose a different limit. On the NVIDIA H20, FlashMLA has to pad short decode queries to meet the WGMMA M-dimension requirement. The FlashMLA-ETAP authors transposed the computation to remove that padding and measured 89 TFLOPS/s at 64K context and batch size 16, against FlashMLA’s 32 TFLOPS/s.

Which DeepSeek Models Use MLA, and What Changed from V2 to V3 and V4?

DeepSeek-V2 introduced MLA alongside DeepSeekMoE, with a 128K context length. Its smaller sibling, DeepSeek-V2-Lite, uses MLA with 16 heads of dimension 128 and the same 512-dimensional KV compression, but it does not compress queries.

DeepSeek-V3 kept MLA and DeepSeekMoE because both had been validated in V2. The MLA settings are 128 heads, a 128-dimensional head, a 512-dimensional KV latent and a 1536-dimensional query latent, plus RMSNorm layers after the compressed latents and scaling factors at the width bottlenecks, both carried over from V2. DeepSeek-R1 also uses MLA, and vLLM lists DeepSeek Coder, V2-Lite, V3 and R1 among the MLA models its optimisations support.

DeepSeek-V3.2 changes one thing in the architecture compared with V3.1-Terminus: it adds DeepSeek Sparse Attention (DSA) through continued training. DSA is built on the MQA mode of MLA, in which each latent vector is shared across all query heads of a token, and it cuts core attention complexity from O(L²) to O(Lk) for k selected tokens.

DeepSeek-V4 adds compression along the sequence dimension. Its Compressed Sparse Attention (CSA) merges every m tokens into one KV entry and then applies sparse attention, while Heavily Compressed Attention (HCA) merges far more tokens per entry and keeps dense attention, both with shared-KV MQA. KV entries store RoPE dimensions in BF16 and the rest in FP8, which roughly halves the cache compared with pure BF16. At one million tokens, DeepSeek reports V4-Pro needing 10% of V3.2’s KV cache and V4-Flash 7%. vLLM’s estimate is 9.62 GiB per sequence for V4 against 83.9 GiB for a 61-layer V3.2-style stack, about 8.7× smaller in BF16, and its FP4 indexer and FP8 attention caches cut roughly 2× from that BF16 estimate. The cost of these gains is that heterogeneous attention types make KV cache management more complex, and vLLM handles them with a fixed 256-token logical block across every compressed layer.

For how these attention choices combine with MoE routing in DeepSeek’s total GPU bill, see our breakdown of the algorithmic choices that drive DeepSeek inference cost.

Serving Engines and Models Converted to MLA

Because MLA differs from standard attention, open-source libraries had not fully optimised it at first. SGLang v0.3 added weight absorption, grouped decoding kernels, FP8 batched matrix multiplication and FP8 KV cache quantisation for MLA, and measured 3× to 7× higher peak output throughput than its baseline on H100 GPUs with ShareGPT prompts. vLLM v0.7.1 reported a 3.4× generation-throughput gain from MLA on 8× H200, and about 9.6× more KV cache capacity, which took token capacity from 54,560 to 512,000 and the batch size from 13 to 128.

Existing models can be converted to MLA. MHA2MLA cut Llama2-7B’s KV cache by 92.19% with a 0.5% drop on LongBench. TransMLA converts GQA-based models into MLA form compatible with DeepSeek’s codebase, and reports compressing 93% of LLaMA-2-7B’s KV cache with a 10.6× inference speedup at 8K context. We would treat any such conversion as a model change that needs its own evaluation on the target tasks, because both papers report quality shifts, however small, and a benchmark average can hide a regression on the workload you actually serve. Converting models, tuning attention kernels and sizing serving clusters are all part of the generative AI engineering TechnoLynx takes on.

Query Heads per GPU Decide the Outcome

MLA cuts the KV cache sharply: a cache independent of head count puts DeepSeek-V3 at 70 KB per token, against 327-516 KB for the two GQA models DeepSeek compares it with. The open question for a deployment is what that cache does to the kernel. With all 128 heads on one GPU, as in DeepSeek’s decode instances, decode attention is compute-bound. Shard the heads and h_q per device drops below that threshold, while every device still holds a replicated latent. Before choosing a parallelism layout for an MLA model, we would work out h_q·s_q per device against the GPU’s FLOPs-to-bandwidth ratio. That calculation tells you which regime you are tuning for.