The MultiSAETrainingRunner allows you to train a sweep of SAEs (e.g., different l1_coefficient values or different layers) simultaneously. The runner performs a single LLM forward pass per batch and multiplexes the resulting activations to all configured SAEs, which is more efficient than training them sequentially.
Key Constraints (V1):
- Does not support CLI/argparse, cached activations, or
from_pretrained_path per entry. compile_sae=True is not supported, but compile_llm=True is.- SAEs sharing a hook must agree on
d_in and hook_head_index.
Configuration:
saes: A dictionary mapping names to SAE configurations (e.g., StandardTrainingSAEConfig or TopKTrainingSAEConfig).hook_names: A dictionary mapping SAE names to their specific hook points, or a single string if all SAEs share the same hook.
Checkpointing:
Checkpoints include per-SAE subdirectories. To resume, use resume_from_checkpoint=<checkpoint_dir> and ensure the keys in cfg.saes match the subdirectory names.
from sae_lens import (
MultiSAETrainingRunner,
MultiSAETrainingRunnerConfig,
StandardTrainingSAEConfig,
TopKTrainingSAEConfig,
LoggingConfig,
)
cfg = MultiSAETrainingRunnerConfig(
saes={
"h5_l1_low": StandardTrainingSAEConfig(d_in=768, d_sae=16 * 1024, l1_coefficient=2.0),
"h5_l1_high": StandardTrainingSAEConfig(d_in=768, d_sae=16 * 1024, l1_coefficient=5.0),
"h10_topk": TopKTrainingSAEConfig(d_in=768, d_sae=16 * 1024, k=64),
},
hook_names={
"h5_l1_low": "blocks.5.hook_resid_pre",
"h5_l1_high": "blocks.5.hook_resid_pre",
"h10_topk": "blocks.10.hook_resid_pre",
},
# OR a single string when every SAE shares one hook:
# hook_names="blocks.5.hook_resid_pre",
model_name="gpt2",
dataset_path="apollo-research/Skylion007-openwebtext-tokenizer-gpt2",
training_tokens=int(1e8),
train_batch_size_tokens=4096,
output_path="output/sweep_run_1",
logger=LoggingConfig(log_to_wandb=True, wandb_project="multi_sae_sweep"),
)
trained_saes = MultiSAETrainingRunner(cfg).run() # dict[name, TrainingSAE]