Capacity Planning and Evaluation for Trillion-Parameter MoE Models Before Deployment

    This article explains how to plan capacity and evaluate a trillion-parameter MoE model before deployment. It covers active parameters and routing efficiency, long-context token and KV cache sizing, GPU and communication estimates, parallelism and load testing, offline business evaluation, staged rollout with rollback, and key operational risks.

    1. Why Total Parameters Are Not Enough: Calculate Active Parameters and Routing Efficiency First

    To determine whether a MoE model can be deployed, start with the number of active parameters per token, the number of experts, the number of experts selected per token (top-k), and inference throughput. Total parameters set the upper bound of knowledge capacity, but each forward pass uses only the activated parameters.

    The following example assumes a model with about 1 trillion total parameters, about 32 billion active parameters per token, an expert pool of 384 experts, and 8 experts routed per token. These numbers are an illustrative configuration, not any released model. Before use, refer to the official documentation.

    The following reference routing implementation runs on a single GPU. It omits capacity limits and cross-device communication and is intended only to illustrate tensor shapes.

    1. import torch
    2. import torch.nn.functional as F
    3. def moe_route(x, gate_weight, experts, top_k=8):
    4. # x: [T, d], gate_weight: [d, E]
    5. probs = F.softmax(x @ gate_weight, dim=-1) # [T, E]
    6. topk_probs, topk_idx = torch.topk(probs, top_k, dim=-1) # [T, k]
    7. topk_probs = topk_probs / topk_probs.sum(-1, keepdim=True) # Whether to normalize depends on model implementation
    8. out = torch.zeros_like(x)
    9. for e, expert in enumerate(experts):
    10. token_idx, slot = (topk_idx == e).nonzero(as_tuple=True)
    11. if token_idx.numel() == 0:
    12. continue
    13. y = expert(x[token_idx]) # [n_e, d]
    14. w = topk_probs[token_idx, slot].unsqueeze(-1) # [n_e, 1]
    15. out.index_add_(0, token_idx, y * w)
    16. return out

    Sparse activation introduces three types of system issues. First, expert parallelism requires cross-device all-to-all communication, and communication time may offset compute gains. Second, if routing persistently favors a small number of hot experts, devices hosting those experts will queue while other devices remain idle. Third, if the capacity factor (CF) is set too small, tokens beyond capacity are dropped and quality degrades; if it is set too large, memory and communication overhead increase.

    Expert capacity is calculated as follows: C = ceil(CF × T × k / E). With T=4096 tokens per batch, k=8, and E=384, each expert receives about 85 tokens on average. When CF is 1.0, capacity is 86; when CF is 1.25, capacity is 107. The actual drop rate depends on the routing distribution and must be measured with real traffic, not estimated from the formula alone.

    2. Long Context: How Much Text Fits in 256K Tokens and How Much Memory Is Needed

    The context limit of this iteration is 256K tokens, calculated as 262,144 tokens. Chinese text uses about 0.6 to 1.5 tokens per character, so 256K tokens correspond to about 175,000 to 437,000 Chinese characters. This conversion varies with the tokenizer and text type. During planning, use measured token counts from the target corpus.

    Long context is suitable for cross-file code understanding, long log analysis, history tracking in multi-turn agent tasks, and comparison of large requirement documents. The cost is that attention computation, KV cache memory, time to first token, and batching complexity all increase.

    The lower bound of KV cache memory can be estimated with the following function:

    1. def kv_cache_gb(layers, kv_heads, head_dim, seq_len, batch, bytes_per=2):
    2. # bytes_per=2 corresponds to FP16/BF16; use 1 for FP8 storage
    3. return layers * 2 * kv_heads * head_dim * seq_len * batch * bytes_per / 1e9

    With grouped-query attention (GQA), kv_heads is much smaller than the number of attention heads, so the KV cache is noticeably smaller than with multi-head attention (MHA). layers, kv_heads, and head_dim must use the real configuration of the target model.

    With an assumed configuration of layers=61, kv_heads=8, and head_dim=128, the KV cache per token is about 0.25MB (FP16). The following table summarizes total KV cache by batch size and single-sequence context length:

    Single-sequence context Batch size 1 Batch size 4 Batch size 8 Batch size 16
    32K 8.2GB 32.8GB 65.5GB 131.0GB
    128K 32.7GB 131.0GB 262.0GB 524.0GB
    256K 65.5GB 262.0GB 524.0GB 1048.0GB

    This table counts only FP16/BF16 KV cache and excludes model weights, activations, and framework buffers.

    Long context should be used in tiers to avoid appending history indefinitely:

    • Cross-file dependencies and global architecture questions: use the full long context.
    • Regular Q&A and fact lookup: use retrieval-augmented generation (RAG) and include only relevant snippets.
    • Multi-turn agent tasks: keep working memory (current plan and key constraints) and write historical details to external storage (files or databases).
    • Batch summarization: summarize in chunks first, then aggregate.

    3. Deployment Capacity Planning: Estimate Weights, KV Cache, and Communication, Then Determine GPU Count

    Step 1: Estimate weight memory. Weight memory (GB) is approximately the total number of parameters (in billions) multiplied by the number of bytes per parameter. 1 trillion parameters is about 1000GB in FP8, about 2000GB in FP16, and about 500GB in INT4. This number includes only weights.

    Step 2: Estimate total memory requirements:

    Total memory ≈ (weights + KV cache + activation and communication buffers) × (1 + headroom)

    Activation and communication buffers can initially be reserved at 10% of the sum of weights and KV cache. A headroom of 20% to 30% is recommended.

    Step 3: Calculate GPU count:

    GPUs ≥ total memory ÷ (per-GPU memory × usable ratio per GPU)

    Here is an example. Assume FP8 weights (1000GB), a serving concurrency of batch size 8 with 256K context, and FP16 KV cache (524GB). Then (1000 + 524) × 1.10 ≈ 1676GB. If each GPU has 80GB and the usable ratio is 0.75, each GPU provides 60GB usable, which gives about 28 GPUs. Rounding to 32 GPUs (4 nodes with 8 GPUs each) makes intra-node expert parallelism splitting easier. This result is only an estimate as a starting point; the final count must be based on load testing.

    Step 4: Estimate expert-parallel communication volume. The per-GPU send volume for each MoE layer can be estimated as follows:

    V ≈ T_dev × k × d × b × 2 × (N − 1) / N

    Here T_dev is the number of tokens processed per GPU per step, k is top-k, d is the hidden dimension, b is the number of bytes per element, 2 represents the two transfers for dispatch and combine, and N is the number of GPUs used for expert parallelism. With T_dev=4096, k=8, d=8192 (illustrative value), BF16, and N=8, each layer is about 0.94GB. Assuming every layer is a MoE layer, all 61 layers total about 57GB. If the effective per-GPU communication bandwidth is 200GB/s, communication time per step is about 0.29 seconds. Bandwidth must be measured on the target cluster; do not reuse this number directly.

    4. Parallelism and Load Testing: Validate Estimates with a Concurrency Matrix and Latency Targets

    The parallel strategy must consider tensor parallelism (TP), expert parallelism (EP), and pipeline parallelism (PP) together. Typically, TP is used within a single node to split attention and dense parts, EP is used to split experts, and cross-node all-to-all traffic should be minimized. The specific combination must be determined by measured results on the target inference framework.

    Before load testing, write down the targets. The thresholds in the following table are starting values and must be calibrated for the business scenario:

    Scenario Input/Output length Concurrency Metric Initial release threshold
    Short Q&A 1K / 256 16 P95 time to first token No higher than 2 seconds
    Long-context analysis 128K / 1K 4 P95 time to first token No higher than 30 seconds
    Long-context analysis 256K / 1K 2 P95 time to first token No higher than 60 seconds
    Code agent 32K / 4K 8 Single-task completion time No higher than 1.2× baseline
    Steady-state throughput Mixed load Full load Output tokens/s No lower than 90% of target

    During load testing, record expert load distribution, token drop ratio, and peak memory at the same time. If some experts are persistently overloaded, adjust routing or the capacity factor first before considering adding more GPUs.

    5. Self-Built Evaluation: Use Offline Sets to Judge Whether Capabilities Meet Business Needs

    Public leaderboards cannot replace business evaluation. An offline evaluation set should contain at least the following five sample types:

    1. General ability questions, to check that basic capability has not regressed.
    2. Domain Q&A from real business questions, with answers annotated by experts.
    3. Long-context positioning tasks, with facts placed at different positions to test recall within the 256K range.
    4. Coding agent tasks taken from real fixes in internal repositories, using pass rate as the metric.
    5. Safety and refusal samples, to check whether the model refuses inappropriate requests according to policy.

    Each sample type should have an independent split to avoid training or prompt leakage into the evaluation set. For human review, sample at least 200 items per type and record scoring consistency.

    6. Staged Rollout and Rollback: Each Stage Needs Release and Fallback Conditions

    The rollout should be divided into the following stages, and each stage must pass before proceeding to the next:

    Stage Traffic Release condition Rollback condition (initial value)
    0 Offline validation None Offline evaluation no lower than baseline Key metric drops by more than 2 percentage points
    1 Shadow traffic Copy requests, do not return results Latency and error rate meet load-test thresholds Error rate higher than 1% for 10 consecutive minutes
    2 Canary 5% Quality spot check passes, no OOM Any metric exceeds threshold for 15 consecutive minutes
    3 Expanded canary 25% to 50% Expert token drop ratio below 0.5% Token drop ratio higher than 0.5% for 30 consecutive minutes
    4 Full traffic 100% Stable operation for one full business cycle Use the rollback conditions from the previous stage

    Before launch, retain the previous model version and a complete configuration snapshot, including CF, parallel mode, and memory parameters. Rollback must be possible within minutes and must have been verified in drills.

    7. Risk Notes

    • Out-of-memory (OOM): estimation errors in weights, KV cache, and communication buffers can all cause OOM. Record peak values during load testing and keep at least 20% headroom.
    • Expert load imbalance: hot experts slow down the entire batch. Monitor the receive volume of each expert.
    • Token dropping: a CF that is too small silently degrades quality. Include the drop ratio as a formal monitoring metric.
    • Long-context cost: 256K requests have much higher time to first token and memory usage than short requests. Set rate limits and billing by request length.
    • Parameter and performance sources: the architecture numbers in this article are illustrative. Before launch, rely on official documentation and measured data on the target hardware. Do not base procurement or commitments on the example numbers in this article.