Inside a transformer, what is the residual stream and how does attention interact with it?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
The residual stream is the d_model-wide per-token vector that flows untouched through the network; every sub-layer reads it via projections and writes a delta back via a skip add.
Picture a long conveyor belt running through a factory. At every station, a worker reaches over, looks at what is on the belt, builds a small modification, and drops the modification back onto the belt without removing the original. By the time the conveyor reaches the end, the product carries the original input plus every worker's contribution layered on top. That conveyor belt is the residual stream. Attention is one type of worker; the feed-forward layer is another. They all read the belt and add to it, never replacing it.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Define the stream as the persistent d_model-wide per-token vector, walk how attention reads via projections and writes via the skip add, contrast pre-norm vs post-norm preservation of the stream, connect to interpretability.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking each layer REPLACES the activations rather than ADDS to them. The whole architectural point is that information persists down the stack via the unmodified skip path.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.