From MLA to MQA: How to Choose LLM Attention Architectures
Open-source LLMs have not settled on a single attention design. This article compares MHA, MQA, GQA, and MLA on KV cache size, compute, tensor parallelism, and kernel support, then offers a practical checklist for architecture selection.
Introduction: Attention Architectures Have Not Converged
For a while, many people assumed open-source large language models had settled on a default attention design, with Multi-Head Latent Attention (MLA) as a leading example. After DeepSeek-V2 introduced MLA, it compressed the key-value (KV) cache into low-dimensional latent vectors. At inference time, only those vectors are stored; full multi-head keys and values are reconstructed when needed. The design clearly reduces memory pressure for long-context inference and therefore attracted wide attention.
Architecture choice did not stop there. A few teams have returned to Multi-Query Attention (MQA) in specific settings, while more teams use the compromise design, Grouped-Query Attention (GQA). Attention design still has room to move. The right option depends on context length, concurrency, hardware, and team capability.
This article compares the trade-offs across memory, compute, and engineering, then provides a selection checklist.
Where Standard Multi-Head Attention Hits a Wall
In standard Multi-Head Attention (MHA), each head has independent query, key, and value projections. During inference, every head’s keys and values must be written to the KV cache. Cache size grows with the number of heads, head dimension, number of layers, and context length.
A hypothetical model makes the pressure clear. Assume 32 layers, 32 KV heads per layer, head dimension 128, and FP16 storage (2 bytes per element). Each token needs 2 × 32 × 128 = 8,192 elements per layer, or 16 KB; 32 layers total about 512 KB. For 128k tokens, a single request’s KV cache is about 67 GB, not counting model weights. GB figures in this article use 10^9 bytes.
How MQA and GQA Shrink the Cache
MQA lets all query heads share one set of keys and values. Cache size then depends only on that KV pair and context length; adding query heads no longer inflates the cache. Using the same hypothetical model, each token stores 2 × 1 × 128 = 256 elements per layer. A 128k-context cache is about 2.1 GB, 1/32 of MHA.
GQA groups query heads so each group shares one KV set. With 8 groups, the cache drops to 1/4 of MHA, about 16.8 GB. The GQA paper reports that with a suitable group count, quality stays close to MHA while speed approaches MQA. Models such as Llama 2 70B, Llama 3, and Qwen2 use GQA.
MQA’s cost is expressiveness. Sharing one KV set across heads reduces the ability to capture diverse attention patterns, and quality drops have been reported on some tasks. GQA exists to balance the two.
MLA’s Memory Advantage Is Smaller Than It First Appears
MLA compresses the cache with low-dimensional latent vectors. In DeepSeek-V2’s public configuration, the latent dimension is 512, plus 64 dimensions of decoupled rotary position embeddings, for 576 elements. On the same hypothetical model, each token needs 576 × 2 = 1,152 bytes per layer; a 128k-context cache is about 4.7 GB.
That is larger than MQA’s 2.1 GB but far smaller than GQA’s 16.8 GB. MLA’s main value is a small cache while retaining more capacity. Versus MQA, it saves little extra memory; what it buys is model capability.
The cost is mainly compute. Inference must reconstruct latents, or absorb reconstruction into other matrix multiplies. That adds FLOPs and implementation complexity. Frameworks need specialized attention kernels, which raises debugging and maintenance cost.
Why Some Teams Reconsider MQA
The answer depends on the whole system, not a single module. Cache size alone favors MLA. Including tensor parallelism, kernel performance, and framework support can change the conclusion.
First, KV head count affects tensor parallelism. MHA and GQA KV heads can be sharded across GPUs, so each card stores only a slice. MQA has a single KV set that cannot be sharded, so every card keeps a full copy. In multi-GPU serving, that duplication offsets some memory savings. MLA latents face a similar issue, depending on the parallel strategy.
Second, the kernel ecosystem is more mature. MQA and GQA have regular memory access patterns. FlashAttention-style kernels and paged attention in major inference frameworks are well optimized for them. MLA needs extra reconstruction or absorption. Teams either use a framework-specific implementation or maintain their own kernels, which lengthens launch time and raises error risk.
Third, decode-time bandwidth differs. Each generated token must read the full history KV. Simpler layouts make that traffic easier to use efficiently, especially for small-batch, latency-sensitive services.
Some teams therefore choose MQA not because it is stronger, but because it is more predictable to deploy. Public system-level comparisons remain limited, so this is not yet an industry trend.
Factors Beyond Architecture
Final model quality comes from many stages. Attention is only one of them. Memory freed by architecture changes can go to larger batches or longer context, but gains in reasoning, hallucination rate, and instruction following usually come from data quality, training recipes, and post-training alignment. Attributing those gains entirely to architecture is not justified.
Optimizers matter too. In 2024, Keller Jordan released the Muon optimizer. It approximately orthogonalizes momentum updates, typically via Newton-Schulz iteration. In some public experiments it showed strong training efficiency under specific setups. Results depend on model scale and hyperparameters such as learning rate; they need validation on your own stack.
Low-level programming and compilation also matter. Tools such as Triton for writing GPU kernels in Python, and template libraries such as CUTLASS, let developers write operators closer to the hardware. Whether MLA lands efficiently depends heavily on those kernels.
Architecture Selection Checklist
Before choosing an attention design, confirm:
- Target context length and peak concurrency? Cache scales linearly with both.
- Memory budget, including weights, cache, and framework overhead?
- Latency targets for first token and per token? Extra reconstruction may or may not be acceptable.
- Does the inference framework support the structure natively? If you must write kernels, can the team maintain them?
- Tensor parallel degree? Do KV heads match it, or is there heavy duplication?
- Are fine-tuning, quantization, and distillation compatible?
- Can you load-test on your own traffic? Theory is a starting point; throughput and latency need measurement.
After the checklist, compare candidate designs on the same request mix for throughput, latency, and peak memory, then decide.
Considerations for Managed Inference
If you will not run your own cluster, managed inference from a cloud provider is an option. Pay attention to:
- Billing: token-based versus instance-based costs differ by load.
- SLAs and limits: availability, concurrency caps, and timeouts.
- Data compliance: region, retention, and access audit.
- Migration cost: API compatibility with the open-source ecosystem, and whether models and fine-tunes can be exported to avoid lock-in.
Conclusion
Attention architectures are still evolving. MHA, GQA, MQA, and MLA each address different constraints. For developers, understanding the relationships among cache, parallelism, kernels, and capability is more useful than chasing a design labeled as optimal.
