Paper commentary
GLU Variants Improve Transformer
Gated linear unit variants give Transformers better pre-training quality than ReLU
- 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
- What we show
- Paper info and commentary
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}
}