Communication Library Design for MoE Expert Parallelism

    This article breaks down why expert parallelism (EP) is necessary for large MoE models and why All-to-All communication becomes the central bottleneck. It highlights key design choices in MoE-oriented communication libraries, including dual high-throughput and low-latency kernels, native low-precision support, compute-communication overlap, topology-aware scheduling, and load balancing with capacity control. It also outlines a practical evaluation and tuning workflow, plus general guidance for deploying these capabilities on cloud infrastructure.

    1. Why Expert Parallelism Is Necessary

    Once a large model exceeds the memory and compute limits of a single device, some form of parallelism becomes mandatory. Common approaches in engineering practice include data parallelism (DP), pipeline parallelism (PP), and tensor parallelism (TP). Data parallelism scales throughput by replicating the model. Pipeline parallelism splits the model by layers and distributes different stages across devices. Tensor parallelism splits the matrix operations within a single layer horizontally, making it highly sensitive to interconnect bandwidth, so it is often used cautiously in bandwidth-constrained clusters.

    The Mixture-of-Experts (MoE) architecture offers a different scaling path. Instead of involving all parameters in every forward pass, a gating network (also called a routing network) selects a small subset of experts for each token. Because experts are independent of one another and have no data dependencies, the parameter load can be partitioned along the expert dimension and distributed across devices, with each device running its assigned experts at runtime. This is the core idea of expert parallelism (EP).

    2. Why All-to-All Becomes the Core Bottleneck

    Under expert parallelism, tokens are routed to experts on remote devices, and the results are sent back to the original device. At the communication layer, this “dispatch-compute-combine” process appears as All-to-All. It presents three challenges at once:

    1. Bursty traffic: load across experts within the same batch is naturally uneven, so devices hosting popular experts receive more data instantaneously.
    2. Uncertain data volume: the number of tokens each expert receives cannot be precisely known before runtime, so buffers and scheduling must adapt dynamically.
    3. Latency sensitivity: dispatch and combine sit on the critical path, so any synchronization wait directly increases per-step latency.

    In essence, a communication library built for MoE must solve the problem of “efficiently completing bidirectional data exchange under uncertain load.”

    3. Notable Design Highlights

    3.1 Dual Kernel Paths for High Throughput and Low Latency

    Mature implementations usually distinguish two scenarios: training and prefill phases prioritize throughput, while the decode phase prioritizes latency. The former can amortize communication overhead with larger batches, while the latter needs fast completion for small messages. Providing separate high-throughput and low-latency All-to-All kernels for these two goals is the most direct highlight of such libraries.

    3.2 Native Support for Low Precision

    Low-precision formats such as FP8 can significantly reduce the number of communication bytes. The challenge lies in numerical stability: quantization before dispatch, dequantization after combine, and scaling-factor management must be designed in coordination with the compute flow, rather than simply swapping the data type.

    3.3 Overlapping Computation and Communication

    Splitting dispatch, expert computation, and combine into pipeline-able stages, so that communication is hidden behind computation, is a key technique for improving end-to-end efficiency. Illustrative pseudocode:

    1. # Pseudocode: three-stage overlap of dispatch-compute-combine
    2. disp = dispatch(tokens, topk_idx) # Stage 1: dispatch by routing results
    3. with compute_stream:
    4. out = experts[disp.expert_id](disp.payload) # Stage 2: local expert computation
    5. merged = combine(out, disp.layout) # Stage 3: combine back to the original layout

    3.4 Topology-Aware Scheduling

    Bandwidth differs greatly between intra-node and inter-node links. Placing experts that interact frequently within the same node allows most traffic to travel over high-speed interconnects, leaving only a small amount of cross-node traffic to bear the extra overhead.

    3.5 Load Balancing and Capacity Control

    Using capacity factors, dropping, or rerouting strategies to cap the peak load of individual experts prevents certain devices from becoming long-tail bottlenecks. Meanwhile, reserving elastic space for buffers reduces jitter caused by dynamic resizing.

    4. How to Evaluate and Tune

    It is recommended to establish an evaluation baseline across four dimensions: per-step latency, effective throughput (tokens/s), communication ratio, and load skew. Tuning can proceed in the following order:

    • First, measure the routing distribution to confirm whether obvious expert hotspots exist.
    • Then, check whether communication and computation are truly overlapped, avoiding serial waits.
    • Next, verify whether the accuracy loss of the low-precision path is within an acceptable range.
    • Finally, adjust expert placement and the capacity factor, and observe whether the long tail converges.

    5. General Guidance for Cloud Deployment

    If you plan to build this kind of communication capability on a container platform or bare-metal cluster, prioritize whether high-speed interconnects and topology information are visible to scheduling, and continuously monitor the communication ratio and skew metrics with monitoring, alerting, and logging services. Models and data can be stored separately in object storage and a parallel file system to enable rapid experimental iteration. In such high-performance training and inference scenarios, Baidu AI Cloud typically provides general support around high-speed networking, container orchestration, and observability.

    6. Summary

    The value of expert parallelism lies in decoupling the parameter load along the expert dimension, while engineering success depends on the efficiency of All-to-All communication. Designing around dual throughput and latency paths, low-precision support, compute-communication overlap, topology awareness, and load balancing, and driving tuning with quantitative metrics, are the most worthwhile directions when building such a communication library.