The whole thing, as four lines
- : multi-head self-attention.
- : the position-wise feed-forward network.
- : layer normalisation.
That is a modern pre-norm block in its entirety. Everything else in a large language model is this, repeated.
The two sublayers do different jobs
Attention mixes information between positions and does almost nothing to each position on its own.
The feed-forward layer transforms each position on its own and mixes nothing between them.
Neither can do the other's job, and a block is exactly one of each.
Attention works across positions, and the feed-forward network works within one.
What each wrapper is for
Every sublayer is wrapped in a residual connection and a normalisation, and both are load-bearing.
The residual gives the gradient a path with an identity in it, which is what lets the stack be 80 layers deep instead of 12.
The normalisation keeps the scale of the activations stable as they pass through those additions, which would otherwise grow without bound down the stack.
The parameter count for one block
Attention contributes four squared, the feed-forward layer eight.
At that is about 200 million parameters per block, and a 70B model is roughly 80 such blocks plus embeddings.
That approximation is accurate to within a few percent for most decoder-only models, and it is worth being able to do in your head.
One block, in order
- Normalise the input.
- Run multi-head self-attention over it.
- Add the original input back.
- Normalise that result.
- Run the feed-forward network and add again.
What changes between models
Very little. The activation function, whether normalisation is pre or post, whether the feed-forward layer is gated, how positions are encoded, and how many key-value heads are shared.
The shape above has been stable since 2017, and almost all of the improvement since has come from scale, data and training procedure rather than from the block.