Multi-Head Attention (MHA) has served as the core sequence-mixing primitive in autoregressive Transformer architectures since the introduction of the Transformer by Vaswani et al. (2017). In production serving environments, autoregressive generation requires caching key and value projections for all previous tokens in high-bandwidth GPU memory (HBM). As sequence lengths expand toward 128k tokens and beyond, this Key-Value (KV) cache grows linearly with context length, batch size, and layer count, rapidly becoming the primary memory and throughput bottleneck during inference.
Architectural variants such as Multi-Query Attention (MQA) proposed by Shazeer (2019) and Grouped-Query Attention (GQA) introduced by Ainslie et al. (2023) mitigate KV cache growth by forcing multiple query heads to share a reduced number of key-value head pairs. While GQA reduces KV cache memory by factors of 4x to 8x, it prunes the representational parameter capacity of keys and values, introducing an empirical trade-off between memory footprint and model expressivity.
Multi-Head Latent Attention (MLA), introduced by DeepSeek-AI (2024) in the DeepSeek-V2 architecture and carried forward in DeepSeek-V3, addresses this dilemma through low-rank joint key-value compression combined with decoupled positional encodings. Instead of reducing the number of attention heads, MLA factorizes key and value spaces into a compact latent vector while preserving full multi-head expressive capacity. At inference time, linear algebraic properties allow projection matrices to be absorbed into query transformations and output projections, eliminating the need to materialize uncompressed keys and values in memory.
The KV Cache Memory Bottleneck in Standard Attention
In standard Multi-Head Attention with hidden dimension , attention heads, and per-head dimension , the model projects an incoming token hidden state into query, key, and value vectors for each head :
q_{t, i} = W_i^Q h_t
k_{t, i} = W_i^K h_t
v_{t, i} = W_i^V h_tDuring autoregressive generation at sequence step , the key and value vectors for all preceding positions must remain resident in GPU memory to avoid recalculating past projections. The per-token memory consumption in the KV cache for a single transformer layer under 16-bit precision (FP16 or BF16, 2 bytes per element) is:
Memory_MHA = 2 * 2 * n_h * d_h bytes/token/layerFor a model with and , storing uncompressed keys and values requires bytes (64 KB) per token per layer. Across a 60-layer foundation model serving a context of 128,000 tokens for a single user request, the KV cache alone demands approximately 491.5 GB of GPU memory, requiring multi-node tensor or pipeline parallelism merely to store activation state.
Grouped-Query Attention (GQA) reduces this memory burden by grouping query heads into groups and allocating only one key head and one value head per group (). For , the cache footprint scales down to bytes per token per layer. However, sharing keys and values across multiple query heads reduces the model capacity to learn distinct subspace interactions between queries and tokens.
Low-Rank Key-Value Joint Compression
MLA replaces independent high-dimensional key and value projections with a low-rank joint compression mechanism. The input hidden state is mapped to a shared low-dimensional latent vector via a down-projection matrix :
c_t^{KV} = RMSNorm(W^{DKV} h_t)The compression dimension is chosen such that . For example, DeepSeek-V2 and DeepSeek-V3 configure while supporting heads with (where ).
From this shared latent representation , head-specific content key vectors and value vectors are generated through head-specific up-projection matrices and :
k_{t, i}^C = W_i^{UK} c_t^{KV}
v_{t, i}^C = W_i^{UV} c_t^{KV}To reduce training activation memory and parameter overhead, MLA also applies a low-rank decomposition to query projections:
c_t^Q = RMSNorm(W^{DQ} h_t)
q_{t, i}^C = W_i^{UQ} c_t^Qwhere down-projects the query into latent dimension , and up-projects to individual query head subspaces. Because queries are computed only for active tokens during the current decoding step and are not retained across time steps, does not occupy persistent KV cache memory during inference.
The RoPE Incompatibility Problem and Decoupled RoPE
Modern autoregressive language models rely on Rotary Position Embeddings (RoPE), formulated by Su et al. (2021), to inject relative positional information via complex rotation matrices applied directly to queries and keys:
q_{t, i}^{RoPE} = R_t q_{t, i}
k_{s, i}^{RoPE} = R_s k_{s, i}where is a block-diagonal orthogonal rotation matrix for sequence index . The inner product between rotated vectors naturally encodes the relative distance because .
A fundamental architectural tension arises when combining RoPE with low-rank key compression. If RoPE were applied directly to the up-projected keys , the attention score between query token and cached token would be:
Score_{t, s, i} = (R_t q_{t, i}^C)^\top (R_s W_i^{UK} c_s^{KV})Because the rotation matrix depends on position and does not commute with the up-projection matrix (), the up-projection cannot be factored out or pre-computed. If keys were rotated in this manner, the inference runtime would be forced to compute and store the full uncompressed vectors across all heads for every cached token, entirely negating the memory benefits of the low-rank latent representation.

To resolve this incompatibility, MLA decouples positional encodings from content representations. The query and key vectors are divided into content sub-vectors and dedicated positional sub-vectors:
q_{t, i} = [q_{t, i}^C ; q_{t, i}^R]
k_{t, i} = [k_{t, i}^C ; k_t^R]The positional key vector is projected directly from the hidden state via a shared projection matrix and rotated with standard RoPE:
k_t^R = RoPE(W^{KR} h_t)Crucially, is shared across all attention heads rather than being replicated per head. The positional query vector is projected per head and rotated accordingly:
q_{t, i}^R = RoPE(W_i^{QR} c_t^Q)The attention score between query and cached token in head decomposes into the sum of a content inner product and a positional inner product:
q_{t, i}^\top k_{s, i} = (q_{t, i}^C)^\top k_{s, i}^C + (q_{t, i}^R)^\top k_s^R
= (q_{t, i}^C)^\top W_i^{UK} c_s^{KV} + (q_{t, i}^R)^\top k_s^RBecause content keys are free of position-dependent rotations, their projection matrices remain static across all token positions.
Weight Absorption: Zero Decompression at Inference
The linearity of the un-rotated content transformations enables weight absorption during inference serving, eliminating the requirement to materialize or uncompress or in memory.
Key Matrix Absorption into Queries
During inference, rather than multiplying the cached vector by for every past token , the serving engine transposes and absorbs directly into the current query vector :
q'_{t, i} = (q_{t, i}^C)^\top W_i^{UK} \in \mathbb{R}^{1 \times d_c}The content attention score is then computed via a single vector-matrix multiplication directly against the cached latent states:
Score_{t, s, i}^C = q'_{t, i} c_s^{KV}This reduces the dot-product computation from head dimension across individual cached vectors to a single dot product in the latent space .
Value Matrix Absorption into Output Projections
A complementary absorption occurs for value vectors during attention aggregation. The attention output for head is defined as the weighted sum over value vectors:
o_{t, i} = \sum_s A_{t, s, i} v_{s, i}^C = \sum_s A_{t, s, i} (W_i^{UV} c_s^{KV})Because matrix multiplication distributes over addition, the static matrix factors outside the summation:
o_{t, i} = W_i^{UV} \left( \sum_s A_{t, s, i} c_s^{KV} \right) = W_i^{UV} u_{t, i}where is the attention-weighted sum of raw cached latent vectors.
When the multi-head outputs are concatenated and multiplied by the standard attention output projection matrix (partitioned into per-head blocks ), the final layer output is:
O_t = \sum_{i=1}^{n_h} W_i^O o_{t, i} = \sum_{i=1}^{n_h} W_i^O (W_i^{UV} u_{t, i}) = \sum_{i=1}^{n_h} (W_i^O W_i^{UV}) u_{t, i}By pre-computing the combined output projection matrix:
W'_i^O = W_i^O W_i^{UV} \in \mathbb{R}^{d \times d_c}the inference engine aggregates attention directly over the compressed latent KV vectors and projects directly to the model hidden state , completely bypassing value decompression.
KV Cache Footprint Comparison
Through weight absorption, the inference KV cache needs to retain only two tensors per token per layer: the compressed content latent vector and the decoupled shared positional key .
Consider the concrete architecture dimensions of DeepSeek-V2 and DeepSeek-V3 (, , , ):
- Standard Multi-Head Attention (MHA):
- Caches elements per token per layer.
- At 16-bit precision: 65,536 bytes/token/layer.
- Grouped-Query Attention (GQA, 8 groups):
- Caches elements per token per layer.
- At 16-bit precision: 4,096 bytes/token/layer.
- Multi-Head Latent Attention (MLA):
- Caches elements per token per layer.
- At 16-bit precision: 1,152 bytes/token/layer.
MLA achieves a 98.24% reduction in per-token KV cache memory relative to full MHA and a 71.88% reduction relative to 8-group GQA. Unlike GQA, which restricts the model to 8 effective key-value head representations, MLA maintains 128 distinct query heads attending to rank-compressed representations with separate up-projection pathways.
Empirical evaluations reported by DeepSeek-AI (2024) and verified in independent architectural studies such as MHA2MLA by Wang et al. (2025) demonstrate that MLA matches or exceeds the modeling perplexity and downstream benchmark accuracy of standard Multi-Head Attention while operating at a fraction of the memory footprint.
Sources
- DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model (DeepSeek-AI, 2024)
- DeepSeek-V3 Technical Report (DeepSeek-AI, 2024)
- Attention Is All You Need (Vaswani et al., 2017)
- Fast Transformer Decoding: One Write-Head is All You Need (Shazeer, 2019)
- GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints (Ainslie et al., 2023)
- RoFormer: Enhanced Transformer with Rotary Position Embedding (Su et al., 2021)
- Towards Economical Inference: Enabling DeepSeek's Multi-Head Latent Attention in Any Transformer-based LLMs (Wang et al., 2025)



