MoE Model Deployment and Long-Context Memory Planning for Production
Deploying large-scale MoE models requires more than estimating memory from activated parameters. This article explains how to plan GPU memory across full model weights, KV cache, runtime overhead, and concurrency headroom; how to choose precision and hardware at different business stages; and how to estimate long-context KV cache and set tiered context windows. It also covers production monitoring and optimization boundaries for OOM, TTFT, token throughput, and KV cache usage.
1. Memory Planning Cannot Rely on Activated Parameters Alone
Many teams estimate hardware requirements for MoE models by using the number of activated parameters. This approach underestimates actual memory requirements.
When an MoE model processes each token, the routing network selects only a few experts for computation, so the per-step compute is close to that of a dense model with several billion parameters. However, routing results change with the input, and the system cannot know in advance which experts will be called. As a result, all expert weights must remain resident in GPU memory. For a model with nearly 100B total parameters, the weights alone consume a large amount of memory, far more than the number implied by activated parameters. If memory is sized by activated parameters, the model may encounter OOM (out-of-memory) errors during loading or under high concurrency.
A complete memory plan should include the following four parts:
- Model weights: parameters for all experts, attention layers, and shared layers.
- KV Cache: key-value pairs that store context and grow with input and output length.
- Runtime overhead: CUDA context, intermediate activations for operators, and temporary buffers.
- Concurrency headroom: each concurrent request requires an independent KV Cache.
Before launch, use the following checklist:
- Whether total weight memory is calculated using all parameters and the actual deployment precision;
- Whether KV Cache is calculated for the target context length and peak concurrency;
- Whether runtime overhead and peak headroom have been reserved;
- Whether there is a fallback plan for insufficient memory, such as reducing concurrency, reducing context length, or changing precision.
2. Choose Compute and Precision by Business Stage
Deployment precision determines weight memory usage. The table below uses a model with approximately 100B total parameters as an example. It calculates weight memory only and does not include KV Cache or runtime overhead.
| Precision | Estimated Weight Memory | Suitable Stage | Main Risk |
|---|---|---|---|
| FP16/BF16 | ~200 GB | Precision baseline, quality comparison | High memory usage, limited concurrency headroom |
| FP8 | ~100 GB | Small-to-medium production, general production | Accuracy and operator support need validation |
| INT4 (e.g., Q4) | ~50–60 GB | Fast POC, low-cost validation | Noticeable accuracy loss; dedicated evaluation required |
Compared with BF16, FP8 usually halves weight memory, and in most scenarios the quality is close to the original precision. Whether the result is lossless depends on the model itself, the calibration method, and hardware operator support. It must be confirmed with your own evaluation set.
INT4 is suitable for running a business flow with fewer GPUs during the early POC stage. Its accuracy degradation may affect complex reasoning and code generation tasks, so it must be re-evaluated before formal production launch.
2.1 Single-Node 8-GPU FP8 Deployment Reference
A single node with 8 GPUs at 141 GB each provides about 1128 GB of GPU memory. FP8 weights are about 100 GB. After tensor parallelism distributes them across 8 GPUs, each GPU carries only a small weight footprint, leaving the remaining space for KV Cache and runtime overhead. This configuration can support initial validation for small-to-medium concurrency. It is only a reference example. The actual concurrency it can handle depends on input and output lengths, batching strategy, and the framework’s memory utilization settings, and must be confirmed through stress testing.
2.2 Large-Memory Configuration for Million-Token Contexts
A single node with 8 GPUs at 180 GB each provides about 1440 GB of GPU memory. In long-context scenarios, KV Cache usage increases significantly, and larger memory can preserve headroom for concurrency. Before selecting a configuration, clarify the following measurement basis: total and activated model parameters, deployment precision, input and output lengths, batch size, target QPS, TTFT (time to first token), and token generation speed (tokens/s). The above configuration is also only an example and must be adjusted based on stress test results.
2.3 Business Metrics Determine the Final GPU Count
QPS, TTFT, token generation speed, and peak concurrency are the final basis for determining GPU count. Sufficient memory only means the model can fit; it does not mean latency requirements can be met. It is recommended to first run stress tests with a request model close to real traffic, and then determine GPU count based on the results.
3. Production Considerations for Long Context
A 1M context is the model’s capability ceiling. Online services usually do not expose this window by default. Long context increases both computation and memory usage. Attention computation grows approximately quadratically with sequence length, and TTFT rises noticeably as a result. KV Cache memory grows approximately linearly with sequence length, and as concurrency increases, KV Cache scales proportionally.
3.1 KV Cache Estimation
The following formula can be used to approximate KV Cache memory:
KV_Cache_Size ≈ 2 * batch_size * seq_len * num_layers * num_kv_heads * head_dim * dtype_size
Here, 2 represents the Key and Value parts, and dtype_size is the number of bytes per element (2 for FP16, 1 for FP8). In an MHA (multi-head attention) structure, num_kv_heads equals num_heads. GQA and MQA structures should use the actual number of KV heads and cannot simply use hidden_size as a substitute.
For example, assume the model has 60 layers, 8 KV heads, head_dim of 128, batch size of 1, context length of 1M, and KV Cache in FP16. Substituting into the formula gives: 2 × 1 × 1,000,000 × 60 × 8 × 128 × 2 bytes, approximately 2.46 × 10^11 bytes, or about 246 GB (decimal). If KV Cache uses FP8, usage is about 123 GB. This example is only for judging order of magnitude. With this configuration, at around 5 concurrent requests, KV Cache alone would exceed the total memory of 8 GPUs at 141 GB each.
3.2 Tiered Default Context Windows
- 32K: Use as the default service window. It covers most chat and document Q&A, supports higher concurrency, and makes latency easier to control.
- 128K: For long-document analysis. Set separate concurrency limits and longer timeouts.
- 1M: Open only for high-value, low-concurrency paths. Before launch, evaluate the memory and latency budget. When the budget is exceeded, degrade to 128K and return a clear message to the user.
3.3 Applicability Boundaries of Optimization Techniques
- PagedAttention: Allocates KV Cache in blocks and can reduce memory fragmentation. Block size needs to be tuned, and KV Cache usage and preemption count should be monitored.
- Dynamic batching: Can improve throughput but increases queue wait time. Queue duration and P99 latency should be monitored together.
- Distributed KV Cache: Can expand cache capacity across nodes but introduces network transfer overhead. Cross-node bandwidth usage, cache hit rate, and additional latency should be monitored.
For long-running services, continuously monitor OOM count, preemption count, TTFT P99, token generation speed, and KV Cache usage, and set alert thresholds for each metric. Managed LLM services from mainstream cloud providers can take over part of the operations work; when selecting a service, confirm its capabilities against the metrics above.
4. Conclusion
The deployment cost of MoE models is mainly determined by full weights, KV Cache, and concurrency overhead. During planning, calculate full memory first, then choose a precision option such as FP8 or INT4, and finally determine GPU count based on stress test results. For million-token contexts, estimate the KV Cache upper bound first, and then decide the default window and degradation strategy.
