Legacy Concept Lab

SwiGLU & Gated Activations

Used in LLaMA, PaLM, and most modern LLMs—replaced ReLU in transformer FFN

Concept 67 of 100Core TrainingPhase 2
#67SwiGLUCore Training
key equation
SwiGLU(x)=(xW1SiLU(xW2))W3\text{SwiGLU}(x) = (xW_1 \cdot \text{SiLU}(xW_2)) W_3
Phase 2: Architecture fundamentalsConcept 67 of 100
Migrated:view the updated version in /domainsThis /foundations page is legacy during migration.

Why It Matters for Modern Models

  • Used in LLaMA, PaLM, and most modern LLMs—replaced ReLU in transformer FFN
  • Empirically better than ReLU/GELU at same compute budget
  • The gating mechanism adds multiplicative interactions, increasing expressiveness

What Tutorials Skip

What is still poorly explained in textbooks and papers:

  • Gates let the network learn which features to pass through, not just which to zero out
  • SwiGLU needs 50% more parameters for same hidden dim—but quality gains are worth it
  • Smooth activations (SiLU vs ReLU) may help optimization by avoiding gradient discontinuities

Interactive Visualization

Core Math (Optional Deep Dive)

If you want intuition first, start with the key equation and the visualization. Come back here for the full walkthrough.

Key Equation
SwiGLU(x)=(xW1SiLU(xW2))W3\text{SwiGLU}(x) = (xW_1 \cdot \text{SiLU}(xW_2)) W_3

Gated Linear Unit (GLU):

GLU(x)=(xW1)σ(xW2)\text{GLU}(x) = (xW_1) \odot \sigma(xW_2)

SwiGLU uses SiLU (Swish) activation:

SwiGLU(x)=(xW1SiLU(xW2))W3\text{SwiGLU}(x) = (xW_1 \cdot \text{SiLU}(xW_2)) W_3

where SiLU(x)=xσ(x)\text{SiLU}(x) = x \cdot \sigma(x).

The gating mechanism: one path produces values, another produces gates.
More expressive than ReLU at same parameter count (but uses 50% more compute).

Canonical Papers

GLU Variants Improve Transformer

Shazeer2020arXiv
Read paper →

LLaMA: Open and Efficient Foundation Language Models

Touvron et al.2023arXiv
Read paper →

Connections

Prerequisites

Next Moves

Explore this concept from different angles — like a mathematician would.