In standard descriptions of transformer architectures, multi-head attention and feedforward networks receive the vast majority of analytical focus. However, the operational backbone coordinating these sublayers is the residual stream. First introduced in convolutional computer vision models by He et al. (2016) to mitigate vanishing gradients in deep networks, residual skip connections operate in large language models as a persistent, high-dimensional linear communication bus.
Rather than processing information sequentially through a rigid, monolithic transformation pipeline, modern transformers rely on the residual stream as a shared memory canvas. Individual attention heads and feedforward layers read specific features from this stream, perform isolated computations, and write additive updates back into the channel without destroying the existing state (Elhage et al., 2021). This linear additive formulation fundamentally dictates how transformer circuits compose, how representations scale with model depth, and how gradients propagate during optimization.
The Mathematical Mechanics: Reading and Writing to the Bus
At the start of a transformer forward pass, an input sequence of tokens is converted into initial continuous representations via a learned embedding matrix and combined with positional information:
The vector enters the residual stream at layer 0. For each subsequent transformer layer , the state transitions according to two sequential additive operations:
where represents layer normalization (such as RMSNorm or standard Pre-LayerNorm).

Every sublayer interacts with the residual stream through explicit linear projections:
- Reading from the Stream: An attention head reads from the stream by projecting the unnormalized state via query, key, and value weights: , , and . Similarly, a gated feedforward network (such as SwiGLU) reads the vector state via gate and up-projection matrices: and .
- Local Computation: The attention head calculates softmax attention patterns across sequence positions: , producing intermediate value mixtures . The MLP evaluates non-linear activation gating: .
- Writing to the Stream: The computed representations are mapped back into the model dimension using output projection matrices and . The resulting vectors are added directly into the stream:
By expanding this recursion across all layers of the network, the final pre-unembedding state is revealed as a pure linear accumulation of updates:
Subspace Allocation and High-Dimensional Geometry
Because the residual stream is additive and fixed at width (such as 4,096 in LLaMA-7B or 8,192 in LLaMA-70B), the vector space acts as a shared memory address space. In high-dimensional Euclidean space, the number of mutually near-orthogonal directions scales exponentially with dimensionality.
This geometric property allows the transformer to partition the residual stream into quasi-independent linear subspaces (Elhage et al., 2021):
- Dedicated Feature Channels: A layer can write syntactic information (such as subject-verb number agreement) into subspace , while another layer writes semantic domain tags into orthogonal subspace . Because , operations projecting onto remain unaffected by updates written into .
- Superposition and Polysemanticity: In practical LLMs, the number of distinct human concepts, grammatical rules, and factual associations vastly exceeds . Models accommodate this by packing non-orthogonal features into superposition (Elhage et al., 2022), relying on non-linear MLP activations in subsequent layers to denoise and extract target signals when activated.
Direct Logit Attribution and Circuit Composition
The linear structure of the residual stream has critical implications for interpretability and model internals. In standard autoregressive architectures, the final prediction is obtained by projecting through an unembedding matrix :
Ignoring the final LayerNorm scale factor for first-order linear analysis, the logit vector decomposes additively across every component in the network:
This formulation enables Direct Logit Attribution (DLA). Researchers and engineers can compute to measure the exact numerical contribution that a single attention head or MLP neuron makes toward promoting or suppressing a specific token in the vocabulary.
Furthermore, it explains how circuits compose across non-adjacent layers:
- K-Composition: An attention head in layer 10 can read key information directly written by layer 2 without layer 3 through 9 needing to forward or re-encode that information.
- V-Composition and Induction: Induction heads (Olsson et al., 2022) depend on previous-token heads writing position-shifted token identities into the stream, which downstream search heads subsequently attend to across long token spans.
Virtual Ensembles and Gradient Flow Dynamics
The additive skip connection fundamentally alters how depth functions in transformers. As demonstrated by Veit et al. (2016), residual networks do not behave like monolithic serial pipelines of depth . Instead, an -layer residual architecture acts as a virtual ensemble of distinct computational paths of varying lengths.
Input x0 ───────────────────────────────────────────────────────────> Output xL
│ │ │ ▲
└──> [ Attn 1 ] ──(+)───┴──> [ Attn 2 ] ──(+)───┴──> [ MLP L ] ──(+)──┘
│ ▲ │ ▲ │ ▲
└──> [ MLP 1 ] ────┘ └──> [ MLP 2 ] ────┘ └──> [ ... ] ─────┘When evaluating a two-layer transformer block with paths through sublayers , the computational graph unrolls into four parallel pathways:
In an -layer model, most data paths bypass the majority of intermediate layers, allowing the network to dynamically route tokens through shallow or deep computational circuits depending on task complexity.
Gradient Highway Mechanics
During backpropagation, the gradient of the loss with respect to early representations is computed via the chain rule:
The presence of the identity matrix creates an uninterrupted gradient highway. Even if intermediate sublayer gradients vanish or become ill-conditioned, the backpropagated error signal flows directly to early layers and input embeddings without attenuation.
Architectural Trade-Offs and Stability Bottlenecks
While the residual stream provides modularity and stable optimization, scaling depth introduces physical and mathematical constraints:
Residual Stream Norm Growth in Pre-LN Models
In modern Pre-LN and Pre-RMSNorm transformers (Wang et al., 2019), each layer adds a zero-mean, non-zero variance update to . Assuming updates are weakly correlated, the variance and Euclidean norm of the residual vector grow with depth:
Consequently, in deep models (such as 80 to 120 layers), is significantly larger than . As the residual stream norm expands, the relative contribution of later layers naturally diminishes unless layer normalization rescales inputs or explicit branch scaling parameters (such as DeepNorm or ReZero multipliers ) are applied (Wang et al., 2022).
Bandwidth Bottlenecks in Deep-Narrow Configurations
Because every sublayer must communicate through , narrow networks with extreme depth experience residual stream bandwidth pressure. If is too small relative to layer count , sublayers overwrite or corrupt existing subspace allocations, degrading long-range circuit composition. Balancing residual width against depth remains a core optimization frontier in foundation model pre-training.
Sources
- A Mathematical Framework for Transformer Circuits (Elhage et al., 2021)
- Deep Residual Learning for Image Recognition (He et al., 2016)
- Residual Networks Behave Like Ensembles of Relatively Shallow Networks (Veit et al., 2016)
- Attention Is All You Need (Vaswani et al., 2017)
- In-context Learning and Induction Heads (Olsson et al., 2022)
- Toy Models of Superposition (Elhage et al., 2022)
- Learning Deep Transformer Models for Machine Translation (Wang et al., 2019)
- DeepNet: Scaling Transformers to 1,000 Layers (Wang et al., 2022)



