The Evolution of LLM Attention: Trade-offs Between MQA and MLA

    This article examines why million-token context windows are constrained by GPU memory capacity and memory bandwidth rather than compute, and how KV cache size scales with layers, KV heads, head dimension, sequence length, and batch size. It compares Multi-Query Attention (MQA), Grouped-Query Attention (GQA), and Multi-head Latent Attention (MLA), explains why system-level coupling makes attention redesign harder than isolated innovation, and offers practical guidance on capacity and cost planning for long-context serving.

    1. Background: Million-Token Context Is Not Solved by Bigger Parameters

    When the context window grows from a few thousand tokens to the million-token range, the bottleneck shifts quickly from compute to memory capacity and memory bandwidth. The reason is straightforward: during autoregressive decoding, every generated token requires re-reading the entire history of keys and values (KV), and the KV cache grows linearly with “layers × heads × head dimension × sequence length × batch size.” A rough estimate with 80 layers, 128 heads, head dimension 128, sequence length of 1 million, and FP16 precision puts the KV cache for a single request in the range of several thousand gigabytes, before any batching concurrency is considered. So the practical constraint on long context is often not “can the model understand it” but “can the server hold it and read it fast enough.”

    Two main approaches have emerged in the industry: compressing the KV representation (low-rank projection, latent vector caching) and reducing the number of KV heads (multi-query/grouped-query). A notable signal has appeared in recent public technical discussions: a very large model abandoned the low-rank latent attention scheme it had previously used in a new release and switched to the older multi-query approach, while several open-source models in the same period continue to pursue the low-rank route. This indicates that architectures have not converged and that meaningful room for improvement remains.

    2. How the Two Approaches Work

    In multi-head attention (MHA), every head has its own keys and values, which gives the strongest expressiveness but the largest cache. Multi-query attention (MQA) lets all query heads share a single set of keys and values, shrinking the cache to 1/number-of-heads of the original, at the cost of reduced expressiveness and worse training stability. Grouped-query attention (GQA) is a compromise between the two, sharing by group to balance quality and overhead, and has become a common default in both closed-source and open-source models.

    Multi-head latent attention (MLA) takes a different path: it jointly compresses keys and values into a low-dimensional latent space, caches only this low-rank vector, and projects it back up during inference. Its cache size is on the same order as MQA or even smaller, while decoupled positional encoding dimensions preserve part of the multi-head characteristics, so it performs well on “small cache without quality loss.” However, it introduces additional projection matrices and inverse-projection computation, and its many custom operators make it less friendly to kernel adaptation in inference frameworks, quantization schemes, and parallel partitioning.

    The difference can be summarized in one sentence: MQA trades sharing for bandwidth, and MLA trades compression for bandwidth. The former is simple to implement with a mature ecosystem; the latter achieves a higher compression ratio but is more deeply coupled to engineering.

    3. Why System-Level Coupled Optimization Is Harder Than a Single Innovation

    A single innovation can be validated in a paper; a system-level optimization must be validated in real serving. Take attention redesign as an example, where one change affects everything downstream:

    • Parallelism strategy: changes in the number of KV heads directly alter how tensor parallelism is partitioned. When there are too few heads to fill the devices, data parallelism or sequence parallelism must be introduced to compensate.
    • Memory and scheduling: once the cache layout changes, paging management, prefix reuse, and block size selection all need retuning, or hit rate and fragmentation will deteriorate.
    • Operators and quantization: the new projection structure requires rewritten fused operators, and low-bit quantization behaves completely differently in latent space than in the original space.
    • Numerical stability: low-rank compression amplifies variance in certain directions, requiring adjustments to normalization placement and initialization scale.

    An illustrative capacity calculation (pseudocode, expressing only order-of-magnitude relationships):

    1. kv_bytes = layers * kv_heads * head_dim * seq_len * batch * bytes_per_elem
    2. # MQA: kv_heads = 1; GQA: kv_heads = 8; MHA: kv_heads = query_heads
    3. # MLA: kv_bytes ≈ layers * (latent_dim + rope_dim) * seq_len * batch * bytes_per_elem

    4. Practical Advice: Capacity and Cost Planning for Long Context

    1. Define service goals first, then choose the architecture. Specify four metrics — context length, concurrency, first-token latency, and cost per token — and work backward to a cache budget, rather than starting from model leaderboards.
    2. Treat prefix caching as a first-class citizen. Long-document question answering, code repository understanding, and multi-turn agents all have large amounts of repeated prefixes, and enabling prefix reuse usually pays off more than switching models.
    3. Use tiered caching and offloading. Keep hot data in GPU memory, warm data in host memory, and cold data in object storage, with monitoring and alerts to track hit rate and queueing time.
    4. Load-test with real traffic. Construct length distributions and repetition patterns close to your workload, and record cache hit rate, peak memory, throughput, and tail latency, avoiding optimistic conclusions drawn only from short samples.
    5. Keep the architecture replaceable. Make the attention implementation, quantization scheme, and parallelism degree configuration items so you can switch between workloads and reduce lock-in risk from single-point optimization.

    5. Conclusion

    Delivering long context is a systems engineering problem: the choice of attention mechanism is only the entry point, and what really determines success is the coordination of cache management, operator adaptation, parallel partitioning, and scheduling strategy. Understanding the trade-off between MQA and MLA helps make more robust capacity and cost decisions when building your own inference service or adopting general-purpose capabilities such as cloud container platforms, object storage, and logging and monitoring.