Module 4 — putting the engine in the chassis: one block, stacked many times
2 short math sidebars (residual connection · layer-norm)~25–35 min read + your own notesFree · last updated
The one-sentence version: A transformer block is one repeatable workstation — attention (mix in
context) then a feed-forward network (each word thinks on its own) — and the residual stream
is the running notebook that travels through a whole stack of these blocks, each one reading it and adding its
contribution back, until the sentence fully understands itself.
🔌 One wording note
"word" = "token." The true unit is the token — every token has its own vector, makes its own Q/K/V, and rides
the stream on its own. We say "word" only because it reads easier, and for common words 1 token = 1 word anyway.
Mentally substitute "token" throughout.
Section 0
Why we're here (from one operation to the whole stack)
Module 3 gave you the hardest piece: attention, where every word looks at the others and pulls in context.
By the end of one attention step, bank had listened to river
and updated itself.
But attention is one operation. A real model — GPT-2, GPT-4, Claude — isn't one attention step. It's
dozens of layers stacked on top of each other, run one after another. Two questions fall out of that, and this
module answers both:
What exactly is the repeatable unit that gets stacked? (The transformer block —
attention is only part of it.)
What carries the information from one layer up to the next, so 96 layers can build on each other without
losing the thread? (The residual stream — the most-referenced object in every interp
paper you'll read.)
By the end you'll be able to explain
the two workers in a block — attention vs feed-forward — and the difference · the residual stream
and why layers add instead of replace · residual connections + layer normalization · how
one full block is assembled · why stacking (depth) builds richer understanding · what
"read off / patch the residual stream" means.
Section 1
The two workers inside a block
A transformer block has two processing steps, and they do opposite kinds of work. This contrast is
the thing to lock in.
Worker 1 — Attention
You already know this one. Moves information between words — each word reaches out and blends in
what's relevant. The communication step: words talking to words.
Worker 2 — Feed-Forward (FFN / MLP)
Lets each word think about what it just gathered, on its own. Processes each word
independently — no looking at neighbors. The computation step: each word digesting privately.
Key contrast — lock this in
Attention = words talk to each other (info moves between tokens). Feed-forward = each word
thinks by itself (info processed within one token, no mixing). A block does both, in order:
gather, then digest.
What does the FFN actually do? Intuition is enough: it's a small network that takes the word's context-filled
vector, expands it, runs a non-linear step (so it can represent more complex things), and shrinks it back. This is
widely believed to be where a lot of the model's stored factual knowledge and per-word computation lives. You
don't need the matrix math to read papers — just hold: FFN = each token's private thinking step, right after
attention's group discussion.
Analogy — the assembly line
Picture a long line of identical workstations. A product rides down the belt and stops at each one. At every
station two workers touch it in order: first a discussion worker (attention) who lets this product compare
notes with the others on the line, then a specialist worker (FFN) who works on this one product alone based on
what it just learned. That pair — discussion then solo work — is one transformer block.
Section 2
The residual stream — the notebook on the conveyor belt
Here's the crucial design choice, and it's simpler than it sounds. When attention or the FFN produces an output, the
block does not throw away the word's old vector and replace it. It adds its output on top of what
was already there:
new vector = old vector+ what this step computed
That running, ever-accumulating vector — the thing that flows up through the whole stack, getting added to at every
step — is the residual stream.
Think of it as a notebook riding the conveyor belt. Each worker doesn't rewrite the notebook from scratch —
they read what's in it, write their addition in the margin, and pass it on. The notebook keeps
everything: the original word, plus every layer's contribution stacked up.
the residual stream — an information highway running the full length of the model
The residual stream is a highway running the full length of the model. Every block has an on-ramp (reads the
current traffic) and adds its own cars to the flow, but the highway never stops or resets. Information from layer 1
can ride all the way to layer 96 untouched — unless some later layer chooses to act on it.
Why add instead of replace? Two big reasons, both worth holding:
Nothing gets lost. If layer 3 needs the original word identity, it's still right there in the stream —
earlier information stays available to every later layer. Replacing would erase the past at each step.
The deep stack stays trainable. Adding creates a clean, uninterrupted path for the learning signal to
travel back down during training (backprop). Without these add-back paths, a 96-layer
model's signal would fade to nothing on the way down and the bottom layers would never learn.
📐 2-minute math — the residual connection (skip connection)
A "residual connection" is exactly the + in
output = input + f(input). The sub-layer f (attention or FFN)
computes a change, and you add that change back to its own input.
"Residual" means the sub-layer only has to learn the difference it wants to make, not
rebuild the whole vector. This single trick (from ResNets, vision, 2015 [1]) is what let neural nets get deep —
and it's why the carried-along vector is called the residual stream.
Section 3
Layer normalization — the stabilizer
There's one more part in a block, with a humble job: keep the numbers sane.
When you stack dozens of layers, each adding to the residual stream, the values can drift — some blow up huge, some
shrink tiny. That makes training unstable (the model thrashes or stalls). Layer normalization (LayerNorm)
fixes this: right before each worker does its job, it re-centers and re-scales the vector so its numbers sit
in a clean, consistent range. Then the worker operates on the tidied-up version.
Analogy — the calibration step
Before each station on the assembly line, a quick calibration straightens and standardizes the product, so
every worker operates on something predictable — no station gets handed a wildly oversized or microscopic part.
Hold the role (no formula needed)
LayerNorm = a normalize step that keeps values in a stable range so a deep stack can train without blowing up or
vanishing. It's a helper, not a thinker — it doesn't add meaning, it keeps the meaning-carrying steps stable.
Footnote you'll meet in papers: there's a debate about putting LayerNorm before each sub-layer
("pre-norm") vs after it ("post-norm"). Modern models mostly use pre-norm because it trains more stably. Same
role either way — don't get snagged on it.
Section 4
The block, assembled
Now put the pieces together. One transformer block, start to finish, operating on the residual stream:
one transformer block — seven steps:
read the residual stream (the current vector for each word)
LayerNorm → tidy the numbers
ATTENTION → each word gathers context from the others
ADD the attention output back into the stream (residual connection)
LayerNorm → tidy again
FEED-FORWARD → each word thinks on its own about what it gathered
ADD the feed-forward output back into the stream (residual connection)
pass the updated stream up to the next block
That unit is one block. Notice the rhythm: normalize → mix (attention) → add back → normalize → digest
(FFN) → add back. Gather, then think — writing both contributions into the same running notebook.
Key takeaway
A transformer block is not "attention." Attention is step 3 of 7. A block = attention +
feed-forward + the two residual add-backs + the layer-norms — the whole workstation, not just the
discussion worker.
Section 5
Stacking — why depth builds understanding
A single block is the unit. The model is that block, repeated — its own fresh weights each time:
Depth in real models
GPT-2 (small) = 12 blocks · GPT-3 = 96 blocks · big frontier models = dozens to over a hundred.(GPT-2 came in sizes; smallest 12, largest 48 — "12" is the canonical small one.)
Each block reads the residual stream the block below it produced, does its gather-then-think, and writes its
refinement back. So the stream gets progressively richer as it climbs:
early layers catch simple, local things — word identity, grammar, which word sits next to which;
middle layers assemble those into phrases, references, simple facts;
late layers hold abstract, whole-sentence meaning — who it refers to, the
sentiment, the gist, what word comes next.
input words → [block 1] → [block 2] → … → [block 96] → final vectors
│ │ │
all reading & writing the SAME residual stream, bottom to top
Analogy — the assembly line, finished
A product rolling down a 96-station line is barely shaped at station 1 and fully built by station 96 — because
each station added to what the last one did, all recorded on the same traveling notebook. Depth is why a
transformer goes from "a row of word-vectors" to "a represented thought."
Section 6
"Reading off the residual stream" — the interpretability picture
Here's the payoff that makes this module load-bearing if you go on to read alignment research.
Because every block reads from and writes to the same residual stream, that stream is a single, continuous
record of everything the model is computing — at every layer, for every token. A researcher can tap the
stream at any layer and inspect what's encoded there, or edit it and watch how the output changes.
That's exactly what these phrases (which you'll see constantly) mean:
"we read off the residual stream at layer 8" → we looked at the carried-along vector at that depth to see
what the model had figured out so far;
"we patched the residual stream" → we swapped in a different vector at some layer to test what that
information was causing (activation patching);
"the feature is written into the residual stream" → some concept (e.g. "this text is in French") shows up
as a direction in that carried vector.
“The residual stream is the model's shared workspace — every layer reads
it, every layer writes to it. Mechanistic interpretability is, in large part, the art of reading that
workspace.”
🔌 Forward hook
This idea is worth reading more about later, under the name mechanistic interpretability (as opposed to behavioral interpretability). For now the win is: when a paper
says "residual stream," you see the information highway every layer reads and writes — not a mystery term.
Section 7
The handoff to Module 5
You now hold the whole engine: text → tokens (M1) → embedding vectors (M2) → attention mixes context (M3) →
stacked blocks refine it on the residual stream (M4). After the final block, each word has a final, deeply
context-aware vector.
But the model's job was to produce a word — the next token. So one question remains: how does that final
vector become an actual chosen word?
Module 5 (Output: Logits → Softmax → Sampling) closes the machine: the final vector → a score for every word
in the vocabulary (logits) → softmax turns those into probabilities → a sampling strategy picks the
next token (and is why the same prompt can give different answers). After M5 you'll have traced one token's entire
journey, prompt in to word out.
🧠 Recap
The whole module in six lines
A transformer block has two workers: attention (words talk — info moves between tokens)
then a feed-forward network (each word thinks alone — info processed within one token). Gather,
then digest.
Layers don't replace a word's vector; they add their output to it: new = old + computed.
The running, accumulating vector is the residual stream — a notebook on a conveyor
belt every layer reads and writes.
Adding (a residual / skip connection) instead of replacing keeps early information available to all later
layers and keeps the deep stack trainable (a clean path for backprop's signal).
LayerNorm re-centers and re-scales the vector before each worker — a stabilizer that keeps a deep
stack's numbers sane. It keeps order; it doesn't add meaning.
One block = norm → attention → add back → norm → feed-forward → add back. Stack it many times (GPT-2: 12,
GPT-3: 96) — early layers catch simple patterns, late layers catch abstract meaning. Depth builds
understanding.
Because every layer reads/writes the same residual stream, interp researchers "read off" or "patch"
the residual stream to see and steer what the model computes. (Worth reading about later: mechanistic interpretability.)
✅ Now go and use it
Read it, write your own notes, then talk it through
Step 1 — talk it through. This copies a prompt with the whole module already inside it.
Paste it into any AI assistant: it asks you questions one at a time, answers the ones you wrote
down, and explains why a wrong answer was tempting. It will not test you.
Step 2 — only when you feel ready. The closed-book gate. It carries
this module's own questions and tells the assistant to score you strictly and explain what you
misunderstood. Write your own notes first — the notes are for encoding, not for shrinking the test,
and the questions cover the whole module, not just what you
wrote down.
a readb your own notesc discussd scored checke on to Module 5
Any assistant works — Claude, ChatGPT, Gemini,
an open-source model you run yourself. Free tiers are fine. You can dictate your answers instead of
typing.
Sources
Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun, Deep Residual Learning for Image Recognition, 2015 — arXiv:1512.03385. The ResNet paper: where the residual (skip) connection comes from.