The Evolution of LLM Attention Mechanisms: MQA vs. MLA Explained
This article breaks down why attention design has become the central bottleneck for long-context LLMs. It compares Multi-Query Attention (MQA), Grouped-Query Attention (GQA), and Multi-head Latent Attention (MLA), explains the KV Cache cost structure behind autoregressive decoding, and examines why one new ~1.6T-parameter model moved back to MQA while other open-source models stayed with MLA. It also outlines the four engineering pillars needed to make million-token context practical and gives developers concrete guidance on model selection, cache hit rates, and long-range evaluation.
1. Background: Why Attention Became the Core Bottleneck for Long Context
When people discuss the iteration of ultra-large-scale models, a pattern keeps repeating: growth in parameter count does not always translate into a proportional improvement in the user experience. What really shapes how a model feels in production is the cost and stability of the inference stage. One key signal from the source material is that a new-generation ultra-large model (roughly 1.6T parameters, up from about 670B in the previous generation) dropped the Multi-head Latent Attention (MLA) that the two prior generations had relied on and went back to Multi-Query Attention (MQA), while other open-source models released around the same time continued to use MLA. That “rollback” is the best entry point for understanding the engineering constraints of long context.
To make sense of it, start with the cost structure of autoregressive decoding. When generating token t, the model has to read the Key/Value cache (KV Cache) for every preceding token. Its memory footprint can be approximated as:
KV_bytes ≈ 2 × layers × kv_heads × head_dim × seq_len × batch × dtype_bytes
kv_heads is the only factor that architecture design can compress directly. As the context grows from a few thousand tokens to the million range, seq_len scales linearly and the KV Cache quickly overtakes the weights as the dominant memory consumer. At the same time, every generated token requires moving the entire KV Cache from memory to the compute units, which creates a classic bandwidth wall and makes decoding memory-bound.
2. The Essential Difference Between the Two Technical Routes
2.1 Multi-Query Attention: Compressing KV Heads to 1
MQA lets all query heads share a single set of K/V, meaning kv_heads = 1. The benefit is immediate: the KV Cache shrinks to 1/number-of-heads of its original size, and bandwidth pressure drops by the same ratio. The cost is reduced expressiveness, because different heads can no longer attend to different semantic subspaces. On tasks that demand fine-grained retrieval or multi-hop reasoning, quality tends to regress.
2.2 Grouped-Query Attention: The Compromise
The industry then widely adopted Grouped-Query Attention (GQA), which splits query heads into several groups that share K/V within each group, with kv_heads set to an intermediate value. This is the default choice for most open-source and closed-source models today, and it sits in the most reliable cost-performance range from an engineering standpoint.
2.3 Multi-Head Latent Attention: Low-Rank Compression Instead of Head Pruning
MLA takes an orthogonal approach to the first two. It does not reduce the number of heads. Instead, it projects K/V into a low-dimensional latent space, caches the compressed latent vectors, and projects them back up when they are needed. The effective KV dimension drops substantially, and because each head keeps its own independent path, the quality loss is usually smaller than MQA at the same compression ratio.
Illustrative comparison (showing order-of-magnitude relationships only, not measured data):
# Pseudocode: effective KV heads for different attention schemesdef effective_kv_heads(kind, n_heads, n_groups=8):if kind == "mha": return n_heads # standard multi-head, no compressionif kind == "gqa": return n_groups # grouped sharingif kind == "mqa": return 1 # fully sharedif kind == "mla": return n_heads # head count unchanged, compressed via low-rank latent vectors
2.4 Why “Going Back to MQA” Is Actually a Sign of Progress
A common misreading needs correcting here: an architectural rollback is not a technical regression. The cost of MLA lies in the fact that its decoding path is deeply coupled with the operators, paged cache management, and parallel sharding strategies of mainstream inference engines, so any change has to be realigned across the entire chain. If a new design recovers quality through other means (for example, more aggressive sparsification, finer-grained cache eviction, or layout reordering coordinated with the parallelism strategy) while significantly reducing system complexity, the overall outcome is positive. This supports the core judgment in the source material: system-level coupled optimization is harder than a single-point innovation, and also more valuable.
3. Four Pillars That Bring Million-Token Context Into Reality
Attention mechanisms alone cannot support million-level context. It takes a combined engineering effort of four moves:
- Sparse and selective attention. Not every historical token needs to be attended to by every new token. Retrieval-based selection, block-level sparsity, or a mix of sliding-window and global tokens can push the effective computation from O(n²) down to nearly linear.
- Cache tiering and offloading. Cold KV blocks can be pushed down to host memory or object storage, with paged management bringing them back on demand, trading controllable latency for memory capacity.
- Coordinated parallelism. The way context parallelism, tensor parallelism, and pipeline parallelism are sharded has to match the attention layout; otherwise communication volume will eat up the gains from compression.
- Coordinated precision and quantization. When the KV Cache uses a lower-bit representation, error accumulation under long-range dependencies needs to be evaluated, and outlier channels usually keep higher precision.
4. Practical Advice for Developers
- Do not pick a model based on first-token latency alone. For long-context scenarios, use “end-to-end cost per million tokens and the quality degradation curve” as the metric.
- Cache hit rate is the cost lever. The source material notes that after one model cut the price of cache-hit inputs further and substantially, users’ willingness to try it clearly increased, which suggests engineering teams should proactively design reusable prefix structures (fixed system prompts, stable few-shot blocks) to raise the cacheable ratio.
- Cover long-range tasks in evaluation. Short question-answering cannot expose the flaws of attention compression, so add use cases such as long-document retrieval, cross-section multi-hop reasoning, and instruction following in long conversations.
- Watch hallucination and instruction following together. Architectural changes usually affect these two first, rather than benchmark scores.
In related practice at Baidu AI Cloud, capabilities like these are typically offered as general-purpose building blocks: a container platform hosts inference service orchestration, object storage and message queues handle cache tiering and asynchronous pipelines, and logging plus monitoring and alerting are used to observe cache hit rates, memory watermarks, and tail latency. Developers can map the architecture selection principles above directly onto these general components to build an observable, elastically scalable long-context inference pipeline.
