The residual stream as a shared channel
Explain that every sublayer reads from and adds into one d-dimensional stream, so the final state is the embedding plus all sublayer outputs. Explain how later components can use what earlier ones wrote.
Builds on: The pre-norm transformer block, Near-orthogonality in high dimensions
What the animation says
No wire from block 3 to block 25
Block twenty-five of a thirty-two block model needs something that block three's attention figured out. But there is no wire between them. Each sublayer only sees the one vector it is handed at its position. So when block four runs, what happens to block three's result?
One shared vector everyone writes into
Block four adds. It never overwrites. Each token position owns one vector of d numbers, called the residual stream. Every sublayer reads the stream through a norm, computes, and adds its result back. So a write stays in the sum, unless a later sublayer adds its exact opposite. Any later reader at that position sees every earlier write. Here are three positions side by side. Tap the sublayer that can bring in information from another position.
Writing and reading in four numbers
Let's make it concrete, with just four numbers. The embedding starts as one, zero, zero, zero. Attention one adds two in the second slot. Then the FFN adds three in the last slot. The stream is now one, two, zero, three. A later head reads the second direction with a dot product and gets two, exactly attention one's write. Reading the first direction still gives the embedding's one. Now a later sublayer adds minus two in the second slot. Read the second direction again: what comes out?
Unrolling the additions
Zero. Adding the opposite is the only way to erase a write. Each block makes two writes: attention's output, then the FFN's output on the updated stream. Unroll all the blocks, and the final stream is the embedding, plus every attention write, plus every FFN write. A later reader applies a norm, then a matrix, like the query weights. The norm only divides by one number and applies a fixed linear map. So the read is still a sum, with one piece per earlier write.
Many writes, one space — and a check
Real streams have thousands of dimensions, and writes aren't on neat axes. Random directions in high dimensions are nearly orthogonal, so a reader picks up only about one over root d of each other write. So many writes share the same space with little crosstalk. Here's a check in NumPy. Stand-in sublayers read the normalized stream and record their writes. At the end it prints True: final equals embedding plus all writes. Tap the line that makes that true.
One shared vector everyone writes into
Unrolling the additions
Writing and reading in d = 4
Check: final state = embedding + all writes
import numpy as np
rng = np.random.default_rng(0)
T, d, L = 3, 8, 4
norm = lambda r: r / np.sqrt((r**2).mean(-1, keepdims=True) + 1e-6)
Ws = [rng.normal(size=(d, d)) / np.sqrt(d) for _ in range(2 * L)]
r0 = rng.normal(size=(T, d)); r = r0.copy(); writes = []
for W in Ws: # stand-ins for Attn/FFN sublayers
out = np.tanh(norm(r) @ W) # read the whole stream
writes.append(out)
r = r + out # add, never overwrite
print(np.allclose(r, r0 + sum(writes))) # True
Remember this
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.
Bytewise
All courses