This is a research fork of decoderesearch/SAELens,
repurposed as the model-organism-interp project. It uses the upstream SAELens
library as a foundation and adds an analysis pipeline for studying how fine-tuning
shifts SAE feature usage in quirked model organisms (e.g. Gemma 3 1B IT variants
trained to talk about submarines in military contexts, or to express Italian-food
preferences).
What this fork adds on top of upstream:
scripts/model_organism_interp_analysis/— full pipeline (per-MO feature analysis, sibling-diff variants, LLM-based feature judging via OpenRouter, cross-MO noise floors, paper plots). Seescripts/model_organism_interp_analysis/README.mdfor the full overview and command reference.- uv-based dependency management (
uv.lock,pyproject.tomlrewrite) with a CUDA symlink fix-up script atscripts/fix_cuda_libs.sh. CLAUDE.md— project guidance for Claude Code.
Run once after uv sync, or on a new machine:
uv sync
bash scripts/fix_cuda_libs.sh # symlinks system CUDA .so files into the venvRequired before running analysis. Gemma 3 is gated; OpenRouter is needed for the
LLM judge. Copy .env.example to .env and fill in both keys:
HF_TOKEN=<your_token>
OPENROUTER_API_KEY=<your_key>
bash scripts/model_organism_interp_analysis/run_binary_pipeline.shFor per-step commands, judge options, regeneration flags, sibling pipeline, plots,
and exports, see
scripts/model_organism_interp_analysis/README.md.
python3 -m http.server 8080 --directory results
# then open e.g.: http://localhost:8080/military_submarine_binary/runs/<run>_feature_analysis.html
# http://localhost:8080/italian_food_binary/runs/<run>_feature_analysis.htmlThe upstream SAELens README follows below, describing the underlying library.
SAELens exists to help researchers:
- Train sparse autoencoders.
- Analyse sparse autoencoders / research mechanistic interpretability.
- Generate insights which make it easier to create safe and aligned AI systems.
SAELens inference works with any PyTorch-based model, not just TransformerLens. While we provide deep integration with TransformerLens via HookedSAETransformer, SAEs can be used with Hugging Face Transformers, NNsight, or any other framework by extracting activations and passing them to the SAE's encode() and decode() methods.
Please refer to the documentation for information on how to:
- Download and Analyse pre-trained sparse autoencoders.
- Train your own sparse autoencoders.
- Generate feature dashboards with the SAE-Vis Library.
SAE Lens is the result of many contributors working collectively to improve humanity's understanding of neural networks, many of whom are motivated by a desire to safeguard humanity from risks posed by artificial intelligence.
This library is maintained by Joseph Bloom, Curt Tigges, Anthony Duong and David Chanin.
Pre-trained SAEs for various models can be imported via SAE Lens. See this page for a list of all SAEs.
The new v6 update is a major refactor to SAELens and changes the way training code is structured. Check out the migration guide for more details.
- SAE Lens + Neuronpedia
- Loading and Analysing Pre-Trained Sparse Autoencoders
- Understanding SAE Features with the Logit Lens
- Training a Sparse Autoencoder
- Training SAEs on Synthetic Data
- SynthSAEBench: Evaluating SAE Architectures on Synthetic Data
Feel free to join the Open Source Mechanistic Interpretability Slack for support!
- dictionary-learning: An SAE training library that focuses on having hackable code.
- Sparsify: A lean SAE training library focused on TopK SAEs.
- Overcomplete: SAE training library focused on vision models.
- SAE-Vis: A library for visualizing SAE features, works with SAELens.
- SAEBench: A suite of LLM SAE benchmarks, works with SAELens.
Please cite the package as follows:
@misc{bloom2024saetrainingcodebase,
title = {SAELens},
author = {Bloom, Joseph and Tigges, Curt and Duong, Anthony and Chanin, David},
year = {2024},
howpublished = {\url{https://github.com/decoderesearch/SAELens}},
}