Gated linear unit

Also known as: GLU

On this page 7

A gated linear unit (GLU) is a neural network building block that computes two linear projections of the same input and multiplies them element by element, with one projection passed through a gating nonlinearity. In neural networks, the gate decides how much of each feature passes through, giving the layer a data-dependent, multiplicative form of control that a plain activation function such as ReLU does not provide.

The GLU was introduced in 2016 for gated convolutional language models, and its variants later became the standard feed-forward design in large transformers. Today the SwiGLU form appears in many leading open-weight language models, which makes the gated linear unit one of the most consequential small design choices in modern artificial intelligence.

How a gated linear unit transforms its input

A gated linear unit computes GLU(x) = (xW + b) multiplied element-wise by sigma(xV + c), where W and V are separate weight matrices and sigma is the sigmoid function. The first term is the value path, a linear projection that carries content; the second is the gate path, which produces numbers between 0 and 1 that scale each value.

Because the value path stays linear, gradients can flow through it without being squashed by a saturating nonlinearity. The original authors argued that this linear path reduces the vanishing gradient problem compared with the tanh-based gates used in LSTM cells, while the sigmoid gate still provides the nonlinearity needed for expressive power.

PartComputationFunction
Value projectionxW + bCarries candidate features
Gate projectionxV + cScores the relevance of each feature
Gate activationSigmoid, Swish, GELU or noneMaps scores to a scaling range
Element-wise productValue times activated gateLets the input control its own flow
Parts of a gated linear unit

In convolutional and recurrent settings, the gate resembles the gates of an LSTM or gated recurrent unit, but a GLU has no memory cell or recurrence. It is a stateless, position-wise operation, which makes it easy to parallelize on modern accelerators.

GLU variants and their gate functions

GLU variants differ only in the activation applied to the gate path, yet those differences produce measurable changes in training quality. A 2020 study systematically replaced the standard transformer feed-forward network with these variants and found that gated versions consistently lowered perplexity at matched compute.

VariantGate activationTypical use
GLUSigmoidGated convolutional language models
BilinearNone (identity)Research baseline, purely multiplicative
ReGLUReLUEarly transformer experiments
GEGLUGELUSeveral encoder and vision models
SwiGLUSwish (SiLU)Most modern large language models
Common GLU variants

SwiGLU dominates current practice because the smooth Swish gate allows small negative values and gives well-behaved gradients. No complete theoretical explanation exists for why it outperforms the others; the evidence is mainly empirical, and the gaps between GEGLU and SwiGLU are often small.

GLU in transformer feed-forward blocks

In a transformer, the GLU replaces the first layer of the position-wise feed-forward network. A standard block expands the hidden size with one matrix, applies ReLU or GELU and projects back down; a GLU block uses three matrices: gate, value (often called up) and down projection.

To keep the parameter count equal to a standard block with a 4x expansion, designers reduce the intermediate width to about two thirds of 4d, roughly 2.67 times the model width. Implementations then round this value to a multiple of 64, 128 or 256 for efficient hardware use.

PropertyStandard blockGLU block
Weight matrices2 (up, down)3 (gate, up, down)
Intermediate widthAbout 4dAbout 2.67d at equal parameters
NonlinearityReLU or GELU on one pathActivated gate times linear value
Quality at equal computeBaselineUsually lower perplexity
Kernel complexitySimpleExtra multiply, often fused
Standard feed-forward block versus GLU block

In mixture of experts architectures, each expert is usually a small SwiGLU feed-forward block, so the same design scales from dense to sparse models without change.

Implementing a gated linear unit efficiently

Efficient implementation centers on merging the gate and value projections into one matrix multiplication. Frameworks concatenate W and V into a single weight of width 2h, run one GEMM, then split the output into two halves before applying the activation and product.

  • Fuse the activation and multiplication into one kernel to avoid writing the intermediate tensor to memory.
  • Choose an intermediate width that is a multiple of the hardware tile size to keep accelerators fully utilized.
  • Keep the gate computation in higher precision when training in low-precision formats, because large gate values can overflow.
  • Initialize gate and value weights with standard schemes such as Xavier or He initialization, scaled for the fan-in.
  • Track activation statistics; outlier channels in the product can complicate later quantization.

The final down projection is unchanged, so residual connections and normalization layers such as RMSNorm work exactly as in a standard transformer block.

Trade-offs and common misconceptions

The main trade-off of the gated linear unit is better quality per parameter at the cost of slightly more complex kernels and memory traffic. At equal parameter counts the compute is similar, but the third matrix and the extra product add overhead that matters at inference scale.

MisconceptionReality
GLU is an activation functionIt is a layer with its own weights
GLU adds parameters for freeWidth is reduced to match parameter budgets
The gate must use a sigmoidAny activation works; Swish is most common
GLU and GRU are the sameGRU is recurrent; GLU is stateless
Misconceptions about gated linear units

Another subtle issue is that the multiplicative product can produce very large activations in a few channels. These outliers are harmless in full precision but make post-training quantization harder, so quantization methods for SwiGLU models often treat the down projection input with special care.

Understanding it simply

Think of a gated linear unit as a mixing desk with a fader on every channel. One part of the layer produces the sound on each channel. Another part decides how far to push each fader up or down.

Both parts look at the same input. So the input itself decides which features get through and which stay quiet. This simple trick makes neural networks learn better. That is why almost every large language model uses some version of it today.

Applied in practice

A team training a 1.3-billion-parameter language model compares two otherwise identical transformer designs. The baseline uses a GELU feed-forward block with a model width of 2048 and an intermediate width of 8192. The alternative uses a SwiGLU block with an intermediate width of 5632, which keeps the parameter count nearly identical.

Both models train on the same 100 billion tokens with the same learning rate schedule. The SwiGLU model reaches the baseline’s final validation loss about 10 to 15 percent earlier in training and ends with slightly lower perplexity. Throughput drops by a few percent until the engineers fuse the gate activation and product into one kernel, after which the difference becomes negligible. The team adopts SwiGLU as the default for all later model sizes.