Residual Stream is Key to Transformer Interpretability

StableNearly slopllmmechanistic_interpretability
Last reviewed17 min read

I. A High-Level Overview

High-Level Architecture of a Transformer
A high-level view of the Transformer architecture, emphasizing the residual stream.

A Transformer model processes information in a sequence. It begins with token embedding, where an input token tt (represented as a one-hot vector) is mapped to an embedding vector x0x_0 via an embedding matrix WEW_E. This vector then passes through a series of residual blocks. Finally, the output of the last block, xLx_{L}, undergoes token unembedding, where it is mapped to a vector of logits L(t)L(t) via an unembedding matrix WUW_U.

In the pre-normalized decoder-only architecture used as our running model, each residual block (or Transformer block) consists of an attention layer followed by an MLP layer. Both sublayers read their input from the residual stream—the central pathway carrying vectors like xi,xi+1,x_i, x_{i+1}, \dots—and subsequently write their results back to it. Suppressing normalization for the moment, each write has the residual form xi+1=xi+sublayer(xi)x_{i+1} = x_i + \operatorname{sublayer}(x_i).

II. The Residual Stream as a Communication Channel

If we conceptualize a Transformer as a complex computational device, the residual stream is one of its most critical components (analogous to the cell state in LSTMs or the identity skip path in a residual network). In a pre-normalized Transformer, it is the initial token embedding plus the cumulative sum of the updates written by preceding sublayers: a sublayer reads Norm(xi)\operatorname{Norm}(x_i) but still writes its update additively to xix_i. A post-normalized block, which normalizes after the addition, does not admit this literal cumulative-sum unrolling across blocks.

Intuition (Communication Channel Analogy)

We can view the residual stream as a communication channel because the skip path itself only adds updates. The components connected to it are not linear in general: attention weights depend nonlinearly on the stream, MLPs contain activations, and practical models usually normalize before or after a sublayer. Subject to those qualifications, attention heads and MLP layers read information from the shared stream, process it, and write updates that later components can access.

A defining feature of the residual stream is its additive skip path. This is closely related to a ResNet: in the usual residual block, the skip path is the identity while nonlinearities live in the residual branch, although some variants also apply an activation after the addition. Transformer sublayers likewise contain nonlinear computation, even when their first and last learned maps are linear projections.

Remark (Linear Transformations in Practice).
  • Attention Layer: To process an input vector xix_i from the residual stream, the layer projects it into query, key, and value vectors using weight matrices WQ,WK,WVW_Q, W_K, W_V. These are the “read” transformations. After computing the attention head’s output, this result is projected back into the residual stream’s dimension via the output matrix WOW_O. This is the “write” transformation.
  • MLP Layer: A standard Transformer MLP consists of two linear transformations with a non-linearity between them. Using column vectors in this subsection, the first linear layer, WinW_{in}, reads from the residual stream. The second, WoutW_{out}, projects the activated hidden layer back into the stream. The full operation is WoutGELU(Winx)W_{out}\operatorname{GELU}(W_{in}x).

These descriptions omit LayerNorm or RMSNorm. When normalization is present, the projections read the normalized stream rather than xix_i directly.

In the simplified architecture analyzed by Elhage et al.—where every operation that touches the residual stream is transformed consistently and there is no fixed coordinatewise normalization on that stream—the residual space has no privileged basis 1. In that setting, we can change the basis of the residual stream and transform the matrices that interact with it without changing the model’s computational behavior. Ordinary LayerNorm, RMSNorm with learned per-coordinate gains, or other coordinate-dependent operations restrict this symmetry, so the exact claim should not be transferred to every Transformer unchanged.

1. Understanding the Privileged Basis

Definition (Basis).For an NN-dimensional vector space VV, a basis is a set of NN linearly independent vectors, {b1,,bN}\{b_1, \dots, b_N\}, such that any vector in VV can be uniquely expressed as a linear combination of these basis vectors. In the context of neural networks, the hidden state space is a vector space of dimension dmodeld_{model}, and the most common basis is the standard basis {e1,,eN}\{e_1, \dots, e_N\}, where each eie_i is a vector of zeros with a 1 in the ii-th position. Each standard basis vector corresponds to the activation of a single neuron.

The concept of a “privileged basis” is defined in 1 as follows:

“A privileged basis occurs when some aspect of a model’s architecture encourages neural network features to align with basis dimensions, for example because of a sparse activation function such as ReLU.”

Let’s dissect this with an example.

Definition (Feature).

Following the work of Olah et al. [Olah et al., 2020], a feature is a meaningful property that a neural network learns to detect in its input. Rather than thinking of a feature as a single neuron, it’s more accurate to consider it a concept or direction in activation space. Examples could include “is a vertical edge,” “is a proper noun,” or “carries a positive sentiment.”

The critical distinction is how these features are represented:

  • In a privileged basis, the architecture treats its coordinate axes specially, which can encourage learned features to align with individual neurons or small sparse sets of neurons.
  • In a non-privileged basis, the architecture does not prefer those coordinate axes. A feature may therefore be represented by a dense direction rather than by a single neuron, but basis freedom alone does not determine what training will learn.

Consider a simple MLP trained to classify shapes. Let’s focus on a hidden layer LL with N=4N=4 neurons, whose activation space is R4\mathbb{R}^4. The standard basis vectors are e1=[1,0,0,0],,e4=[0,0,0,1]e_1=[1,0,0,0], \dots, e_4=[0,0,0,1].

  • Case 1: No Sparse Activation (e.g., Linear Layer)

    • The feature for “square” might be represented by the dense vector [1.2, -0.9, 0.8, 1.1].
    • The feature for “triangle” might be represented by [-0.8, -1.1, 1.3, -0.9].
    • Here, each feature is a complex combination of all four neurons. No single neuron is the “square detector.” The features are not aligned with the basis vectors. This is a non-privileged basis.
  • Case 2: With a Sparse Activation (e.g., ReLU)

    • The pre-activation vector for “square,” [1.2, -0.9, 0.8, 1.1], becomes [1.2, 0, 0.8, 1.1] after passing through ReLU. Because ReLU is applied coordinate by coordinate, rotating the coordinates generally changes the function; the architecture therefore singles out the neuron basis. Training might also produce a sparser representation like [1.5, 0, 0, 0], but ReLU alone does not prove that this will happen or that Neuron 1 is a reliable square detector.
    • Similarly, “triangle” might activate Neuron 3, becoming [0, 0, 1.3, 0].
    • The justified architectural claim is that ReLU privileges the coordinate basis and can produce sparse activations by zeroing negative coordinates. Whether learned features actually align with individual neurons is an empirical question, and even an aligned activation does not by itself establish a causal or exclusive detector.

The bare additive skip path has no coordinatewise activation and therefore does not itself create this pressure. Features can occupy arbitrary directions, although normalization and other operations around the stream may still privilege or restrict particular coordinates.

2. Rotational Invariance

Intuition (Why Rotate the Basis?)
  • A model with a non-privileged basis is like an alien that speaks an unintelligible language. It computes the correct answers, but its internal representations—the features it uses—are encoded along arbitrary, dense directions in its high-dimensional state space.
  • The standard basis (neuron activations) is the language we humans can directly read. But inspecting individual neuron activations is meaningless if features aren’t aligned with them.

The hope behind “rotating the basis” is to find a coordinate system whose axes better align with useful learned features. A candidate direction can then be tested as, say, a circle-related feature. This direction is not literally a neuron in the original network, and finding a rotation does not by itself establish a clean or causal interpretation.

Under the simplified assumptions stated above, we can apply rotations without changing the model’s output. Let’s see why.

Let RR be an arbitrary orthogonal rotation matrix, meaning R1=RTR^{-1} = R^T and RTR=IR^T R = I. Suppose we rotate a vector xix_i on the residual stream to get xi=Rxix'_i = R x_i. For the model’s behavior to remain unchanged, every component that interacts with the stream must adapt.

Consider an attention component:

  • Read Operation: The component reads from the stream using matrices WQ,WK,WVW_Q, W_K, W_V. To preserve the computation, we need new matrices WQ,WK,WVW'_Q, W'_K, W'_V such that:
WQxi=WQxiW_Q x_{i} = W'_{Q} x'_{i}

Substituting xi=Rxix'_i = Rx_i, we get WQxi=WQRxiW_Q x_i = W'_Q R x_i. For this to hold for all xix_i, we must have WQ=WQRW_Q = W'_Q R, which implies WQ=WQR1=WQRTW'_Q = W_Q R^{-1} = W_Q R^T. Thus, the new weight matrices simply “un-rotate” the input before applying the original transformation: WQxi=(WQRT)(Rxi)=WQxiW'_Q x'_i = (W_Q R^T)(R x_i) = W_Q x_i. The underlying logic is unchanged.

  • Write Operation: The layer writes its output back to the rotated stream:
xi+1=xi+WOhead_outputx'_{i+1} = x'_{i} + W'_{O} \cdot \text{head\_output}

Since all vectors on the stream must be consistently rotated, xi+1=Rxi+1x'_{i+1} = R x_{i+1} and xi=Rxix'_i = R x_i. Substituting these into the original update rule xi+1=xi+WOhead_outputx_{i+1} = x_i + W_O \cdot \text{head\_output} gives:

R(xi+WOhead_output)=Rxi+WOhead_output    RWOhead_output=WOhead_outputR(x_i + W_O \cdot \text{head\_output}) = R x_i + W'_O \cdot \text{head\_output} \\ \implies R W_O \cdot \text{head\_output} = W'_O \cdot \text{head\_output}

This requires WO=RWOW'_O = R W_O. The output projection is simply rotated along with the rest of the space.

Since the internal calculations of each component in this simplified model remain invariant after applying these compensatory rotations to the weight matrices, we call its residual stream rotationally invariant or basis-free. A normalized production architecture needs a separate symmetry analysis; the calculation above is not a proof for it.

III. Virtual Weights

Virtual Weights across layers
The linearity of the residual stream allows us to compose weight matrices, forming 'virtual weights' that connect non-adjacent layers.

The additive structure of the residual stream has another useful implication: for a direct write from one component followed by a linear read from a later component, we can compose their projection matrices into a “virtual weight.” This describes that direct path, not the complete nonlinear computation between the components.

Note (Virtual Weights Induced by the Residual Stream)

The additive residual path implicitly defines virtual weights between the writes and later linear reads of components, regardless of how far apart they are in depth. Such a virtual weight matrix is the product of the earlier component’s output projection and the later component’s input projection. If the later component first applies normalization, this fixed matrix no longer represents its entire read; it is best understood as the corresponding direct linear path in the normalization-free analysis.

Let CjC_j be the computation of component jj (e.g., an attention head or MLP), with input weights WIjW_I^j and output weights WOjW_O^j. The update rule at step jj is:

xj+1=xj+WOjCj(WIjxj)x_{j+1} = x_j + W_O^j \cdot C_j(W_I^j x_j)

Now, consider how the next component, j+1j+1, reads from the stream:

WIj+1xj+1=WIj+1(xj+WOjCj())=WIj+1xj+(WIj+1WOj)Cj()W_I^{j+1} x_{j+1} = W_I^{j+1}(x_j + W_O^j \cdot C_j(\dots)) = W_I^{j+1} x_j + (W_I^{j+1} W_O^j) \cdot C_j(\dots)

The term WIj+1WOjW_I^{j+1} W_O^j is a virtual weight matrix. It directly maps the output of component jj to the input of component j+1j+1. This shows that information written by layer jj is read by layer j+1j+1 through this composite matrix.

We can extend this bookkeeping across multiple layers. In the normalization-free model, the input projection of component ii receives the direct contribution of component jj (where j<ij<i) through WIiWOjW_I^i W_O^j. This supports the useful picture of later components reading earlier writes through the shared stream, while nonlinearities, attention patterns, normalization, and intervening writes still determine the actual computation.

IV. Subspaces and Bandwidth of the Residual Stream

The residual stream is a high-dimensional vector space (e.g., dmodel=768d_{model} = 768 for BERT-base, dmodel=2304d_{model} = 2304 for Gemma-2B). This dimensionality makes it possible for different layers and attention heads to use partly distinct subspaces, but the architecture does not require those subspaces to be disjoint or orthogonal.

Definition (Direct Sum of Subspaces).

Subspaces U1,,UNU_1,\dots,U_N form an internal direct sum when every vector in their sum has a unique decomposition u1++uNu_1+\cdots+u_N with uiUiu_i\in U_i. Equivalently,

UijiUj={0}for every i.U_i \cap \sum_{j\ne i} U_j = \{\mathbf 0\} \quad\text{for every }i.

We write their sum as U1UNU_1\oplus\cdots\oplus U_N. If they also span all of VV, then

V=U1U2UN={u1+u2++uNuiUi}.V = U_1 \oplus U_2 \oplus \dots \oplus U_N = \{ u_1 + u_2 + \dots + u_N \mid u_i \in U_i \}.

For more than two subspaces, the weaker condition U1UN={0}U_1\cap\cdots\cap U_N=\{\mathbf 0\} is not sufficient. Orthogonal subspaces do form a direct sum, but a direct sum need not be orthogonal.

In a multi-head attention layer, each head has a relatively small value dimension (often, but not always, dhead=dmodel/nheadsd_{head}=d_{model}/n_{heads}). After its output projection, head kk can write only into the image of WOkW_O^k, a subspace of dimension at most dheadd_{head}. Different heads may learn partly separated or nearly orthogonal write subspaces, but this is an empirical property of a trained model rather than a guarantee of multi-head attention. Overlap can also be useful because it lets heads reinforce or cancel one another.

Because later updates are added, an earlier write remains as an algebraic summand of the residual stream. That does not guarantee that the information remains decodable: later writes, normalization, or cancellation can obscure or erase it. With this caveat, dmodeld_{model} is a useful analogy for communication bandwidth or working memory, and a larger stream offers more representational degrees of freedom without giving a simple capacity formula.

The framework paper further notes that embedding and unembedding maps can leave directions that are weakly constrained by direct token input or logit output 2. Calling these directions “free” is an intuition, not a guarantee that trained intermediate layers reserve or independently allocate them; the relevant ranks and usage must be measured in the model being analyzed.

Residual Stream Bandwidth
The residual stream's dimensionality serves as a communication bandwidth, which can become a bottleneck.

Definition (Computational Dimension).Here, the term refers to the dimensionality of components that perform active computation, such as the MLP or the Attention Heads (in contrast, the residual stream primarily serves as an information carrier rather than a site of computation). For example, the output dimensionality of an Attention layer can match dmodeld_{model} (after concatenating the multiple attention heads). In contrast, the hidden layer of the MLP typically has a dimensionality that is 4 times larger than dmodeld_{model}.

This shared bandwidth can nevertheless constrain communication between sublayers. The computational dimensions of components can exceed the residual stream’s dimension; for instance, many MLP hidden layers are wider than dmodeld_{model}. This makes the residual stream a bottleneck in the dimensional sense defined below, although dimensionality alone does not show that useful information is lost.

Definition (Bottleneck Activations).An activation vector is a dimensional bottleneck when its dimension is smaller than those of the representations on either side. The map must pass through a lower-dimensional space, although useful information need not be lost when the relevant data occupy a sufficiently low-dimensional set.

  • For example, the residual stream can be regarded as a form of bottleneck activation. MLP layers at different depths (which typically have activations of higher dimensionality than the residual stream) must communicate with one another through the residual stream. Consequently, the residual stream acts as an intermediary between two MLP layers whose hidden activations may have much larger dimensionality. Moreover, the residual stream is the only pathway through which any given MLP layer can communicate with subsequent layers. It must also carry forward information originating from other MLP layers along the path toward the extreme bottleneck.

  • Similarly, a value vector (in the Q,K,VQ, K, V decomposition of an attention head) also constitutes a bottleneck activation.

    • In the common equal-width parameterization, each value vector has dimensionality dv=dmodel/hd_v=d_{model}/h, where hh denotes the number of attention heads. More generally, dvd_v is an architectural choice.
    • Let xsx_s denote the residual stream at token position ss. The corresponding value vector is vs=xsWVv_s = x_s W_V. This value vector vsv_s is then used to update the residual stream at another position tt: xt=xt+(attention_score×vs)WO.x_t = x_t + (\text{attention\_score} \times v_s) W_O .
    • In this way, information from residual state xsx_s is projected into vsv_s and contributes to the update at position tt. When dv<dmodeld_v<d_{model}, that projection is a dimensional bottleneck. Within the standard Transformer block covered here, attention’s weighted value path is the mechanism for cross-token communication; token-wise MLPs and normalizations do not themselves mix positions. Architectures with convolutions, recurrence, routing, or other mixing layers need not satisfy this claim.

In a particular trained model, an MLP neuron or attention head that writes the negative of an earlier component’s contribution can be interpreted as performing a memory-management-like operation. The algebra makes cancellation possible, but it does not imply that components generally allocate named dimensions or deliberately “free memory”; that interpretation requires causal evidence from the model.

V. Attention Heads Contribute Parallel Updates

A multi-head attention layer computes each head from the same input in parallel. Conditional on that input, one head’s forward calculation does not consume another head’s result, and the projected head outputs are summed. The heads are not statistically or functionally independent in general: they are trained jointly, share the residual input, and can interact through their summed write and through later layers.

Using row vectors for tokens, let XRN×dX\in\mathbb R^{N\times d} and let XiX_i denote the row at token position ii. For head kk, define

Q(k)=XWQ(k)RN×dk,K(k)=XWK(k)RN×dk,V(k)=XWV(k)RN×dv,Aij(k)=exp ⁣(Qi(k)(Kj(k))T/dk)iexp ⁣(Qi(k)(K(k))T/dk)(ji),Ri(k)=jiAij(k)Vj(k)R1×dv,Ri=[Ri(1)Ri(h)]R1×hdv,Yi=RiWOR1×d,Xi+1=Xi+YiR1×d.\begin{aligned} Q^{(k)} &= XW_Q^{(k)} \in \mathbb R^{N\times d_k},\\ K^{(k)} &= XW_K^{(k)} \in \mathbb R^{N\times d_k},\\ V^{(k)} &= XW_V^{(k)} \in \mathbb R^{N\times d_v},\\ A^{(k)}_{ij} &= \frac{\exp\!\left(Q^{(k)}_i(K^{(k)}_j)^T/\sqrt{d_k}\right)} {\sum_{\ell\le i}\exp\!\left(Q^{(k)}_i(K^{(k)}_\ell)^T/\sqrt{d_k}\right)} \quad (j\le i),\\ R^{(k)}_i &= \sum_{j\le i}A^{(k)}_{ij}V^{(k)}_j \in\mathbb R^{1\times d_v},\\ R_i &= [R^{(1)}_i\mathbin{\|}\cdots\mathbin{\|}R^{(h)}_i] \in\mathbb R^{1\times hd_v},\\ Y_i &= R_iW_O\in\mathbb R^{1\times d},\\ X^{\ell+1}_i &= X^\ell_i+Y_i\in\mathbb R^{1\times d}. \end{aligned}

Here Aij(k)A^{(k)}_{ij} is the weight with which query position ii reads value position jj; masked entries with j>ij>i are zero. Using \ell for layer depth avoids overloading the token index ii.

Let r(k)r^{(k)} be the result row vector from head kk, with dimension dvd_v. In the original Transformer paper, the hh head results are concatenated and then projected by WORhdv×dW_O\in\mathbb R^{hd_v\times d}. Partition WOW_O into row blocks WO(k)Rdv×dW_O^{(k)}\in\mathbb R^{d_v\times d}, one for each head. Then

[r(1)r(h)]WO=[r(1)r(h)][WO(1)WO(h)]=r(1)WO(1)++r(h)WO(h)=k=1hr(k)WO(k).\begin{aligned} \left[r^{(1)}\mathbin{\|}\dots\mathbin{\|}r^{(h)}\right]W_{O} &= \begin{bmatrix} r^{(1)} & \dots & r^{(h)} \end{bmatrix} \begin{bmatrix} W_{O}^{(1)} \\ \vdots \\ W_{O}^{(h)} \end{bmatrix} \\ &= r^{(1)}W_{O}^{(1)} + \dots + r^{(h)}W_{O}^{(h)} \\ &= \sum_{k=1}^h r^{(k)}W_{O}^{(k)}. \end{aligned}

This decomposition shows that the total output is the sum of the separately projected head results. Each head contributes an update vector, but, as noted above, this algebraic decomposition does not imply that the learned head functions are independent.

VI. Attention Heads as Information Movers

Attention Head Movement
Attention Head Movement

Within the standard Transformer architecture covered here, an attention head is the component that moves information between token positions. It reads value information from residual states at source positions and contributes a weighted update at each query position.

To formalize this, let’s analyze the computation for a single head.

  • Let XX be the matrix of input row vectors from the residual stream, with shape N×dmodelN\times d_{model}, where NN is sequence length.
  • The head computes value vectors V=XWVRN×dvV = X W_V\in\mathbb R^{N\times d_v}. This is a per-token operation.
  • It computes an attention matrix AA (shape [N×N][N \times N]), where AijA_{ij} is the softmax score from query ii to key jj.
  • The result vectors are computed by mixing values: R=AVR = A V. This is an across-token operation, where the result for token ii, rir_i, is jAijvj\sum_j A_{ij} v_j.
  • Finally, with WORdv×dmodelW_O\in\mathbb R^{d_v\times d_{model}}, the output written to the stream is H=RWO=AXWVWORN×dmodelH = R W_O = AXW_VW_O\in\mathbb R^{N\times d_{model}}.

This sequence of operations—per-token projection, across-token mixing, per-token projection—can be expressed using the Kronecker product (\otimes), following the notation in the framework paper 3.

Definition (Bilinear Map).

A bilinear map ff is a function that combines elements from two vector spaces into an element of a third vector space. Moreover, a bilinear map is linear in each of its arguments when the other is fixed. Formally, a bilinear map f:X×YWf : X \times Y \to W satisfies:

f(λx,y)=λf(x,y),λF,xX,yY,f(x,λy)=λf(x,y),λF,xX,yY,f(x1+x2,y)=f(x1,y)+f(x2,y),f(x,y1+y2)=f(x,y1)+f(x,y2).\begin{aligned} f(\lambda x, y) &= \lambda f(x, y), \quad \forall \lambda \in F, \, x \in X, \, y \in Y, \\ f(x, \lambda y) &= \lambda f(x, y), \quad \forall \lambda \in F, \, x \in X, \, y \in Y, \\ f(x_{1} + x_{2}, y) &= f(x_{1}, y) + f(x_{2}, y), \\ f(x, y_{1} + y_{2}) &= f(x, y_{1}) + f(x, y_{2}). \end{aligned}
Definition (Tensor Product).

A tensor product VWV \otimes W is a vector space together with a canonical bilinear map f:V×WVWf : V \times W \to V \otimes W that is universal with respect to bilinear maps (i.e., for any bilinear map g:V×WUg : V \times W \to U, there exists a unique linear map g~:VWU\tilde{g} : V \otimes W \to U such that g=g~fg = \tilde{g} \circ f).

If AA is an m×nm \times n matrix and BB is a p×qp \times q matrix, then their Kronecker product (denoted ABA \otimes B) is the block matrix of size (mp)×(nq)(mp) \times (nq) given by

AB=[a11Ba1nBam1BamnB].A \otimes B = \begin{bmatrix} a_{11} B & \cdots & a_{1n} B \\ \vdots & \ddots & \vdots \\ a_{m1} B & \cdots & a_{mn} B \end{bmatrix}.
  • The Kronecker product is a concrete realization of the tensor product when AA and BB are regarded as linear maps between vector spaces.
  • Define rvec(X)=vec(XT)\operatorname{rvec}(X)=\operatorname{vec}(X^T), where the ordinary vec\operatorname{vec} stacks columns. Thus rvec\operatorname{rvec} stacks the rows of XX into a column, matching our convention that tokens are rows. For compatible matrices A,X,BA,X,B, the useful identity is
rvec(AXB)=(ABT)rvec(X).\operatorname{rvec}(AXB)=(A\otimes B^T)\operatorname{rvec}(X).
Remark (Attention Head as a Tensor Product).

If we stack the rows of XX into rvec(X)RNdmodel\operatorname{rvec}(X)\in\mathbb R^{Nd_{model}}, then, conditional on holding the attention matrix AA fixed, the value-and-output path can be written as a linear transformation:

rvec(H)=(INWOT)Write: project resultsfor each token(AIdv)Mix: combine value vectorsacross tokens(INWVT)Read: compute valuefor each tokenrvec(X).\operatorname{rvec}(H) = \underbrace{(I_N \otimes W_O^T)}_{\substack{\text{Write: project results} \\ \text{for each token}}} \cdot \underbrace{(A \otimes I_{d_v})}_{\substack{\text{Mix: combine value vectors} \\ \text{across tokens}}} \cdot \underbrace{(I_N \otimes W_V^T)}_{\substack{\text{Read: compute value} \\ \text{for each token}}} \cdot \operatorname{rvec}(X).

Using the mixed-product rule for Kronecker products, this becomes

rvec(H)=(A(WVWO)T)rvec(X).\operatorname{rvec}(H) = \left(A\otimes (W_VW_O)^T\right)\operatorname{rvec}(X).

This compact form separates the fixed pattern of movement between token positions, AA, from the value-output map WVWOW_VW_O applied in feature space. It is not a global linearization of self-attention: normally A=A(X)A=A(X) because queries and keys are computed from XX, so the full map XA(X)XWVWOX\mapsto A(X)XW_VW_O is nonlinear.

We will stop at this general decomposition. To go further, we would need to study how A(X)A(X) is formed in a one-layer attention-only Transformer; that is a question for another note.

Citation

BIBTEX
@misc{ln2025residual,
author={Nguyen Le},
title={Residual Stream is Key to Transformer Interpretability},
year={2025},
url={https://lenguyen.vercel.app/note/math-transformers}
}

References

  1. [Elhage et al., 2021]
    A Mathematical Framework for Transformer Circuits[HTML]
    Elhage, Nelson, Nanda, Neel, Olsson, Catherine, et al., 2021. Transformer Circuits Thread.
  2. [Olah et al., 2020]
    Zoom In: An Introduction to Circuits[HTML][DOI]
    Olah, Chris, Cammarata, Nick, Schubert, Ludwig, et al., 2020. Distill.

Footnotes

  1. https://transformer-circuits.pub/2021/framework/index.html#def-privileged-basis 2

  2. https://transformer-circuits.pub/2021/framework/index.html#d-footnote-6

  3. https://transformer-circuits.pub/2021/framework/index.html#notation-tensor-product