The residual stream is the core communication channel in a transformer architecture, implemented as a vector of a fixed dimension that persists across all layers. Each sub-layer—whether an attention head or an MLP block—reads its input directly from this stream via a residual connection, performs its computation, and then adds its output back into the same stream. This additive update mechanism allows the model to preserve information from earlier layers while incrementally refining the representation.
Glossary
Residual Stream

What is Residual Stream?
The residual stream is the central information highway in a transformer model, serving as a shared, accumulating state vector that each layer reads from and writes its output back to.
Mechanistically, the residual stream acts as an accumulating memory that prevents the vanishing gradient problem in deep networks. Because each layer's contribution is summed rather than replacing the previous state, the model learns to compute deltas or corrections to the existing representation. Techniques like the logit lens and tuned lens exploit this property by applying the unembedding matrix directly to intermediate residual stream states, revealing how the model's next-token prediction converges layer by layer.
Key Properties of the Residual Stream
The residual stream is the central information highway in a transformer, accumulating outputs from each layer. Understanding its properties is essential for mechanistic interpretability.
Linear Accumulation
The residual stream operates on a simple principle: each sub-layer's output is added to the existing stream. This means the final representation is a linear sum of contributions from every attention head and MLP layer.
- Enables Direct Logit Attribution: the final logit can be decomposed into a sum of independent, layer-wise contributions.
- Preserves information flow, allowing gradients to propagate directly to early layers.
Shared Communication Bus
Unlike feedforward networks where layers process sequentially, the residual stream acts as a shared memory or communication bus. Every component reads its input from and writes its output to this single, expanding vector.
- Attention heads write vectors that move information between token positions.
- MLP layers write vectors that process information at the current position.
- This read/write architecture is the basis for circuits analysis.
Expanding Residual Dimension
In many architectures, the residual stream's dimension (d_model) is larger than the output dimension of individual attention heads (d_head). This expansion creates a high-dimensional space where:
- Features can be stored in superposition, representing more concepts than dimensions.
- Sparse Autoencoders are used to decompose this dense, polysemantic stream into interpretable, monosemantic feature directions.
The Logit Lens
Because the residual stream accumulates the model's current prediction state, applying the unembedding matrix directly to intermediate stream states (the Logit Lens) reveals the model's evolving next-token predictions.
- Early layers often show nonsensical predictions.
- Middle layers refine syntactic structure.
- Final layers converge on the output distribution.
- The Tuned Lens improves this with learned affine transformations per layer.
Causal Intervention Target
The residual stream is the primary target for causal techniques that isolate circuit function.
- Activation Patching: Replacing a stream value at a specific layer and token position with one from a corrupted run to measure its impact on the output.
- Path Patching: Isolating the direct effect of a specific computational path (e.g., Head A -> Head B) by patching the stream along that path while freezing others.
Steering Vectors
The linear nature of the residual stream allows for direct behavioral modification via Activation Engineering. By adding a pre-computed steering vector to the stream during a forward pass, a model's behavior can be controlled without prompt engineering.
- A 'happy' vector added to the stream biases the model toward positive sentiment.
- Function Vectors are a specific type of steering vector extracted from in-context learning examples that can trigger a task.
Residual Stream vs. Hidden State vs. Activations
Clarifying the distinct architectural roles of these frequently conflated terms in transformer models.
| Feature | Residual Stream | Hidden State | Activations |
|---|---|---|---|
Primary Definition | The central, accumulating data highway where each sub-layer reads from and writes its output back to via residual connections. | The output of a specific layer or block, often used interchangeably with the residual stream state at a given depth. | The output values of any neural network layer after applying a non-linear activation function. |
Scope | Model-wide, persistent across all layers. | Layer-specific, a snapshot at depth L. | Component-specific, the output of a single function. |
Mathematical Role | Sum of all previous layer outputs and the initial token embedding: x_0 + Σ layer_i(x). | The state vector x_L at a specific layer L, serving as input to the next sub-layer. | The result of σ(W·x + b), where σ is a non-linearity like GELU or ReLU. |
Persistence | Persistent. It accumulates information additively from layer 0 to layer N. | Transient. It is the stream's value at a single point in the computation graph. | Transient. Exists only as the immediate output of a weight matrix operation. |
Analogy | A legal document being drafted, where each lawyer adds clauses without erasing previous ones. | The state of the document after a specific lawyer's edit. | The rough notes a lawyer makes before formalizing a clause. |
Causal Intervention Target | Patching the stream at layer L affects all subsequent layers' computations. | Patching the output of layer L isolates that layer's direct contribution. | Patching activations inside an MLP tests the function of a specific neuron or feature. |
Decoding Technique | Logit Lens or Tuned Lens applied directly to the stream to read intermediate predictions. | Probing classifiers trained on the hidden state at layer L to detect encoded concepts. | Feature visualization or Sparse Autoencoders applied to decompose polysemantic neurons. |
Typical Dimensionality | d_model (e.g., 4096 for Llama-2-7B, 8192 for Llama-3-70B). | d_model, identical to the residual stream dimension. | d_ff (e.g., 11008 for Llama-2-7B), typically 2.5x to 4x larger than d_model. |
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the transformer architecture's central information highway.
The residual stream is the primary, additive information highway in a transformer architecture. It is a vector of a fixed dimension d_model that is initialized as the sum of the token embedding and positional encoding. At each layer, the attention and MLP sub-layers read from this stream, perform their computations, and write their output additively back into it. This means the stream's state is not overwritten but continuously accumulated, allowing each layer to inject new information while preserving all previous computations. The final state of the residual stream after the last layer is passed through an unembedding matrix to produce the logits for next-token prediction. This design, inspired by residual connections from computer vision, is the fundamental reason transformers can be scaled to hundreds of layers without degradation.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The residual stream is the central data structure of the transformer. Understanding it requires familiarity with the components that read from and write to it, and the techniques used to decode its contents.
Logit Lens
A decoding technique that applies the unembedding matrix directly to intermediate residual stream activations to reveal the model's next-token predictions at each layer. This provides a window into the evolving state of the residual stream, showing how early layers contribute syntactic structure before later layers resolve semantic meaning.
Activation Patching
A causal intervention technique that replaces a model's internal activation at a specific layer and token position with a value from a corrupted or alternative forward pass. By patching activations in the residual stream, researchers can isolate which components are causally responsible for a specific behavior. Path patching extends this to isolate specific computational paths between two components.
Sparse Autoencoders
An unsupervised architecture trained to decompose a model's dense, polysemantic residual stream activations into a sparse set of interpretable, monosemantic features. SAEs address the superposition hypothesis by finding an overcomplete basis where each active dimension corresponds to a single human-understandable concept, making the residual stream's contents legible.
Linear Representation Hypothesis
The conjecture that high-level concepts are encoded as linear directions in the representation space of a neural network's activation vectors. If true, the residual stream can be understood as a sum of independent feature vectors. This hypothesis underpins techniques like activation engineering, where steering vectors are added to the stream to control model behavior.
Direct Logit Attribution
A linear decomposition technique that attributes the final logit output for a token directly to the individual contributions of each attention head and MLP layer. Since the residual stream is a sum of all previous component outputs, DLA uses the linearity of the unembedding operation to quantify exactly how much each write to the stream influenced the final prediction.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us