Searching for Efficient Transformers for Language Modeling

David So, Wojciech Mańke, Hanxiao Liu, Zihang Dai, Noam Shazeer, Quoc V LeNeurIPS 2021

TL;DR

Researchers at Google Brain used evolutionary search to discover Primer, a more efficient Transformer architecture for language modeling. By making two simple low-level changes—squaring ReLU activations and adding depthwise convolutions to the attention heads—Primer achieves the same performance as standard Transformers with up to 4.2x less training compute.

What Problem Does This Paper Address?

The "compute wall" in AI is a pressing reality. While scaling Transformer models has led to massive breakthroughs in natural language processing, the financial and environmental costs of training these models have become prohibitively expensive. Most research focuses on scaling up existing architectures, but this paper asks a more fundamental question: Is the standard Transformer architecture actually the most efficient way to use our hardware?

To answer this, the authors aim to find architectural "primitives" (low-level operations) that improve the training efficiency of auto-regressive (decoder-only) language models. The goal is to ensure that every floating-point operation (FLOP) spent on training yields the maximum possible gain in model quality.

Methods

The authors employed an automated approach called Neural Architecture Search (NAS), specifically using a technique known as Regularized Evolution with hurdles.

Unlike many NAS papers that search over high-level blocks (e.g., choosing between a 3x3 or 5x5 convolution), this search was performed at a much lower level: the TensorFlow computation graph. The search space consisted of basic primitives like ADD, MATMUL, and SIN.

Overview of the low-level search space mapping subprograms to TensorFlow code.

To make this massive search space feasible, they utilized:

  1. Conceptual Initialization: Instead of starting from scratch, they initialized the search population with the standard Transformer architecture.
  2. Implicit Efficiency Objective: They gave every candidate model a fixed training budget (e.g., 24 TPUv2 hours) and defined "fitness" as the model's perplexity. This forced the evolutionary algorithm to favor models that learn faster, not just models that might eventually reach a better final state given infinite time.

Datasets

The study utilized several standard benchmarks to ensure the findings generalized across tasks:

  • LM1B (One Billion Word Benchmark): Used for the initial evolutionary search.
  • C4 (Colossal Clean Crawled Corpus): Used for large-scale verification (up to 500M parameters).
  • PG19: A dataset of books used to test transferability to long-context modeling.
  • Proprietary Pretraining Dataset: Used for the 1.9B parameter "GPT-3 XL" scale experiments.

Key Insights and Ideas

  • The Power of Squared ReLU: The most impactful discovery was replacing the standard ReLU activation with its square: $\text{ReLU}(x)^2$. While standard activations like GeLU and Swish are popular, Squared ReLU has different "asymptotics" (it grows faster as $x$ increases), which the authors found significantly boosts training speed in Transformers.
Comparison of activation functions showing Squared ReLU achieving the best performance.
  • Multi-DConv-Head Attention (MDHA): The search found that adding a simple 3x1 depthwise convolution after the Query, Key, and Value projections in self-attention provides a major boost. This effectively allows the attention mechanism to consider local spatial context before performing the global attention operation.
  • Efficiency Scales with Size: One of the most promising findings is that Primer’s advantages over the standard Transformer actually increase as the models get larger. The compute savings follow a power law, meaning the bigger the model, the more compute you save by switching to Primer.
  • "Primer-EZ": The authors identified that the bulk of the gains come from just the Squared ReLU and the MDHA. They call this simplified version "Primer-EZ," suggesting it as an easy "drop-in" replacement for existing codebases.

Key Results

  • 4.2x Speedup at Scale: In a 500M parameter T5 configuration on the C4 dataset, Primer reached the same quality as the T5 baseline using 4.2x less compute.
  • GPT-3 Scale Gains: At a 1.9B parameter scale (similar to GPT-3 XL), Primer achieved the same one-shot performance as a standard Transformer using only 1/3 of the training compute.
  • Robustness: The improvements were consistent across different hardware (TPUv2, v3, v4, and V100 GPUs) and different codebases (Tensor2Tensor, T5, and Lingvo).

Limitations and Future Work

  • Decoder-Centric: The study focused almost exclusively on auto-regressive, decoder-only models. When testing on encoder-decoder models (like the original T5), the gains were less dramatic, performing similarly to the already-optimized "Transformer++" baseline.
  • Search Bias: While the search space was "low-level," the search was initialized with a Transformer. This means the discovered "Primer" is an evolution of the Transformer, not a completely new paradigm.
  • Future Directions: The authors suggest that further investment in simple changes to activation functions and local spatial operations could yield even more efficient architectures, potentially moving beyond the "Squared ReLU" discovered here.

Summary updated

BibTeX
@inproceedings{so2021searching,
  author = {David So and Wojciech Mańke and Hanxiao Liu and Zihang Dai and Noam Shazeer and Quoc V Le},
  title = {{Searching for Efficient Transformers for Language Modeling}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=bzpkxS_JVsI},
}
Figure