How does a SwiGLU feed-forward layer differ from a standard two-layer MLP?

Last updated 22 November 2026

  • A standard MLP is two linear layers with a pointwise nonlinearity (d → 4d → d with ReLU). SwiGLU uses three matrices (gate, up, down): W2 · (SiLU(W1 x) ⊙ W3 x).

  • The SiLU gate branch scales the up branch elementwise. This adds multiplicative feature interactions and smoother gradients than ReLU's hard cutoff.

  • The hidden size shrinks to about 8/3·d to keep parameters and FLOPs equal. At matched compute it gives lower perplexity (an empirical gain, not a theoretical one).

  • https://www.ultralytics.com/glossary/swiglu
  • https://dev.to/mshojaei77/swiglu-the-ffn-upgrade-i-use-to-get-free-performance-33jc
  • https://github.com/raiyanyahya/how-to-train-your-gpt/blob/master/explanations%20and%20examples%20WIP/swiglu.md
All Transformers interview questions