Abstract
We combine the capacity of sparsely gated Mixture-of-Experts (MoE) with the speed and stability of linear, mixing transformations to design the Sparse Mixer encoder model. Sparse Mixer slightly outperforms (<1%) BERT on GLUE and SuperGLUE, but more importantly trains 65% faster and runs inference 61% faster. We also present a faster variant, prosaically named Fast Sparse Mixer, that marginally underperforms BERT on SuperGLUE, but trains and runs nearly twice as fast. We justify the design of these two models by carefully ablating through various mixing mechanisms, MoE configurations and hyperparameters. Sparse Mixer overcomes many of the latency and stability concerns of MoE models and offers the prospect of serving sparse student models, without resorting to distilling them to dense variants.
Introduction
While Mixture-of-Experts (MoE) models have successfully scaled Transformers to trillions of parameters, they are rarely utilized in latency-sensitive production environments. Most MoE research focuses on "scaling up" to achieve state-of-the-art quality, which often results in models that are slower per-step than their dense counterparts. Furthermore, MoE models are notoriously unstable to train and difficult to distill into smaller, "servable" dense models without significant quality loss.
Sparse Mixers aim to "scale down" these costs while maintaining high performance. By combining the high capacity of sparsely gated MoE with the speed of linear mixing transformations, this architecture provides a BERT-like encoder that matches or exceeds standard BERT performance while significantly reducing training and inference time. This offers a practical path to serving sparse models in production without the need for complex distillation.
Architecture and Methodology
The Sparse Mixer architecture deviates from the standard Transformer in two fundamental ways to optimize for speed and stability:
1. Mixing instead of Attention
The model replaces the majority of self-attention sublayers with simpler, linear "mixing" transformations. These operations—such as Fourier transforms or simple linear projections—mix input representations across the sequence dimension significantly faster than the quadratic dot-product operations required by standard attention. To capture complex, token-dependent relationships, the model retains a small number of self-attention layers only at the very top of the encoder stack.
2. Sparse MoE Layers
To compensate for the reduced capacity caused by "thinning" the model (reducing the hidden dimension $d_m$ to 512 compared to BERT's 768), the authors insert MoE sublayers. Specifically, they employ an "Experts Choose" routing mechanism. In this setup, experts pick the top-$k$ tokens they are best suited to process, ensuring that experts are utilized efficiently and eliminating the need for complex load-balancing losses common in "Tokens Choose" (Switch Transformer style) routing.
Structural Configuration
The final Sparse Mixer configuration utilizes 14 layers. The design philosophy favors a "thin and deep" approach—smaller embedding dimensions but more layers—adding back capacity via MoE to distribute parameters efficiently for speed.
Experimental Setup
Models were pre-trained on the C4 (Colossal Clean Crawled Corpus) dataset for 1 million steps using Masked Language Modeling (MLM) and Next Sentence Prediction (NSP) objectives. Evaluation was conducted on the GLUE and SuperGLUE benchmarks, covering a wide variety of Natural Language Understanding (NLU) tasks, including sentiment analysis, natural language inference, and question answering.
Key Insights
The Stability Synergy
A primary finding is that mixing layers stabilize MoE training. Replacing dense feed-forward layers in BERT with MoE usually leads to highly unstable gradients. However, when the majority of self-attention is replaced by mixing, these instabilities vanish. This suggests that the token-dependent nature of attention may be a primary source of instability that linear mixing avoids.
Top-Heavy Attention
Ablation studies demonstrated that self-attention is most valuable at the end of the encoder stack. By concentrating attention in the final layers and using mixing elsewhere, the model retains BERT-level accuracy while drastically slashing latency.
Parameter vs. FLOP Efficiency
Despite having a higher total parameter count due to the MoE experts, Sparse Mixer uses significantly fewer FLOPs per example than BERT. This is because only a small fraction of the total parameters are activated for any given token, allowing for high capacity without the computational tax of a dense model of equivalent size.
Results
- Sparse Mixer: This model slightly outperformed BERT on GLUE and SuperGLUE while being 65% faster to train and 61% faster for inference.
- Fast Sparse Mixer: A variant optimized for extreme speed, it marginally underperforms BERT (by less than 0.2% on SuperGLUE) but runs nearly twice as fast (89% faster training, 98% faster inference).
Limitations and Future Work
The current study focuses strictly on BERT-like encoder models. While the logic may extend to decoders, cross-attention in encoder-decoder models might be more difficult to replace with simple mixing. Additionally, because the model retains some self-attention layers, it does not fully solve the $O(N^2)$ scaling issue for extremely long sequences. Future work may explore replacing the remaining attention layers with efficient linear attention approximations and applying automated architecture searches (AutoML) to further optimize the configuration.
Summary updated