It is the quiet workhorse of the transformer: while attention gets the headlines, the feed-forward block holds most of the parameters and does most of the per-token “thinking.”
Take a single token's vector
Step 1 — expand into a wider hidden layer. Multiply by a matrix that maps from
The standard choice is
Step 2 — apply the nonlinearity. Pass the hidden vector through an
Without this nonlinearity the two matrices would collapse into one — the activation is what gives the block its expressive power.
Step 3 — project back down to the model width. A second matrix brings the wide
hidden vector back to
Step 4 — read it as one expression. Composing the three steps:
Up to
Step 5 — the same network at every position. Crucially, the very same
It's tempting to assume that somewhere in a transformer block, every sublayer must be
shuffling information between token positions — after all, that is the point of a transformer. But
the feed-forward block does no such thing. It is fed one token's vector at a time, has never seen
the other positions, and simply cannot look sideways:
All cross-position mixing in a transformer happens in attention; the feed-forward block only ever transforms a token's own representation. The two sublayers are complementary by design — gather (attention), then think (feed-forward) — and conflating what each one does is a common source of confusion when first reading the architecture.
Step 6 — count the parameters. The two weight matrices dominate:
Two attention-vs-FFN facts fall out of this. Attention's projections are roughly
The division of labour is clean: attention mixes information across tokens; the feed-forward block transforms each token in place. Gather, then think.
A productive way to read the feed-forward block is as a key–value memory.
The first matrix
Modern models often replace the plain MLP with a gated variant — GeGLU or SwiGLU.
The idea is to compute two projections of the token and let one gate the other before the
down-projection, e.g.
Each token's vector is pushed up into a wider hidden layer, squashed by the ReLU, and brought back
down to the original width. Notice the hidden column is the fat one — that
Attention and the feed-forward block are the two sublayers of a transformer. Before they can be
safely stacked dozens deep, each one is wrapped in a residual connection and a normalization step —
the