SwiGLU and Gated Linear Units in Transformers are advanced activation architectures where feed-forward networks use gated mechanisms to selectively combine multiple transformation branches — achieving higher capacity per parameter than ReLU networks with 30% parameter reduction for equivalent performance.
Gated Linear Unit $(\mathrm{GLU})$ Fundamentals:
- Gate Mechanism: splitting dimension $D$ into two branches: $y = (W_{1x} \odot \sigma (W_{2x}))$ where $\odot \text{is} \text{element-wise}$ multiplication and $\sigma $ is sigmoid function
- Gating Effect: sigmoid output $\sigma (W_{2x}) \in $ [0,1] acts as soft gate selecting which dimensions from $W_{1x}$ to pass — learned dynamic routing
- Parameter Efficiency: maintaining output dimension $D$ while using $2D$ input projection ($2\times D$ parameters) vs traditional expansion $4D$
- Variant Forms: variants include Bilinear $(y = W_{1x} \odot W_{2x}), \text{Tanh-gated} (y = W_{1x} \odot \tanh(W_{2x}))$, and linear gated architectures
SwiGLU Architecture:
- Swish Activation: replacing standard sigmoid gate with Swish (SiLU): $y = (W_{1x}) \odot SiLU(W_{2x})$ where $SiLU(z) = z\cdot \operatorname{sigmoid}(z)$
- Gating Function: SiLU provides smoother gradient flow compared to sigmoid — 0.5-1.0 at zero, approaching linear for large values
- Capacity Enhancement: SwiGLU with intermediate dimension 2.67D achieves same performance as ReLU with $4D$ — 33% parameter reduction
- Empirical Validation: PaLM models using SwiGLU consistently outperform ReLU baseline by 1-2% accuracy across downstream tasks
Transformer Feed-Forward Integration:
- Traditional FFN: two linear layers with $\operatorname{ReLU}: \mathrm{FFN}(x) = \operatorname{ReLU}(W_1x)W_2$ with output dimension $d_{\text{model}}$, intermediate $4\times d_{\text{model}}$
- GLU Variant FFN: $\mathrm{GLU}(x) = (W_{1x} \odot \sigma (W_2x))W_3$ with 3 linear layers, intermediate typically $2.67\times d_{\text{model}}$ or $8/3\times d_{\text{model}}$
- Parameter Count: $SwiGLU(d) \approx 2.67 \times d \times d$ vs traditional FFN 4 $\times d \times d$ — 33% reduction while maintaining or improving performance
- Computation: SwiGLU requires 3 matrix multiplications vs 2 for ReLU — $\sim 1.5x$ compute per token despite parameter reduction
Performance Benchmarks:
- PaLM Models: $8B$ PaLM with SwiGLU matches $10B$ with ReLU on downstream tasks (SuperGLUE 90.2% vs 89.8%) — clear parameter efficiency
- Scaling Laws: SwiGLU-based models scale more efficiently with data, requiring 10-15% fewer training tokens for target performance
- Fine-tuning: SwiGLU-based models fine-tune more effectively on low-data tasks — 3-5% improvement on few-shot classification
- Downstream Transfer: consistent 1-2% improvements across MMLU, HellaSwag, TruthfulQA — holds across model scales $8B$ to $540B$
Mathematical Properties:
- Gradient Flow: SwiGLU gradient $\partial y/\partial x$ includes both multiplicative (gate) and additive (Swish) components — richer gradient signal than ReLU
- Non-linearity: SwiGLU introduces stronger non-linearity (second-order polynomial in gate component) vs ReLU (piecewise linear)
- Activation Saturation: gate output $\sigma (x)$ saturates to 0 or 1 for extreme inputs, providing regularization effect — reduces need for explicit dropout
- Inductive Bias: gating mechanism biases toward sparse activation patterns (some dimensions suppressed per-token) — aligns with lottery ticket hypothesis
Comparative Activation Functions:
- ReLU: simple, linear for positive inputs, zero for negative — foundation of deep learning but gradient-starved in sparse settings
- GELU: smooth approximation of ReLU with element-wise probability gate — better gradient flow, used in BERT and $\mathrm{GPT}-2$
- SiLU (Swish): self-gated activation $x\cdot \operatorname{sigmoid}(x)$, smooth everywhere — improves over ReLU by 1-2% in language models
- GLU Variants: bilinear, tanh-gated, linear-gated all provide gating benefits — SwiGLU empirically optimal for transformers
Implementation Details:
- Llama Models: recent Llama versions use SwiGLU gate activation with $2.67\times $ intermediate dimension — standard for frontier models
- PaLM Architecture: introduced SwiGLU and demonstrated consistent improvements across all parameter scales — influential for modern designs
- Inference Optimization: gating provides implicit sparsity (30-40% of neurons inactive per token) — enables 20-30% speedup with structured pruning
- Scaling Consideration: SwiGLU adds 50% computation per token compared to ReLU-based 4D intermediate — balanced by parameter efficiency
SwiGLU and Gated Linear Units in Transformers represent modern activation design — enabling more parameter-efficient models with improved performance through learned gating mechanisms that rival or exceed traditional feed-forward networks.