Sparse MoE LLMs: Balancing Performance and Inference Cost

    This article explains how sparse Mixture-of-Experts (MoE) models reduce inference cost while preserving capability. It covers the core architecture of sparse activation, including shared and routed experts with Top-K routing, compares different sparsity levels, and examines long-context bottlenecks addressed by sparse attention and cache reuse. It also presents a practical cost model and deployment recommendations for capacity planning, routing observability, evaluation, and tiered serving.

    1. The Core Tension: Flagship Capability vs. High Inference Cost

    The capability ceiling of large language models has long been correlated with parameter count. However, inference cost, GPU memory usage, and time-to-first-token all rise with scale. When the context expands from a few thousand tokens to the million-token range, the quadratic growth of attention computation amplifies the cost pressure further. The mainstream answer from the industry is sparsification: build models with a large capacity that compute only a small fraction of parameters per token.

    It is important to note that sparsification is not a free lunch. It shifts part of the cost from compute to memory and bandwidth, and it raises the bar for routing quality, load balancing, and engineering implementation. Understanding this trade-off is the prerequisite for making a sound model selection.

    2. Architecture: Why Sparse Activation Lowers Cost

    Take a flagship sparse MoE model as an example. It has roughly 770B total parameters and about 49B activated parameters, an activation ratio of about 6.4%, and a context length that can reach the million-token level. Its structure can be abstracted as a 78-layer network. Except for the first layer, each layer is configured with 256 routed experts and 1 shared expert, and each token is processed by only the Top-8 routed experts plus the shared expert.

    1. # Illustrative single-layer forward logic (pseudocode)
    2. shared = SharedExpert(x) # Every token passes through
    3. idx, gate = Router(x, top_k=8) # Select 8 out of 256 experts
    4. routed = sum(gate[i] * Expert[idx[i]](x) for i in range(8))
    5. out = shared + routed

    There are three key points. First, the shared expert carries general knowledge and reduces the routing burden. Second, Top-K routing keeps the per-token compute roughly constant, decoupled from the total parameter count. Third, capacity gains come mainly from the number of experts rather than the per-token compute depth. This is the source of the “huge body weight, only about 6% actually working” effect, and the structural reason why input and output unit prices can be pushed into a low range.

    3. Sparsity Comparison: Aggressive vs. Conservative

    Different teams adopt different sparsity strategies, which can be grouped into three tiers:

    • About 6.4% activation ratio: ample capacity, robust performance, and manageable engineering complexity;
    • About 5.6% activation ratio: more aggressive, with a smaller main model;
    • About 4.8% activation ratio: the most aggressive, expanding capacity through a massive N-gram embedding table that can be offloaded to memory, pushing cost to the extreme.

    The pattern is clear: the lower the activation ratio, the lower the unit cost, but the more sensitive the model becomes to routing accuracy, expert utilization, and memory bandwidth. Criticism of being “not sparse enough” is essentially a reminder that lower sparsity is not always better; it should match the capability target.

    4. The Second Battleground for Long Context: Sparse Attention and Cache Reuse

    Under million-token contexts, the bottleneck is often not the expert layers but attention. A common industry approach is to introduce gated sparse attention, where a learnable gate decides which historical blocks to attend to, combined with an index cache that reuses previously computed results to significantly reduce the computation and memory access for long text. In engineering practice, chunked prefill, prefix caching, and KV reuse are also needed to turn the theoretical advantage into actual throughput.

    5. Cost Model: Look Beyond Unit Price

    1. Cost per request ≈ input tokens × input unit price + output tokens × output unit price
    2. + repeated computation from cache misses
    3. + amortized GPU memory/bandwidth usage

    A low unit price does not necessarily mean a low total bill. In long-context scenarios, cache hit rate, batching efficiency, and expert load balance often determine the final bill more than unit price does.

    6. Practical Recommendations

    1. Capacity planning: estimate GPU memory based on peak concurrency and context length, and reserve space for expert offloading and caching;
    2. Routing observability: monitor expert load distribution and routing entropy to avoid hot experts slowing down an entire batch;
    3. Evaluation alignment: assess coding, tool calling, and long-document understanding together, using blind-test average scores rather than a single leaderboard;
    4. Tiered deployment: route short requests to a low-activation configuration and long requests to a path optimized with sparse attention and caching;
    5. Cloud deployment: build an elastic inference pipeline by combining container platforms, object storage, logging services, and monitoring/alerting; general capabilities from Baidu AI Cloud can serve as the underlying foundation.