Understanding Sparse Mixture of Experts (MoE) LLMs: Architecture, Cost, and Deployment

    This article breaks down how sparse Mixture of Experts (MoE) models reduce the cost of large language models by decoupling total capacity from per-token computation. It explains Multi-head Latent Attention (MLA), fine-grained expert routing with shared experts, how to interpret capability and training-efficiency claims, and a practical framework for API pricing versus self-hosted inference, along with common deployment pitfalls.

    1. Why Sparsity Has Become the Key Path to Lower LLM Costs

    The “capability versus cost” tension in large models is long-standing. In a dense architecture, every token passes through all parameters, so doubling the parameter count doubles both computation and memory usage. A second-generation open-source MoE (Mixture of Experts) model, released on May 6, 2024, takes a different approach: it decouples “total capacity” from “per-token computation.” The model has 236 billion total parameters, yet each token activates only about 21 billion parameters—completing a single forward pass with less than one-tenth of the parameters.

    This design delivers two direct benefits: a significant drop in floating-point operations for both training and inference, and fewer weights that need frequent reads and writes in memory. It is worth stressing that sparsity does not reduce memory requirements proportionally—all expert weights must still reside in memory or be swapped in on demand. In engineering terms, this means you must combine expert parallelism, weight sharding, and caching strategies to turn theoretical gains into real throughput improvements.

    2. Architecture Breakdown: Latent Attention and Fine-Grained Expert Routing

    2.1 Multi-Head Latent Attention (MLA)

    The memory bottleneck of traditional multi-head attention comes mainly from the KV Cache: the longer the context, the more key-value pairs are cached, and memory grows linearly. Multi-head Latent Attention compresses keys and values into a low-dimensional latent space before caching, then restores them via up-projection during inference, substantially shrinking the cache size. The benefit is amplified in long-context scenarios: with support for a 128K context, sticking with an uncompressed cache would make per-request memory overhead unacceptable.

    Illustrative pseudocode (expressing only the compress–cache–restore logic, not a specific implementation):

    1. # 1) Map the input to a low-dimensional latent representation
    2. latent = x @ W_down # [batch, seq, d_latent], d_latent << d_head * n_head
    3. cache = latent # cache only the low-dimensional latent vectors
    4. # 2) Up-project on demand to restore K/V during inference
    5. k = cache @ W_up_k
    6. v = cache @ W_up_v
    7. # 3) Standard scaled dot-product attention
    8. scores = (q @ k.transpose(-1, -2)) / sqrt(d_head)
    9. out = softmax(scores) @ v

    Engineering note: the latent dimension is a trade-off knob between memory and representational capacity. Too small loses information; too large weakens the compression benefit. At the same time, the up-projection matrices introduce extra computation, which must be amortized through operator fusion and batching.

    2.2 Fine-Grained Expert Splitting and Shared Experts

    The key to MoE is not just “how many experts” but “how to split and how to route.” Fine-grained splitting makes experts smaller and more numerous, letting each token choose from more expert combinations, which improves parameter utilization and the degree of knowledge specialization. Keeping a small number of always-active shared experts to carry general knowledge reduces capability fluctuations caused by routing jitter. Combined with a load-balancing loss and capacity-factor control, this avoids a few popular experts becoming overloaded while the rest sit idle.

    The routing logic can be abstracted as:

    1. gate = softmax(x @ W_gate) # expert scoring
    2. topk_idx, topk_val = topk(gate, k=6)
    3. y = sum(topk_val[i] * Expert[i](x) for i in topk_idx)
    4. y += SharedExpert(x) # shared expert carries general capability

    3. Reading Capability and Training Efficiency Correctly

    Public benchmarks show that this class of model sits alongside the leading closed-source models of the same period on Chinese comprehensive benchmarks, performs on par with 70-billion-parameter dense models on English benchmarks, and surpasses some mainstream sparse models. Pre-training used roughly 8.1 trillion tokens of multi-source, high-quality corpus, and the supervised fine-tuning stage used about 1.5 million multi-domain dialogue samples.

    On training efficiency, the claim that “compute is about one-fifth of a same-generation 70B dense model and one-twentieth of a top closed-source model” needs to be understood with qualifications: it measures the compute required to reach comparable results, not wall-clock speed per unit time. Actual training is still constrained by communication overhead, expert-parallelism partitioning strategy, All-to-All bandwidth, and fault-recovery capability. The takeaway for developers: when evaluating a sparse model, look at four metrics together—“activated parameters per token,” “FLOPs per token,” “peak memory,” and “cluster interconnect quality.” Looking at total parameter count alone leads to wrong conclusions.

    4. Deployment and Cost: From API Pricing to Self-Hosted Inference

    The model’s API pricing is 1 RMB per million input tokens and 2 RMB per million output tokens. This low-price strategy prompted several cloud vendors and platforms to follow with price cuts, pushing large models from a “scarce resource” toward a “basic capability that can be invoked in batches.” For cost-sensitive workloads, the recommended decision order is:

    1. Start with a token budget: measure the input/output ratio. For long-document summarization, output accounts for a low share, so cost falls mainly on the input side.
    2. Then assess caching gains: system prompts and knowledge-base snippets can reuse a prefix cache; on a hit, billing and compute for the repeated portion drop significantly.
    3. Finally decide between self-hosting and API calls: self-hosting must cover GPU or domestic accelerator resources, an inference framework, batching and rate limiting, monitoring and alerting, and logging services. Fixed costs only amortize under stable high concurrency.

    On domestic hardware adaptation, this class of model was brought online in February 2025 on a domestic AI accelerator platform community with processor adaptation completed, and was subsequently integrated in full (including V1/V2/V3 and inference-enhanced versions) by a cloud platform—showing that the compatibility chain across mainstream hardware and cloud platforms is maturing.

    5. Implementation Advice and Common Pitfalls

    • Context is not better when longer: the 128K capability should be paired with retrieval and segmentation strategies to avoid irrelevant content diluting attention and driving up cost.
    • Sparse does not mean small memory: always estimate peak usage as “all expert weights + KV Cache + activations.”
    • Routing observability: after launch, monitor expert load distribution, drop rate, and tail latency to prevent hot experts from causing jitter.
    • Fine-tuning strategy: prefer parameter-efficient fine-tuning and high-quality small-sample data; avoid full-parameter fine-tuning that can break routing balance.
    • If you use Baidu AI Cloud’s general capabilities (such as a container platform to host inference services, object storage for corpora, and logging plus monitoring and alerting for observability), combining elastic scaling with canary releases can further reduce per-token cost.

    Overall, the sparse Mixture of Experts architecture combined with latent attention is the current mainstream engineering paradigm for balancing capability, long context, and cost. Understanding the true distribution of memory and compute matters more to a project’s success than chasing parameter scale.