MLA: Multi-Head Latent Attention (DeepSeek-AI, 2024)
Paper: arXiv:2405.04434 (DeepSeek-V2)
Core Problem
Grouped-Query Attention (GQA) reduces the *number* of KV heads, but every remaining KV head still has dimensiond_head. Can KV cache be compressed more aggressively — by making each KV head intrinsically "thinner" instead of just fewer heads?Method
Traditional attention caches full-rank K and V per head:K = W_k · x(dim = n_kv_heads × d_head)V = W_v · x(dim = n_kv_heads × d_head)k_t = W^{UK} · c^{KV}_tv_t = W^{UV} · c^{KV}_t- 236B total parameters, 21B activated (MoE)
- KV cache reduction: 93.3%
- Peak generation throughput: up to 5.76×
- Training cost vs DeepSeek-67B: −42.5%
- Pretraining tokens: 8.1T
- Context length: 128K
MLA compresses K and V into a shared low-dimensional latent vector and caches only that latent:
1. Compress: c^{KV}_t = W^{DKV} · h_t (dimension d_c, e.g. 512 vs the naive 8 × 128 = 1024)
2. Cache: store c^{KV}_t
3. Reconstruct on demand:
The cache footprint is now proportional to d_c, not n_kv_heads × d_head.
Key Numbers (DeepSeek-V2)
Impact
MLA is the "endgame" of KV cache compression. GQA reduces head count; MLA reduces per-head dimensionality — the two are orthogonal and stack. Combined with DeepSeekMoE, DeepSeek-V2 substantially outperforms same-scale dense models on inference efficiency. The idea — caching a low-rank latent instead of full K/V — has influenced subsequent work on KV cache quantization and dynamic / adaptive compression.Feynman's Take
> Don't ask "how do we store the photo faster?" — ask "do we need to store the photo at all?" GQA still stores K and V, just fewer copies. MLA questions a more fundamental assumption: K and V are high-dimensional, but is that dimensionality actually necessary? If the relevant information fits in a low-dimensional latent, cache the latent. It's the difference between storing a RAW image and a JPEG — lossy, but with massive savings when the loss is controlled.Source: arXiv 2405.04434