Abstract
Mixture of Experts (MoE) models have become a cornerstone of large-scale language modeling, offering high capacity with manageable computational costs by activating only a subset of "experts" for any given input. However, traditional inference systems utilizing Expert Parallelism (EP) frequently encounter severe load imbalance, where specific GPUs become bottlenecks while others remain idle. This paper introduces MoEShard, a novel inference system that eliminates these bottlenecks by sharding every expert across all available GPUs. By combining tensor parallelism with block-sparse matrix multiplication, MoEShard achieves perfect load balancing and up to a 6.4x speedup in end-to-end inference without the need for token dropping.
Introduction: The MoE Efficiency Paradox
Mixture of Experts (MoE) architectures are the engine behind many of the world's most capable Large Language Models (LLMs). By partitioning a model into specialized sub-networks (experts) and using a router to select only one or two experts per token, these models provide the benefits of massive parameter counts with the inference speed of much smaller dense models.
Despite this theoretical efficiency, practical deployment often hits a wall known as the "noisy neighbor" problem. In standard Expert Parallelism (EP), each GPU is assigned a specific set of experts. If a batch of input text happens to trigger one expert more frequently than others—a common occurrence in natural language—the GPU hosting that expert becomes a processing bottleneck. To maintain throughput, many current systems employ "Capacity Factors" to simply drop tokens that exceed a GPU's processing window, which directly degrades the model's output quality and accuracy.
The MoEShard Approach
MoEShard reimagines the relationship between experts and hardware. Rather than assigning whole experts to specific GPUs, MoEShard treats experts as parallelizable resources through a technique known as Expert Sharding.
1. Tensor Parallelism for Experts
In MoEShard, every expert matrix is split across all available GPUs. Specifically, the first weight matrix ($W_i$) is sharded column-wise, while the second weight matrix ($W_o$) is sharded row-wise. This ensures that every GPU participates in the computation of every expert activated in a batch.
2. Unified Workflow
When tokens are routed to experts, the system replicates the input tokens across all GPUs. Each GPU then computes a partial result using its local shard of the required expert. Finally, these partial results are aggregated via an all-reduce operation to produce the final output. This architecture ensures that every GPU performs an identical amount of work for every batch, regardless of the router's choices.
3. Kernel Fusion via MegaBlocks
To mitigate the overhead of managing thousands of tiny matrix multiplications (which would occur if each shard were treated as a separate operation), MoEShard utilizes MegaBlocks. This block-sparse matrix multiplication framework allows the system to group all expert computations into a single, massive operation, significantly reducing kernel launch overhead and maximizing hardware utilization.
Experimental Evaluation
The researchers evaluated MoEShard using the Google Switch Transformer (Switch-Base) on the BookCorpus dataset, which contains over 7,000 unique books. This dataset was chosen to simulate realistic, skewed token routing scenarios where certain experts are naturally more "popular" than others.
Key Results
- Throughput and Latency: MoEShard achieved up to a 4.25x speedup in per-layer latency compared to the industry-standard DeepSpeed-MoE. In end-to-end tests measuring Time to First Token (TTFT), the system demonstrated speedups of up to 6.4x.
- Zero Token Loss: Unlike DeepSpeed, which must drop tokens to maintain performance during expert congestion, MoEShard processed 100% of tokens. This ensures that the model's full predictive power is maintained without a speed penalty.
- Scaling Efficiency: Interestingly, MoEShard’s performance advantage over traditional baselines increases as batch sizes grow. While larger batches amplify imbalances in EP systems, they provide MoEShard with more opportunities for efficient parallel work.
Discussion: The Communication Trade-off
A common critique of replicating tokens across GPUs is the perceived communication cost. However, MoEShard demonstrates that on modern hardware equipped with high-speed interconnects (such as NVIDIA A100s with NVLink), the communication cost is approximately 0.15ms. This is negligible compared to the significant time wasted when GPUs sit idle in an imbalanced EP configuration.
Limitations and Future Work
While MoEShard represents a significant leap in MoE inference, it is currently optimized for high-speed interconnect environments. Performance may vary on distributed systems relying on standard Ethernet. Additionally, while the current study focused on encoder-based architectures like the Switch Transformer, future work is required to optimize the compute-to-communication ratio for autoregressive decoding in GPT-style models. Finally, the memory overhead associated with replicating input tokens across all GPUs must be carefully managed as sequence lengths and batch sizes continue to scale.
Summary updated