MoE Sparse Activation: Cutting Inference Costs in Large Models
This article explains how Mixture-of-Experts (MoE) architecture reduces inference cost in large language models. It covers the cost bottleneck of dense models, the structure of MoE, the Top-k routing mechanism, how to estimate activation ratio and compute savings, the hidden costs of sparsity (memory, load imbalance, communication), attention challenges in long contexts, and the trade-offs in activation scale. Aimed at engineers and researchers evaluating model architectures for cost-efficient deployment.
Introduction
As large language model parameters continue to grow, inference cost becomes a primary constraint on real-world deployment. The key architectural question is how to increase total parameter count while keeping per-request computation manageable. Mixture-of-Experts (MoE) is one of the mainstream solutions: instead of activating all parameters for every token, it dynamically selects a small subset based on the input. This article examines the principle, computational model, costs, and engineering practice of MoE.
1. The Cost Bottleneck of Dense Models
In a dense architecture, every token interacts with all parameters of each layer. When the parameter count doubles, the computation per inference roughly doubles as well, causing a linear increase in compute demand for both training and inference. Memory usage and latency also scale up accordingly.
This linear relationship becomes especially problematic at the hundred-billion parameter scale. On the serving side, the bottleneck is not just the cost of a single request but also the throughput ceiling under concurrent load. A model that requires a large cluster of accelerators to run may achieve excellent quality, but its unit cost makes it difficult to offer as a low‑priced service.
2. Basic MoE Structure
MoE replaces the feed‑forward network layer with a set of parallel expert sub‑networks and adds a router (also called a gate network). The router receives the hidden state of each token, computes a score for each expert, and selects the top‑scoring experts to process that token.
A typical MoE block consists of three components:
- Routed experts: a large number of experts, of which only k are activated per token.
- Shared expert: always active for all tokens, captures general knowledge, and avoids each routed expert learning the same common features.
- Router: performs scoring and selection; its own parameter count is small.
Attention layers, embedding layers, and output layers are usually shared by all tokens and are not part of the expert parameters. This distinction is important when estimating active parameters.
3. The Top-k Routing Process
The following simplified Top‑k routing code illustrates how a token selects experts:
import numpy as npdef softmax(x):x = x - x.max(axis=-1, keepdims=True)e = np.exp(x)return e / e.sum(axis=-1, keepdims=True)def top_k_route(hidden, gate_weight, k=8):# hidden: [num_tokens, d_model]# gate_weight: [d_model, num_experts]logits = hidden @ gate_weighttopk_idx = np.argsort(-logits, axis=-1)[:, :k]topk_logits = np.take_along_axis(logits, topk_idx, axis=-1)weights = softmax(topk_logits)return topk_idx, weights
The whole process can be divided into three steps: the router computes a score for every expert given the token; the top‑k experts are selected; the selected scores are normalized via softmax to serve as weighting coefficients for the expert outputs. The final output is the weighted sum of the selected experts’ outputs plus the shared expert’s output.
Because selection is done per token, different tokens in the same batch may route to completely different expert combinations. This flexibility comes at the cost of the load imbalance issue discussed later.
4. Converting Activation Ratio to Cost
The phrase “activated parameters as a fraction of total parameters” is commonly used to measure sparsity, but it is often misread. The actual fraction depends on how much of the model consists of expert parameters, not just on the ratio k / E (where k is the number of activated experts and E is the total number of experts).
Consider a hypothetical model with 100B total parameters, where expert parameters account for 90% and there are 256 routed experts, with 8 experts activated per token. Then:
- Total expert parameters: 90B
- Expert parameters actually used per token: 90B × 8 / 256 ≈ 28.1B
- Non‑expert parameters (attention, embeddings, etc.): 10B, all fully computed
- Total activated parameters per token: approximately 128.1B
- Activation ratio: approximately 12.8%
This example illustrates two points. First, the activation ratio is jointly determined by the expert share and the k / E ratio; the larger the non‑expert portion, the smaller the sparsity benefit. Second, even with many experts, the non‑expert parts are still fully computed, which limits the upper bound of sparsification.
According to a common rough estimate, the forward computation per token is proportional to the number of activated parameters. In the hypothetical example above, compared to a dense model with the same total parameters, the computation drops to about one‑eighth. This is only an estimate at the compute level; actual latency is also affected by memory access, communication, and scheduling.
5. Three Types of Costs Introduced by Sparsity
Memory cost. Sparse activation saves compute, not storage. Any token may route to any expert, so all expert parameters must reside in fast‑accessible memory. When planning deployment, memory or high‑speed storage capacity still needs to accommodate the full parameter size. This is an often‑overlooked issue during model selection.
Load imbalance. If the router tends to send most tokens to a few “hot” experts, those experts become bottlenecks while others remain idle. Common mitigation approaches include adding an auxiliary load‑balancing loss during training, or dynamically adjusting routing biases during inference and training. The former may slightly degrade model quality; the latter is more complex to implement and requires trade‑offs based on the scenario.
Communication overhead. In multi‑GPU or multi‑node deployments, experts are distributed across devices. Tokens must first be dispatched to the devices hosting the selected experts, and the results are then aggregated. This all‑to‑all communication can become a major source of latency in small‑batch inference, so the expert parallelization strategy must be designed together with the hardware topology.
6. Attention in Long Contexts
As the context length grows, the attention computation typically scales quadratically with the sequence length. Even if MoE reduces the cost of feed‑forward layers, attention can still dominate in long‑text scenarios.
Common industrial approaches include:
- Sparse attention: each token attends to only a subset of historical positions, such as local windows plus global anchors, or positions selected via learned patterns.
- Reuse of intermediate results: reusing indices or intermediate computed values across adjacent layers to avoid redundant computation.
- KV cache compression: reducing cache footprint to increase the number of concurrent requests a single GPU can handle.
The effectiveness of these methods depends on the task type. In retrieval‑oriented tasks, critical information is often sparsely distributed, and sparse attention yields clear benefits. In tasks that require global reasoning, excessive sparsity may damage quality; the boundaries must be determined through evaluation.
7. Trade‑offs in Activation Scale
From an architectural perspective, the activation scale is a multi‑objective trade‑off:
- Capability: more activated parameters give each token more computation to work with, which generally helps complex reasoning.
- Cost: fewer activated parameters mean cheaper inference and higher throughput.
- Engineering complexity: higher expert counts and sparsity levels complicate routing, scheduling, and communication.
There is no single optimal activation ratio for all scenarios. For high‑frequency, low‑complexity requests, a higher sparsity level may be preferable. For a small number of high‑value tasks, accepting higher per‑request cost can be justified.
