MLA vs MQA: How to Choose the Right Attention Mechanism for Open-Source LLMs

    With rumors of an open-source team switching from MLA back to MQA, attention architecture is once again a hot topic. This article compares MHA, MQA, GQA, and MLA in terms of KV cache size, expressiveness, and implementation complexity, and provides a practical selection framework covering memory estimation, inference framework support, prefix caching, optimizer interactions, and kernel development—so you can choose based on your own benchmarks rather than community debate.

    Why Attention Architecture Is Back in the Spotlight

    For a while, MLA (Multi-head Latent Attention) was adopted by many open-source models and was widely regarded as a leading reference design. Recently, discussions have emerged in the community suggesting that a new version from one open-source team has moved from MLA back to the earlier MQA (Multi-Query Attention). This claim has not been explicitly confirmed in any official technical report, so treat it only as a starting point for discussion, not as fact.

    The discussion is worth paying attention to because it highlights a key point: there is no single right answer for attention architecture. The trade-offs among inference bandwidth, memory footprint, training efficiency, and model quality vary with model scale, context length, and deployment environment.

    Core Differences Among Four Attention Mechanisms

    1. MHA (Standard Multi-Head Attention)

    Each attention head has its own Key and Value projections. During inference, the KV cache stores the Key and Value of every historical token, and its size grows linearly with the number of heads. You can estimate the KV cache size with this formula:

    KV cache bytes ≈ 2 × number of layers × number of KV heads × head dimension × sequence length × batch size × bytes per element

    The factor of 2 accounts for storing both Key and Value. With fp16, each element takes 2 bytes.

    2. MQA (Multi-Query Attention)

    All query heads share a single set of Key and Value, so the KV head count is 1. Compared with MHA, the KV cache shrinks to 1/(number of heads) of the original size. The cost is a potential drop in model expressiveness, and training recipes need more careful tuning.

    3. GQA (Grouped-Query Attention)

    GQA divides query heads into groups, with each group sharing one set of Key and Value. The number of groups equals the number of KV heads. GQA strikes a balance between cache size and quality and is a common choice for many general-purpose LLMs today.

    4. MLA (Multi-head Latent Attention)

    MLA does not cache Key and Value directly. Instead, it projects them into a low-rank latent space and caches only the compressed latent vectors. At decode time, the computation is recovered through techniques such as matrix absorption. In theory, MLA preserves more expressiveness under a smaller cache budget. In practice, it is more complex in terms of kernel optimization and positional encoding handling (e.g., RoPE), and inference frameworks need dedicated support.

    The table below is a qualitative comparison. Actual numbers depend on the model configuration and should be verified by your own measurements.

    Mechanism KV Cache Size Expressiveness Implementation Complexity Typical Scenarios
    MHA Largest Strongest Low Small models, short contexts
    MQA Smallest Usually somewhat reduced Low High-concurrency, bandwidth-sensitive inference
    GQA Between MHA and MQA Close to MHA Medium Most general-purpose LLMs
    MLA Small (compressed latent vectors) Can theoretically balance cache and expressiveness High; depends on dedicated kernels Long contexts with mature framework support

    A Decision Framework for Selection

    Before choosing, check the following five questions one by one.

    1. Where is the bottleneck? If you handle many concurrent requests and memory is tight, cache size is the top priority, and MQA or GQA usually fits better. If quality degrades noticeably on long contexts, expressiveness carries more weight.
    2. How many requests can fit in memory? Use the formula above to estimate the KV cache per request. For example, suppose a model has 60 layers, 8 KV heads, head dimension 128, fp16, a 32k context, and batch size 8—the KV cache is roughly 60 GiB. With 64 KV heads instead (i.e., MHA), the cache grows to roughly 480 GiB. These numbers only illustrate orders of magnitude; use the official configuration of your actual model.
    3. Does the quality meet your bar? Test on your own task set rather than relying only on public leaderboards.
    4. Is it supported by your inference framework? Check the release notes of your inference engine to confirm that the model architecture and attention variant are supported with corresponding performance optimizations.
    5. Can your team maintain it? Custom kernels and complex cache compression logic increase maintenance costs. If your team lacks kernel development experience, prefer options with mature framework support.

    This framework has no universal conclusion. If your bottleneck is memory bandwidth under high concurrency, MQA or GQA is often more straightforward. If your workload depends on long-context quality and your team can support kernel development, MLA may deliver real gains.

    Scale and Cost: Don’t Look at Parameter Count Alone

    Total parameter count determines storage and memory footprint, while activated parameter count more closely reflects per-inference compute—especially in Mixture-of-Experts (MoE) architectures. The two should be evaluated separately. Comparing parameter counts alone can easily lead to wrong cost conclusions.

    API pricing also needs a close look. Some platforms offer discounts for input cache hits and charge regular prices on misses. Before use, confirm these rules:

    • What is the minimum cacheable length?
    • What defines a “hit”? Does it require the prefix to match token by token exactly?
    • What is the cache TTL (time to live)?
    • What is the exact hit discount, and is there a cache storage fee?

    Prefix caching works like this: when multiple requests share the same prefix, the already-computed KV can be reused directly without recomputation. To make prefix caching effective, structure your prompts carefully:

    • Put stable system prompts, tool definitions, and long documents at the front;
    • Put content that changes on every request (user questions, timestamps, random IDs) at the end;
    • Avoid inserting dynamic fields into the prefix—otherwise the prefix differs each time and the cache never hits;
    • Use logs to track cache hit rates and validate your design.

    How Optimizers Interact with Architecture

    Training-side changes also affect architecture. Take Muon as an example: this class of optimizer orthogonalizes the update for 2D weight matrices, commonly implemented via Newton–Schulz iteration. Other parameters (such as embedding and normalization layers) usually still use traditional optimizers like AdamW.

    When applying such optimizers, verify the following:

    • Training stability: Observe loss curves and gradient norms across different learning rates—are there spikes or divergence?
    • Mixed-precision compatibility: Under bf16 or fp8 training, is the numerical error of the orthogonalization computation under control?
    • Distributed communication overhead: Under sharding strategies such as FSDP or ZeRO, what fraction of each step is spent on communication, and does throughput (tokens/s) meet expectations?

    Optimizer changes alter the numerical distribution of parameter updates, which in turn affects activation ranges and precision strategies. Gains observed in one configuration may not transfer to other models or clusters.

    Bringing Inference to Production: From Paper to Service

    The critical path from a new attention architecture in a paper to production is usually kernel development. A typical workflow looks like this:

    1. Write a reference implementation in PyTorch to ensure logical correctness;
    2. Compare numerical outputs against the reference and check whether errors are within acceptable bounds;
    3. Write the kernel, either in hand-written CUDA or in a GPU-oriented DSL such as Triton;
    4. Integrate the kernel into an inference engine such as SGLang or vLLM;
    5. Profile performance with tools like Nsight and compare against the baseline.

    DSLs lower the barrier for researchers to validate kernel hypotheses themselves, but they do not eliminate the need for numerical verification and performance profiling.

    In addition, inference engines adopt new attention architectures at different speeds. When choosing, check the release notes of the specific version to confirm support for the model and attention variant, rather than relying on word of mouth in the community.

    A Practical Checklist for Developers

    Before making an architecture or deployment decision, design an A/B evaluation covering these metrics:

    • Quality: Task accuracy on your own evaluation set, which should include typical scenarios such as long context, code, and tool calling;
    • Latency: Time to first token, plus P95 and P99 latency;
    • Throughput: Tokens generated per second per GPU;
    • Cache hit rate: The actual prefix hit ratio under real traffic;
    • Unit cost: Actual cost per thousand requests or per task.

    A minimal experiment can be designed as follows: fix an evaluation set of 200 to 500 samples, run both candidate solutions on identical hardware, concurrency, and inference parameters, repeat each run three times, and record the mean and variance. If the difference between results is smaller than the variance, do not draw conclusions from it.

    If you use a cloud platform, you can leverage its monitoring and logging features to continuously track these metrics, so version selection and architecture adjustments are backed by data.

    Conclusion

    There is no universal standard answer for attention architecture. MHA, MQA, GQA, and MLA each have their applicable boundaries. The choice should be based on bottlenecks you have measured yourself and reproducible evaluation results—not on following some model’s roadmap or the conclusion of any single community discussion.