MoE Large Model Deployment in Practice: Compute, Precision, and Cost
This article explains the key engineering considerations for deploying Mixture-of-Experts (MoE) large language models: what sparse activation actually saves, how to evaluate heterogeneous hardware and operator coverage, what FP8 formats and scaling factors really mean, how to support 160K long contexts with KV cache mechanisms, and how to estimate per-request costs based on cache hit rates.
Start with the Specs: What Sparse Activation Saves—and What It Doesn’t
Mixture-of-Experts (MoE) models trade lower per-token compute for larger overall model capacity. Taking an open-source model from a public technical report as an example: it has 671B total parameters, but only 37B parameters are activated per token—an activation ratio of about 5.5%.
Sparse activation reduces the compute per token, but all parameters must still reside in GPU memory or host memory, and expert routing introduces cross-device communication. As a result, the typical deployment bottlenecks are memory capacity, communication bandwidth, and scheduling strategy—not raw compute alone.
1. Heterogeneous Hardware Adaptation: Verify Operator Coverage First
1.1 TileLang and Multi-Backend Operators
TileLang is a domain-specific language (DSL) for developing high-performance GPU operators. Developers describe tiled computations with it, and the compiler generates kernel code for the target platform. Tools like this reduce the effort of handwriting a separate set of operators for each type of hardware. TileLang generates the kernel code, but performance still depends on tiling parameters and the specific hardware.
The source material claims that a certain model achieves “Day 0 adaptation” across multiple domestic Chinese AI chips, but provides no chip models, driver versions, or scope of adaptation. This article does not adopt that claim. When evaluating such statements, confirm three things: the supported chip models and driver versions; the operator coverage (whether it includes MoE routing, attention, and communication operators); and the performance gap compared to native CUDA implementations.
1.2 FP8 Formats and Scaling Factors
The “UE8M0-like FP8” mentioned in the source material can easily be misread as a new data format. In practice, values are still stored in FP8 formats such as E4M3 or E5M2, while scaling factors in E8M0 format are shared per block to dynamically scale values into the representable range of FP8.
| Format | Exponent Bits / Mantissa Bits | Common Use | Characteristics |
|---|---|---|---|
| E4M3 | 4 / 3 | Forward computation of weights and activations | Higher precision, smaller dynamic range, max value 448 |
| E5M2 | 5 / 2 | Scenarios requiring a larger dynamic range | Large dynamic range, lower precision, max value 57344 |
| E8M0 | 8 / 0 | Scaling factors | Represents only integer powers of 2; does not carry values directly |
A common approach is block-wise quantization over vectors or matrices, with one scaling factor per block. Finer quantization granularity yields better accuracy, but also increases the storage and compute overhead of scaling factors. Precision and throughput must be measured on the target task, comparing evaluation scores, time-to-first-token, and output tokens per second (tokens/s) against a BF16 baseline.
2. Long Context: 160K Requires Caching Mechanisms
The original report states a context length of 160K (roughly 160,000 tokens). Whether this length is supported depends on the specific model version and inference engine—refer to the model card or official documentation.
Under standard multi-head attention, KV cache usage can be estimated with the following formula: 2 × number of layers × number of KV heads × head dimension × sequence length × bytes per element. For models using compressed attention such as MLA, the calculation must follow their actual architecture.
Common engineering techniques include:
- Paged KV cache to reduce GPU memory fragmentation;
- Prefix caching to reuse the KV corresponding to identical system prompts;
- Chunked prefill for very long inputs, reducing the peak in time-to-first-token;
- Length-bucketed batch scheduling so short requests are not slowed down by long ones.
Object storage (such as Baidu AI Cloud BOS, or equivalent services from other cloud providers) is suitable for storing corpora and documents. It cannot directly accelerate the KV cache. Document loading, chunking, and vectorization can be handled in asynchronous tasks; time-to-first-token is mainly determined by prefill computation.
3. Cost: Estimate Your Bill by Cache Hit Rate
The original article gives the following example pricing: input cache hit at 0.2 CNY per million tokens, cache miss at 2 CNY per million tokens, and output at 3 CNY per million tokens. The original text does not specify an effective date or model version; actual pricing is subject to the official pricing page.
The per-request cost is calculated as follows:
Cost per request = (hit tokens × hit price + missed tokens × miss price + output tokens × output price) ÷ 1,000,000
Assume an input of 200,000 tokens, of which 180,000 hit the cache and 20,000 miss, with 1,000 output tokens. At the prices above, the cost per request is about 0.079 CNY. Without caching, the entire input is billed at the miss price, and the cost per request is about 0.403 CNY.
Cache hits require the prefix to match byte for byte. Therefore, system prompts should be placed at the very front, with dynamic content placed after them. The example below separates the fixed prefix from the dynamic content, and adds timeout handling, exception handling, and usage logging:
import osimport timeimport requestsAPI_URL = os.environ["LLM_API_URL"] # Read from environment variables, never hardcodeAPI_KEY = os.environ["LLM_API_KEY"]MODEL = os.environ.get("LLM_MODEL", "your-model-name") # Use the model name from the official documentation# Fixed...
