Skip to content

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.

(5.1)
GELU
up-projection, typically to 4d
down-projection, back to d
(5.2)
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 .

(5.3)
gate and up, d × d_ff
down, d_ff × d
inner width, often ~ 8d/3 so parameter count matches 4d GELU
(5.4)
(5.5)

Why it mattersYou need this derivative in the backward pass. The extra σ(z)(1−σ(z)) term is the sigmoid Jacobian.