What is SwiGLU (Swish-Gated Linear Unit)?
SwiGLU (Swish-Gated Linear Unit) is a gated activation structure used in transformer feed-forward layers, combining two separate linear projections of the input by passing one through the Swish function and multiplying it element-wise with the other.
Unlike single-input activation functions such as Rectified Linear Unit, which zeroes negative values of one projection, SwiGLU uses one projection to decide how much of each component of the other passes. The feed-forward layer therefore has three weight matrices instead of two.
- Topic
- Machine learning, models and training
- Also known as
- GLU variant
- Origin
- Shazeer, 2020
How SwiGLU (Swish-Gated Linear Unit) works
- The input is mapped to two vectors with two separate weight matrices.
- The first passes through Swish (usually SiLU), which multiplies the input by its own sigmoid.
- The result is multiplied element-wise with the second vector and projected back to model size by a third matrix.
- To keep parameter count, the hidden size is reduced; one model family cuts it to two thirds of the standard size.
In more detail
Activation outliers in quantisation
Because SwiGLU multiplies two linear projections, the values entering the block's final projection can occasionally show very large activations. These outliers can amplify error in FP8 or INT8 schemes that also quantise activations and in low-precision training, so calibration measures such as smoothing scales or keeping these layers at higher precision are used.
Its place in mixture-of-experts models
Beyond dense models such as LLaMA, Qwen and Mistral, SwiGLU is also the feed-forward structure inside each expert of sparse mixture-of-experts models such as Mixtral and DeepSeek-V3, where every expert is in effect a small SwiGLU block.
Commonly confused terms
| Term | How it differs |
|---|---|
| SiLU (Swish) | SiLU, Swish with beta set to 1, is a single-input activation that multiplies each component of one vector by its own sigmoid, whereas SwiGLU is a gated two-branch feed-forward block that multiplies a SiLU branch element-wise by a second linear branch. |
| GeGLU | GeGLU is the sibling variant tested in the same Shazeer (2020) paper and keeps the three-matrix gated structure; it differs from SwiGLU by using GELU instead of Swish in the gate. Gemma models use this variant. |
| GLU (gated linear unit) | GLU, proposed by Dauphin et al. (2017), is the original form with a plain sigmoid gate; SwiGLU replaces the sigmoid with Swish, which improved language modelling quality in Shazeer's experiments. |
Why SwiGLU (Swish-Gated Linear Unit) matters for on-premises AI
The study testing gated linear unit variants in the transformer feed-forward layer showed that some improve quality over the common ReLU and GELU activations; SwiGLU is now used in many open-weight model families. For in-house operators it matters practically: the architecture affects quantisation and inference engine support and the feed-forward layer's share of memory and compute. Its three matrices need a different hidden size for the same parameter count.
Before running a new open-weight model on its in-house inference server, a software company sees in the architecture file that the feed-forward layer uses SwiGLU; it tests that its quantisation tool and inference engine support it.
Common questions
How does SwiGLU differ from ReLU?
ReLU zeroes negative values of one projection. SwiGLU uses one of two projections as a gate controlling the other component by component.
Does SwiGLU increase parameter count?
With three matrices it does at the same hidden size, so the hidden size is usually reduced to keep the count.
Related terms
- Activation function
- Rectified Linear Unit
- Transformer
- Multilayer perceptron
- Parameter count
- Decoder-only architecture
Sources
- Shazeer, GLU Variants Improve Transformer, 2020
- Touvron et al., LLaMA: Open and Efficient Foundation Language Models, 2023
In the glossary: Glossary, R to Z