The Attention Architecture Debate: MLA, MQA, and Million-Token Contexts

    MLA is not a universal replacement for MQA or other attention mechanisms. This article compares MHA, GQA, MQA, and MLA from a system-level perspective, covering KV-cache capacity, implementation complexity, quality trade-offs, million-token context engineering, optimizer and kernel considerations, and practical guidance for model developers.

    1. Bottom Line

    This article focuses on system-level trade-offs. It does not argue that MLA has completely replaced MQA. There is no universally optimal attention architecture. The right choice depends on the model’s total size, deployment hardware, target context length, and support from the inference framework.

    2. Key Differences Among Four Attention Mechanisms

    In multi-head attention (MHA), each query head has its own key-value (KV) head. Multi-query attention (MQA), introduced by Shazeer in 2019, shares a single set of KV heads across all query heads. Grouped-query attention (GQA), introduced by the Google team in 2023, divides query heads into groups, with each group sharing one set of KV heads. It can be viewed as a compromise between MHA and MQA.

    Multi-head latent attention (MLA), publicly promoted through DeepSeek-V2 in 2024, does not directly cache KV states. Instead, it caches compressed, low-dimensional latent vectors and reconstructs them through an up-projection during inference.

    Mechanism KV-cache size Computation and implementation complexity Kernel implementation difficulty Quality risk Common use cases
    MHA Largest Low Low Lowest Small- and medium-sized models, short contexts
    GQA Medium, depending on the number of groups Low Low Relatively low Most general-purpose large models
    MQA Smallest, with only one KV set Low Low Potentially higher under the same training recipe; training compensation may be required Severe memory constraints, throughput-first deployments
    MLA Small, using latent-vector caching High, requiring fused projections High, depending on implementation quality Reported in papers to be close to or better than MHA; depends on the configuration Large-scale, long-context workloads with mature implementations

    MLA trade-offs. MLA caches low-dimensional latent vectors. Through matrix absorption, the up-projection can be folded into subsequent attention computation, reducing memory-access operations. The trade-off is a more complex computation graph. The up- and down-projections introduce additional parameters and FLOPs, while kernel quality becomes more important.

    MQA trade-offs. MQA minimizes KV-cache size. Its computation graph is simple, its kernels can achieve high hardware utilization, and it has relatively low coupling with distributed inference frameworks. The trade-off is reduced representational capacity for KV states. Under the same training recipe and model scale, MQA may deliver lower quality than MHA. However, this can potentially be offset with more training data, adjusted head dimensions, or a larger model. The conclusion must be validated through measurement and should not be applied universally.

    3. Why the Optimal Structure Changes with the System

    Model quality depends not only on the attention mechanism itself, but also on how it interacts with MoE routing, expert capacity, context-extension methods, and the inference engine. When total model parameters reach the trillion scale and the context window extends to one million tokens, a computationally simpler architecture with predictable memory-access patterns may offer better end-to-end throughput and cost efficiency, even if its isolated quality metrics are slightly lower.

    The architecture with the best standalone benchmark results is not necessarily the best end-to-end solution. Evaluation should check whether ablation experiments in technical reports compare configurations under equivalent conditions and whether they report throughput, latency, and memory consumption in addition to quality.

    4. Engineering Challenges of Million-Token Contexts

    4.1 Attention Complexity

    The computational cost of naive attention grows quadratically with sequence length. If the sequence length doubles, the attention-related computation increases by approximately four times.

    A common approach is to combine sliding-window attention with sparse attention. Most tokens perform only local computation, while a smaller number of important tokens participate in global computation. The sparse patterns used during training and inference must remain consistent. Otherwise, retrieval quality may decline significantly for extremely long inputs.

    4.2 Estimating KV-Cache Size

    The following estimates use these assumptions: 60 layers, a head dimension of 128, BF16 precision with 2 bytes per element, a single sequence, and no quantization.

    The KV-cache size per token can be estimated as:

    1. Number of layers × Number of KV heads × Head dimension × 2 (K and V) × 2 bytes
    • 1 KV head (MQA): approximately 30 KB per token, or about 30 GB for one million tokens.
    • 8 KV heads (GQA): approximately 245 KB per token, or about 246 GB for one million tokens.
    • 64 KV heads (MHA): approximately 1.97 MB per token, or about 1.97 TB for one million tokens.

    These figures cover only the KV cache. They do not include model weights, activations, or framework overhead. MLA cache size depends on the latent-vector dimension and must be recalculated according to the specific configuration.

    4.3 KV-Cache Storage and Scheduling

    Inference frameworks need to manage KV caches through a paged memory system. Hot data can remain in HBM, warm data can be placed in DRAM, and local NVMe SSDs can serve as a secondary cache. Object storage generally has too much latency and insufficient throughput for hot KV-cache migration. It is usually more suitable for cold backups or offline archiving.

    Prefix caching can reuse KV states associated with identical system prompts, reducing time to first token and computation costs. However, teams must evaluate both cache hit rates and the amount of HBM consumed.

    Eviction and recomputation also require a trade-off. Recomputing consumes compute capacity, while moving data in and out consumes bandwidth.

    4.4 Consistency Between Training and Inference

    Long-context capabilities need to be established during training. Common methods include positional-encoding extrapolation and data curricula that progressively increase sequence length.

    During evaluation, “needle-in-a-haystack” tests can be used to measure retrieval at different sequence lengths and positions. This helps identify whether performance degrades significantly as context length increases.

    5. Optimizers and Kernels: Changes on the Training and Inference Sides

    AdamW maintains first- and second-order moments for every parameter. In trillion-parameter MoE models, these optimizer states consume a large amount of memory and represent one of the main sources of training pressure.

    Two directions have attracted attention:

    • Orthogonalized-momentum optimizers, represented by Muon. These optimizers orthogonalize the update direction for two-dimensional weight matrices. Implementations commonly use Newton–Schulz iterations as an approximation. Public technical reports have documented their use in training some large models. They mainly target matrix parameters in hidden layers, while embedding and output layers typically continue to use other optimizers.
    • Second-order approximation optimizers, represented by Shampoo and SOAP. These methods use preconditioner matrices to approximate second-order information. Under some configurations, they may provide better convergence, but they also introduce additional compute and memory costs and require more sophisticated engineering.

    At the kernel level, tile-oriented programming abstractions such as Triton and TileLang allow developers to describe tiled computation at a relatively high level, reducing the cost of writing low-level kernels by hand. Whether they can achieve peak performance on specific domestic or heterogeneous hardware depends on the implementation of the relevant backend and on measured results.

    A common theme across these directions is that architecture, optimizer design, and kernel implementation must be considered together. Improving only one component may produce limited gains if another part of the system becomes the bottleneck.

    6. Practical Guidance for Developers

    1. Do not treat any single architecture as the default optimal choice. First define the model scale, hardware constraints, and target context length.
    2. Evaluate end-to-end metrics, including throughput, time to first token, cost per unit of usage, and quality.
    3. When calling a cloud model API, place stable system prompts at the beginning of the request to improve the chance of a prefix-cache hit. Check the provider’s official documentation for cache support and billing rules, as these vary across platforms.
    4. Read technical reports and ablation studies directly. Pay particular attention to whether comparison conditions are equivalent.

    Frequently Asked Question

    How do MLA and MQA differ?