Sparse Mixture-of-Experts LLMs: A Technical Breakdown of Architecture, Cost, and Deployment

    This article explains how second-generation open-source Sparse Mixture-of-Experts (MoE) models decouple knowledge capacity from per-token compute, and what that means for engineers. It covers the three layers that matter in practice (capacity, routing, and KV cache), how Multi-head Latent Attention (MLA) compresses the KV cache to make 128K context deployable, and how fine-grained plus shared experts affect load balancing. It also reviews the data and alignment setup (roughly 8.1T pretraining tokens and about 1.5M supervised fine-tuning dialogues), typical benchmark positioning, the cost structure that triggered industry-wide API price cuts, and a practical framework for architecture selection, deployment, and common pitfalls.

    1. Why “Large Parameter Count” and “Low Inference Cost” Can Coexist

    In traditional dense models, capability scales almost linearly with parameter count. Double the parameters, and you double both the compute and the memory footprint per token, which pushes up the bar for training and for serving in production. Second-generation open-source Sparse Mixture-of-Experts (MoE) models take a different approach: decoupling. They split “knowledge capacity” and “per-token compute” into two independent variables.

    The key structural metrics can be summarized as follows: roughly 236 billion total parameters, with about 21 billion activated per token, an activation ratio below 9%; a context window of up to 128K; and a training compute budget roughly one-fifth that of a comparable 70B-class dense model from the same period, and about one-twentieth that of larger closed-source models. Three layers are worth separating to understand the logic:

    • Capacity layer: the total volume of expert networks determines how much knowledge and how many patterns the model can hold.
    • Routing layer: the gating network selects a small subset of experts for each token, which determines actual compute spend.
    • Cache layer: the attention key-value cache sets the memory floor for long context.

    The real engineering difficulty is not “stacking more experts.” It is keeping routing balanced and keeping the cache small. Otherwise, the theoretical gains from sparsity get eaten by load skew and memory overflow.

    2. Latent Attention: Compressing the KV Cache to a Deployable Size

    The core idea of Multi-head Latent Attention (MLA) is low-rank joint compression of keys and values. During inference, only one compact latent vector is cached per layer, and it is projected back up on demand, instead of storing full keys and values for every head at every layer.

    Illustrative pseudocode (conceptual only, not a specific implementation):

    1. # Training/prefill stage: compress to lower dimension
    2. c_kv = W_dkv @ concat(k_1, v_1, ..., k_h, v_h) # low-rank latent representation
    3. cache.append(c_kv) # cache only c_kv
    4. # Decode stage: reconstruct on demand
    5. k_i, v_i = W_uk_i @ c_kv, W_uv_i @ c_kv
    6. attn_i = softmax(q_i @ k_i.T / sqrt(d)) @ v_i

    There are three direct benefits. First, memory usage for long context drops substantially, which is what makes 128K-level inputs feasible in production. Second, batching can hold more concurrent requests, improving throughput. Third, the quality loss associated with multi-query or grouped-query attention is mitigated, because the compression is a learned joint representation rather than simple sharing.

    Engineering note: too low a compression rank loses accuracy; too high a rank degenerates into a conventional cache. In practice, it needs to be tuned alongside the positional encoding scheme (such as Rotary Position Embedding and its variants), with dedicated regression testing on tasks like long-document retrieval and cross-file code understanding.

    3. Fine-Grained and Shared Experts: Load Balancing Is the Lifeline

    The second pillar of MoE is the expert partitioning strategy. Splitting experts into finer, more numerous units while keeping a small number of always-active shared experts improves compositional flexibility and training stability. But sparse models have two typical failure modes that must be designed against up front:

    1. Routing collapse: a few experts get over-selected while the rest are “starved,” and the effective parameter count drops sharply.
    2. Load skew: during distributed training, individual devices become bottlenecks and everything else waits.

    Common mitigations include adding a load-balancing auxiliary loss to the gate, setting a capacity factor and a drop policy, using expert parallelism with sensible communication overlap, and on the inference side warming up expert caches and aggregating requests within a batch.

    1. # General form of routing
    2. logits = gate(hidden) # [tokens, num_experts]
    3. weights, idx = topk(softmax(logits), k=6)
    4. weights = weights / weights.sum(-1, keepdim=True) # normalization
    5. aux_loss = balance_penalty(logits) # balancing constraint

    4. Data and Alignment: What 8.1T Tokens and Million-Scale Dialogue Tuning Actually Buy

    Pretraining uses roughly 8.1 trillion tokens of multi-source, high-quality corpus. The point is not the raw volume but the mixture and the cleaning: the Chinese-to-English ratio, the share of code and math, and the deduplication and quality-filtering thresholds all materially shape the resulting capability distribution. Supervised fine-tuning uses about 1.5 million multi-turn dialogues spanning multiple domains, which turns raw “continuation ability” into instruction following and conversational ability.

    The typical evaluation takeaway is that Chinese-language capability lands in the top tier, on par with mainstream strong models; English capability is around the level of a 70B-class dense model and above sparse baselines from the same period. The caveat matters: leaderboards are only a screening signal. Before production, build your own business evaluation set covering long-document understanding, structured output, tool calling, and refusal and safety boundaries.

    5. Cost Structure and Architecture Selection

    The original API pricing of 1 RMB per million input tokens and 2 RMB per million output tokens triggered broad price cuts across the industry. The lesson for developers is that inference cost is now a first-class input to architecture decisions. Evaluate in roughly this order:

    • Input/output ratio: workloads with long inputs and short outputs (document review, code-base Q&A) are most sensitive to input price.
    • Cache hit rate: for batch jobs with heavy prefix repetition, prefer a service form that supports prefix caching.
    • Memory and concurrency: when self-hosting, size GPUs based on “cache plus activated parameters,” not total parameters.
    • Elasticity strategy: absorb peaks with general-purpose container platforms and autoscaling on public cloud, run steady-state load on a fixed resource pool, keep cold data and model weights in object storage, smooth traffic spikes with a message queue in the call path, and close the loop with logging and monitoring plus alerting for observability.

    6. Ecosystem and Deployment Path

    This class of model is now broadly supported. Chip vendor communities offer one-click downloads and ready-to-run images; carrier cloud platforms support online trials, API access, and dedicated resource provisioning in minutes, and integration into agent platforms. To deploy on Baidu AI Cloud, a general path works: run inference services on a container platform, distribute weights via object storage, track latency and failure rates with monitoring and alerting, and use a unified gateway for canary releases and rate limiting.

    7. Common Pitfalls

    • Judging cost by total parameters alone: real cost is driven by activated parameters and cache.
    • Ignoring routing balance: it looks fine under small canary traffic, then quality fluctuates at full volume.
    • Overusing long context: irrelevant content dilutes attention, so pair it with retrieval and reranking.
    • Too much low-quality fine-tuning data: prefer small and high-quality to avoid catastrophic forgetting.

    In short, sparse MoE combined with latent attention trades “conditional computation plus representation compression” for an order-of-magnitude cost reduction at comparable quality. Keep three threads in view — activation ratio, cache footprint, and routing balance — and you can make verifiable engineering judgments in selection, deployment, and tuning.