The Transformer

Layer 1 · Intuition

The Transformer

How attention, an MLP, residual connections, and normalization combine into 'the block' that every LLM is just a stack of.

6 min read40 XP

Listen to this lesson

Podcast-style walkthrough · ~6 min

No recording yet · generated on first play

One transformer block: attention sublayer, then MLP sublayer, each wrapped in a residual connection.

Attention (previous star) answers one question: *which other tokens matter to me, and how should I blend their information in?* But attention alone, stacked, is just repeated weighted averaging — it needs a partner that can do genuine per-token computation, and needs plumbing that lets very deep stacks of both actually train. The transformer block is that complete, self-contained unit: attention, a small per-token neural network, and the wiring that makes stacking dozens of them possible.

The four ingredients

Attention

tokens exchange information

MLP

per-token nonlinear processing

Residual connections

let information and gradients skip through

Normalization

keeps activations numerically stable

Every frontier LLM's architecture is these four ingredients, arranged and repeated.

The MLP (sometimes called the feed-forward network) is deliberately simple: expand each token's vector to a wider dimension, apply a nonlinearity, then project back down. It has no notion of other tokens at all — it's the same function applied independently, in parallel, to every position. This is where most of a model's raw capacity to store and recombine facts actually lives; attention only decides what information *flows*, the MLP is where it gets *transformed*.

Residual connections: why depth doesn't break training

Instead of a sublayer's output replacing its input, the input is simply *added back*: output = input + sublayer(input). This residual, or 'skip', connection means gradients during backpropagation always have a direct, unobstructed path all the way back to the very first layer, alongside whatever path runs through all the intervening sublayers. Without residuals, stacking more than a handful of layers reliably makes training unstable or impossible — this single addition is what made genuinely deep networks trainable at all.

Normalization: keeping the notepad legible

As a residual stream accumulates contributions from dozens of blocks, its scale can drift wildly. Normalization (LayerNorm historically, RMSNorm in most current models) rescales activations back to a consistent range before each sublayer processes them, which keeps training numerically stable across very deep stacks.

Stacking: depth is just repetition

Block 32

attention + MLP

Block 31

attention + MLP

identical structure, different learned weights

Block 2

attention + MLP

Block 1

attention + MLP

Token + position embeddings

input

A 32-layer model is the exact same block, structurally, repeated 32 times with independent weights.

"GPT-4 has more layers than GPT-2" is a statement about depth, not about a fundamentally different architecture — the block itself has barely changed since 2018. Nearly all of the visible progress in frontier LLM architecture is scale (more layers, wider layers, more data, more compute) layered onto small, well-understood refinements (better normalization placement, better position encodings, better attention variants) rather than a wholesale redesign.

Check your understanding

4 questions · answer all to submit

  1. 1.In a transformer block, what is the key structural difference between the attention sublayer and the MLP sublayer?

  2. 2.What problem do residual connections primarily solve in deep transformer stacks?

  3. 3.Why is a 32-layer transformer often described as 'the same block repeated 32 times'?

  4. 4.Which claim best characterizes the difference between GPT-2 and much larger, more recent decoder-only models?