Handbook demystifies MHA, MQA, GQA, MLA tradeoffs
"Understanding MHA, MQA, GQA & MLA: From Multi-Head Attention to Latent KV Compression" is a 40-page educational reference manual by @techNmak detailing how attention mechanisms govern memory bandwidth and KV-cache capacity during autoregressive LLM decoding. Through mathematical derivations and DeepSeek-V2 configurations, the guide contrasts MHA, MQA, and GQA head multiplicity against DeepSeek's low-rank latent KV compression and decoupled RoPE.
Most practitioners view attention variants along a linear spectrum of head counts, but understanding why MLA decouples RoPE to preserve linear matrix absorption is the definitive prerequisite for modern LLM systems engineering. While MHA, GQA, and MQA solely adjust KV-head counts for conventional per-head tensors, MLA replaces per-head storage with a low-rank compressed latent plus a shared positional key. Decoupling RoPE is necessary because standard position-dependent rotations prevent the query-side absorption of key up-projections during latent decoding. Crucially, DeepSeek-V2's MLA caches 4.5 head dimensions per token per layer, meaning standard MQA actually consumes fewer raw bytes while MLA prioritizes expressive capacity. Ultimately, attention representations, execution schedules like FlashAttention, and memory allocators like PagedAttention operate across orthogonal serving layers that complement one another.
DISCOVERED
53m ago
2026-09-12
PUBLISHED
1h ago
2026-09-12
RELEVANCE
AUTHOR
techNmak