Approximating Two-Layer Feedforward Networks for Efficient Transformers

Róbert Csordás, Kazuki Irie, Jürgen Schmidhuber

Abstract

How to reduce compute and memory requirements of neural networks (NNs) without sacrificing performance? Many recent works use sparse Mixtures of Experts (MoEs) to build resource-efficient large language models (LMs). Here we introduce several novel perspectives on MoEs, presenting a general framework that unifies various methods to approximate two-layer NNs (e.g., feedforward blocks of Transformers), including product-key memories (PKMs). Leveraging insights from this framework, we propose methods to improve both MoEs and PKMs. Unlike prior work that compares MoEs with dense baselines under the compute-equal condition, our evaluation condition is parameter-equal, which is crucial to properly evaluate LMs. We show that our MoEs are competitive with the dense Transformer-XL on both the WikiText-103 and enwiki8 datasets at two different scales, while being much more resource efficient. This demonstrates that MoEs are relevant not only to extremely large LMs but also to any-scale resource-efficient LMs.

Introduction

Large Language Models (LLMs) have revolutionized natural language processing but at a significant cost in terms of computational resources and memory. While Mixture of Experts (MoE) layers—which activate only a subset of "experts" for each input—offer a path toward scaling, they are often viewed as difficult to train, prone to "expert collapse," and only applicable to trillion-parameter models. This paper challenges these notions by introducing $\sigma$-MoE, a refined MoE variant that treats Transformer feedforward blocks as sparse approximations of two-layer networks.

The Sparsity Hypothesis

A core insight of this work is that sparsity is a natural, emergent property of standard dense Transformers. Preliminary studies of dense Transformer-XL models reveal that only a small fraction of feedforward channels are active at any given time, particularly after the first layer.

Active channels per layer in a dense Transformer-XL model, demonstrating natural sparsity.

By explicitly hardware-accelerating this property through MoEs, we can achieve significant efficiency gains without deviating from the underlying mechanics of successful dense architectures.

Methodology: The $\sigma$-MoE Framework

The authors propose a unified theoretical framework that views feedforward blocks, MoEs, and Product-Key Memories (PKMs) as different ways to approximate a two-layer neural network. The resulting $\sigma$-MoE incorporates several key technical innovations:

  • Sigmoid Gating: Standard MoEs use softmax gating, which forces experts to compete. $\sigma$-MoE uses sigmoid activations, allowing experts to act more like independent neurons in a dense layer, which improves training stability and prevents expert collapse.
  • Improved Initialization: Expert weights are initialized to match the standard deviation of the dense baseline, ensuring the model starts in a regime similar to its dense counterpart.
  • Simplified Load Balancing: Instead of complex engineering, the model uses a simple entropy-maximization loss and "expert dropout" to ensure balanced utilization across all experts.
  • Parameter-Equal Evaluation: Unlike many studies that compare models based on FLOP-equivalence, this work insists on comparing MoEs to dense models with the same total number of parameters, providing a more rigorous assessment of model capacity.

Experimental Results

The $\sigma$-MoE was evaluated across multiple benchmarks, including WikiText-103, Enwik8, C4, and peS2o. The results consistently show that $\sigma$-MoE matches or outperforms dense Transformer-XL baselines while requiring significantly fewer FLOPs.

Performance comparison of $\sigma$-MoE and dense baselines across various datasets and scales.

As shown in the table above, the 262M parameter $\sigma$-MoE achieved performance parity with the dense baseline on WikiText-103 while using only 12.5% of the FFN FLOPs. Similar efficiencies were observed across other datasets, proving that MoEs are relevant for resource-efficient LMs at any scale.

Conclusion

By unifying MoEs and dense layers under a single framework and introducing sigmoid gating, this work demonstrates that sparse models can be as effective as their dense counterparts while being far more efficient. The release of a custom CUDA kernel further proves that these theoretical FLOP savings translate into real-world wall-clock speedups, making $\sigma$-MoE a practical choice for modern LLM development.

Summary updated

BibTeX
@inproceedings{csordas2023approximating,
  author = {Róbert Csordás and Kazuki Irie and Jürgen Schmidhuber},
  title = {{Approximating Two-Layer Feedforward Networks for Efficient Transformers}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=3Z2B6NBqxr},
}
Figure