ExpertFlow: Optimized Expert Activation and Token Allocation for Efficient Mixture-of-Experts Inference

Xin He, Shunkang Zhang, Yuxin Wang, Haiyan Yin, Zihao Zeng, Shaohuai Shi, Zhenheng Tang, Xiaowen Chu, Ivor W. Tsang, Yew-Soon Ong · DOI

Abstract

Mixture-of-Experts (MoE) models have become a cornerstone of large-scale AI, yet their massive parameter counts often exceed the VRAM capacity of standard GPUs. While offloading experts to system RAM is a common workaround, it is frequently bottlenecked by slow I/O and unpredictable routing. ExpertFlow introduces a novel system that optimizes MoE inference through a transformer-based routing path predictor and a token scheduler that re-batches requests to minimize expert swaps. Our evaluation shows that ExpertFlow achieves up to 93.72% memory savings and speeds up inference by 2x to 10x compared to existing offloading baselines.

Introduction

Large Language Models (LLMs) are scaling at a rate that outpaces GPU memory growth. Mixture-of-Experts (MoE) architectures, such as Mixtral-8x7B, mitigate computational costs by only activating a subset of "experts" for each token. However, the requirement to store the entire model—often exceeding 96GB for a single instance—remains a significant barrier for modest hardware setups.

Existing offloading techniques move idle experts to the CPU, but they suffer from three primary issues: severe I/O bottlenecks during expert swapping, the inability to prefetch data due to unpredictable routing, and inefficient batching where tokens in a single batch require a wide, disparate array of experts. ExpertFlow addresses these challenges by making expert activation predictable and data movement efficient.

The ExpertFlow Architecture

ExpertFlow employs a three-pronged strategy to streamline the execution of MoE models on heterogeneous hardware. At its core, the system manages the placement of experts between the GPU (active) and CPU (idle) while hiding the latency of data transfers.

The ExpertFlow system architecture, featuring the Routing Path Predictor, Token Scheduler, and Expert Cache Engine.

1. Routing Path Prediction

Instead of determining expert activation layer-by-layer during execution, ExpertFlow uses a lightweight, T5-based transformer to predict the entire routing path for a token across all layers in a single pass. By treating routing as a binary classification task (Active vs. Idle), the predictor remains fast and memory-efficient (~7MB) while providing the necessary lead time for prefetching.

2. Predictive Locality-aware Expert Caching (PLEC)

The Expert Cache Engine (ECE) utilizes these predictions to proactively move experts into the GPU cache. This "proactive management" ensures that by the time a non-expert layer completes its computation, the required experts are already present in VRAM. A real-time correction mechanism handles any mispredictions by performing emergency swaps, ensuring model accuracy is never compromised.

Optimizing Token Allocation

The most significant innovation in ExpertFlow is the Token Scheduler. Standard inference pipelines process batches in the order they arrive, which often results in a "fragmented" expert requirement where every expert in the model must be loaded for a single batch.

The Token Scheduler re-batches tokens to group those requiring similar experts, significantly reducing the unique expert load per batch.

As shown in the figure above, the Token Scheduler uses K-means clustering to reorganize tokens from multiple incoming batches. By grouping tokens that share expert requirements, the system reduces the total number of unique experts needed per batch. This optimization increases the cache hit ratio by 15% to 35% and allows the system to compute more tokens per expert activation, effectively attacking the I/O bottleneck at its source.

Key Results and Performance

ExpertFlow was evaluated on standard NLP tasks (WMT16, XSUM) using Switch Transformer and Mixtral-8x7B models. The system demonstrated substantial improvements across all key metrics:

  • Inference Speed: ExpertFlow achieved a 2x to 10x speedup over SE-MoE baselines. On the Switch-128 model, it reached a peak speedup of nearly 10x by effectively overlapping computation with expert prefetching.
  • Memory Efficiency: The system ran massive models with up to 93.72% GPU memory savings, enabling high-parameter models to function on hardware that would otherwise be insufficient.
  • Predictor Accuracy: The T5-based predictor achieved batch-level accuracies between 73% and 87%, proving that transformer-based models are uniquely suited to predicting the contextual routing decisions of larger LLMs.

Conclusion

ExpertFlow demonstrates that the bottlenecks of MoE offloading are not insurmountable. By combining predictive caching with intelligent token scheduling, the system significantly lowers the hardware requirements for state-of-the-art AI. Future work will explore moving the predictor to the CPU to further save VRAM and integrating quantization techniques to enable even larger models on consumer-grade devices.

Summary updated

BibTeX
@misc{he2024expertflow,
  author = {Xin He and Shunkang Zhang and Yuxin Wang and Haiyan Yin and Zihao Zeng and Shaohuai Shi and Zhenheng Tang and Xiaowen Chu and Ivor W. Tsang and Yew-Soon Ong},
  title = {{ExpertFlow: Optimized Expert Activation and Token Allocation for Efficient Mixture-of-Experts Inference}},
  year = {2024},
  eprint = {2410.17954},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.17954},
}
Figure