Accelerating MoE Model Inference with Expert Sharding

Oana Balmau, Anne-Marie Kermarrec, Rafael Pires, André Loureiro Espírito Santo, Martijn de Vos, Milos Vujasinovic · DOI

TL;DR

MoEShard is a novel inference system for Mixture-of-Experts (MoE) models that achieves perfect load balancing across multi-GPU setups by sharding individual expert matrices rather than distributing whole experts. By combining strategic row- and column-wise matrix decomposition with block-sparse kernel fusion, MoEShard eliminates token dropping and idle GPU time, delivering up to a 6.4× speedup in Time-to-First-Token (TTFT) compared to DeepSpeed.

What Problem Does This Paper Address?

Mixture-of-Experts (MoE) architectures scale model capacity efficiently by replacing standard feed-forward networks with multiple smaller "experts" and activating only a subset per token. However, running these massive models requires distributing experts across multiple GPUs (Expert Parallelism).

In practice, token routing is highly skewed—certain popular experts receive a massive influx of tokens while others sit idle. As shown in Figure 1, this imbalance is particularly severe in the later layers of the model.

Figure 1. ECDF of token distribution per expert for the first and last layer, for a Switch transformer.

This load imbalance creates severe hardware inefficiencies, as the overall inference time is bottlenecked by the slowest, most overloaded GPU. Current workarounds either enforce a strict "capacity factor" that drops excess tokens (which degrades model accuracy) or dynamically replicate popular experts (which introduces high profiling overhead and consumes scarce GPU memory).

Methods

The authors introduce MoEShard, which shifts the paradigm from Expert Parallelism to Tensor Sharding for MoE layers. Instead of assigning whole experts to specific GPUs, MoEShard splits every expert across all available GPUs.

An expert's computation typically involves two matrix multiplications ($W_i$ and $W_o$). MoEShard splits $W_i$ column-wise and $W_o$ row-wise across the GPUs, as illustrated in Figure 2.

Figure 2. Expert computations with and without MoEShard. An expert consists of matrices 𝑊𝑖(in green) and 𝑊𝑜(in red).

This specific sharding strategy allows both matrix multiplications to proceed sequentially on each GPU without requiring intermediate synchronization or communication barriers.

To combat the overhead of launching thousands of tiny GPU kernels for each expert shard, MoEShard introduces two key optimizations:

  1. Token Concatenation: It groups and concatenates tokens destined for the same expert from all GPUs into a single tensor, reducing the number of expert shard computations.
  2. Sparse Matrix Fusion: It leverages variable-sized block-sparse matrix multiplication (via MegaBlocks) to fuse all expert shard computations into a single large operation, making kernel launch overhead independent of the number of experts.

Datasets

The system was evaluated using the BookCorpus dataset, a large-scale text dataset containing text from over 7,000 unique books. No new benchmarks or datasets were introduced in this work.

Key Insights and Ideas

  • Perfect Load Balancing by Design: By sharding every expert matrix uniformly, every GPU processes an identical fraction of every token. This completely bypasses the need for dynamic load-balancing heuristics or complex scheduling algorithms.
  • Zero Token Loss: Unlike standard frameworks that drop tokens when an expert hits its capacity limit, MoEShard is completely "dropless," preserving full model accuracy.
  • Communication Trade-off: MoEShard requires replicating all input tokens across all GPUs (all-to-all communication). While this sounds expensive, the authors demonstrate that over modern high-speed interconnects like NVLink, this overhead is negligible (~0.15 ms) compared to the compute savings gained by eliminating GPU idle time.

Key Results

The authors evaluated MoEShard against DeepSpeed-MoE using a Switch-Base encoder model on four NVIDIA A100 GPUs:

  • Per-layer Latency: MoEShard reduced per-layer inference latency from ~180 ms (DeepSpeed) down to 41.5–43.5 ms, achieving up to a 4.25× speedup.
  • Time-to-First-Token (TTFT): MoEShard demonstrated up to a 6.4× speedup in TTFT (Figure 3a). As batch sizes and the number of experts scaled up, MoEShard's performance advantage over DeepSpeed widened due to the increasing severity of routing skew in the baseline system (Figure 3b).
Figure 3. The average TTFT of MoEShard with respect to DeepSpeed for varying numbers of experts (left) and batch sizes (right).

Limitations and Future Work

  • Encoder-Only Focus: The current evaluation focuses strictly on the encoder portion of MoE models. Autoregressive decoder generation, which processes tokens one by one and is heavily memory-bandwidth bound rather than compute-bound, remains unexplored.
  • Homogeneous Hardware Assumption: The system assumes all GPUs have identical computational capacity and memory, and are connected via high-speed local links (a single-server setup). Adapting this to multi-node clusters or heterogeneous hardware environments would introduce more complex communication bottlenecks.

Summary updated

BibTeX
@inproceedings{balmau2025accelerating,
  author = {Oana Balmau and Anne-Marie Kermarrec and Rafael Pires and André Loureiro Espírito Santo and Martijn de Vos and Milos Vujasinovic},
  title = {{Accelerating MoE Model Inference with Expert Sharding}},
  booktitle = {EuroMLSys},
  year = {2025},
  doi = {10.1145/3721146.3721940},
}
Figure