GLU Variants Improve Transformer

The paper showed that replacing the standard Transformer feed-forward activation with gated linear unit variants can improve model quality.

Metadata

FieldValue
PaperGLU Variants Improve Transformer
AuthorNoam Shazeer
Year2020
VenuearXiv preprint
arXiv2002.05202
Related GLU paperLanguage Modeling with Gated Convolutional Networks
Statusfull note started

One-Line Takeaway

The paper turns the Transformer feed-forward network from a simple two-layer MLP into a gated token-wise block, making GLU-style FFNs a reusable architecture component for modern language models.

Question

Attention Is All You Need alternates multi-head attention with a position-wise feed-forward network:

The usual reading focuses on attention, but a large fraction of Transformer parameters and compute is inside the FFN. The paper asks:

More concretely:

Main Claim

The paper tests several GLU variants inside Transformer feed-forward sublayers and finds that some gated variants improve quality over standard ReLU or GELU FFNs.

The durable architecture claim is:

This matters because later decoder-only models often use SwiGLU-style FFNs as part of their default block recipe, including LLaMA-style models.

Architecture Contract

ItemContract
Inputtoken representation
Outputtoken representation in
Position mixingnone; applied independently per token
Channel mixingyes, through linear projections and gating
Main operationelementwise product between value and gate paths
Main replacementFFN activation and first projection
Attention changenone
Common modern formSwiGLU FFN

For a token matrix:

the FFN maps each row independently:

This is why the block is “position-wise.” It changes each token’s feature vector after attention has already mixed information across tokens.

Standard Transformer FFN

The original Transformer FFN can be written as:

Later Transformer variants often use GELU:

The shape contract is usually:

If , then the FFN has roughly:

projection parameters per block, ignoring biases. This is a major part of the model.

GLU Form

The original GLU idea from gated convolutional language models uses two linear projections:

Here:

  • produces a gate pre-activation;
  • maps the gate into a soft on/off range;
  • produces the value stream;
  • is elementwise multiplication.

The key difference from a normal activation is that the block has two learned paths:

The gate can suppress or pass features in a data-dependent way.

GLU Variants

Shazeer tests variants that replace the sigmoid gate with other nonlinearities. A bias-free notation is:

with:

The FFN form then applies an output projection:

Parameter-Matched Reading

A gated FFN has two input projections before the output projection:

Approximate parameter count:

A standard two-layer FFN with width has:

To keep parameter count similar:

so:

This is why many gated FFNs use a smaller hidden width than a standard FFN. Without this adjustment, a gated FFN can look better simply because it has more parameters.

Block View

Inside a pre-norm Transformer block:

The paper only changes the second residual branch:

Attention, positional encoding, and the residual interface remain the same.

Why Gating Helps

A normal activation transforms features independently:

A gated FFN creates a multiplicative interaction:

This lets one projected feature modulate another projected feature. In architecture terms:

MechanismWhat It Adds
activationnonlinear feature transform
gatedata-dependent feature selection
value streamlinear path that carries content
output projectionmixes gated hidden features back into model dimension

The gate is local to a token’s feature vector. It is not attention, routing, or memory by itself.

Evidence to Read

The paper compares variants in Transformer sequence-to-sequence models.

ClaimEvidence TypeWhat It SupportsCaveat
GLU variants can beat ReLU/GELUTransformer FFN ablationFFN activation choice mattersmodel/task scale is narrower than modern LLM pretraining
GEGLU and SwiGLU are strong variantsvariant comparisonsmoother gated activations are usefullater adoption depends on recipe and parameter matching
FFN design is not a minor detailreplacing only FFN sublayer changes qualitytoken-wise MLP block is a core architecture componentgains can be confounded by hidden width and parameter budget
GLU transfers from convolutional LM ideaslink to original GLU workmultiplicative feature gating is reusableoriginal context was gated convolution, not Transformer FFN

The main lesson is not “always use SwiGLU.” It is that the FFN should be read as an architectural block with its own design space.

Relation to Other Architecture Notes

PaperSimilarityDifference
Attention Is All You Needdefines the Transformer block with position-wise FFNuses ReLU-style FFN rather than GLU variants
LLaMAuses SwiGLU-style gated FFNs in a modern decoder-only recipeLLaMA combines SwiGLU with RMSNorm, RoPE, data, and scaling choices
Root Mean Square Layer Normalizationsmall repeated block in modern TransformersRMSNorm normalizes scale; SwiGLU changes token-wise channel mixing
Switch Transformerchanges FFN computationSwitch routes tokens to sparse experts; GLU variants modify the dense expert block
T5sequence-to-sequence Transformer contextT5 is a full text-to-text recipe, not a GLU-only paper

LLaMA-Style FFN

Many modern decoder-only models use a form close to:

This is often described as SwiGLU, with naming conventions varying by implementation:

Name in codeRole
gate_projproduces gate pre-activation
up_projproduces value stream
down_projprojects gated hidden features back to
intermediate_sizegated hidden width

When reading a model architecture table, “SwiGLU FFN” is not a decorative detail. It changes parameter count, activation statistics, and kernel shape.

Limitations

  • The original paper is short and focused on sequence-to-sequence Transformer experiments.
  • It does not by itself prove SwiGLU is optimal for every model size, dataset, or modality.
  • Gated FFNs can increase parameter count unless hidden width is adjusted.
  • Runtime can depend on kernel fusion, memory bandwidth, and implementation layout.
  • In modern LLMs, SwiGLU gains are entangled with RMSNorm, RoPE, data scale, optimizer settings, and training compute.

Common Misreadings

MisreadingBetter Reading
SwiGLU is just an activation functionit is a gated FFN block with multiple projections
the paper changes attentionit changes the position-wise FFN sublayer
GLU variants are freethey change parameter count and compute unless width is adjusted
LLaMA is good because of SwiGLU aloneSwiGLU is one part of a broader recipe
FFNs are secondary to attentionFFNs hold a large part of Transformer parameters and compute

What to Remember

The core equation:

The core reading rule:

The FFN activation, gating structure, hidden width, and output projection are architecture decisions.