SwiGLU, short for Swish-gated linear unit, is a gated activation used in the feedforward blocks of neural networks, most prominently in transformers, where it multiplies a Swish-activated projection of the input by a second linear projection before the result is projected back to the model dimension. It was proposed by Noam Shazeer in 2020 as one of several gated linear unit variants and has since become the default feedforward design in many large language models.
Its appeal is practical: at a matched parameter and compute budget, SwiGLU consistently delivers lower training loss and better downstream quality than the classic ReLU or GELU feedforward layer. The price is a slightly more complex block with three weight matrices instead of two and a hidden width that must be adjusted to keep model size constant.
How SwiGLU computes its output
SwiGLU replaces the single activation in a feedforward layer with a gate that controls information flow element by element. The input vector x is projected twice, by matrices W and V, into the hidden dimension; one projection passes through the Swish function, and the two results are multiplied element-wise before the output matrix W2 maps them back.
Written compactly, the block computes FFN(x) = W2 (Swish(xW) ⊙ xV), where ⊙ denotes element-wise multiplication. Swish, also called SiLU when its parameter β equals 1, is defined as Swish(z) = z · sigmoid(βz). In practice almost all implementations use β fixed at 1, and bias terms are usually omitted.
The table below lists the components of a standard SwiGLU feedforward block and the role each one plays.
| Component | Shape | Role |
|---|---|---|
| Gate projection W | d × h | Produces values passed through Swish |
| Up projection V | d × h | Produces the linear value path |
| Swish activation | Element-wise | Smoothly scales the gate signal |
| Element-wise product | h | Lets the gate modulate each feature |
| Down projection W2 | h × d | Returns to the model dimension |
The key mechanism is multiplicative interaction. Because the gate output multiplies the value path, the network can switch features on, off or partially on depending on the input, which gives each layer more expressive, input-dependent filtering than an additive nonlinearity alone.
Parameter budget and hidden dimension
A SwiGLU block has three weight matrices of size d × h, whereas a conventional feedforward layer has two. To compare designs fairly, practitioners shrink the hidden width by a factor of two thirds, which keeps the parameter count and the floating-point operations roughly equal.
A classic transformer uses a hidden width of 4d. SwiGLU models therefore often use a width near 8d/3, about 2.67d, rounded to a multiple of 64, 128 or 256 for efficient matrix multiplication on accelerators. Some model families deliberately choose larger ratios when they want more capacity in the feedforward path.
The following table compares the budget of a standard and a SwiGLU feedforward block for a model dimension of 4,096, ignoring biases.
| Design | Hidden width | Weight matrices | Approximate parameters |
|---|---|---|---|
| ReLU or GELU block | 16,384 | 2 | 134 million |
| SwiGLU at matched budget | about 10,923 | 3 | 134 million |
| SwiGLU with full 4d width | 16,384 | 3 | 201 million |
The matched configuration is the fair comparison, and the quality gain reported for SwiGLU holds at equal parameters, not merely because the block is larger.
SwiGLU compared with other activations and GLU variants
SwiGLU belongs to the gated linear unit family, which differs from plain activations such as ReLU and GELU by using two parallel projections. The variants differ only in the function applied to the gate, yet that choice measurably affects training quality.
| Activation | Gate function | Gated | Typical use |
|---|---|---|---|
| ReLU | None, max(0, z) | No | Original transformer, CNNs |
| GELU | None, Gaussian-weighted | No | BERT and GPT-2 era models |
| GLU | Sigmoid | Yes | Early gated convolutional models |
| ReGLU | ReLU | Yes | Research comparisons |
| GeGLU | GELU | Yes | Several encoder-decoder models |
| SwiGLU | Swish | Yes | Most modern decoder-only LLMs |
In Shazeer’s experiments, GeGLU and SwiGLU produced the best perplexity among the tested variants, with very small differences between them. SwiGLU became the more common choice after large models such as PaLM and LLaMA adopted it, and many later open-weight models followed that precedent.
No complete theoretical explanation exists for why gating helps so reliably. Common hypotheses point to smoother gradients from Swish, the ability of multiplicative gates to represent feature interactions directly, and an implicit form of per-token feature selection similar in spirit to a mixture of experts at fine granularity.
Implementation and practical considerations
Implementing SwiGLU efficiently mostly concerns memory layout and kernel fusion. Many codebases concatenate W and V into one matrix of width 2h so that a single matrix multiplication produces both paths, which are then split before the activation.
- Fused kernels compute Swish and the element-wise product in one pass, reducing memory traffic.
- Activation memory is higher than in a plain block because two hidden tensors are kept for backpropagation.
- Quantization must handle outliers in the gate path, which can be larger than in ReLU layers.
- Initialization follows standard schemes, often with a scaled down projection for deep residual stacks.
SwiGLU is usually paired with RMSNorm, rotary position embedding and pre-normalization, the combination that defines the typical modern decoder-only architecture. In mixture-of-experts models, each expert is commonly a small SwiGLU block.
Limitations and common misunderstandings
SwiGLU is a robust improvement rather than a dramatic one, and several misconceptions surround it. The table below lists the most frequent ones and the more accurate view.
| Misconception | More accurate view |
|---|---|
| SwiGLU is just Swish | It is a gated block with two input projections |
| It always adds parameters | Width is usually reduced to match budget |
| It is free at inference | It adds one matmul and more activation memory |
| It fixes training instability | Normalization and learning rate matter more |
| Gains are large | Gains are consistent but modest |
The modest size of the gain means SwiGLU is chosen because it is cheap, stable and repeatedly validated, not because it transforms model capability. For small models with tight latency budgets, a plain GELU block can remain a reasonable choice.
The idea in brief
Inside a language model, each layer has a small processing unit that transforms the signal. SwiGLU gives that unit two paths and a gate. One path carries information. The other path decides how much of it should pass.
Picture a mixing desk with one fader per channel. The signal is the music, and the gate is the hand on each fader. The hand moves differently for every song. This input-dependent volume control helps the model learn a little better at the same size.
A practical scenario
A research team is training a 1.3-billion-parameter decoder-only model on a code and text mix. The baseline uses a GELU feedforward block with a hidden width of four times the model dimension of 2,048, which is 8,192.
They switch to SwiGLU and set the hidden width to 5,632, close to 8d/3 and divisible by 256 for efficient kernels. The parameter count stays within one percent of the baseline. They also fuse the gate and up projections into one matrix multiplication to limit the speed cost.
After the same number of training tokens, the SwiGLU model reaches a measurably lower validation loss and slightly better scores on code completion tests. Training throughput drops by only a few percent. The team keeps SwiGLU as the default feedforward block for its next model generation.