crosscoder-learning

Train and evaluate sparse autoencoders and crosscoders on language model activations.

75|7|Updated May 2, 2026
One-click install
npx skills add https://github.com/zjunlp/Mechanist --skill crosscoder-learning-zjunlp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: crosscoder-learning
Source: https://github.com/zjunlp/Mechanist/tree/main/skills/mechanism-skills/feature-dictionary-learning/crosscoder
Command: npx skills add https://github.com/zjunlp/Mechanist --skill crosscoder-learning-zjunlp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, nnsight, dictionary_learning, transformers, datasets, sae_lens, huggingface_hub, and includes scripts (resource) components.

What problem does it solve? Training sparse autoencoders (SAEs) and crosscoders for mechanistic interpretability requires wiring together model hooking, activation buffering, dictionary training, and evaluation, which is error-prone to set up from scratch. This Skill provides working scripts and guidance for the dictionary_learning library so you can train dictionaries, load pretrained weights, and compare model internals without reinventing the pipeline. ## Core Features & Use Cases - SAE Training: Train sparse autoencoders on MLP, attention, or residual stream activations using StandardTrainer, ActivationBuffer, and trainSAE with configurable sparsity penalties and dead-neuron resampling. - CrossCoder Model Diffing: Train crosscoders (including BatchTopKCrossCoder) to identify which features change between a base model and its fine-tuned variant. - Pretrained Dictionaries & Evaluation: Load pretrained AutoEncoders, JumpReLU SAEs, and crosscoders from disk or the Hugging Face Hub, and evaluate them with MSE, L0/L1 sparsity, and variance-explained metrics. - Use Case: Compare a base model against its chat fine-tuned variant by training a crosscoder on paired activations to isolate concepts introduced during fine-tuning. ## Quick Start Ask the assistant to train a sparse autoencoder on layer 1 MLP activations of Pythia-70m using the train_sae_demo.py script and report the evaluation metrics.

Frequently Asked Questions about crosscoder-learning

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I train a sparse autoencoder on language model activations?

Load the model with nnsight's LanguageModel, wrap a submodule such as an MLP layer in an ActivationBuffer, then call trainSAE with a StandardTrainer config specifying activation_dim, dict_size, learning rate, and l1_penalty. The scripts/train_sae_demo.py file shows the full pipeline.

How do I compare a base model and its fine-tuned variant with crosscoders?

Train a CrossCoder or BatchTopKCrossCoder on paired activations from both models at the same layer. Features that reconstruct one model's activations better than the other's reveal concepts introduced or removed during fine-tuning, as described in the BatchTopK crosscoder paper.

Can I load pretrained SAEs from the Hugging Face Hub?

Yes, the dictionary_learning library supports loading pretrained AutoEncoders, JumpReLU SAEs, and crosscoders from local disk or the Hugging Face Hub, and can push trained dictionaries back to the Hub. JumpReLU loading from sae_lens requires the sae_lens package.

What metrics should I use to evaluate a trained SAE?

Standard metrics are MSE reconstruction loss, L0 sparsity (average active features per sample), L1 sparsity, fraction of alive dictionary features, and variance explained. The evaluation scripts compute these from encoded features and reconstructions.

Why does my SAE have many dead neurons during training?

Dead neurons are dictionary features that never activate, often caused by a high learning rate or excessive L1 penalty. Enable periodic dead-neuron resampling via the resample_steps parameter in trainSAE to reinitialize them during training.