What is the role of the feed-forward sublayer in a Transformer block?

Last updated 22 November 2026

The feed-forward sublayer is a per-token MLP applied after attention. Attention mixes information across tokens, and the FFN then transforms each token's representation nonlinearly. It holds most of the block's parameters and much of the model's stored knowledge.

  • Structure:

    • FFN(x) = W_2 · act(W_1 x + b_1) + b_2, with an inner width d_ff of about 4·d_model. The original used ReLU; later models use GELU or SwiGLU.

    • It is position-wise: the same weights apply to every token independently, with no cross-token interaction.

  • Division of labor: Attention routes information ("which tokens matter"). The FFN processes it ("what to compute from it").

  • Adds nonlinearity and capacity:

    • Attention output is a weighted average of value vectors, so it is linear in the values. Without FFNs, stacked layers would have limited expressive power.

    • The FFN accounts for roughly two-thirds of the parameters in a standard block.

  • Interpretation as key-value memory: Rows of W_1 act like keys that detect patterns, and columns of W_2 write the associated values into the residual stream (Geva et al., 2021). Factual knowledge is often localized here.

  • Modern variants:

    • SwiGLU gating (LLaMA, Mistral).

    • Mixture-of-Experts replaces the single FFN with many expert FFNs and a router, which scales parameters without scaling per-token compute.

  • https://mbrenndoerfer.com/writing/transformer-feed-forward-networks
  • https://dev.to/jackm_345442a09fb53b/llm-interview-series3-transformers-explained-attention-is-all-you-need-523o
  • https://medium.com/@huanzidage/llm-interview-series-3-transformers-explained-attention-is-all-you-need-000a17af5b75
All Transformers interview questions