Optimizing Mixture of Experts using Dynamic Recompilations

Ferdinand Kossmann, Zhihao Jia, Alex AikenarXiv 2022 · DOI

Abstract

Scaling Mixture of Experts (MoE) models is often constrained by the static nature of current deep learning frameworks. We introduce DYNAMOE, a library featuring a novel RECOMPILE mechanism that allows models to dynamically resize tensors and cache expert assignments during training. This approach results in up to a 1.8x baseline speedup and the capability to train models 2.3x larger than existing state-of-the-art systems.

Introduction

Mixture of Experts (MoE) is a powerful architecture that enables the scaling of model parameters into the trillions without a proportional increase in computational cost (FLOPs). By activating only a small subset of the network—experts—for any given input sample via a gating network, MoEs maintain efficiency.

However, MoEs are inherently dynamic; the number of samples assigned to a specific expert changes every iteration. Current frameworks like TensorFlow and PyTorch are designed for static computation graphs with fixed tensor sizes. To accommodate MoEs, these frameworks often use inefficient workarounds like padding tensors to a maximum capacity or dropping samples. This leads to significant memory waste, unnecessary computation, and potential degradation in model quality.

The DYNAMOE System and RECOMPILE Mechanism

DYNAMOE, built on the FlexFlow framework, addresses these inefficiencies through its core innovation: the RECOMPILE mechanism. This mechanism enables dynamic graph adjustments with negligible overhead by planning changes on the CPU while the GPU continues execution.

Overview of the DYNAMOE system architecture, illustrating the interaction between the computational graph, initialization, and execution phases with the RECOMPILE trigger.

Key features of DYNAMOE include:

  1. Dynamic Graph Adjustments: Batch dimensions for specific experts can be altered during training.
  2. Overlapped Execution: Graph planning and GPU training occur in parallel to prevent "stop-the-world" stalls.
  3. Dynamic Capacity Factors: The system monitors expert load and resizes tensors to match actual needs rather than relying on fixed global capacity factors.
  4. Sample Assignment Caching: By caching gating assignments, the system can run experts and the gating network in parallel, significantly increasing hardware utilization.

Key Insights

A critical observation in DYNAMOE is the "disposable dependency" of the gating network. Since gating assignments tend to converge early in training, the system can use assignments from the previous epoch to start expert computation early, breaking a major bottleneck in model parallelism. Additionally, the research highlights that "Specification loss" (letting experts learn independently) outperforms "Cooperation loss," as it encourages better expert specialization.

Performance Results

Evaluations on the CIFAR-10 dataset using CNN-based MoEs demonstrate that DYNAMOE is up to 1.8x faster than FastMoE and supports 2.3x larger model sizes on identical hardware. Enabling RECOMPILE-based optimizations (dynamic capacity and caching) provides an additional 1.7x speedup.

Comparison of GPU execution timelines with caching disabled (top) and enabled (bottom), showing improved utilization and reduced idle time during the forward and backward passes.

DYNAMOE also exhibits near-linear scaling in throughput and supported model size as more GPUs are added. Importantly, optimizations like sample assignment caching have a negligible effect on model convergence and final accuracy.

Limitations and Future Work

While DYNAMOE shows significant promise, several areas for improvement remain. The current hardware mapping is limited to expert parallelism; broader mappings could unlock further gains. Additionally, the triggers for recompilation are currently naive and could benefit from more sophisticated, AI-driven policies. Finally, while tested on multiple nodes, scaling to the hundreds or thousands of GPUs required for trillion-parameter models remains a future challenge. Training instabilities also present a hurdle, as caching must be disabled during unstable phases, nullifying its speed benefits.

Summary updated

BibTeX
@misc{kossmann2022optimizing,
  author = {Ferdinand Kossmann and Zhihao Jia and Alex Aiken},
  title = {{Optimizing Mixture of Experts using Dynamic Recompilations}},
  year = {2022},
  eprint = {2205.01848},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.01848},
}
Figure