End-to-End Deployment of a 2.8T MoE Model on Two Servers with Domestic NPUs

    This guide walks through deploying a 2.8T-parameter Mixture of Experts (MoE) model across two servers. The example setup uses eight 128GB NPUs per server. It explains why the model needs two servers, how to estimate memory with the KV cache formula and a capacity check script, how W4A8 quantization works and how to validate it, how to choose tensor, expert, and pipeline parallelism, how to launch the service on both nodes, and how to troubleshoot common failures.

    1. Why Ultra-Large MoE Models Need Two Servers

    A sparse Mixture of Experts (MoE) model splits its network into many experts. Each token passes through only a few of them. The example model has about 2.8T total parameters, but a single forward pass activates only about 104B parameters (104 billion). That puts the per-step compute close to a dense model of the same scale, on the order of 100 billion parameters. Memory use, however, depends on the full 2.8T parameters. Every expert must stay resident in memory because the router can select any of them at any time.

    The example model supports a context window of 1M tokens. The quantized weight file is about 1.47TB. A single server can hardly hold the weights, the KV cache, and runtime overhead at the same time, so the deployment uses two servers that work together.

    Deployment difficulty comes down to three challenges:

    • Capacity: Weights plus runtime overhead exceed the usable memory of one server.
    • Communication: Experts are spread across multiple cards and nodes. Token routing causes heavy data exchange between cards, and communication efficiency determines throughput.
    • Long context: The KV cache grows linearly with context length. Limits on context length, concurrency, and scheduling policy must keep it under control.

    The first step is to work out the resource budget. Starting the service comes after that.

    Example environment for this article

    All numbers in this article come from the environment below. Replace them with the actual specifications of your own servers:

    • Two servers, each with eight domestic NPUs, 128GB of memory per card, for 2048GB in total.
    • The two servers connect over a high-speed RDMA network. Bandwidth between cards within a node is significantly higher than bandwidth between nodes.
    • The inference framework supports tensor, pipeline, and expert parallelism and provides an HTTP interface compatible with the OpenAI API style.

    2. Memory Estimation Before Deployment

    Memory demand has three components:

    1. Weight memory: The size of the quantized weight file, sharded across cards according to the parallelism strategy.
    2. KV cache: The KV size per token, multiplied by the context length, then multiplied by the number of concurrent requests.
    3. Runtime reserve: Communication buffers, operator workspace, and memory fragmentation. This article reserves 10% of total memory.

    Calculate the KV cache size per token with this formula:

    KV bytes per token = 2 × number of layers × number of KV heads × head dimension × bytes per element

    The factor of 2 accounts for storing K and V separately. Read the number of layers, KV heads, and head dimension from the model configuration file. Bytes per element depend on KV cache precision: 2 bytes for BF16 and 1 byte for FP8.

    Assume the model has 61 layers, 8 KV heads, and a head dimension of 128, with the KV cache in BF16. Each token then uses 2 × 61 × 8 × 128 × 2 = 249856 bytes, or about 0.25 MB. These values only illustrate the calculation method. Use the real values from the model configuration. At this rate, one request that fills the full 1M-token context needs about 262 GB of memory. A 32K context with 8 concurrent requests needs about 65.5 GB.

    The script below checks whether capacity is sufficient. All units are in GB (10^9 bytes).

    1. def check_capacity(weight_gb, nodes, mem_per_card_gb, cards_per_node,
    2. kv_bytes_per_token, ctx_len, concurrency, reserve_ratio=0.1):
    3. """Check whether weights plus KV cache fit within the cluster's usable memory."""
    4. raw_gb = nodes * cards_per_node * mem_per_card_gb
    5. usable_gb = raw_gb * (1 - reserve_ratio)
    6. kv_gb = kv_bytes_per_token * ctx_len * concurrency / 1e9
    7. headroom_gb = usable_gb - weight_gb - kv_gb
    8. return {
    9. "usable_gb": round(usable_gb, 1),
    10. "weight_gb": weight_gb,
    11. "kv_gb": round(kv_gb, 1),
    12. "headroom_gb": round(headroom_gb, 1), # Negative values mean insufficient capacity
    13. }
    14. print(check_capacity(
    15. weight_gb=1470,
    16. nodes=2,
    17. mem_per_card_gb=128,
    18. cards_per_node=8,
    19. kv_bytes_per_token=249856, # Example value. Calculate it from the model configuration.
    20. ctx_len=32768,
    21. concurrency=8,
    22. ))

    Running the script produces {'usable_gb': 1843.2, 'weight_gb': 1470, 'kv_gb': 65.5, 'headroom_gb': 307.7}. The table below lists each value:

    Item Calculation Example value
    Raw cluster memory 2 × 8 × 128GB 2048GB
    Usable memory Raw memory × (1 − 10%) 1843.2GB
    Weight memory Size of the quantized weight file 1470GB
    KV cache 249856 bytes × 32768 × 8 65.5GB
    Remaining space Usable memory − weights − KV cache 307.7GB

    If the remaining space is negative, add cards, lower the context limit, or reduce concurrency.

    Enough total memory does not guarantee that every card has enough. After weights are sharded across cards, check each card’s usage separately. Expert load is often uneven. Cards hosting popular experts take more compute and memory pressure, so leave headroom on every card.

    3. How W4A8 Quantization Works and Its Trade-offs

    W4A8 stores weights as 4-bit integers and represents activations with 8 bits. Both its benefits and its costs are clear.

    The benefit is that weights shrink to about one quarter of their 16-bit floating-point size. This reduces memory use and memory bandwidth pressure at the same time. 8-bit activations strike a reasonable balance between compute efficiency and numerical precision.

    The cost is that 4 bits can represent only 16 discrete values, so quantization error is unavoidable. Outliers, meaning weights or activations with absolute values far above the rest, widen the quantization range. This reduces precision for most ordinary values. Layers sensitive to outliers can show noticeable output deviation.

    A rough calculation confirms the file size. If all 2.8T parameters are stored in 4 bits, the total is about 1.4TB. If every group of 128 weights shares one 16-bit scaling factor, each weight effectively uses 4.125 bits, and the total is about 1.44TB. The remaining 26GB or so comes from a small number of layers kept at higher precision, such as the embedding, output, and routing layers, along with other metadata. This closely matches the actual 1.47TB weight file. If the two numbers differ significantly, first check whether the weight file is complete and whether the quantization method is what you expected.

    Before quantizing, confirm the following:

    1. Calibration data: Use 512 to 1,024 representative samples that cover your target workloads and long-context scenarios. When calibration data differs from real traffic, quantization error increases.
    2. Group size: Weights are quantized in groups of 128 elements, each with its own scaling factor. Smaller groups improve accuracy but require more storage for scaling factors.
    3. Outlier handling: Use smoothing or rotation transforms to move the dynamic range of outlier activation channels into the weights. This reduces activation quantization error.
    4. High-precision layers: Embedding, output, routing gate, and normalization layers usually stay in high precision. Errors in routing layers can change expert selection and directly affect output stability.
    5. Fallback: Restore any layer whose output deviation exceeds a threshold to BF16, and record that decision in the calibration report.

    Checking whether the model runs is not enough. Run systematic validation in three areas:

    1. Fix the random seed, then compare the outputs of the quantized model and the original-precision model on identical inputs. Measure the top-1 token consistency rate.
    2. Score the models on evaluation sets relevant to your application, and compare the key metrics.
    3. Check long-context outputs for repetition, truncation, or broken logic.

    The thresholds below are starting points. Adjust them to your requirements: the average evaluation score drops by no more than 1 percentage point, top-1 token consistency is at least 95%, and the long-context repetition rate is no higher than the original model’s.

    4. Choosing a Parallelism Strategy

    Multi-node deployment depends on splitting the model across many cards. There are three common strategies, and each has different communication characteristics:

    Parallelism type What is split Communication pattern Best placement Main risk
    Tensor parallelism Weight matrices within a layer All-reduce after each layer’s computation Within a node More cards mean more frequent intra-layer communication
    Expert parallelism Individual experts All-to-all. Tokens are routed to their target experts. Within a node preferred Uneven expert load can overload cards hosting popular experts
    Pipeline parallelism Layers grouped into consecutive stages Point-to-point activation transfer between adjacent stages Across nodes Pipeline bubbles lower utilization and increase first-token latency

    Tensor and expert parallelism both communicate frequently, so keep them inside a single server where possible. Pipeline parallelism passes activations only between stages. Its communication volume is smaller, so it suits cross-node deployment.

    This example uses tensor parallelism of 8 within each node and pipeline parallelism of 2 across the two servers. This setup minimizes the communication volume between the servers. If network bandwidth is high enough, you can also test cross-node expert parallelism. Measure throughput before deciding. Check the official documentation for your framework for exact parameter names and valid value ranges.

    5. Launching the Multi-Node Service

    Before launching, confirm three things: the weights directory path is the same on both servers, the model files are complete, and the specified ports are reachable between the two servers.

    Run the following on the master node (rank 0):

    1. export MASTER_ADDR=<master node IP>
    2. export MASTER_PORT=29500
    3. export WORLD_SIZE=2
    4. export NODE_RANK=0
    5. <framework launch command> --model-path <weights directory> \
    6. --tensor-parallel-size 8 \
    7. --pipeline-parallel-size 2 \
    8. --max-model-len 32768 \
    9. --max-num-seqs 8

    On the worker node (rank 1), run the same command with NODE_RANK set to 1. Keep all other parameters identical. Otherwise, the parallel topology on the two nodes will not match.

    Start the master node first, then the worker node. Once the master node log shows a message such as “waiting for worker nodes to join,” start the worker node. The service is ready once both servers have loaded the weights and per-card memory usage has stabilized.

    6. Verifying the Service

    After the service is ready, send a simple request to confirm that the API responds:

    1. curl http://<master node IP>:8000/v1/chat/completions \
    2. -H "Content-Type: application/json" \
    3. -d '{
    4. "model": "<model name>",
    5. "messages": [{"role": "user", "content": "Introduce yourself in one sentence."}],
    6. "max_tokens": 64,
    7. "temperature": 0
    8. }'

    A 200 status code and a fluent reply mean the basic path works. Then run three more checks:

    1. Short-text correctness: Run a few question-answering, calculation, and simple coding tasks. Verify the answers manually.
    2. Long context: Build an input close to 32K tokens. Confirm that the model correctly references information from earlier and later in the input, and that the output is not truncated.
    3. **Concurrency