Sparse is Enough in Scaling Transformers

Sebastian Jaszczur, Aakanksha Chowdhery, Afroz Mohiuddin, Lukasz Kaiser, Wojciech Gajewski, Henryk Michalewski, Jonni Kanerva

TL;DR

This paper introduces Scaling Transformers, a new architecture that leverages dynamic sparsity across all layers—not just attention—to drastically reduce inference costs. By replacing dense layers with sparse equivalents, the authors achieve the same performance as standard Transformers while delivering up to a 37x speedup in decoding for 17-billion parameter models.

What Problem Does This Paper Address?

Large-scale Transformer models (like GPT-3 or T5) have revolutionized NLP, but they come with a staggering "computational tax." As we increase the model size ($d_{model}$), the computational complexity of the layers grows quadratically ($d_{model}^2$). This makes these models incredibly expensive to train, environmentally taxing, and—crucially—too slow for real-time unbatched decoding (inference).

While previous research has focused on "Sparse Attention" to handle long sequences, the feedforward (FF) and Query-Key-Value (QKV) layers remain dense bottlenecks. This paper asks a bold question: Can we make every part of the Transformer sparse without losing the "magic" of its performance?

Methods

The authors propose a two-pronged approach to sparsify the Transformer's architecture, targeting the heaviest computational bottlenecks:

Diagram illustrating the Sparse Feedforward and Sparse QKV mechanisms.
  1. Sparse Feedforward (FF) Layers: In a standard Transformer, the FF block is the heaviest component. The authors introduce a dynamic sparsity mechanism where a "controller" (a low-rank bottleneck layer) decides which small subset of weights to activate for each specific token. Instead of processing the full width, the model only activates 1 out of every $N$ blocks.
  2. Sparse QKV Layers: Standard QKV layers lack the non-linearities (like ReLU) that make FF layers easy to sparsify. To solve this, the authors developed a Multiplicative Layer that can represent arbitrary permutations of the embedding space with far fewer parameters. This is combined with a Convolutional Layer to reduce the complexity of the attention mechanism's linear projections from $O(d_{model}^2)$ to $O(d_{model}^{1.5})$.
  3. Terraformer: For long sequences, the authors combine these sparse layers with reversible layers (for memory efficiency) and Locality-Sensitive Hashing (LSH) attention.

Datasets

The models were rigorously tested on several standard benchmarks:

  • C4 (Colossal Clean Crawled Corpus): Used for large-scale pre-training and perplexity measurements.
  • GLUE Benchmark: Used to evaluate fine-tuning performance on downstream tasks like sentiment analysis (SST-2) and natural language inference (MNLI).
  • arXiv Dataset: A challenging task involving the summarization of long scientific papers.
  • Synthetic Tasks: "Long addition" and "decimal copying" to test how well the models generalize to sequences longer than those seen during training.

Key Insights and Results

  • "Sparse is Enough" (Performance Parity): The most surprising finding is that you don't need dense connectivity to maintain model quality. A fully sparse Scaling Transformer can match the log-perplexity of a dense baseline model while using significantly less computation per token.
Log-perplexity over training steps showing sparse variants matching or exceeding baseline performance.
  • The Scaling Advantage: The benefits of sparsity actually increase as the model gets larger. While an 800M parameter model sees a ~3x speedup, a 17B parameter model sees a massive 37.64x speedup (achieving a decoding speed of 0.097s per token compared to 3.651s for the dense baseline). This suggests that sparsity is the key to sustainable "hyper-scaling."
  • Permutation Matters: The "Multiplicative Layer" is a clever workaround for the lack of ReLUs in attention layers. By allowing the model to learn how to reshuffle information efficiently, it maintains the expressivity of dense projections at a fraction of the cost.
  • Summarization & Generalization: The Terraformer variant yielded results competitive with state-of-the-art models like BigBird-Pegasus on long-text summarization, despite using a simpler training objective. Furthermore, in synthetic "out-of-distribution" tests, Terraformer significantly outperformed standard Transformers, showing a better ability to handle sequences much longer than those in the training set (e.g., 99.9% accuracy on copying tasks where the baseline hit 79.8%).

Limitations and Future Work

  • Inference vs. Training: Currently, the primary speedups are observed during inference (decoding). The authors note that more work is needed to translate these gains into faster training times.
  • Hardware Optimization: The benchmarks were performed on CPUs for unbatched inference. Implementing these sparse kernels efficiently on GPUs/TPUs remains a technical challenge due to the way modern accelerators handle memory coalescing.
  • Hyperparameter Tuning: The authors used hyperparameters borrowed from dense models. They speculate that even better results could be achieved by specifically tuning architectures for sparsity from the ground up.

Summary updated

BibTeX
@inproceedings{jaszczur2021sparse,
  author = {Sebastian Jaszczur and Aakanksha Chowdhery and Afroz Mohiuddin and Lukasz Kaiser and Wojciech Gajewski and Henryk Michalewski and Jonni Kanerva},
  title = {{Sparse is Enough in Scaling Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=1f0HqPs5tWB},
}
Figure