# Attention SAEs Scale to GPT-2 Small

*This is an interim report that we are currently building on. We hope this update + open sourcing our SAEs will be useful to related research occurring in parallel. Produced as part of the*[* ML Alignment & Theory Scholars Program*](https://www.matsprogram.org/) *\- Winter 2023-24 Cohort*

Executive Summary
-----------------

*   In a previous post, we showed that [sparse autoencoders (SAEs) work on the attention layer outputs](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs) of a two layer transformer. We scale our attention SAEs to GPT-2 Small, and continue to find sparse interpretable features in every layer. This makes us optimistic about our ongoing efforts scaling further, especially since we didn’t have to do much iterating
*   We open source our SAEs. Load them from [Hugging Face](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers) or this [colab notebook](https://colab.research.google.com/drive/1hZVEM6drJNsopLRd7hKajp_2v6mm_p70?usp=sharing)
    *   The SAEs seem good, often recovering more than 80% of the loss relative to zero ablation, and are sparse with less than 20 features firing on average. The majority of the live features are interpretable
*   We continue to find the same three feature families that we found in the [two layer model](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs): [induction features](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs#Induction_Feature__Board_induction), [local context features](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs#Local_Context_Feature__In_questions_starting_with__Which_), and [high level context features](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs#High_Level_Context_Feature___In_a_text_related_to_pets__feature). This suggests that some of our lessons interpreting features in smaller models may generalize
*   We also find new, interesting feature families that we didn’t find in the two layer model, providing hints about fundamentally different capabilities in GPT-2 Small
    *   See our [feature interface](https://ckkissane.github.io/attn-sae-gpt2-small-viz/) to browse the first 30 features for each layer
    *   New: use [Neuronpedia](https://www.neuronpedia.org/) to visualize these SAEs

Introduction
------------

In [Sparse Autoencoders Work on Attention Layer Outputs](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs) we showed that we can apply SAEs to extract sparse interpretable features from the last attention layer of a two layer transformer. We have since applied the same technique to a 12-layer model, GPT-2 Small, and continue to find sparse, interpretable features in every layer. Our SAEs often recover more than 80% of the loss[^0i58xkotesxs], and are sparse with less than 20 features firing on average. We perform shallow investigations of the first 30 features from each layer, and we find that the majority (often 80%+) of non-dead SAEs features are interpretable. See the features with our [interactive visualizations](https://ckkissane.github.io/attn-sae-gpt2-small-viz/) for each layer.

We open source our SAEs in hope that they will be useful to other researchers currently working on dictionary learning. We are particularly excited about using these SAEs to better understand attention circuits at the feature level. See the SAEs on [Hugging Face](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers) or load them using this [colab notebook](https://colab.research.google.com/drive/1hZVEM6drJNsopLRd7hKajp_2v6mm_p70?usp=sharing). Below we provide the key metrics for each SAE:

|     | L0 norm | loss recovered | dead features | % alive features interpretable |
| --- | --- | --- | --- | --- |
| [L0](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L0_Hcat_z_lr1.20e-03_l11.80e%2B00_ds24576_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v9.pt) | 3   | 99% | 13% | 97% |
| [L1](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L1_Hcat_z_lr1.20e-03_l18.00e-01_ds24576_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v5.pt) | 20  | 78% | 49% | 87% |
| [L2](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L2_Hcat_z_lr1.20e-03_l11.00e%2B00_ds24576_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v4.pt) | 16  | 90% | 20% | 95% |
| [L3](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L3_Hcat_z_lr1.20e-03_l19.00e-01_ds24576_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v9.pt) | 15  | 84% | 8%  | 75% |
| [L4](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L4_Hcat_z_lr1.20e-03_l11.10e%2B00_ds24576_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v7.pt) | 15  | 88% | 5%  | 100% |
| [L5](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L5_Hcat_z_lr1.20e-03_l11.00e%2B00_ds49152_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v9.pt) | 20  | 85% | 40% | 82% |
| [L6](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L6_Hcat_z_lr1.20e-03_l11.10e%2B00_ds24576_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v9.pt) | 19  | 82% | 28% | 75% |
| [L7](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L7_Hcat_z_lr1.20e-03_l11.10e%2B00_ds49152_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v9.pt) | 19  | 83% | 58% | 70% |
| [L8](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L8_Hcat_z_lr1.20e-03_l11.30e%2B00_ds24576_bs4096_dc1.00e-05_rsanthropic_rie25000_nr4_v6.pt) | 20  | 76% | 37% | 64% |
| [L9](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L9_Hcat_z_lr1.20e-03_l11.20e%2B00_ds24576_bs4096_dc1.00e-06_rsanthropic_rie25000_nr4_v9.pt) | 21  | 83% | 48% | 85% |
| [L10](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L10_Hcat_z_lr1.20e-03_l11.30e%2B00_ds24576_bs4096_dc1.00e-05_rsanthropic_rie25000_nr4_v9.pt) | 16  | 85% | 41% | 81% |
| [L11](https://huggingface.co/ckkissane/attn-saes-gpt2-small-all-layers/blob/main/gpt2-small_L11_Hcat_z_lr1.20e-03_l13.00e%2B00_ds24576_bs4096_dc3.16e-06_rsanthropic_rie25000_nr4_v9.pt) | 8   | 89% | 84% | 66% |

It’s worth noting that we didn’t do much differently to train these,[^i9ha37eedx] leaving us optimistic about the tractability of scaling attention SAEs to even bigger models.

Excitingly, we also continue to identify feature families. We find features from all three of the families that we identified in the two layer model: [induction features](https://www.lesswrong.com/posts/FSTRedtjuHa4Gfdbr/attention-saes-scale-to-gpt-2-small#Induction_Features), local context features, and high level context features. This provides us hope that some of our lessons from interpreting features in smaller models will continue to generalize. 

We also find new, interesting feature families in GPT-2 Small, suggesting that attention SAEs can provide valuable hints about new[^zdfaflvpr6n] capabilities that larger models have learned. Some new features include:

*   [Successor features](https://www.lesswrong.com/posts/FSTRedtjuHa4Gfdbr/attention-saes-scale-to-gpt-2-small#Successor_Features), which activate when predicting the next item in a sequence such as “15, 16” -> “17” (which are partly coming from [Successor Heads](https://arxiv.org/abs/2312.09230) in the model), and boost the logits of the next item.
*   [Name mover features](https://www.lesswrong.com/posts/FSTRedtjuHa4Gfdbr/attention-saes-scale-to-gpt-2-small#Name_Mover_Features), which predict a name in the context, such as in the [IOI](https://arxiv.org/abs/2211.00593) task
*   [Duplicate token features](https://www.lesswrong.com/posts/FSTRedtjuHa4Gfdbr/attention-saes-scale-to-gpt-2-small#Duplicate_Token_Features), which activate on the second instance of a token (heads discussed in [this section](https://transformer-circuits.pub/2021/framework/index.html#:~:text=COPYING%20/%20PRIMITIVE%20IN%2DCONTEXT%20LEARNING) of A Mathematical Framework for Transformer Circuits”)
*   [Suppression features](https://www.lesswrong.com/posts/FSTRedtjuHa4Gfdbr/attention-saes-scale-to-gpt-2-small#Suppression_Features), which suppress the prediction of an earlier token in the context (which explain [Copy Suppression](https://arxiv.org/abs/2310.04625))
*   [n-gram features](https://www.lesswrong.com/posts/FSTRedtjuHa4Gfdbr/attention-saes-scale-to-gpt-2-small#Finding_Surprising_Behaviors__n_gram_Features), which predict a word in a common n-gram, like "two and a" -> "half", a surprising use of attention in a real model

We note that these feature families corroborate most known attention mechanisms found in GPT-2 Small in the literature.[^9axqbf7l4op] The fact that the SAE lens organically agrees with other techniques gives us confidence that we are headed in the right direction.

Looking forward, we are most excited about leveraging our attention SAEs for circuit analysis at the feature level, and using them to develop a more detailed understanding of attention heads.

Feature Families
----------------

We continue to find the existence of feature families in GPT-2 Small. We find familiar families from the two layer model, like induction, as well as new, interesting feature families that seem new to GPT-2 Small. We are excited about both. 

The familiar features show us that our efforts interpreting smaller models are not in vain, as at least some of the features may generalize. On the other hand, the new features suggest that we can use our SAEs to gain insight into fundamentally new and more interesting capabilities as we scale up to larger models. 

We choose to highlight the most interesting features that show up in the middle-to-late layers. For a more comprehensive view of what each layer learns, see the [interactive visualizations](https://ckkissane.github.io/attn-sae-gpt2-small-viz/). While we don’t rigorously study these features in detail, we showcase signs of life using techniques like max activating dataset examples, direct feature attribution, and weight based logit analysis.

**Induction Features**

We continue to find many induction features in the middle-to-late layers of GPT2 small. Just as we found in the two layer model, these seem to be of the form “X is next by induction”, where X is some token in the vocabulary. Specifically, they activate on the second token in prompts of the form “<token> X … <token>”. 

To see what past information is being used to compute these features, we leverage our [“direct feature attribution” (aka DFA) technique](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs#Understanding_how_the_feature_is_computed_) by decomposing the feature activations into a linear combination of the contributions from the value vectors at each source position. We add this to our feature interface, highlighting the position with the top DFA in blue. We observe that the attention layer is moving the previous instance of ‘X’ following the first <token> to compute this feature. Here is one example of a “‘-’ is next by induction” feature from layer 5:

![](https://lh7-us.googleusercontent.com/H5Ew09zfmHHMpCeUIIRrcfOSknL1AQf-TtHRcvWb3h5FgoLMYMQadQ88ZN6FYB9UcQCQeQNrdx-rPjyEDmgWTw4G7gLxAZlbQwhWLWaScsUpGXLCmeUmvmIEs8iIXAWyCX7k4xux1S62iDqjohR2sCM)

Layer 5 Feature 35744: ‘-’ is next by induction

These features also have an interpretable causal effect, clearly boosting the logits of X (in this case ‘-’).

![](https://lh7-us.googleusercontent.com/ovpS_vAnXhcgUJPY_WVKFy_Oad-XgsD6HOrB-KybBgfxmIWpHfmC-2ZFhrQpVn9lBcfSlUizBAULjVOdo07gmrvbvaw2N-7aPE2e6GBUZeyAs5GaIiEmWSbtTZdfePtWY95y1gsglJ8IoeOHtkc4tJM)

We also find that the decoder weights of the SAE mostly attribute these features to a subset of the induction heads of GPT-2 Small. In this case, L5H5.[^q20jd3x6yum]

![](https://lh7-us.googleusercontent.com/YXXjUnCTpx4r-gQe62yrK6kSshwkbncp49PuWiMIXGMPhCfHgbyWtyWlIWddsvGksBoQxwFI7SxOB6KH9an0USysy5vInhoVw2Ksuj4hn007fUNz3bF1E8TdBiESJPyhD5N_a9KX_44tublwtJFl-i4)

GPT2 Small induction head scores: computed based on the attention patterns on random repeated tokens

We attempted to heuristically identify induction related features using a similar heuristic to [the one applied in our previous post](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs#Automatic_Induction_Feature_Detection) on a 2L model. Consider layer 6 which has one induction head L6H9. As the equivalent of the Induction Selection Heuristic, we then identified features in Layer 6 which had at least 50% weight based attribution to L6H9. We applied the same Induction Behavior Heuristic as in the previous post (namely, at least 60% induction pass rate on a batch of 200 examples) to heuristically identify 117 of 158 possible induction features, showing the technique generalizes to GPT-2-Small.

![](https://lh7-us.googleusercontent.com/fFMHcvOBkpNf66IkHnK5iAfWdPn6-qKpEwPbUoVFYGVo3qFP0y4z-kyQAB6gwFwPzHxaeHripsDhnYPfGpoyisSc8mxdkzKIlXG0B66QKoA7L8iH4fPt2cd6S-2-mdndd0eIrh8C9GWL0NKOGO3zmRA)

As a negative sanity check, we randomly chose features that passed an inversion of the Induction Selection Heuristic (namely less than 20% attribution to L6H9) and found that none of the features passed the Induction Behavior Heuristic.  
 

![](https://lh7-us.googleusercontent.com/E5aAdLizQ-8oN545tjPFRe1xijsAjZUnpB7RNet3fc35-97Yd1os79mg_UEguiA5vJak_39ZvNtE96UJTq4xPyu9I7KQaiytoDHNaULunKlEXQAiE39c0wnyN7kNvwvNvjDV1ynFH5J83mlCOs2FocA)

**Duplicate Token Features**

We now highlight new feature families that we did not observe during our analysis of the two layer model. In Layer 3, we find many features which activate on repeated tokens. However, unlike induction, these have high direct feature attribution to the previous instance of that token (rather than the token following the previous instance).

![](https://lh7-us.googleusercontent.com/bk9XYaBHOnMMngBeMTvmPL9-E7wz8DQHQA09Tmt_aSYSW_JbOorMFD1ax1dKEl1BscsvBnEaGCHVkY1GTJfaNVVTsEcEWd8LpmNzrunKlH476a4R9fsKtPq3fwUUAIrluILsE0q4-8-mdWhESjgT83Q)

Layer 3 Feature 342: Duplicate token feature

We also notice that the norms of the decoder weights corresponding to L3H0, identified as a duplicate token head by [Wang et al](https://arxiv.org/abs/2211.00593), stand out. This shows that, similar to the induction feature, we can use weight based attribution to heads with previously known mechanisms to suggest the existence of certain feature families and vice versa.

![](https://lh7-us.googleusercontent.com/wHQvTMyXUe5eABbg4km3B0Yob4qGlMyiO6YVrwE8qeYLBmC-GKahQe1CKO4B2v5K70ZogmTgGZgd8UcEwp4cwsNwz3xql8_EyttPySz2Qi0-06rYJTDGMPfv8-vCyGe-3zUzvlArAR9Ejq8br2f7ONk)

**Successor Features**

In our Layer 9 SAE, we find features that activate in sequences of numbers, dates, letters, etc. The DFA by source position also suggests that the attention layer is looking back at the previous item(s) to compute this feature.

![](https://lh7-us.googleusercontent.com/fPk5dcS7KgPM3OhKEprxL_WaH1GXxppp_8BbEYH849Dcf4VXy8N3mw3YojJ7MS0jhiBL02Ht0EXmT-skbeJRJ7oVav-0pIumXS5Mg0c4Oolm5n5CBGaKbGlParmJOezcnwTntYN5VtvzQXdJFAQ07IY)

Layer 9 Feature 18: 16 -> 17 successor feature

The top logits of these features are also interpretable, suggesting that these features boost the next item in the sequence. Finally, the decoder weight norms also suggest that they heavily rely on head 9.1, a [successor head](https://arxiv.org/abs/2312.09230) in GPT-2 Small.

![](https://lh7-us.googleusercontent.com/pL4uJKZH_DNQM_WYo6F3fN78lKnlUNCSQ3-mHEl-m5QsKP7xNhwif0FF6k08dWvFau3yhiTyK15XRbWfWnGk4za8DKGJIrSjgN0Bds-SJYz8KwOoLcCgD3FTk_8OieiG-UhBhs6JqgJ5H3f5QL2gSRo)

**Name Mover Features**

In the later layers, we also find features that seem to predict a name in the context. The defining characteristic of these features is a very high logit boost to the name. We also see very high DFA to the past instances of this name in the context. Once again, our decoder weights also suggest that heads 9.9 and 9.6 are the top contributors of the feature, which were both identified as name mover heads in the [IOI paper](https://arxiv.org/abs/2211.00593). 

![](https://lh7-us.googleusercontent.com/47lV95ot_ipYaEvvKfxWs3nDQ0OOipFhein646ZVdQF88Rse5He2TC7ZgyOO6pw_gsAfhPcTh6TFqyuZBKZBWlF3QAVmFhSVvtoI5QCZcTaxyj-B_BGoezQI_maJsFfSFbYFcqpJj1atVDjxu5J6IPk)

![](https://lh7-us.googleusercontent.com/xBr15NnbACQZQrW0ToMyglvUC8LqsRNQJUeYRWidcNKZk-Os7YTTfHJpljrneX_Mfxn4rK9LQXXc0FqLDY4ytQom4qCFCOOjcvi_2cE7uArFDQB2UI-XL_prCV_uCjbb7ckGKDI-kZZbFXgaiyDeQxM)

Layer 9 Feature 17875: ‘James’ name mover feature

Interestingly, we find a relatively large number of name movers within our shallow investigations of the first 30 random features, suggesting that this might explain a surprisingly large fraction of what the late attention layers are doing.

**Suppression Features**

Finally, in layer 10 we find suppression features. These features show very low negative logits to a token in the context, suggesting that they actually seem to suppress these predictions. We use DFA to confirm that these features are being activated by previous instances of these tokens. Interestingly, our decoder weights also identify head 10.7 as the top contributing head, the same head identified to do copy suppression by [McDougall et al](https://arxiv.org/abs/2310.04625).

![](https://lh7-us.googleusercontent.com/g6TYVpIgTOdzYLQ1Ax51t00_2JWFAo3JE35liw1o7Ywv7AYAV5nTMJY0-0CVYDgI3KkC1AYkmWfGKetk3J1-ODhKFS4PyoAt3dIBkEo8PhmiBczhVAK6txHZ3SCxw1zHI_ctFxa1147rMlBRu6ubtuA)

![](https://lh7-us.googleusercontent.com/xuPK30xBxcuW1QdLITeRRtmt7vPjFHAU7iEWpOC88VKsR_rec8jI6BhMHelUBL0uq-RUDSt2I6bCynji0zlnfT0FHfiHgemAf39zHtPQ7Lms04NKoTbZ-sdDQKHIei3eRNSj75xD6On-YgHBZK4NDXg)

Layer 10 Feature 1610: ‘paper’ suppression

**Finding Surprising Behaviors: n-gram Features**

All of the features we have shown so far are related to previously studied behaviors, making them easier to spot and understand. We now show that we can also use our SAE to find new, surprising things attention layers have learned. This feature from Layer 9 seems to be completing a common n-gram, predicting the “half” in phrases like “<number> and a half”.

![](https://lh7-us.googleusercontent.com/0q2RMXiWhggQb-CxNc4h7AwISybG3SxZ5vZ8-rO-faCskON1WmkV70sXNXc08378-Jnl0waXsc8o0sP9oZjtjGnkHxXLuu1g8_gB2QZCtr02OPWqv_lLyy5KIouIJrWWwxHsKKrEluEYxoJkXoy4IW0)

![](https://lh7-us.googleusercontent.com/jT7fmzdDZ1hwOouqk7tGSd7lPeGn7jBSdrY_t6ZIwv-AcZFoD3Cb9tzk5Blyiq-R8MB6qTbfttBI13q0qwZ_QTcht3cOF8D-MNES8sEGbmVPtEg52hSd3TZf5geqZlG67m41OQZ_QDTUADBKTCmEe8U)

Layer 9 Feature 15: “<number> and a half” n-gram

Though n-grams may seem like a simple capability, it's worth emphasizing why this is surprising. The intuitive way to implement n-grams would involve some kind of boolean AND (eg the current token is "and" AND the previous token is a number). This feels like a job for the MLP, not attention.

Limitations
-----------

*   Our feature investigations are relatively shallow, so it’s possible that our initial hypotheses are missing subtleties.
*   We already had priors on what kind of feature families would exist based on previous work, making them easier to spot. It’s likely that these are overrepresented in this post, and we are missing many additional behaviors that the attention layers have learned, like the n-gram feature.

Future Work 
------------

We feel pretty convinced that attention SAEs extract interpretable features, and allow for interesting exploration of what attention layers have learned. Now we focus on leveraging our SAEs to develop even deeper understanding of the attention layers. In particular we plan to apply our attention SAEs to better understand circuits and attention heads at the feature level.

For projects ideas that we likely won't prioritize (but would be excited to see explored) please see Joseph Bloom's [post](https://www.lesswrong.com/posts/f9EgfLSurAiqRJySD/open-source-sparse-autoencoders-for-all-residual-stream#What_research_directions_could_you_pursue_with_SAEs__).

Citing this work
----------------

Feel free to use [the citation from the first post](https://www.lesswrong.com/posts/DtdzGwFh9dCfsekZZ/sparse-autoencoders-work-on-attention-layer-outputs#Citing_this_work), or this citation specifically for this current post:

    @misc{gpt2_attention_saes,
      author= {Connor Kissane and Robert Krzyzanowski and Arthur Conmy and Neel Nanda},
      url = {https://www.alignmentforum.org/posts/FSTRedtjuHa4Gfdbr},
      year = {2024},
      howpublished = {Alignment Forum},
      title = {Attention SAEs Scale to GPT-2 Small},
    }

Author Contributions Statement
------------------------------

Connor and Rob were core contributors on this project. Connor trained the SAEs, performed shallow investigations of random features, and identified the new feature families. He also added the DFA visualizations to the feature dashboards and created the web pages with feature visualizations for each layer. Rob performed automated feature family detections such as induction feature checks and also investigations of random features. Arthur and Neel gave guidance and feedback throughout the project. The original project idea was suggested by Neel.

  
 

[^0i58xkotesxs]: Using a zero ablation baseline 

[^i9ha37eedx]: Since the last post, we've implemented Anthropic's resampling scheme and a periodic learning rate warmup 

[^zdfaflvpr6n]: Note we haven't systematically checked all ~16,000 features in the two layer model to confirm this, but they never appeared in our investigations 

[^9axqbf7l4op]: With the exception of the n-gram feature, which hints at new mechanisms not yet attributed to attention heads within the existing literature (to our knowledge). 

[^q20jd3x6yum]: Studying how and why features are distributed across heads is an exciting area of future work