Serving Massive-Scale Open-Source MoE Models: Architecture and Inference Engineering Guide
This guide is for engineers responsible for model selection, inference deployment, and platform operations. It covers how to set the MoE capacity factor based on GPU memory and latency targets, how to estimate KV Cache usage for million-token contexts and decide whether hybrid linear attention and hierarchical caching are needed, and how to build a metrics dashboard covering latency, throughput, cache hit rate, and cost per unit. The capability gains of very large models depend on the interplay of architecture, training, inference, and operations. Parameter scale is only the starting point; stable serving is what determines a model's real value.
Who This Article Is For and What You’ll Get
This article targets engineers responsible for model selection, inference deployment, and platform operations. After reading it, you should be able to do three things:
- Set the MoE capacity factor based on GPU memory and latency targets.
- Estimate the KV Cache footprint of a million-token context and determine whether hybrid linear attention plus hierarchical caching is required.
- Build a metrics dashboard covering latency, throughput, cache hit rate, and unit cost.
The capability gains of very large models depend on the coordination of architecture, training, inference, and operations. Parameter scale is the starting point, but the ability to serve users reliably is what determines a model’s actual value.
Architecture Design: MoE Routing and the Capacity Factor
In a Mixture-of-Experts (MoE) model, total parameters are large, but each token only passes through a small number of experts. The router selects the top-k experts for each token, and results are merged by weighted sum. This design balances capacity against compute, but it also introduces problems such as uneven expert load and high communication overhead.
How to Set the Capacity Factor
The capacity factor determines how many tokens each expert can accept at most. It is calculated as:
Expert capacity C = ceil(capacity_factor × tokens per batch × top_k ÷ number of experts)
For example, with 8,192 tokens in a batch, top_k = 2, 64 experts, and a capacity_factor of 1.25, each expert’s capacity is ceil(1.25 × 8192 × 2 ÷ 64) = 320. If an expert is assigned 400 tokens, the extra 80 are dropped or rerouted according to policy.
In practice, values between 1.0 and 1.5 are common. A lower value saves GPU memory and compute but increases the token drop rate; a higher value reduces dropping but wastes compute on padding. You should monitor the token drop rate per layer and the load variance across experts. If the drop rate consistently exceeds 1%, first raise the capacity factor or strengthen the load-balancing loss before considering changes to the number of experts.
The following configuration is illustrative only. Placeholders such as ${EXPERT_COUNT} and ${TOP_K} are example values that must be replaced according to model scale and hardware.
model:architecture: moe_transformernum_experts: ${EXPERT_COUNT} # Example placeholder, e.g. 64active_experts_per_token: ${TOP_K} # Example placeholder, e.g. 2capacity_factor: 1.25 # Per-expert capacity as a multiple of uniform allocationrouter:load_balance_loss_weight: 0.01 # Auxiliary load-balancing loss weight, typically around 1e-2z_loss_weight: 0.001 # Suppresses oversized router logits, typically around 1e-3attention:type: hybrid_linear_attentionlocal_window: ${WINDOW_SIZE} # Example placeholderglobal_tokens: ${GLOBAL_TOKEN_COUNT} # Example placeholder
Long Context: Hybrid Linear Attention and the KV Cache
Estimating the KV Cache First
For million-token contexts, the main pressure comes from the KV Cache. Here is an illustrative estimate, assuming a model with 60 layers, 8 KV heads, a head_dim of 128, and fp16 storage:
Single-sequence KV Cache ≈ 2 × layers × KV heads × head_dim × sequence length × bytes per element
= 2 × 60 × 8 × 128 × 1,000,000 × 2 bytes ≈ 246 GB
If all layers used full attention, a single million-token request would consume the memory of multiple accelerator cards. This is exactly the problem hybrid linear attention is designed to solve: only a few full-attention layers need to retain
