05 · C · Compute
MLP and SwiGLU
Per-token computation and the wide matrices that store features.
Two-layer GELU FFN (GPT-2)
Attention moves information between positions. The MLP is the per-token computation: feature mixing, and a large fraction of stored knowledge in the wide matrices.
- GELU
- up-projection, typically to 4d
- down-projection, back to d
- standard Gaussian CDF; Hendrycks and Gimpel, 2016
SwiGLU (Llama)
Gated linear units (Shazeer, 2020) replace the single nonlinearity with a product of a SiLU-gated branch and a linear “up” branch. There is no bias in the usual Llama formulation. The up-projection is written so it is never confused with the unembedding .
- gate and up, d × d_ff
- down, d_ff × d
- inner width, often ~ 8d/3 so parameter count matches 4d GELU
Why it mattersYou need this derivative in the backward pass. The extra σ(z)(1−σ(z)) term is the sigmoid Jacobian.