# GLU Variants Improve Transformer

Gated linear unit variants give Transformers better pre-training quality than ReLU

Noam Shazeer · arXiv · 2020-2-12

- **Problem** Swapping the Transformer feed-forward ReLU for GELU or Swish barely changed pre-training perplexity at short training lengths. Researchers had not tested the gated linear unit variants in that same sublayer.
- **Method** GLU variants swap the feed-forward sublayer's first map for a gated product.
- **Results** After 524,288 steps, GEGLU reaches 1.633 log-perplexity against 1.677 for the ReLU baseline. The gated variants also score higher on GLUE and SuperGLUE, with no single variant leading on all three measures.

## Where the Transformer feed-forward layer stands

Each Transformer block pairs attention with a position-wise feed-forward sublayer, which the paper calls the FFN. The FFN takes the hidden vector x at one position and passes it through two learned linear maps, W1 and W2, with bias vectors b1 and b2. In the original form, a rectified-linear (ReLU) activation sits between the two linear maps.

Following the T5 codebase, the paper drops the biases, so the baseline becomes FFN\_ReLU(x, W1, W2) = max(xW1, 0)W2.

Because the ReLU sits between the two matrices, the first map and the activation are the parts a variant can change. Subsequent work replaced the ReLU with GELU, defined as xΦ(x), and with Swish, defined as xσ(βx). Dauphin et al. introduced Gated Linear Units, where one sigmoid-activated linear map multiplies componentwise with a second linear map.

The same authors also suggest omitting the activation, which gives a bilinear layer.

At 65,536 steps, FFN\_ReLU has a heldout log-perplexity of 1.997 with an inter-run standard deviation of 0.005. In the same setting, FFN\_GELU scored 1.983 and FFN\_Swish scored 1.994. The GELU and Swish swaps therefore buy little at this short training length. At 524,288 steps, FFN\_GELU reached 1.679. FFN\_Swish reached 1.683, against 1.677 for FFN\_ReLU.

The encoder and decoder each have 12 layers with d\_model of 768. The baseline FFN uses a hidden size d\_ff of 3072. Pre-training runs for 524,288 steps on the span-filling objective over C4, with no dropout. Each batch holds 128 examples, with 512 input tokens and 114 output tokens.

## Gating the first linear map

A GLU gates one linear branch with the other, unit by unit, instead of passing a single branch through an activation. Dauphin et al. defined it as a sigmoid applied to one projection, multiplied elementwise with a second projection. GLU(x, W, V, b, c) = σ(xW + b) ⊗ (xV + c) Dropping the sigmoid gives the bilinear layer, which Dauphin et al.

attribute to Mnih and Hinton.

The authors swap the sigmoid for other activations, producing ReGLU, GEGLU and SwiGLU. They place these variants in the FFN in place of the first linear map and its activation, and keep the second map. The GEGLU version reads FFN\_GEGLU(x, W, V, W2) = (GELU(xW) ⊗ xV)W2, with no bias terms. Each gated layer has three weight matrices, where the original FFN has two.

The study follows the T5 codebase and drops bias terms, so the baseline is FFN\_ReLU(x, W1, W2) = max(xW1, 0)W2. To keep parameters and computation constant, the hidden width d\_ff drops by a factor of 2/3 for the three-matrix layers. The reduction applies to the second dimension of W and V and to the first dimension of W2. In the T5 base setup, the baseline FFN\_ReLU uses a hidden width of 3072.

The GLU-variant layers use 2048 instead, which keeps parameter and operation counts matched. The encoder and decoder each have 12 layers, with d\_model set to 768 in the T5 base setup.

## Pre-training perplexity on C4

The pre-training run uses the span-filling objective on C4, which asks the model to predict text segments deleted from its input. Each batch holds 128 examples, and each example has 512 input tokens and an output of 114 tokens. The authors train for 524,288 steps, the same length as the T5 setup they follow. Unlike T5, they don't use dropout during pre-training, because they found that this gave superior results.

Adafactor drives the optimization, with an inverse-square-root schedule and a linear decay over the final 10 percent of steps.

The gated variants keep the parameter and operation count of the base model by shrinking the hidden size to 2048. Each gated layer has three weight matrices, instead of the two in the original FFN, so the width has to shrink. The authors score log-perplexity on the training objective over a heldout shard of C4, which they treat as a good indicator of model quality.

After 524,288 steps, FFN\_GEGLU reaches 1.633 and FFN\_SwiGLU reaches 1.636. Both sit below the FFN\_ReLU baseline, which reaches 1.677 at the same length. FFN\_GLU at 1.663 and FFN\_Bilinear at 1.648 also beat the baseline. FFN\_GELU at 1.679 and FFN\_Swish at 1.683 come out worse than the baseline.

For each architecture, the authors trained four models for a shorter period of 65,536 steps to measure inter-run variability. At that length, FFN\_GEGLU scores 1.942 (0.004) and FFN\_SwiGLU scores 1.944 (0.010). Both are compared to 1.997 (0.005) for FFN\_ReLU in the same table. The gap is larger than the parenthetical variability values. These runs stop well short of the 524,288 steps used for the full comparison.

## Fine-tuning on GLUE and SuperGLUE

Each finished model gets one fine-tuning pass over a mixture weighted by example count, covering SQuAD, GLUE and SuperGLUE. Dropout at rate 0.1 covers each layer's outputs, the feed-forward hidden units, and the attention weights. Unlike T5, which fine-tuned each task separately, the authors chose one fine-tuning run for simplicity.

The authors report the best score of any checkpoint saved during fine-tuning, and they call the results noisy. On GLUE, FFN\_ReGLU has the highest development average at 84.67. That compares to 83.80 for FFN\_ReLU and 84.12 for FFN\_GEGLU.

On SuperGLUE, FFN\_SwiGLU has the highest development average at 74.56. That compares to 72.76 for FFN\_ReLU. On the WiC column, FFN\_SwiGLU scores 85.20, against 83.39 for FFN\_ReLU.

On heldout perplexity at 524,288 steps, FFN\_GEGLU reaches 1.633 and FFN\_SwiGLU reaches 1.636. No single variant leads on all three measures. GEGLU and SwiGLU lead perplexity, ReGLU leads GLUE, and SwiGLU leads SuperGLUE. The authors attribute the weaker T5 results to the dropout that T5 used during pre-training.

## Limitations

The authors offer no explanation of why the GLU-variant architectures work, and they attribute their success to divine benevolence in the conclusions. Fine-tuning used one run per model, and the authors describe the development scores as noisy.

The T5 gap is tied to pre-training dropout by the authors' belief, and the paper runs no dropout comparison of its own. All experiments use the 12-layer, d\_model 768 model with the C4 span-filling objective, and scores come from development sets only.

## Paper info

- **Authors**: Noam Shazeer
- **Venue**: arXiv · Preprint
- **First published**: 2020-2-12
- **Added**: 2026-10-18
- **Updated**: 2020-2-12
- **Version**: v1
- **arXiv**: 2002.05202
- **Category**: cs.LG · cs.NE · stat.ML
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2002.05202v1) · [PDF ↗](https://arxiv.org/pdf/2002.05202v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Noam Shazeer (2020). GLU Variants Improve Transformer. arXiv:2002.05202v1. https://arxiv.org/abs/2002.05202v1

**BibTeX**

```
@misc{shazeer2020variants,
  title = {{GLU Variants Improve Transformer}},
  author = {Noam Shazeer},
  year = {2020},
  eprint = {2002.05202},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2002.05202v1}
}
```

## Related papers

- [GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding](https://refivu.com/en/papers/2481fdbe-b100-433d-877a-6976f982ccaa-gshard-scaling-giant-models-with-conditional-computation-and.md)
- [Convolutional Sequence to Sequence Learning](https://refivu.com/en/papers/48e91a54-308d-4269-9616-28e683053df1-convolutional-sequence-to-sequence-learning.md)
- [End-to-End Object Detection with Transformers](https://refivu.com/en/papers/8dd88d07-a896-4e8b-812e-b56f620aeed0-end-to-end-object-detection-with-transformers.md)
- [Temporal Fusion Transformers for Interpretable Multi-horizon Time Series Forecasting](https://refivu.com/en/papers/cb8f01c7-c9ff-43ea-879b-8d0eb97a6e96-temporal-fusion-transformers-for-interpretable-multi-horizon.md)
- [Attention Is All You Need](https://refivu.com/en/papers/9645c9a1-cc92-404a-bc65-1ec437b1deab-attention-is-all-you-need.md)
- [SQuAD: 100,000+ Questions for Machine Comprehension of Text](https://refivu.com/en/papers/b88d7f5b-b008-4a74-a452-4513427bbf9f-squad-100-000-questions-for-machine-comprehension-of.md)

## Other paper commentary

- [Understanding the Parameter Space Volume of Transformers Encoding Boolean Functions](https://refivu.com/en/papers/f4dbf6ce-3357-44a3-b4ed-38147e384f67-understanding-the-parameter-space-volume-of-transformers.md)
- [Variationally correct physics-informed operator learning for nonlinear partial differential equations](https://refivu.com/en/papers/cf8b9cd8-5f0b-470f-b5a1-a84a0d686de9-variationally-correct-physics-informed-operator-learning-for.md)
- [Halting in Recurrent Sequence Models](https://refivu.com/en/papers/3e3e9dd0-e1c9-4bd6-9f74-6401fab7fbfb-halting-in-recurrent-sequence-models.md)
- [Shortcut Learning in Feature-Based Algorithm Selection](https://refivu.com/en/papers/aa7e77ed-0585-4907-95a2-a75a2656749e-shortcut-learning-in-feature-based-algorithm-selection.md)
- [Multi-Branch Transformer](https://refivu.com/en/papers/41db7368-f02a-4b93-a29d-688fd514713c-multi-branch-transformer.md)
- [Synthetic Neurosymbolic Task Generation with Controlled Constraint Complexity](https://refivu.com/en/papers/ebe4fa7e-eeaf-4ae2-b493-81d2f69199e5-synthetic-neurosymbolic-task-generation-with-controlled.md)
- [HyperCLOVA X THINK Technical Report](https://refivu.com/en/papers/65985bb3-f3b5-458a-83af-6011ecf92927-hyperclova-x-think-technical-report.md)
- [Instance Normalization: The Missing Ingredient for Fast Stylization](https://refivu.com/en/papers/d30fae5e-d1ad-4ef1-9b41-da9a7a9f25cf-instance-normalization-the-missing-ingredient-for-fast.md)
- [Group Normalization](https://refivu.com/en/papers/73ea525c-b90c-43b2-b656-bb21666ab914-group-normalization.md)
- [Layer Normalization](https://refivu.com/en/papers/2f67f179-7720-4b69-8cac-e7157bee38ae-layer-normalization.md)
- [Root Mean Square Layer Normalization](https://refivu.com/en/papers/97c61522-5940-4a28-ad7d-4126a3ce8c01-root-mean-square-layer-normalization.md)
- [LoRA: Low-Rank Adaptation of Large Language Models](https://refivu.com/en/papers/fec4f8e4-2771-4948-a986-0295db47b321-lora-low-rank-adaptation-of-large-language-models.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [ReLU](https://refivu.com/en/terms/7b22f5612f6c-relu)
- [C4](https://refivu.com/en/terms/87725552ed79-c4)
- [SQuAD](https://refivu.com/en/terms/097ea97dc6b6-squad)
- [SwiGLU](https://refivu.com/en/terms/9b64288c190e-swiglu)
- [Adafactor](https://refivu.com/en/terms/b0f03894f97e-adafactor)
- [GELU](https://refivu.com/en/terms/8897c492bcfe-gelu)
- [GEGLU](https://refivu.com/en/terms/9d6ee5d4da52-geglu)
- [Swish](https://refivu.com/en/terms/74b3cc4b1961-swish)
- [denoising objective](https://refivu.com/en/terms/19b80c0be4c2-denoising-objective)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/c3dee4d7-2b9f-4de8-91c8-a9f401792e6d-glu-variants-improve-transformer)
