Glossary
What is the Residual Stream? A Transformer's Main Path
The residual stream is the running vector in a transformer that each attention and MLP layer reads from and adds its output to, token by token.
The residual stream is the sequence of hidden-state vectors in a transformer, one per token, that starts as the token embedding and accumulates the output of every attention and MLP layer through residual connections until the final layer turns it into next-token predictions.
Definition
In a transformer, each token position carries a vector of size d_model from the input to the output. That vector is the residual stream. It starts as the token's embedding. Every attention block and every MLP block reads the current vector, computes something, and adds the result back. After the last layer, the unembedding turns the final vector into scores over the vocabulary.
The term was popularized by A Mathematical Framework for Transformer Circuits (Elhage, Nanda, Olsson, Henighan et al., Anthropic, 2021). The paper describes layers that "read" their input from the residual stream with a linear projection and "write" their result by adding a linear projection back in, and it treats the stream as a communication channel between components.
How it works
For one token, with x₀ as the embedding:
- x₁ = x₀ + Attention₁(x₀)
- x₂ = x₁ + MLP₁(x₁)
- … and so on for every layer.
Two properties follow.
- It is additive. The final vector is the sum of the embedding and every layer's contribution. You can ask how much a given layer wrote along a given direction by taking a dot product with its output.
- It is largely linear in how it is used. Layers read the stream through linear projections, so a feature encoded as a direction can be read by any later layer that projects onto it. Many interpretability results, including linear probes and steering vectors, rely on features being represented this way.
The attention mechanism moves information between token positions; the residual stream keeps each position's running state.
Example
In a model with d_model = 4,096 and 60 layers, the residual stream for a 500-token prompt is a 500 × 4,096 matrix that changes 120 times: once after each attention block and once after each MLP. If you record it at layer 30 for many prompts and average over harmful and harmless prompts separately, the difference between the two averages is a candidate refusal direction. This is the first step of the method in Arditi et al. (2024).
How it relates to Abliterator
Abliteration works on the residual stream. Directional ablation removes the refusal direction from the stream at every layer while the model runs; weight orthogonalization edits every matrix that writes to the stream so the direction can never appear. For DeepSeek V4.1 Flash Abliterated, Abliterator edited the 15,442 matrices that write to the stream with W − 2 r rᵀ W, which reverses the refusal component instead of only removing it; every other byte matches the official checkpoint. Because the edit is in the weights, no hooks run at inference time.
Related terms
- Refusal direction: a direction in the residual stream that mediates refusal.
- Directional ablation: removing a direction from the stream at inference.
- Weight orthogonalization: removing it from the weights that write to the stream.
- Abliteration: the full procedure.
Frequently asked questions
Is the residual stream the same as the hidden state?
In most code, yes. The hidden state that a library returns for layer l is the residual stream at that point: the embedding plus every layer output added so far.
Why does abliteration work on the residual stream?
Because every layer communicates through it by addition. If no layer can write the refusal direction into the stream, no later layer can read it, so editing the writers is enough to remove the behavior.