insideout Get Pro

08 · Norm, attention, MLP, residual

Pro

Transformers, lesson 8

Norm, attention, MLP, residual

The four parts of one transformer block, and why each is there.

You need "Heads in parallel" (multi-head attention) and the layers of neurons from "Stacking neurons into layers".

Part 1. Attention gathers, the MLP works alone

After attention, the vector for "it" holds information pulled in from "animal" and "because". Gathering is all attention does. Turning what was gathered into something useful is the job of a second, plainer part of the block.

That part is a small two-layer network, like the ones in "Stacking neurons into layers". In GPT-2 small it widens each token's 768 numbers to 3,072, applies a bend (GELU, a smooth cousin of ReLU), and narrows back to 768. Every token goes through the same weights, one at a time.

Your turn

Can this two-layer network move information from token 2 into token 5?

It's applied to each position on its own, with no step that reads other positions. In a transformer, attention is the only place tokens exchange information. This part works on whatever each token has already collected.

MLP

The per-token two-layer network inside each block, short for multilayer perceptron. Papers also call it the feed-forward network, or FFN. It holds most of a block's weights: in GPT-2 small, 2 × 768 × 3,072 ≈ 4.7 million, against about 2.4 million for attention.

Studies that probe trained models (Geva et al., 2021, for one) suggest many stored facts, like which city a landmark is in, live largely in these MLP weights. Attention fetches the right context. The MLP reacts to it.

Part 2. Add, don't replace

Keep going with Pro

You've done the first part. Pro opens the rest of this lesson, and every other one.

Still to come
  1. Add, don't replace
  2. Layer norm keeps the scale steady
  3. The block, stacked

Transformers overviewSpotted a mistake? Tell us.