- The paper introduces a novel neuroscientific approach, viewing the transformer's residual stream as a dynamical system to analyze its layer-by-layer computations.
- Analysis of Llama 3.1 shows that individual residual stream units maintain surprising continuity across layers, while the overall residual stream vector accelerates and becomes denser.
- Findings suggest that transformer representations follow structured, self-correcting curved trajectories, indicating stable computational patterns that actively maintain desired dynamics.
The paper "Transformer Dynamics: A neuroscientific approach to interpretability of LLMs" introduces a novel framework for studying computations in deep learning systems, drawing inspiration from dynamical systems approaches in neuroscience. The authors conceptualize the residual stream (RS) in transformer models as a dynamical system evolving across layers. Their analysis focuses on characterizing the behavior of individual RS units and the overall dynamics of the RS vector. The model used in the experiments is Llama 3.1 8B, where L=32 represents the number of layers and D=4096 is the model dimension.
Key findings include:
- Continuity of Residual Stream Units: The paper demonstrates that individual units in the RS maintain strong correlations across layers, despite the RS not being a privileged basis. The Pearson correlation coefficient between activations at different layers is computed as:
rl,l+1u=σhliσhl+1icov(hli,hl+1i)
where:
- rl,l+1u is the Pearson correlation coefficient between layers l and l+1 for unit u
- cov(hli,hl+1i) is the covariance of activations of unit i at layers l and l+1
- σhli is the standard deviation of activations of unit i at layer l
This continuity suggests an unexpected stability in the representations learned by the transformer.
Evolution of the Residual Stream: The RS systematically accelerates and grows denser as information progresses through the network's layers. The velocity V of the RS vectors is calculated as ∥Vl∥=∥hl+1−hl∥2, where ∥⋅∥2 denotes the Euclidean norm. The magnitude of activations at the last token position for input sequences increases over the layers. Units tend to preserve their sign over the layers.
Mutual Information Dynamics: The authors identify a sharp decrease in mutual information (MI) during early layers, indicating a transformation in how the network processes information. The mutual information is computed using kernel density estimation:
MI(l,l+1)=∑p(x,y)log((p(x)p(y)p(x,y))
where:
- MI(l,l+1) is the mutual information between layers l and l+1
- p(x,y) is the joint probability density of activations at layers l and l+1
- p(x) and p(y) are the marginal densities of activations at layers l and l+1 respectively.
This decrease occurs simultaneously with increasing linear correlations between layers.
Unstable Periodic Orbits: Individual RS units trace unstable periodic orbits in phase space, suggesting structured computational patterns at the unit level. The number of rotations in the 2D phase space (defined by the unit's activation value and its gradient across layers) is quantified by tracking the cumulative change in angle of the tangent vector along the trajectory. The total number of rotations R is calculated as:
R=2π1∑lΔθl
where:
- Δθl=θl+1−θl is the angle change between consecutive points
- θl=arctan2(Δyl,Δxl) represents the angles of tangent vectors
- Δxl=xl+1−xl and Δyl=yl+1−yl are the tangent vectors between consecutive points.
- Curved Trajectories and Attractor-like Dynamics: Representations in the RS follow self-correcting curved trajectories in reduced dimensional space, with attractor-like dynamics in the lower layers. Dimensionality reduction is performed using both a compressing autoencoder (CAE) and Principal Component Analysis (PCA). Perturbation analysis in PCA space reveals that trajectories "teleported" to various points tend to return to the original trajectory, indicating self-correcting dynamics. The inverse PCA transformation is given by:
xi=ziV[:2]T+μ
where:
- xi is the reconstructed activation vector
- zi is the point in the 2D grid
- V[:2] contains the first two principal components
- μ is the mean of the original activation distribution.
The authors suggest that their findings support the notion that transformers develop stable computational channels that actively maintain desired trajectories, possibly self-correcting errors through their dynamics. They propose that this "neuroscience of AI" approach, which combines theoretical rigor with large-scale data analysis, can advance our understanding of modern neural networks.
The paper contrasts the dynamical systems approach with circuit-based mechanistic interpretability and methods using sparse autoencoders. It suggests that investigating the dynamics of transformers could unify theoretical insights with large-scale data analysis and experimental manipulation. Future work may involve examining the dynamics of the RS in other AI architectures, analyzing the influence of whole sequences of tokens on dynamics, and investigating dynamics over the course of model training.