Abstract
Transformer-based neural networks have achieved state-of-the-art task performance in a number of machine learning domains including natural language processing and computer vision. To further improve their accuracy, recent work has explored the integration of dynamic behavior into these networks in the form of mixture-of-expert (MoE) layers. In this paper, we explore the introduction of MoE layers to optimize a different metric: inference latency. We introduce a novel system named PLANER that takes an existing Transformer-based network and a user-defined latency target and produces an optimized, sparsely-activated version of the original network that tries to meet the latency target while maintaining baseline accuracy. We evaluate PLANER on two real-world language modeling tasks using the Transformer-XL network and achieve inference latency reductions of over 2x at iso-accuracy.
Introduction: The Latency Bottleneck
Transformer models, such as BERT and GPT, have become the standard for natural language processing and computer vision. However, their high computational cost and slow inference speeds present significant challenges for production deployment. Profiling these models reveals a consistent bottleneck: attention layers typically account for over 80% of the total inference latency across different hardware generations.
While traditional optimization techniques like pruning can reduce latency, they often lead to substantial accuracy degradation. Conversely, Mixture-of-Expert (MoE) layers—which activate only a subset of parameters for each input—are usually employed to increase model capacity. This research introduces PLANER, a system that repurposes MoE layers as a "patch" to recover accuracy lost when expensive attention layers are pruned to meet strict latency targets.
The PLANER System
PLANER optimizes Transformer architectures through a two-phase Neural Architecture Search (NAS) process:
- Search Space Exploration: PLANER utilizes a differentiable NAS strategy, representing the network as a sequence of "Super Blocks." Each block can be configured as a skip connection (pruning), a standard attention layer with varying head counts, a feed-forward layer (FFL), or an MoE layer. Using Gumbel-Softmax, these architectural choices become trainable parameters optimized via gradient descent. A latency-aware loss function ensures the model adheres to user-defined speed targets.
- Sampling and Retraining: After identifying the optimal architecture, the model is instantiated and retrained. To prevent "tail latency" caused by expert congestion, an auxiliary load-balancing loss is applied to distribute tokens evenly across MoE experts.
Key Insights and Architectural Trends
The search process reveals distinct patterns in how sparsely activated layers should be integrated. Notably, PLANER consistently places MoE layers toward the end of the network as the latency target becomes more aggressive. This suggests that the later stages of a Transformer benefit most from the specialized processing provided by experts, allowing for the removal of heavy attention layers earlier in the pipeline.
Furthermore, the research demonstrates that MoE layers are more efficient than "iso-parametric" standard layers. When compared to feed-forward layers scaled to the same parameter count, MoE layers provide superior accuracy and speed, confirming that sparsity is a more effective scaling path for latency-sensitive applications.
Results and Performance
Evaluated on the WikiText-103 and enwik8 benchmarks using Transformer-XL, PLANER achieved:
- 2x Inference Speedup: Models met iso-accuracy targets while reducing latency by over 50%.
- Pareto Superiority: PLANER-generated models consistently outperformed existing optimization methods like Sandwich and PAR Transformers in the speed-accuracy trade-off.
- Improved Runtime Efficiency: Enforcing load balancing across experts improved MoE runtime by up to 1.16x by minimizing synchronization overhead.
Conclusion and Future Work
PLANER demonstrates that sparsely activated layers can be a powerful tool for latency optimization, not just capacity scaling. While current implementations face challenges at very small batch sizes due to gating overhead, future work on parallelized MoE implementations and expansion to Vision Transformers (ViTs) promises to further broaden the impact of this approach.
Summary updated