Deploying Large-Scale MoE Models on a 4-Node Local Cluster: A Practical Analysis
This article walks through a practical deployment of an extremely large MoE model on a local 4-node cluster, using native FP8/FP4 mixed quantization and a million-token context window. It covers the three-tier architecture of compute, memory, and storage; mixed-precision loading pitfalls; tensor and expert parallelism tuning; the real constraints of long context; unified management and an AI gateway; and a step-by-step testing methodology for isolating bottlenecks.
1. Background: Why Local Deployment of Very Large MoE Models Got Harder
Over the past two years, model architectures have evolved noticeably faster than single-machine hardware. The sparse approach represented by large-scale MoE (Mixture of Experts) decouples “total parameter count” from “per-inference activation”: the total parameter count can be extremely high, yet each token activates only a small subset of experts. This leads to two direct consequences.
First, memory capacity becomes the primary constraint. Even if a single inference activates only a few experts, all expert weights must still reside in addressable memory; otherwise every inference step has to pull weights from storage again, and latency degrades to the point of being unusable.
Second, memory access and scheduling become the secondary constraint. MoE routing (the Router) determines which experts each token goes to. Load imbalance in routing causes “some nodes busy, some nodes idle,” and in multi-node deployments the network amplifies this problem.
The target scenario of this practice is: deploying an MoE model with an extremely large total parameter count on a local cluster of 4 compute nodes, using the official native FP8 and FP4 mixed quantization format, extending the context window to the million-token level, and exposing standard interfaces through a unified management and gateway layer. The following sections are organized along six dimensions: storage tiering, precision and loading, inference engine, context, operations and governance, and testing methodology.
2. Overall Architecture: Three-Tier Coordination of Compute, Memory, and Storage
A reproducible local cluster typically consists of three types of resources:
- Compute layer: 4 GPU nodes with high-bandwidth interconnect, responsible for matrix multiplication and expert computation;
- Memory layer: the large unified memory of each node, used to hold weight shards, KV Cache, and runtime buffers;
- Storage layer: local NVMe SSDs, serving as a secondary medium for cold data and lookup-type data.
The design principle is “keep hot data close to compute, push cold data down to storage.” Concretely, in this solution weights are distributed across node memory according to a sharding strategy, while lookup-type data (Embedding/lookup tables, referred to as Engram in the original) is offloaded to NVMe SSDs, freeing up precious memory for KV Cache and activations. The benefit is direct: the longer the context, the larger the KV Cache footprint, so moving lookup data out effectively frees up budget for long context.
An illustrative tiered placement logic (pseudocode, expressing the idea only):
# Illustrative tiered placement strategyplacement = {"expert_weights": "node_memory", # Expert weights stay resident in each node's memory"attention_weights": "node_memory","lookup_tables": "local_nvme", # Lookup data pushed down to SSD, read on demand"kv_cache": "node_memory", # Main memory consumer for long context}
Note that tiering is not free. The random-read IOPS and latency of the SSD determine the upper bound of the lookup path, so the lookup data must have a certain locality, and optimizations must be made in SSD selection, filesystem alignment, and prefetch strategy; otherwise a “capacity problem” turns into a “latency problem.”
3. Mixed Precision: How FP8 and FP4 Coexist
The value of native FP8+FP4 mixed precision lies in “allocating a precision budget per layer”: keeping FP8 for numerically sensitive layers with large dynamic range, and using FP4 for layers with concentrated weight distributions and controllable quantization error, thereby balancing total memory footprint against output quality.
Three points must be watched in engineering:
- Quantization format consistency. The quantization scheme loaded by the inference engine must strictly match the scheme used when exporting weights, including the Scale layout of per-tensor versus per-channel. Any mismatch shows up as “garbled output” rather than an error, making troubleshooting extremely costly.
- Dequantization overhead. FP4 must be unpacked in pairs; if the kernel is not fused, separating unpacking from computation significantly eats into the gains from low precision.
- Precision regression validation. Before going live, compare against a high-precision baseline using a fixed small sample set, and monitor the drift in perplexity or task metrics to avoid “it runs but quality collapses.”
4. Inference Engine and Parallelism Strategy
In a 4-node environment, the common parallel combination is tensor parallelism (TP) stacked with expert parallelism (EP): TP splits a single layer’s matrices to reduce per-card pressure, while EP places different experts on different nodes to improve throughput. Higher parallelism is not always better; cross-node communication grows as parallelism increases, so a balance must be found between bandwidth and computation.
Key tuning points include:
- Batching strategy: continuous batching can significantly improve GPU utilization, but it aggravates memory fluctuation, so maximum concurrency and queue limits must be set;
- Paged KV management: allocating KV Cache in blocks reduces fragmentation and is a prerequisite for long-context scenarios;
- Routing balance: monitor the activation frequency distribution across experts, and introduce a capacity factor limit when necessary to prevent hot experts from slowing down the whole batch;
- Warmup and graph capture: the compilation and memory allocation overhead of the first request is large, so warmup should be done before the service goes live to avoid abnormal first-token latency.
5. The Real Constraints of Million-Level Context
A 1M token context is more of a “capability ceiling” than an “everyday configuration.” In practice, the complexity of attention computation grows superlinearly with sequence length, while KV Cache usage grows linearly. Practical approaches include:
- Tiered context: limit regular requests to a shorter window, and route long-document requests through a separate long-context queue;
- Prefix reuse: cache and reuse identical system prompts and document prefixes to avoid repeated computation;
- Chunking and summarization: preprocess extremely long inputs in chunks before feeding them into the main model;
- A clear degradation path: when resources are tight, prioritize the latency of short requests and make long requests asynchronous.
6. Unified Management and AI Gateway
For reuse across multiple teams, a unified entry layer is needed to handle authentication, quotas, routing, and observability: the gateway handles tenant isolation and rate limiting, while the management side handles node health checks, model version management, and canary releases. Observability should cover at least four categories of metrics: throughput (tokens/s), latency (TTFT and TPOT), resources (memory/VRAM/SSD IOPS), and quality (abnormal output rate). Alerts should be bound to specific resource dimensions; for example, a persistently high SSD queue depth often means the lookup path has become the bottleneck.
7. Testing Methodology and Common Bottleneck Identification
It is recommended to validate in the following order, ruling things out layer by layer:
- Single-node baseline: confirm that precision loading is correct and output matches the baseline;
- Two-node scaling: observe whether throughput grows nearly linearly, to judge whether the interconnect is a bottleneck;
- Four-node full load: gradually increase concurrency and record the throughput inflection point;
- Long-context stress test: step up from 32K to longer windows and observe when the latency curve rises sharply;
- Stability soak: run for several hours to observe memory fragmentation, SSD wear, and error rate.
A common rule of thumb for identifying bottlenecks: if concurrency rises but throughput does not increase and latency rises linearly, it is usually scheduling or routing imbalance; if latency rises sharply under long context, it is usually KV Cache and attention computation; if the first token is slow but subsequent tokens are normal, it is usually cold start and lookup misses.
8. Conclusion
Deploying a very large MoE model locally is essentially a systematic trade-off among capacity, bandwidth, and latency. Freeing memory through storage tiering, compressing weights through mixed precision, improving utilization through parallelism and batching, and ensuring stability through a gateway and observability—this methodology also applies to inference service architectures built on Baidu AI Cloud using general capabilities such as container platforms, object storage, log services, and monitoring and alerting.
