Sparse Mixture-of-Experts Architecture: Balancing Efficiency and Capability in Large Language Models

    This article explains why mainstream large language models are converging on a similar architecture centered on sparse activation. It covers how Mixture-of-Experts (MoE) expands model capacity while controlling per-token compute, how attention variants such as MHA, GQA, and MLA reduce KV cache pressure, how to reason about total versus activated parameters and inference cost, and how training and post-training choices differentiate models with similar architectures. It also provides a five-dimension framework for evaluating different technical approaches, helping engineers and decision-makers assess models based on architecture, context capability, inference cost, task performance, and engineering fit rather than parameter counts or leaderboard rankings alone.

    1. Background: Why Mainstream LLM Architectures Are Converging

    Over the past two years, mainstream large language models have shown clear architectural convergence. Most models still build on the Transformer and optimize along three directions. First, Mixture-of-Experts (MoE) expands model capacity while keeping per-token compute under control. Second, improved attention mechanisms reduce memory usage and computation during inference. Third, more refined training and post-training pipelines improve instruction following and reasoning.

    As a result, comparing models solely by parameter count or leaderboard rankings is often insufficient. You need to break down the design trade-offs layer by layer and evaluate how each choice affects quality, cost, and deployment difficulty.

    2. Mixture-of-Experts: Trading Sparse Activation for Model Capacity

    In a dense model, every token passes through all parameters, so compute scales linearly with parameter count. MoE replaces the feed-forward network with multiple expert sub-networks, and a router selects a small number of experts for each token. The total parameter count can be very large, while each token activates only a fraction of them.

    The basic flow of a single MoE layer is:

    1. The router scores every expert for the current token;
    2. The top-k experts with the highest scores are selected;
    3. Their weights are normalized, and the expert outputs are combined as a weighted sum.

    Pseudocode:

    1. function moe_layer(x):
    2. scores = router(x) # one score per expert
    3. probs = softmax(scores)
    4. top = top_k_indices(probs, k) # select k experts
    5. weight_sum = sum(probs[i] for i in top)
    6. y = 0
    7. for i in top:
    8. y += (probs[i] / weight_sum) * experts[i](x)
    9. return y

    Three issues matter in engineering practice.

    Load balancing. If routing consistently favors a few experts, some experts are undertrained while others sit idle. Common solutions include adding an auxiliary balancing term to the loss function, or dynamically adjusting routing bias during training and inference.

    Communication overhead. When experts are distributed across multiple accelerators, tokens must be dispatched across devices and the results aggregated. The parallelism strategy directly affects throughput, and the problem becomes more pronounced as the number of experts grows.

    Expert count and sparsity. Within a certain range, increasing the total number of experts while lowering the activation ratio per token improves model capacity under a similar compute budget. This aligns with the empirical observation in Scaling Law research that increased sparsity brings gains. However, higher sparsity makes routing and communication more complex, and returns gradually diminish.

    3. Attention Optimization: Reducing KV Cache Pressure

    During autoregressive generation, the model caches the Keys and Values of historical tokens—the KV cache. Its size grows linearly with sequence length, number of layers, and number of KV heads, and it is often the memory bottleneck in long-context inference.

    Common attention variants include:

    • Multi-Head Attention (MHA): Each query head has its own key-value heads. It offers strong expressiveness but the largest cache footprint.
    • Grouped-Query Attention (GQA): Multiple query heads share one set of key-value heads, balancing model quality against cache usage. It is widely adopted.
    • Multi-head Latent Attention (MLA): Keys and values are first projected into a low-dimensional latent space for storage and reconstructed during computation, further compressing the cache.

    Another approach is reducing the number of attention heads. Fewer heads reduce both attention computation and KV cache size, but may also weaken model expressiveness. Head count should therefore be evaluated together with hidden dimension and training data volume, not judged in isolation.

    KV cache size can be roughly estimated with the following formula:

    1. function kv_cache_bytes(layers, kv_heads, head_dim, seq_len, dtype_bytes):
    2. # the factor of 2 accounts for caching both Key and Value
    3. return 2 * layers * kv_heads * head_dim * seq_len * dtype_bytes

    For example, suppose a model has 60 layers, 8 KV heads, a head dimension of 128, a sequence length of 32,768, and FP16 storage (2 bytes per value). Plugging these into the formula, the KV cache for a single sequence is about 8,053,063,680 bytes, or roughly 7.5 GiB. This is only an order-of-magnitude estimate; actual numbers depend on the specific model configuration and cache implementation.

    4. Parameter Scale and Inference Cost

    When analyzing inference cost, two concepts must be distinguished. Total parameter count determines storage requirements, while activated parameter count determines the compute per token. For MoE models, memory must still hold all expert weights, so the deployment threshold is mainly set by total parameters. Generation speed is closer to the compute cost of activated parameters, and is also affected by memory bandwidth and cross-device communication.

    Key metrics to consider when selecting a model:

    • Time to first token (TTFT) and output tokens per second, which reflect interactive experience;
    • Throughput under concurrency, influenced by batching strategy and KV cache management;
    • Memory usage in long-context scenarios, which determines sustainable concurrency;
    • Communication topology in multi-GPU deployments, which determines scaling efficiency.

    5. Training and Post-Training: Differences Beyond Architecture

    Similar architectures do not imply similar capabilities. Data quality and mixture ratios, training stage scheduling, long-context extension methods, instruction tuning, preference alignment, and reinforcement learning all significantly affect final results. When reading technical reports, pay attention to whether these stages are described in sufficient detail and whether the evaluation sets cover your target business scenarios.

    6. How to Evaluate Different Technical Approaches

    It is recommended to build an evaluation matrix around five dimensions:

    1. Architecture: Whether MoE is used, total expert count and per-token activated experts, attention variant and head configuration;
    2. Context capability: Accuracy of information retrieval and multi-step reasoning at target context lengths;
    3. Inference cost: Cost per token, memory footprint, and throughput;
    4. Task performance: Build evaluation sets from your own business data rather than relying only on public benchmarks;
    5. Engineering fit: Deployment options, monitoring and alerting capabilities, and scaling flexibility.

    For enterprises deploying LLM services on Baidu AI Cloud, resource planning can follow the dimensions above, combined with logging and monitoring/alerting services to establish a continuous evaluation mechanism, so that model selection adapts dynamically as business data evolves.

    7. Conclusion

    The technical route of mainstream large models is converging. Sparse activation and attention compression are becoming standard tools for balancing efficiency and capability. When comparing models, look beyond parameter counts and rankings: examine how each architecture handles capacity, KV cache, and communication overhead, and evaluate training pipelines and task performance against your own scenarios. A structured, multi-dimensional evaluation is the most reliable way to choose a model that fits both your workload and your budget.