MLA (Multi-head Latent Attention)

Definition

Multi-head Latent Attention (DeepSeek-V2, 2024; arXiv:2405.04434) shrinks the KV cache by caching neither per-head keys nor values, but a single low-rank latent per token, from which per-head K and V are reconstructed at use time. Via weight absorption the reconstruction is folded into the query/output projections so full-width K,V are never materialized, and a decoupled RoPE key carries position separately. It undercuts GQA on cache size and matches/exceeds MHA quality — dominating GQA on both axes.

Key math / How it works

Down-projection (the only thing cached). , , shared across heads. Per-head K,V are recovered as , .

Weight absorption — never materialize K,V. The compressed score term is

so is precomputed into the query path and dotted directly against the cached latent; symmetrically absorbs into . You cache only yet compute exact multi-head attention.

Decoupled RoPE — mandatory. Applying RoPE inserts a position rotation between and ; it does not commute, so the absorbed matrix would depend on — killing absorption. Fix: a separate small key/query part carrying RoPE, shared MQA-style, added as a second score term:

Cache per token per layer: elements.

Numbers. DeepSeek-V2 uses , , → caches 576 elems/token/layer vs. MHA’s (): ~57× smaller, equal to GQA with only groups, at MHA-level quality. DeepSeek-V3 (arXiv:2412.19437) carries it forward at scale [verify exact dims].

Why it matters

MLA is a strict improvement on GQA’s frontier — smaller cache than GQA-2.25 while retaining full multi-head expressivity — because the reduction comes from genuine low-rank K/V structure, not from discarding heads. It is the frontier KV-compression trick and a key enabler of DeepSeek’s economical long-context serving.

Taught in

  • 05-mqa-gqa-mla — §3.3 down/up-projection, weight absorption, decoupled RoPE.

See also