#01 1. The KV Cache VRAM Wall in Long-Context Transformers
During the auto-regressive decoding phase of a large language model (LLM), the bottleneck shifts from being compute-bound to being severely memory-bandwidth-bound. For a 671B-parameter model using standard multi-head attention (MHA) or grouped-query attention (GQA), once the context reaches 128k tokens the KV cache held for a single batch can consume more VRAM than the model weights themselves.
Conventional GQA (as in LLaMA-3) trims that footprint by having several query heads share one set of KV heads, but past a certain compression ratio (8:1 or 16:1, say) the model's representational capacity on hard reasoning tasks degrades irreversibly.
#02 2. The Math Behind MLA: Low-Rank Joint Projection and Decoupled RoPE
The core idea of MLA (Multi-Head Latent Attention) is this: rather than caching high-dimensional Key and Value vectors for every attention head, project them down into a very low-dimensional latent space and cache that instead. At attention time the full vectors are either reconstructed or, better, folded away entirely using matrix associativity.
Deriving the core equations:
For an input hidden state ht ∈ ℝd, MLA first produces a compressed latent vector:
ctKV = WDKV ht (ctKV ∈ ℝdc, dc ≪ d)
The decoupled RoPE positional component is computed on its own path:
ktR = RoPE(WKR ht) (ktR ∈ ℝdR)
At inference time the cache only has to storectKV (512 dims) and ktR (64 dims) per token, instead of the full KV matrices spanning nh × dh (for example 128 × 128 = 16384 dims)!
#03 3. Prototyping the MLA Decode Kernel in Triton / PyTorch
Below is the core pseudocode for MLA absorbing its weight matrices at inference time, together with the Triton kernel scheduling architecture that lets it run at very high throughput:
The section on absorbing the matrices via associativity in MLA is exceptionally clear. Classic GQA loses accuracy badly past 64k, whereas MLA genuinely gets you both the VRAM savings and the representational capacity.
Elena RostovaAI Infra Researcher
2 weeks 前
Question for the author: inside the DualPipe async pipeline, roughly what is the gradient recomputation overhead for MLA's backward pass, and what fraction of it overlaps with pure communication?
The section on absorbing the matrices via associativity in MLA is exceptionally clear. Classic GQA loses accuracy badly past 64k, whereas MLA genuinely gets you both the VRAM savings and the representational capacity.
Question for the author: inside the DualPipe async pipeline, roughly what is the gradient recomputation overhead for MLA's backward pass, and what fraction of it overlaps with pure communication?