The Residual Stream View of Transformers
Rather than picturing a transformer as data flowing through a stack of layers, it helps to picture one running vector that every layer reads from and writes to — a shared communication channel that makes residual connections and interpretability both easier to reason about.
Prerequisites: Residual Connections, Pre-Norm vs Post-Norm Transformer Blocks
The usual way to describe a transformer is "a stack of layers, each transforming its input into an output that feeds the next layer." That's technically correct but obscures something important: because every layer's output is added to its input rather than replacing it, information written by an early layer isn't overwritten by later ones — it persists additively unless something later actively cancels it out. Thinking of layers stacked on top of each other hides this; thinking of it as one shared vector every layer reads from and writes into makes it visible.
The analogy: a shared whiteboard that no one erases
Picture a long meeting where a single whiteboard sits at the front, and every participant, one after another, walks up and adds a note — never erasing what's already there. A participant near the end can still read notes from the very first participant, because nothing was wiped clean; they can also write a note that effectively "cancels out" an earlier one, but the earlier note is never physically removed. That shared, ever-accumulating whiteboard is the residual stream: one vector per token position that every sub-layer reads from and writes into by addition.
The mechanics: reads, writes, and a shared linear space
Formally, the residual stream at layer for a given token is a vector , and every sub-layer follows the same pattern:
In words: a sub-layer reads the current stream, computes a function of it, and writes its output back by addition — never replacing , only incrementing it. Because addition is linear, the final stream after layers is literally the sum of the original embedding plus every sub-layer's contribution:
In words: the final representation for a token is its starting embedding plus the accumulated total of everything every attention head and feedforward block added along the way. This additive structure is exactly what makes Pre-Norm vs Post-Norm Transformer Blocks matter — pre-norm keeps this literal sum untouched by normalization, while post-norm repeatedly rescales it.
Worked example 1: tracing one dimension through 3 layers
Suppose, in a toy model with , a token's residual stream starts at . Layer 1's attention adds : . Its feedforward adds : . Layer 2's attention adds (partially cancelling earlier contributions): . Its feedforward adds : . The final value is fully explained as — every contribution is individually visible, none silently overwritten, they simply summed back to the starting point.
Worked example 2: reading and writing to different subspaces
In a real model with , different sub-layers often specialize in reading from and writing to different, roughly separable subspaces of that stream — one head might mostly handle subject-verb agreement, writing into a largely disjoint set of dimensions from an unrelated head handling punctuation style. Because the stream is shared and additive, both heads can operate on the "same" vector without interfering, as long as their subspaces don't substantially overlap — when they do, one head's contribution can partially distort another's, a real source of interference interpretability researchers study directly.
Every sub-layer's contribution is a vector added into the same shared space — like this explorer's transform acting within one fixed coordinate system rather than switching to a new one at every step — which is exactly why later layers can still "see," and even undo, what earlier layers wrote.
What this means in practice
The residual stream view is the standard lens used in mechanistic interpretability — the research area trying to reverse-engineer what specific circuits inside a trained transformer are actually doing — precisely because "sum of independent additive contributions" is a much more tractable object to analyze than "output of a nonlinear stack of layers." It also explains a very practical fact: a transformer can, in principle, learn to have one layer's sub-layer write a correction that undoes an earlier layer's mistake, which is part of why deeper transformers with more layers to iteratively refine the stream tend to be more capable, not merely because they have more raw parameters.
Every transformer sub-layer reads from and additively writes into one shared vector per token — the residual stream — rather than replacing it. The final representation is literally the sum of the starting embedding and every sub-layer's individual contribution, which is why later layers can read, build on, or even partially cancel what earlier layers wrote, and why this additive structure is the basis for most transformer interpretability work.
Practice
- Given and three sub-layer contributions of , , , compute and verify it equals the sum of all contributions plus .
- Explain in one sentence why post-norm complicates the "pure sum of contributions" interpretation that pre-norm preserves.
- Give one reason two attention heads writing into overlapping subspaces of the residual stream could interfere with each other.
The common confusion is picturing the residual stream as if later layers only see a "processed, compressed summary" of earlier layers' work, the way a standard feedforward stack (with no residual connections) would work. They don't — because every write is additive and nothing is ever overwritten outright, a later layer has direct, unmediated access to the raw contribution of any earlier layer, as long as it reads the right subspace. The residual stream is a shared communication channel, not a sequential refinement pipeline where old information is progressively discarded; that distinction is exactly what separates residual architectures from plain deep feedforward networks.
Related concepts
Practice in interviews
Further reading
- Elhage et al., A Mathematical Framework for Transformer Circuits (2021)
- Vaswani et al., Attention Is All You Need (2017)