DeepSeek Engineering Blog Series · Phase 3

DeepSeek MLA — Major Innovation

Article 3 of 5 · Phase 3 of 10

May 27, 2026 · ml · 16 min read · 3200 words intermediate

MLA vs MQA vs GQA.

ml deepseek transformers phase-3 mla

Phase 2 covered MQA and GQA as sequential responses to the KV cache problem. Phase 3 introduced MLA as a fundamentally different approach. This article puts them all side-by-side: architecture diagrams, memory numbers, quality tradeoffs, and the concrete reasons each approach exists.

The core architectural difference

All four variants (MHA, MQA, GQA, MLA) compute the same thing: scaled dot-product attention with multiple query heads. They differ only in how they handle the key-value side — specifically, what's stored and what's computed.

MHA Q₁ Q₂ Q_H K₁ K₂ K_H V₁ V₂ V_H cached: 2×H heads = 32,768 dims MQA Q₁ Q₂ Q_H K shared V shared cached: 1 K + 1 V = 256 dims (÷128×) GQA (G=4) Q₁ Q₂ Q_H K₁ K₂ K₃ K₄ V₁ V₂ V₃ V₄ cached: 2×G heads = 1,024 dims (÷32×) MLA Q₁ Q₂ Q_H c^KV latent ↓W_UV ↓W_UK cached: 1 latent = 512 dims (÷64×) K,V pre-computed K,V pre-computed K,V pre-computed K,V on-demand

Fig 1 — What each variant stores in the KV cache per token (shown for H=8 heads, G=4 groups). Only MLA stores a compressed latent rather than full K,V vectors.

The compression dimension

Each approach compresses along a different dimension:

VariantCompresses whatHowLimit
MHANothingFull K,V cachedMemory baseline
MQANumber of KV heads: H → 1All queries share 1 K,V pairQuality degrades below MHA
GQANumber of KV heads: H → GGroups of queries share K,VStill linear in d_h; G=1 = MQA
MLADimensionality of KV repr: H×d_h → d_cLow-rank projection to latentQuality loss if d_c too small

MQA and GQA reduce the count of KV pairs stored. MLA reduces the size of each stored representation. Different levers, different tradeoffs.

Memory comparison at scale

Using DeepSeek-V2's architecture: H=128 heads, d_h=128, d_c=512, 60 layers, BF16.

VariantDims/token/layer4K ctx32K ctx128K ctxvs MHA
MHA32,76815.7 GB125 GB503 GB
GQA G=84,0961.97 GB15.7 GB62.9 GB
MQA2560.12 GB0.98 GB3.93 GB128×
MLA5120.25 GB1.97 GB7.86 GB64×

Three things stand out:

  1. MLA (512 dims) is actually slightly larger than MQA (256 dims for H=128, d_h=128, 1 head = 2×128). MLA's advantage isn't maximum compression — it's quality at high compression.
  2. GQA at G=8 is 8× less than MHA but still grows to 62.9 GB at 128K context — real hardware strain.
  3. MLA at 128K context needs just 7.86 GB — comfortably fits on a single A100 80GB alongside other allocations.

Quality comparison

Memory matters, but only if quality holds. Here's what the papers and benchmarks say:

Variantvs MHA qualityWhere it showsSource
MQA−0.1 to −0.5 perplexityStructured generation, reasoningShazeer 2019, GQA paper
GQA G=8Statistically indistinguishableStandard NLP benchmarksAinslie et al. 2023
MLAMatches or exceeds MHAMath, code, long-contextDeepSeek-V2 paper 2024

The DeepSeek-V2 results are remarkable: MLA doesn't just match MHA, it often outperforms an equivalent MHA baseline. The likely mechanism: the low-rank compression acts as a regulariser. The latent bottleneck forces the model to learn the most attention-relevant features of each token, discarding noise. This is similar to why bottleneck architectures (autoencoders, LoRA) often produce better generalisation than their full-rank counterparts.

Compute tradeoff

Memory isn't free in MLA — the savings are paid for with compute.

OperationMHAGQA G=8MLA
KV forward (per token)2 matmuls (W_K, W_V)2 matmuls (smaller)1 down-project + 2 up-projects
Cache write32,768 elements4,096 elements512 elements
Cache read (per decode step)32,768 × seq_len4,096 × seq_len512 × seq_len (+ up-project)
Decode bottleneckHBM bandwidthHBM bandwidthUp-projection compute

MHA and GQA are both bandwidth-bound at decode — they load large K/V tensors from HBM. MLA shifts the bottleneck: it loads small latents from HBM but must compute up-projections on them. On modern GPUs (A100/H100), the up-projection is small relative to the bandwidth savings — MLA wins on total wall-clock decode latency at long sequences.

When to use which

Practical decision guidance:

ScenarioRecommendedWhy
Small model (<7B), short context (<8K)MHA or GQAKV cache isn't the bottleneck
Mid-size model, standard contextGQA G=8Industry standard, well-understood quality
Large model (>70B), long context (>32K)GQA or MLACache size becomes critical
Frontier model, max quality + long contextMLABest quality per cache byte; complex to implement
Inference-only serving, fast iterationGQAEcosystem support (vLLM, TGI) fully mature

MLA requires careful implementation and has limited off-the-shelf tooling compared to GQA. The DeepSeek team built their own inference engine around MLA's specific patterns (absorbed projections, FP8 latent quantisation). For teams using standard serving stacks, GQA remains the pragmatic choice. MLA is the right answer for teams building frontier models from scratch and willing to invest in custom serving infrastructure.

The key insight that MLA adds

MQA and GQA are both answers to the question "how few KV heads do we need?" They vary the integer G from H down to 1 and accept a quality floor.

MLA asks a different question: "how few dimensions per token do we need to reconstruct full-quality attention?" The answer is d_c — and it can be tuned independently of the number of heads or head dimension. You keep all H query heads for full query expressiveness. You keep full d_h for full attention computation. You only compress the cached representation, not the computation.

GQA trades query head diversity against memory. MLA doesn't — it keeps all query heads while compressing storage. That's why MLA matches MHA quality while GQA's quality converges to MQA's as G decreases.

Deployment reality in 2024-2025

As of mid-2025, the landscape looks like this:

  • MHA: older models (GPT-3, early LLaMA), research baselines
  • MQA: production specialised models (PaLM, Falcon, code completion), not new frontier models
  • GQA: virtually all new open-source models — LLaMA-2/3, Mistral, Mixtral, Qwen, Gemma
  • MLA: DeepSeek-V2, V3, V4 — and any frontier model following DeepSeek's architecture

GQA won the mid-tier because ecosystem support arrived quickly. MLA is winning the frontier tier because at 100K+ context with billion-scale parameters, GQA's 8× compression isn't enough — MLA's 64×+ is.

← MLA From Scratch KV Cache Memory →
© cvam — written in plaintext, served warm