LLM & Transformer Fundamentals·Question 14 of 109Basic

What does the feed-forward network in a transformer block actually do, and why is SwiGLU the default now?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Attention moves information between positions; the FFN transforms information at each position independently. It is also where most of the parameters live, roughly two thirds of a dense transformer's weights.

Full worked answer with diagram

Attention moves information between positions; the FFN transforms information at each position independently. It is also where most of the parameters live, roughly two thirds of a dense transformer's weights.

The classic version is two linear layers with a nonlinearity between them, expanding to about 4x d_model and projecting back:

def ffn(x, W1, W2):
    return gelu(x @ W1) @ W2   # d_model -> 4*d_model -> d_model

SwiGLU replaces the single up-projection with a gated pair:

def swiglu_ffn(x, W_gate, W_up, W_down):
    return (silu(x @ W_gate) * (x @ W_up)) @ W_down

That is three matrices instead of two, so to hold the parameter count fixed you shrink the hidden dimension from ~4x d_model to ~8/3 x d_model. Llama-family models do exactly this, and it is why you see odd intermediate sizes like 11008 rather than a clean multiple of 4.

Why it won: it consistently gives lower loss at matched parameters and FLOPs. The gate makes the nonlinearity data-dependent and multiplicative, so a unit can be switched off based on the input rather than passed through a fixed pointwise curve. The GLU-variants work that popularised it is refreshingly honest that the justification is empirical rather than theoretical. GeGLU (GELU instead of SiLU as the gate activation) performs about the same; the choice is mostly convention.

A useful mental model from interpretability: treat W_gate/W_up rows as pattern detectors and W_down columns as the content those patterns write back into the residual stream, so the FFN behaves like a key-value memory.

The misconception worth killing is that the FFN is a boring MLP tacked onto the interesting part. It holds the bulk of the parameters, dominates FLOPs at short and moderate context, and it is exactly the component Mixture-of-Experts replaces, because that is where the capacity is.

Worth sketching. Three matrices meeting at a multiply: it shows immediately why the hidden dimension shrinks to keep the parameter count fixed.

flowchart LR
    X["x, d_model"] --> G["x W_gate"]
    X --> U["x W_up"]
    G --> S["SiLU"]
    S --> M["elementwise multiply:<br/>the gate can switch a unit off"]
    U --> M
    M --> D["W_down, back to d_model<br/>d_ff ~ 8/3 x d_model, not 4x"]
    D --> R["add into residual stream"]

What a good answer covers

  • Attention moves information between positions; the FFN transforms information at each position independently
  • It is also where most of the parameters live, roughly two thirds of a dense transformer's weights
  • That is three matrices instead of two, so to hold the parameter count fixed you shrink the hidden…
  • Llama-family models do exactly this, and it is why you see odd intermediate sizes like 11008 rather than…
  • Why it won: it consistently gives lower loss at matched parameters and FLOPs

Interviewer follow-ups to expect

  1. Where does the FFN stop dominating FLOPs and attention take over?

  2. Why does MoE swap out the FFN rather than attention?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep