The residual stream is a persistent vector of dimension d_model that serves as the central communication channel in a transformer. At each token position, the stream's state is initialized with the token embedding and positional encoding. Each subsequent layer performs a read-modify-write operation: it reads the current state, computes an additive update via its attention and MLP sub-layers, and writes the result back by adding this update to the stream. This additive structure, derived from residual connections, ensures that gradients flow directly to early layers during training and that the model can learn to bypass entire layers if necessary.
Glossary
Residual Stream

What is Residual Stream?
The residual stream is the primary information highway in a transformer model, a shared, accumulating state that each layer reads from and writes to, enabling the model to bypass layers and preserve information flow.
Mechanistically, the residual stream functions as a linear accumulation of information from all preceding layers. The output at layer L is the sum of the initial embedding and the outputs of every sub-layer up to L. This makes it a powerful target for mechanistic interpretability techniques like the logit lens, which applies the unembedding matrix directly to intermediate stream states to decode the model's evolving predictions. The stream's linear nature also enables representation engineering, where steering vectors are added to guide model behavior, and facilitates the study of superposition, as the stream compresses more features than its dimensionality would naively allow.
Key Characteristics of the Residual Stream
The residual stream is the primary information highway in a transformer model. It functions as a shared, accumulating state that each layer reads from and writes to, enabling the model to bypass layers and preserve information flow across the entire depth of the network.
The Accumulating State
The residual stream is not a single static vector but a cumulative sum of outputs from all previous layers. Each transformer block adds its output to the stream via a residual connection. Mathematically, the state at layer l is x_l = x_0 + Σ a_i + Σ m_i, where a_i are attention outputs and m_i are MLP outputs. This means the final representation contains a linear superposition of information from every layer, allowing later layers direct access to early token-level features without compression through intermediate bottlenecks.
The Information Bottleneck Bypass
Residual connections create a gradient superhighway that mitigates the vanishing gradient problem in deep networks. By providing an identity path (y = F(x) + x), the model can learn small, incremental perturbations to the stream rather than full transformations. If a layer learns nothing useful, it can default to near-zero output, effectively skipping the layer and passing information through unchanged. This is why transformers scale to hundreds of layers without degradation.
The Communication Subspace
Attention heads do not directly modify token representations. Instead, they write their results into the residual stream, and MLP layers read from the stream to process information. The residual stream acts as a shared memory bandwidth where heads communicate by writing vectors that other heads in later layers can attend to. This is the basis of induction heads: an early head writes a token into the stream, and a later head reads from that position via the attention pattern, enabling in-context copying.
Linear Representation Hypothesis
Features encoded in the residual stream are often linearly accessible. This means a simple linear probe (a logistic regression classifier) trained on the stream's activations can decode high-level concepts like sentiment, syntax, or truthfulness. The Logit Lens technique exploits this by applying the unembedding matrix directly to intermediate residual states, revealing the model's evolving next-token predictions at every layer. This linearity is a core assumption behind representation engineering and steering vectors.
The Superposition Problem
While the residual stream enables powerful computation, it also forces the model to compress vast amounts of information into a single fixed-width vector. This leads to the superposition hypothesis: the model represents more independent features than it has dimensions by encoding them in almost-orthogonal directions. A single neuron or dimension rarely corresponds to one clean concept. Instead, features are polysemantic, activating for multiple unrelated inputs. Sparse autoencoders (SAEs) are used to decompose this dense, entangled stream into a sparse set of monosemantic features.
The Residual Stream as a Workspace
Mechanistic interpretability treats the residual stream as a computational scratchpad. Subspaces of the stream correspond to specific variables in an algorithm the model has learned. For example, in a modular addition circuit, specific dimensions store the carry bit and the sum. Activation patching intervenes on these subspaces to causally verify their function. By reading and writing to orthogonal subspaces, the model performs complex, multi-step reasoning without interference between parallel computations.
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.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the residual stream, the central information highway of the transformer architecture.
The residual stream is the primary, high-dimensional vector that flows through a transformer model, acting as a shared communication channel and accumulating state. At its core, it is the output of the initial token embedding and positional encoding, which is then passed through each successive transformer layer. Critically, instead of replacing this vector, each sub-layer (attention and MLP) computes an additive update that is summed back into the stream via a residual connection. This means the stream's dimensionality remains constant throughout the model, and every layer reads its input from this single, shared state and writes its output back to it. The residual stream is not just a passive conduit; it is the model's working memory, where information from different layers and token positions is mixed and accumulated to form the final contextualized representation used for prediction.
Related Terms
The residual stream is the central data structure of a transformer. These related concepts explain how information is written to, read from, and decoded within this shared bandwidth.
Attention Head
A computational subunit that reads from the residual stream and writes a weighted sum of value vectors back to it. Each head computes attention scores via the QK circuit to determine where to pull information from, and transforms it via the OV circuit to determine what to write. The result is added into the residual stream at the head's output position, enabling information movement between token positions.
Multi-Layer Perceptron (MLP) Layer
A position-wise feed-forward network that reads each token's residual stream state independently and writes a transformed vector back. MLPs act as key-value memories: the first linear layer projects the input to a high-dimensional space where knowledge neurons activate, and the second layer maps the result back down. This is where the majority of factual knowledge is stored and retrieved.
Logit Lens
A direct probing technique that applies the unembedding matrix to intermediate residual stream states at any layer. This reveals the model's evolving next-token predictions before the final layer norm. By decoding the residual stream at each layer, researchers can observe how the model gradually refines its output distribution, often finding that the final prediction is largely determined by middle layers.
Sparse Autoencoder (SAE)
An unsupervised decomposition technique that breaks the dense, polysemantic activations in the residual stream into a sparse set of monosemantic features. An SAE learns an overcomplete basis where each feature corresponds to a single interpretable concept. This addresses the superposition hypothesis—the theory that models pack more features than dimensions into the residual stream using near-orthogonal directions.
Activation Patching
A causal intervention technique that replaces a specific activation in the residual stream at a given layer and token position with a cached activation from a different forward pass. By patching clean activations into corrupted runs (or vice versa), researchers isolate the causal contribution of specific components. This is the primary method for discovering circuits—minimal subgraphs responsible for specific behaviors.
Representation Engineering
A top-down control method that manipulates high-level representations directly in the residual stream using steering vectors. Rather than modifying individual weights, a direction vector corresponding to a desired behavior (e.g., honesty, refusal) is added to the residual stream at inference time. This provides a lightweight alternative to fine-tuning for controlling model behavior.

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