LLM Architecture Evolution: From Attention Optimization to MoE in Practice

    This article explains why inference cost has become the primary constraint in modern LLM architecture design, and walks through two complementary technical approaches: compressing the attention mechanism to reduce KV cache overhead, and using sparse activation in Mixture-of-Experts (MoE) models to decouple total parameters from per-token compute. It also covers capacity planning for MoE deployment, iterative improvements for AI Agent scenarios, a reusable evaluation and tuning workflow, and common misconceptions about cost, latency, and routing. Readers will gain a practical framework for balancing constraints, architecture, evaluation, and iteration.

    1. Why Inference Cost Became the First Constraint in Architecture Design

    Over the past two years, the focus of LLM competition has shifted quickly from parameter count to cost per token. The reason is straightforward: training is a one-time investment, while inference is an ongoing expense. Once a model is embedded in high-frequency scenarios such as customer support, coding assistance, and document review, every request consumes GPU memory and compute, and cost grows linearly with call volume.

    As a result, the objective function of architecture design has been rewritten: minimize memory usage and redundant computation during inference while maintaining overall performance.

    This constraint has driven two complementary technical approaches. One compresses the attention mechanism itself to reduce caching overhead during inference. The other decouples total parameter count from the number of parameters activated per token, trading sparse activation for capacity. Understanding these two approaches is the foundation for understanding efficient LLM design today.

    2. The Memory Bottleneck of Attention and Optimization Approaches

    Every step of autoregressive decoding reads the key-value cache (KV Cache) of historical tokens. In standard multi-head attention, cache size is proportional to layers × heads × head dimension × sequence length. In long-context scenarios, this portion of GPU memory can quickly exceed the weights themselves, becoming the real ceiling on throughput.

    Commonly accepted optimization directions fall into three categories:

    • Sharing: multiple query heads reuse the same set of key-value projections, reducing the number of entities that need to be cached;
    • Low-rank compression: project keys and values into a lower-dimensional latent space, cache the compressed representation, and project it back up when needed;
    • Quantization and paging: reduce the numerical precision of the cache, or manage cache memory with paging to limit fragmentation.

    Low-rank compression has been the most influential idea, in the form of mechanisms such as Multi-head Latent Attention: keys and values are no longer stored at full dimension but saved as low-rank latent variables, significantly reducing cache usage in long-context settings. It is worth emphasizing that these mechanisms are not free of cost—up-projection adds computation, and a poorly chosen latent dimension can lose representational capacity, so latent dimension, head count, and training data mixture need to be tuned jointly.

    A schematic structural comparison (pseudocode, illustrating design differences only):

    1. # Standard multi-head attention: cache full K/V
    2. cache_k = zeros(batch, n_heads, seq, head_dim)
    3. cache_v = zeros(batch, n_heads, seq, head_dim)
    4. # Low-rank latent attention: cache only the compressed latent representation
    5. cache_c = zeros(batch, seq, latent_dim) # latent_dim << n_heads * head_dim
    6. k = up_proj_k(cache_c) # reconstructed when needed
    7. v = up_proj_v(cache_c)

    The engineering benefit is direct: as cache memory drops, the number of concurrent requests a single GPU can serve increases, batch sizes grow, and cost per token falls. The risk of memory overflow in long-context scenarios is also significantly reduced.

    3. Mixture-of-Experts: Decoupling Capacity from Compute

    The second approach is sparse activation. A Mixture-of-Experts (MoE) model splits the feed-forward layer into multiple parallel expert subnetworks, and a routing network selects a few experts to participate in computation for each token. The key property is that the total parameter count can be very large, while the actual computation per token depends only on the number of activated experts.

    This leads to three consequences:

    1. Capacity gains: under the same inference compute budget, the model can hold more parameters, providing a stronger foundation for knowledge capacity and overall performance;
    2. Controllable cost: inference overhead is determined roughly by the activated scale rather than the total parameter count;
    3. Higher training complexity: imbalanced routing causes some experts to be overloaded while others sit idle, requiring auxiliary load-balancing losses, routing noise, and expert capacity limits as constraints.

    On the deployment side, the memory footprint of MoE differs from that of a conventional dense model: all weights need to be resident (or swapped in on demand), but computation is sparse. Capacity planning therefore needs to consider two dimensions at once—total parameter count sets the memory floor, and activated parameter count determines compute demand. The two cannot be used interchangeably. A common practice is to combine quantization, expert parallelism, and cache reuse to spread memory pressure across multiple devices.

    4. Minor Version Iterations: Bringing Capability Refinement to Agent Scenarios

    Once the architecture is settled, experience improvements come mostly from continuous small steps: adjusting data mixtures, fixing long-context stability, strengthening instruction following and format constraints, and improving the reliability of tool calls and multi-step planning. For Agent applications, what really determines success is often not the fluency of a single-turn answer but stability across long chains of tasks: whether the goal stays on track after multiple tool calls, whether retries happen correctly after failures, and whether structured output that can be parsed is produced reliably.

    The evaluation system should therefore shift from single-point benchmarks to chain-level metrics: task completion rate, average number of steps, ratio of invalid calls, structured output parse success rate, end-to-end latency, and cost per task. Only by including these metrics in regression testing can iteration avoid fixing one thing while breaking another.

    5. Implementation Practice: A Reusable Evaluation and Tuning Workflow

    • Define constraint boundaries first: determine context length, concurrency, latency budget, and the cost-per-token ceiling before choosing an architecture;
    • Measure memory and throughput separately: estimate the memory floor from total parameter count and compute demand from activated scale, leaving room for fragmentation and a safety margin;
    • Prioritize caching strategy: in long-context scenarios, evaluate low-rank compression attention first, along with cache quantization and paging;
    • Watch routing health for sparse models: monitor expert load distribution to avoid wasted effective capacity from long-term imbalance;
    • Build chain-level regression: use a fixed task set covering tool calls, multi-turn rewriting, and structured output, continuously tracking completion rate and cost;
    • Serve in tiers: routing high-frequency simple requests and low-frequency complex requests to different size configurations is one of the most effective ways to reduce total cost.

    6. Common Misconceptions

    • Equating “fewer parameters” with “lower cost”: the memory usage of a sparse model is determined by total parameters, and a design with few parameters but a high activation ratio is not necessarily cheaper;
    • Looking only at time to first token: in long-output scenarios, total time is dominated by the decoding phase, so caching strategy matters far more than prefill;
    • Ignoring routing and data mixture: architecture is only the skeleton; data and training strategy determine the actual capability ceiling;
    • Inferring Agent performance from single-turn metrics: failures in multi-step tasks often come from context management and retry logic rather than a single-point model capability.

    7. Conclusion

    From attention cache compression to sparse expert activation, and then to continuous minor version refinement, the design logic of efficient LLMs always revolves around the same goal: pushing inference memory and compute as low as possible within an acceptable performance loss. For developers, mastering this methodology of constraints, architecture, evaluation, and iteration has more long-term value than chasing a single metric. On cloud platforms such as Baidu AI Cloud, general capabilities like container platforms, object storage, logging services, and monitoring and alerting can turn the evaluation workflow above into a sustainable engineering system.