SAEs on a grokked modular-addition transformer
Collection
Base models and sparse autoencoders for the grokked modular-addition transformer (Nanda et al. 2023). โข 2 items โข Updated
How to use BurnyCoder/modular-addition-saes with SAELens:
# pip install sae-lens
from sae_lens import SAE
sae, cfg_dict, sparsity = SAE.from_pretrained(
release = "RELEASE_ID", # e.g., "gpt2-small-res-jb". See other options in https://github.com/jbloomAus/SAELens/blob/main/sae_lens/pretrained_saes.yaml
sae_id = "SAE_ID", # e.g., "blocks.8.hook_resid_pre". Won't always be a hook point
)Base models and sparse autoencoders (SAEs) from the project sparse-autoencoders-on-modular-addition-transformer by Libor "Burny" Burian. Results, preregistration and paper are in the GitHub repository.
base/<run>/model.pt: the 1-layer modular-addition transformer of Nanda et al. 2023. It uses the TransformerLens 4 demo recipe: p = 113, d_model 128, 4 heads, d_mlp 512, ReLU, no LayerNorm, biases frozen at 0, 30% train split (data seed 598), AdamW lr 1e-3, wd 1, 40k full-batch epochs. Next to it, checkpoints.pt holds a state dict every 100 epochs, and training.json / mechanism.json hold the training curves and the Fourier mechanism analysis.saes/<run_id>/: SAELens inference SAEs (cfg.json + sae_weights.safetensors; BatchTopK SAEs are saved as JumpReLU with a global threshold) trained on last-position (=) activations at resid_mid (the MLP input) or mlp_post. Each folder also has metrics.json (SAE-test FVU, logit FVU, L0, dead fraction, spliced accuracy/KL), and where computed characterization.json (features scored against the mechanism) and steering.json.import torch
from sae_lens import SAE
from modsae import model # from the GitHub repo
m, cfg, history = model.load_model("base/base_s999/model.pt", device="cpu")
sae = SAE.load_from_disk("saes/sae_base_s999_resid_mid_batchtopk_m256_k16_r0", device="cpu")
Note: in TransformerLens 4 the hook alias blocks.0.hook_resid_mid only feeds the MLP branch. To replace the whole residual stream, overwrite blocks.0.hook_attn_out (see src/modsae/interventions.py).