[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KQC0BQM2EWJRVDM25ABNJF":3,"skill-same:01M6KQC0BQM2EWJRVDM25ABNJF":94},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":22,"publishedAt":44,"linkOnly":45,"markdownContent":46,"markdownBody":47,"frontMatter":48,"refName":60,"commitSha":61,"skillDirectory":62,"forksCount":13,"repositoryHtmlUrl":63,"repositoryHomepageUrl":6,"ownerHtmlUrl":64,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":65,"install":66,"resources":79},"01M6KQC0BQM2EWJRVDM25ABNJF","sparse-autoencoder-training",null,"Provides guidance for training and analyzing Sparse Autoencoders (SAEs) using SAELens to decompose neural network activations into interpretable features. Use when discovering interpretable features, analyzing superposition, or studying monosemantic representations in language models.","endman100\u002Fskill-router-nexus","endman100","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F31997019?v=4","01M6KPDX17BYDWW4RRB0TNGGMX","01M6KPDX64Y2QBEWVFG5W5PWPF",0,"MIT","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FAI-Research\u002Fsaelens\u002Fsaelens\u002FSKILL.md",[17],{"categoryNo":18,"categoryName":19,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000021","资料检索与研究","SCENARIO","使用场景",[23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43],"training","sparse autoencoder training","when","research","features","for","orchestra","Sparse Autoencoders","Interpretability","Transformer","lens","neural network","saelens","feature","superposition","Neural","decompose","use","discovery","network","analyzing","2026-11-10 10:12:30",false,"---\nname: sparse-autoencoder-training\ndescription: Provides guidance for training and analyzing Sparse Autoencoders (SAEs) using SAELens to decompose neural network activations into interpretable features. Use when discovering interpretable features, analyzing superposition, or studying monosemantic representations in language models.\nversion: 1.0.0\nauthor: Orchestra Research\nlicense: MIT\ntags: [Sparse Autoencoders, SAE, Mechanistic Interpretability, Feature Discovery, Superposition]\ndependencies: [sae-lens>=6.0.0, transformer-lens>=2.0.0, torch>=2.0.0]\n---\n\n# SAELens: Sparse Autoencoders for Mechanistic Interpretability\n\nSAELens is the primary library for training and analyzing Sparse Autoencoders (SAEs) - a technique for decomposing polysemantic neural network activations into sparse, interpretable features. Based on Anthropic's groundbreaking research on monosemanticity.\n\n**GitHub**: [jbloomAus\u002FSAELens](https:\u002F\u002Fgithub.com\u002FjbloomAus\u002FSAELens) (1,100+ stars)\n\n## The Problem: Polysemanticity & Superposition\n\nIndividual neurons in neural networks are **polysemantic** - they activate in multiple, semantically distinct contexts. This happens because models use **superposition** to represent more features than they have neurons, making interpretability difficult.\n\n**SAEs solve this** by decomposing dense activations into sparse, monosemantic features - typically only a small number of features activate for any given input, and each feature corresponds to an interpretable concept.\n\n## When to Use SAELens\n\n**Use SAELens when you need to:**\n- Discover interpretable features in model activations\n- Understand what concepts a model has learned\n- Study superposition and feature geometry\n- Perform feature-based steering or ablation\n- Analyze safety-relevant features (deception, bias, harmful content)\n\n**Consider alternatives when:**\n- You need basic activation analysis → Use **TransformerLens** directly\n- You want causal intervention experiments → Use **pyvene** or **TransformerLens**\n- You need production steering → Consider direct activation engineering\n\n## Installation\n\n```bash\npip install sae-lens\n```\n\nRequirements: Python 3.10+, transformer-lens>=2.0.0\n\n## Core Concepts\n\n### What SAEs Learn\n\nSAEs are trained to reconstruct model activations through a sparse bottleneck:\n\n```\nInput Activation → Encoder → Sparse Features → Decoder → Reconstructed Activation\n    (d_model)       ↓        (d_sae >> d_model)    ↓         (d_model)\n                 sparsity                      reconstruction\n                 penalty                          loss\n```\n\n**Loss Function**: `MSE(original, reconstructed) + L1_coefficient × L1(features)`\n\n### Key Validation (Anthropic Research)\n\nIn \"Towards Monosemanticity\", human evaluators found **70% of SAE features genuinely interpretable**. Features discovered include:\n- DNA sequences, legal language, HTTP requests\n- Hebrew text, nutrition statements, code syntax\n- Sentiment, named entities, grammatical structures\n\n## Workflow 1: Loading and Analyzing Pre-trained SAEs\n\n### Step-by-Step\n\n```python\nfrom transformer_lens import HookedTransformer\nfrom sae_lens import SAE\n\n# 1. Load model and pre-trained SAE\nmodel = HookedTransformer.from_pretrained(\"gpt2-small\", device=\"cuda\")\nsae, cfg_dict, sparsity = SAE.from_pretrained(\n    release=\"gpt2-small-res-jb\",\n    sae_id=\"blocks.8.hook_resid_pre\",\n    device=\"cuda\"\n)\n\n# 2. Get model activations\ntokens = model.to_tokens(\"The capital of France is Paris\")\n_, cache = model.run_with_cache(tokens)\nactivations = cache[\"resid_pre\", 8]  # [batch, pos, d_model]\n\n# 3. Encode to SAE features\nsae_features = sae.encode(activations)  # [batch, pos, d_sae]\nprint(f\"Active features: {(sae_features > 0).sum()}\")\n\n# 4. Find top features for each position\nfor pos in range(tokens.shape[1]):\n    top_features = sae_features[0, pos].topk(5)\n    token = model.to_str_tokens(tokens[0, pos:pos+1])[0]\n    print(f\"Token '{token}': features {top_features.indices.tolist()}\")\n\n# 5. Reconstruct activations\nreconstructed = sae.decode(sae_features)\nreconstruction_error = (activations - reconstructed).norm()\n```\n\n### Available Pre-trained SAEs\n\n| Release | Model | Layers |\n|---------|-------|--------|\n| `gpt2-small-res-jb` | GPT-2 Small | Multiple residual streams |\n| `gemma-2b-res` | Gemma 2B | Residual streams |\n| Various on HuggingFace | Search tag `saelens` | Various |\n\n### Checklist\n- [ ] Load model with TransformerLens\n- [ ] Load matching SAE for target layer\n- [ ] Encode activations to sparse features\n- [ ] Identify top-activating features per token\n- [ ] Validate reconstruction quality\n\n## Workflow 2: Training a Custom SAE\n\n### Step-by-Step\n\n```python\nfrom sae_lens import SAE, LanguageModelSAERunnerConfig, SAETrainingRunner\n\n# 1. Configure training\ncfg = LanguageModelSAERunnerConfig(\n    # Model\n    model_name=\"gpt2-small\",\n    hook_name=\"blocks.8.hook_resid_pre\",\n    hook_layer=8,\n    d_in=768,  # Model dimension\n\n    # SAE architecture\n    architecture=\"standard\",  # or \"gated\", \"topk\"\n    d_sae=768 * 8,  # Expansion factor of 8\n    activation_fn=\"relu\",\n\n    # Training\n    lr=4e-4,\n    l1_coefficient=8e-5,  # Sparsity penalty\n    l1_warm_up_steps=1000,\n    train_batch_size_tokens=4096,\n    training_tokens=100_000_000,\n\n    # Data\n    dataset_path=\"monology\u002Fpile-uncopyrighted\",\n    context_size=128,\n\n    # Logging\n    log_to_wandb=True,\n    wandb_project=\"sae-training\",\n\n    # Checkpointing\n    checkpoint_path=\"checkpoints\",\n    n_checkpoints=5,\n)\n\n# 2. Train\ntrainer = SAETrainingRunner(cfg)\nsae = trainer.run()\n\n# 3. Evaluate\nprint(f\"L0 (avg active features): {trainer.metrics['l0']}\")\nprint(f\"CE Loss Recovered: {trainer.metrics['ce_loss_score']}\")\n```\n\n### Key Hyperparameters\n\n| Parameter | Typical Value | Effect |\n|-----------|---------------|--------|\n| `d_sae` | 4-16× d_model | More features, higher capacity |\n| `l1_coefficient` | 5e-5 to 1e-4 | Higher = sparser, less accurate |\n| `lr` | 1e-4 to 1e-3 | Standard optimizer LR |\n| `l1_warm_up_steps` | 500-2000 | Prevents early feature death |\n\n### Evaluation Metrics\n\n| Metric | Target | Meaning |\n|--------|--------|---------|\n| **L0** | 50-200 | Average active features per token |\n| **CE Loss Score** | 80-95% | Cross-entropy recovered vs original |\n| **Dead Features** | \u003C5% | Features that never activate |\n| **Explained Variance** | >90% | Reconstruction quality |\n\n### Checklist\n- [ ] Choose target layer and hook point\n- [ ] Set expansion factor (d_sae = 4-16× d_model)\n- [ ] Tune L1 coefficient for desired sparsity\n- [ ] Enable L1 warm-up to prevent dead features\n- [ ] Monitor metrics during training (W&B)\n- [ ] Validate L0 and CE loss recovery\n- [ ] Check dead feature ratio\n\n## Workflow 3: Feature Analysis and Steering\n\n### Analyzing Individual Features\n\n```python\nfrom transformer_lens import HookedTransformer\nfrom sae_lens import SAE\nimport torch\n\nmodel = HookedTransformer.from_pretrained(\"gpt2-small\", device=\"cuda\")\nsae, _, _ = SAE.from_pretrained(\n    release=\"gpt2-small-res-jb\",\n    sae_id=\"blocks.8.hook_resid_pre\",\n    device=\"cuda\"\n)\n\n# Find what activates a specific feature\nfeature_idx = 1234\ntest_texts = [\n    \"The scientist conducted an experiment\",\n    \"I love chocolate cake\",\n    \"The code compiles successfully\",\n    \"Paris is beautiful in spring\",\n]\n\nfor text in test_texts:\n    tokens = model.to_tokens(text)\n    _, cache = model.run_with_cache(tokens)\n    features = sae.encode(cache[\"resid_pre\", 8])\n    activation = features[0, :, feature_idx].max().item()\n    print(f\"{activation:.3f}: {text}\")\n```\n\n### Feature Steering\n\n```python\ndef steer_with_feature(model, sae, prompt, feature_idx, strength=5.0):\n    \"\"\"Add SAE feature direction to residual stream.\"\"\"\n    tokens = model.to_tokens(prompt)\n\n    # Get feature direction from decoder\n    feature_direction = sae.W_dec[feature_idx]  # [d_model]\n\n    def steering_hook(activation, hook):\n        # Add scaled feature direction at all positions\n        activation += strength * feature_direction\n        return activation\n\n    # Generate with steering\n    output = model.generate(\n        tokens,\n        max_new_tokens=50,\n        fwd_hooks=[(\"blocks.8.hook_resid_pre\", steering_hook)]\n    )\n    return model.to_string(output[0])\n```\n\n### Feature Attribution\n\n```python\n# Which features most affect a specific output?\ntokens = model.to_tokens(\"The capital of France is\")\n_, cache = model.run_with_cache(tokens)\n\n# Get features at final position\nfeatures = sae.encode(cache[\"resid_pre\", 8])[0, -1]  # [d_sae]\n\n# Get logit attribution per feature\n# Feature contribution = feature_activation × decoder_weight × unembedding\nW_dec = sae.W_dec  # [d_sae, d_model]\nW_U = model.W_U    # [d_model, vocab]\n\n# Contribution to \"Paris\" logit\nparis_token = model.to_single_token(\" Paris\")\nfeature_contributions = features * (W_dec @ W_U[:, paris_token])\n\ntop_features = feature_contributions.topk(10)\nprint(\"Top features for 'Paris' prediction:\")\nfor idx, val in zip(top_features.indices, top_features.values):\n    print(f\"  Feature {idx.item()}: {val.item():.3f}\")\n```\n\n## Common Issues & Solutions\n\n### Issue: High dead feature ratio\n```python\n# WRONG: No warm-up, features die early\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=1e-4,\n    l1_warm_up_steps=0,  # Bad!\n)\n\n# RIGHT: Warm-up L1 penalty\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=8e-5,\n    l1_warm_up_steps=1000,  # Gradually increase\n    use_ghost_grads=True,   # Revive dead features\n)\n```\n\n### Issue: Poor reconstruction (low CE recovery)\n```python\n# Reduce sparsity penalty\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=5e-5,  # Lower = better reconstruction\n    d_sae=768 * 16,       # More capacity\n)\n```\n\n### Issue: Features not interpretable\n```python\n# Increase sparsity (higher L1)\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=1e-4,  # Higher = sparser, more interpretable\n)\n# Or use TopK architecture\ncfg = LanguageModelSAERunnerConfig(\n    architecture=\"topk\",\n    activation_fn_kwargs={\"k\": 50},  # Exactly 50 active features\n)\n```\n\n### Issue: Memory errors during training\n```python\ncfg = LanguageModelSAERunnerConfig(\n    train_batch_size_tokens=2048,  # Reduce batch size\n    store_batch_size_prompts=4,    # Fewer prompts in buffer\n    n_batches_in_buffer=8,         # Smaller activation buffer\n)\n```\n\n## Integration with Neuronpedia\n\nBrowse pre-trained SAE features at [neuronpedia.org](https:\u002F\u002Fneuronpedia.org):\n\n```python\n# Features are indexed by SAE ID\n# Example: gpt2-small layer 8 feature 1234\n# → neuronpedia.org\u002Fgpt2-small\u002F8-res-jb\u002F1234\n```\n\n## Key Classes Reference\n\n| Class | Purpose |\n|-------|---------|\n| `SAE` | Sparse Autoencoder model |\n| `LanguageModelSAERunnerConfig` | Training configuration |\n| `SAETrainingRunner` | Training loop manager |\n| `ActivationsStore` | Activation collection and batching |\n| `HookedSAETransformer` | TransformerLens + SAE integration |\n\n## Reference Documentation\n\nFor detailed API documentation, tutorials, and advanced usage, see the `references\u002F` folder:\n\n| File | Contents |\n|------|----------|\n| [references\u002FREADME.md](references\u002FREADME.md) | Overview and quick start guide |\n| [references\u002Fapi.md](references\u002Fapi.md) | Complete API reference for SAE, TrainingSAE, configurations |\n| [references\u002Ftutorials.md](references\u002Ftutorials.md) | Step-by-step tutorials for training, analysis, steering |\n\n## External Resources\n\n### Tutorials\n- [Basic Loading & Analysis](https:\u002F\u002Fgithub.com\u002FjbloomAus\u002FSAELens\u002Fblob\u002Fmain\u002Ftutorials\u002Fbasic_loading_and_analysing.ipynb)\n- [Training a Sparse Autoencoder](https:\u002F\u002Fgithub.com\u002FjbloomAus\u002FSAELens\u002Fblob\u002Fmain\u002Ftutorials\u002Ftraining_a_sparse_autoencoder.ipynb)\n- [ARENA SAE Curriculum](https:\u002F\u002Fwww.lesswrong.com\u002Fposts\u002FLnHowHgmrMbWtpkxx\u002Fintro-to-superposition-and-sparse-autoencoders-colab)\n\n### Papers\n- [Towards Monosemanticity](https:\u002F\u002Ftransformer-circuits.pub\u002F2023\u002Fmonosemantic-features) - Anthropic (2023)\n- [Scaling Monosemanticity](https:\u002F\u002Ftransformer-circuits.pub\u002F2024\u002Fscaling-monosemanticity\u002F) - Anthropic (2024)\n- [Sparse Autoencoders Find Highly Interpretable Features](https:\u002F\u002Farxiv.org\u002Fabs\u002F2309.08600) - Cunningham et al. (ICLR 2024)\n\n### Official Documentation\n- [SAELens Docs](https:\u002F\u002Fjbloomaus.github.io\u002FSAELens\u002F)\n- [Neuronpedia](https:\u002F\u002Fneuronpedia.org) - Feature browser\n\n## SAE Architectures\n\n| Architecture | Description | Use Case |\n|--------------|-------------|----------|\n| **Standard** | ReLU + L1 penalty | General purpose |\n| **Gated** | Learned gating mechanism | Better sparsity control |\n| **TopK** | Exactly K active features | Consistent sparsity |\n\n```python\n# TopK SAE (exactly 50 features active)\ncfg = LanguageModelSAERunnerConfig(\n    architecture=\"topk\",\n    activation_fn=\"topk\",\n    activation_fn_kwargs={\"k\": 50},\n)\n```\n","# SAELens: Sparse Autoencoders for Mechanistic Interpretability\n\nSAELens is the primary library for training and analyzing Sparse Autoencoders (SAEs) - a technique for decomposing polysemantic neural network activations into sparse, interpretable features. Based on Anthropic's groundbreaking research on monosemanticity.\n\n**GitHub**: [jbloomAus\u002FSAELens](https:\u002F\u002Fgithub.com\u002FjbloomAus\u002FSAELens) (1,100+ stars)\n\n## The Problem: Polysemanticity & Superposition\n\nIndividual neurons in neural networks are **polysemantic** - they activate in multiple, semantically distinct contexts. This happens because models use **superposition** to represent more features than they have neurons, making interpretability difficult.\n\n**SAEs solve this** by decomposing dense activations into sparse, monosemantic features - typically only a small number of features activate for any given input, and each feature corresponds to an interpretable concept.\n\n## When to Use SAELens\n\n**Use SAELens when you need to:**\n- Discover interpretable features in model activations\n- Understand what concepts a model has learned\n- Study superposition and feature geometry\n- Perform feature-based steering or ablation\n- Analyze safety-relevant features (deception, bias, harmful content)\n\n**Consider alternatives when:**\n- You need basic activation analysis → Use **TransformerLens** directly\n- You want causal intervention experiments → Use **pyvene** or **TransformerLens**\n- You need production steering → Consider direct activation engineering\n\n## Installation\n\n```bash\npip install sae-lens\n```\n\nRequirements: Python 3.10+, transformer-lens>=2.0.0\n\n## Core Concepts\n\n### What SAEs Learn\n\nSAEs are trained to reconstruct model activations through a sparse bottleneck:\n\n```\nInput Activation → Encoder → Sparse Features → Decoder → Reconstructed Activation\n    (d_model)       ↓        (d_sae >> d_model)    ↓         (d_model)\n                 sparsity                      reconstruction\n                 penalty                          loss\n```\n\n**Loss Function**: `MSE(original, reconstructed) + L1_coefficient × L1(features)`\n\n### Key Validation (Anthropic Research)\n\nIn \"Towards Monosemanticity\", human evaluators found **70% of SAE features genuinely interpretable**. Features discovered include:\n- DNA sequences, legal language, HTTP requests\n- Hebrew text, nutrition statements, code syntax\n- Sentiment, named entities, grammatical structures\n\n## Workflow 1: Loading and Analyzing Pre-trained SAEs\n\n### Step-by-Step\n\n```python\nfrom transformer_lens import HookedTransformer\nfrom sae_lens import SAE\n\n# 1. Load model and pre-trained SAE\nmodel = HookedTransformer.from_pretrained(\"gpt2-small\", device=\"cuda\")\nsae, cfg_dict, sparsity = SAE.from_pretrained(\n    release=\"gpt2-small-res-jb\",\n    sae_id=\"blocks.8.hook_resid_pre\",\n    device=\"cuda\"\n)\n\n# 2. Get model activations\ntokens = model.to_tokens(\"The capital of France is Paris\")\n_, cache = model.run_with_cache(tokens)\nactivations = cache[\"resid_pre\", 8]  # [batch, pos, d_model]\n\n# 3. Encode to SAE features\nsae_features = sae.encode(activations)  # [batch, pos, d_sae]\nprint(f\"Active features: {(sae_features > 0).sum()}\")\n\n# 4. Find top features for each position\nfor pos in range(tokens.shape[1]):\n    top_features = sae_features[0, pos].topk(5)\n    token = model.to_str_tokens(tokens[0, pos:pos+1])[0]\n    print(f\"Token '{token}': features {top_features.indices.tolist()}\")\n\n# 5. Reconstruct activations\nreconstructed = sae.decode(sae_features)\nreconstruction_error = (activations - reconstructed).norm()\n```\n\n### Available Pre-trained SAEs\n\n| Release | Model | Layers |\n|---------|-------|--------|\n| `gpt2-small-res-jb` | GPT-2 Small | Multiple residual streams |\n| `gemma-2b-res` | Gemma 2B | Residual streams |\n| Various on HuggingFace | Search tag `saelens` | Various |\n\n### Checklist\n- [ ] Load model with TransformerLens\n- [ ] Load matching SAE for target layer\n- [ ] Encode activations to sparse features\n- [ ] Identify top-activating features per token\n- [ ] Validate reconstruction quality\n\n## Workflow 2: Training a Custom SAE\n\n### Step-by-Step\n\n```python\nfrom sae_lens import SAE, LanguageModelSAERunnerConfig, SAETrainingRunner\n\n# 1. Configure training\ncfg = LanguageModelSAERunnerConfig(\n    # Model\n    model_name=\"gpt2-small\",\n    hook_name=\"blocks.8.hook_resid_pre\",\n    hook_layer=8,\n    d_in=768,  # Model dimension\n\n    # SAE architecture\n    architecture=\"standard\",  # or \"gated\", \"topk\"\n    d_sae=768 * 8,  # Expansion factor of 8\n    activation_fn=\"relu\",\n\n    # Training\n    lr=4e-4,\n    l1_coefficient=8e-5,  # Sparsity penalty\n    l1_warm_up_steps=1000,\n    train_batch_size_tokens=4096,\n    training_tokens=100_000_000,\n\n    # Data\n    dataset_path=\"monology\u002Fpile-uncopyrighted\",\n    context_size=128,\n\n    # Logging\n    log_to_wandb=True,\n    wandb_project=\"sae-training\",\n\n    # Checkpointing\n    checkpoint_path=\"checkpoints\",\n    n_checkpoints=5,\n)\n\n# 2. Train\ntrainer = SAETrainingRunner(cfg)\nsae = trainer.run()\n\n# 3. Evaluate\nprint(f\"L0 (avg active features): {trainer.metrics['l0']}\")\nprint(f\"CE Loss Recovered: {trainer.metrics['ce_loss_score']}\")\n```\n\n### Key Hyperparameters\n\n| Parameter | Typical Value | Effect |\n|-----------|---------------|--------|\n| `d_sae` | 4-16× d_model | More features, higher capacity |\n| `l1_coefficient` | 5e-5 to 1e-4 | Higher = sparser, less accurate |\n| `lr` | 1e-4 to 1e-3 | Standard optimizer LR |\n| `l1_warm_up_steps` | 500-2000 | Prevents early feature death |\n\n### Evaluation Metrics\n\n| Metric | Target | Meaning |\n|--------|--------|---------|\n| **L0** | 50-200 | Average active features per token |\n| **CE Loss Score** | 80-95% | Cross-entropy recovered vs original |\n| **Dead Features** | \u003C5% | Features that never activate |\n| **Explained Variance** | >90% | Reconstruction quality |\n\n### Checklist\n- [ ] Choose target layer and hook point\n- [ ] Set expansion factor (d_sae = 4-16× d_model)\n- [ ] Tune L1 coefficient for desired sparsity\n- [ ] Enable L1 warm-up to prevent dead features\n- [ ] Monitor metrics during training (W&B)\n- [ ] Validate L0 and CE loss recovery\n- [ ] Check dead feature ratio\n\n## Workflow 3: Feature Analysis and Steering\n\n### Analyzing Individual Features\n\n```python\nfrom transformer_lens import HookedTransformer\nfrom sae_lens import SAE\nimport torch\n\nmodel = HookedTransformer.from_pretrained(\"gpt2-small\", device=\"cuda\")\nsae, _, _ = SAE.from_pretrained(\n    release=\"gpt2-small-res-jb\",\n    sae_id=\"blocks.8.hook_resid_pre\",\n    device=\"cuda\"\n)\n\n# Find what activates a specific feature\nfeature_idx = 1234\ntest_texts = [\n    \"The scientist conducted an experiment\",\n    \"I love chocolate cake\",\n    \"The code compiles successfully\",\n    \"Paris is beautiful in spring\",\n]\n\nfor text in test_texts:\n    tokens = model.to_tokens(text)\n    _, cache = model.run_with_cache(tokens)\n    features = sae.encode(cache[\"resid_pre\", 8])\n    activation = features[0, :, feature_idx].max().item()\n    print(f\"{activation:.3f}: {text}\")\n```\n\n### Feature Steering\n\n```python\ndef steer_with_feature(model, sae, prompt, feature_idx, strength=5.0):\n    \"\"\"Add SAE feature direction to residual stream.\"\"\"\n    tokens = model.to_tokens(prompt)\n\n    # Get feature direction from decoder\n    feature_direction = sae.W_dec[feature_idx]  # [d_model]\n\n    def steering_hook(activation, hook):\n        # Add scaled feature direction at all positions\n        activation += strength * feature_direction\n        return activation\n\n    # Generate with steering\n    output = model.generate(\n        tokens,\n        max_new_tokens=50,\n        fwd_hooks=[(\"blocks.8.hook_resid_pre\", steering_hook)]\n    )\n    return model.to_string(output[0])\n```\n\n### Feature Attribution\n\n```python\n# Which features most affect a specific output?\ntokens = model.to_tokens(\"The capital of France is\")\n_, cache = model.run_with_cache(tokens)\n\n# Get features at final position\nfeatures = sae.encode(cache[\"resid_pre\", 8])[0, -1]  # [d_sae]\n\n# Get logit attribution per feature\n# Feature contribution = feature_activation × decoder_weight × unembedding\nW_dec = sae.W_dec  # [d_sae, d_model]\nW_U = model.W_U    # [d_model, vocab]\n\n# Contribution to \"Paris\" logit\nparis_token = model.to_single_token(\" Paris\")\nfeature_contributions = features * (W_dec @ W_U[:, paris_token])\n\ntop_features = feature_contributions.topk(10)\nprint(\"Top features for 'Paris' prediction:\")\nfor idx, val in zip(top_features.indices, top_features.values):\n    print(f\"  Feature {idx.item()}: {val.item():.3f}\")\n```\n\n## Common Issues & Solutions\n\n### Issue: High dead feature ratio\n```python\n# WRONG: No warm-up, features die early\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=1e-4,\n    l1_warm_up_steps=0,  # Bad!\n)\n\n# RIGHT: Warm-up L1 penalty\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=8e-5,\n    l1_warm_up_steps=1000,  # Gradually increase\n    use_ghost_grads=True,   # Revive dead features\n)\n```\n\n### Issue: Poor reconstruction (low CE recovery)\n```python\n# Reduce sparsity penalty\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=5e-5,  # Lower = better reconstruction\n    d_sae=768 * 16,       # More capacity\n)\n```\n\n### Issue: Features not interpretable\n```python\n# Increase sparsity (higher L1)\ncfg = LanguageModelSAERunnerConfig(\n    l1_coefficient=1e-4,  # Higher = sparser, more interpretable\n)\n# Or use TopK architecture\ncfg = LanguageModelSAERunnerConfig(\n    architecture=\"topk\",\n    activation_fn_kwargs={\"k\": 50},  # Exactly 50 active features\n)\n```\n\n### Issue: Memory errors during training\n```python\ncfg = LanguageModelSAERunnerConfig(\n    train_batch_size_tokens=2048,  # Reduce batch size\n    store_batch_size_prompts=4,    # Fewer prompts in buffer\n    n_batches_in_buffer=8,         # Smaller activation buffer\n)\n```\n\n## Integration with Neuronpedia\n\nBrowse pre-trained SAE features at [neuronpedia.org](https:\u002F\u002Fneuronpedia.org):\n\n```python\n# Features are indexed by SAE ID\n# Example: gpt2-small layer 8 feature 1234\n# → neuronpedia.org\u002Fgpt2-small\u002F8-res-jb\u002F1234\n```\n\n## Key Classes Reference\n\n| Class | Purpose |\n|-------|---------|\n| `SAE` | Sparse Autoencoder model |\n| `LanguageModelSAERunnerConfig` | Training configuration |\n| `SAETrainingRunner` | Training loop manager |\n| `ActivationsStore` | Activation collection and batching |\n| `HookedSAETransformer` | TransformerLens + SAE integration |\n\n## Reference Documentation\n\nFor detailed API documentation, tutorials, and advanced usage, see the `references\u002F` folder:\n\n| File | Contents |\n|------|----------|\n| [references\u002FREADME.md](references\u002FREADME.md) | Overview and quick start guide |\n| [references\u002Fapi.md](references\u002Fapi.md) | Complete API reference for SAE, TrainingSAE, configurations |\n| [references\u002Ftutorials.md](references\u002Ftutorials.md) | Step-by-step tutorials for training, analysis, steering |\n\n## External Resources\n\n### Tutorials\n- [Basic Loading & Analysis](https:\u002F\u002Fgithub.com\u002FjbloomAus\u002FSAELens\u002Fblob\u002Fmain\u002Ftutorials\u002Fbasic_loading_and_analysing.ipynb)\n- [Training a Sparse Autoencoder](https:\u002F\u002Fgithub.com\u002FjbloomAus\u002FSAELens\u002Fblob\u002Fmain\u002Ftutorials\u002Ftraining_a_sparse_autoencoder.ipynb)\n- [ARENA SAE Curriculum](https:\u002F\u002Fwww.lesswrong.com\u002Fposts\u002FLnHowHgmrMbWtpkxx\u002Fintro-to-superposition-and-sparse-autoencoders-colab)\n\n### Papers\n- [Towards Monosemanticity](https:\u002F\u002Ftransformer-circuits.pub\u002F2023\u002Fmonosemantic-features) - Anthropic (2023)\n- [Scaling Monosemanticity](https:\u002F\u002Ftransformer-circuits.pub\u002F2024\u002Fscaling-monosemanticity\u002F) - Anthropic (2024)\n- [Sparse Autoencoders Find Highly Interpretable Features](https:\u002F\u002Farxiv.org\u002Fabs\u002F2309.08600) - Cunningham et al. (ICLR 2024)\n\n### Official Documentation\n- [SAELens Docs](https:\u002F\u002Fjbloomaus.github.io\u002FSAELens\u002F)\n- [Neuronpedia](https:\u002F\u002Fneuronpedia.org) - Feature browser\n\n## SAE Architectures\n\n| Architecture | Description | Use Case |\n|--------------|-------------|----------|\n| **Standard** | ReLU + L1 penalty | General purpose |\n| **Gated** | Learned gating mechanism | Better sparsity control |\n| **TopK** | Exactly K active features | Consistent sparsity |\n\n```python\n# TopK SAE (exactly 50 features active)\ncfg = LanguageModelSAERunnerConfig(\n    architecture=\"topk\",\n    activation_fn=\"topk\",\n    activation_fn_kwargs={\"k\": 50},\n)\n```\n",{"name":5,"tags":49,"author":54,"license":14,"version":55,"description":7,"dependencies":56},[30,50,51,52,53],"SAE","Mechanistic Interpretability","Feature Discovery","Superposition","Orchestra Research","1.0.0",[57,58,59],"sae-lens>=6.0.0","transformer-lens>=2.0.0","torch>=2.0.0","main","f19b254e8975d0bfddb394686706106930d7964d","AI-Research\u002Fsaelens\u002Fsaelens","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus","https:\u002F\u002Fgithub.com\u002Fendman100","2026-11-11 18:19:10",{"source":8,"skillName":5,"commands":67,"prompt":77,"zipAvailable":78},[68,71,74],{"tool":69,"command":70},"npx","npx skills add endman100\u002Fskill-router-nexus --skill sparse-autoencoder-training",{"tool":72,"command":73},"bunx","bunx skills add endman100\u002Fskill-router-nexus --skill sparse-autoencoder-training",{"tool":75,"command":76},"pnpm","pnpm dlx skills add endman100\u002Fskill-router-nexus --skill sparse-autoencoder-training","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FAI-Research\u002Fsaelens\u002Fsaelens\u002FSKILL.md",true,[80,86,90],{"path":81,"resourceType":82,"resourceTypeDesc":83,"sizeBytes":84,"sourceHtmlUrl":85},"references\u002Fapi.md","REFERENCE","参考文档",6968,"https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FAI-Research\u002Fsaelens\u002Fsaelens\u002Freferences\u002Fapi.md",{"path":87,"resourceType":82,"resourceTypeDesc":83,"sizeBytes":88,"sourceHtmlUrl":89},"references\u002FREADME.md",2155,"https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FAI-Research\u002Fsaelens\u002Fsaelens\u002Freferences\u002FREADME.md",{"path":91,"resourceType":82,"resourceTypeDesc":83,"sizeBytes":92,"sourceHtmlUrl":93},"references\u002Ftutorials.md",9383,"https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FAI-Research\u002Fsaelens\u002Fsaelens\u002Freferences\u002Ftutorials.md",[95,119,153,175,184,208],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":99,"sourceHtmlUrl":100,"categories":101,"keywords":107,"publishedAt":44},"01M6MPCT5BXVER8HQZTW3QE9AS","create-master","基于佛教经典文献，生成特定高僧大德的 AI 教学角色","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FMetaphysics-and-Spirituality\u002FMaster-skill\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FMetaphysics-and-Spirituality\u002FMaster-skill\u002FSKILL.md",[102],{"categoryNo":103,"categoryName":104,"taxonomyType":105,"taxonomyTypeDesc":106},"01JBSEEDCAT000000000000039","教师与教育","PROFESSION","适用职业",[108,109,110,111,112,113,114,115,116,117,118],"create master","master","create","生成","true","webfetch","edit","write","read","grep","Bash",{"skillNo":120,"name":121,"nameZh":6,"description":122,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":123,"sourceHtmlUrl":124,"categories":125,"keywords":135,"publishedAt":44},"01M6M43AKE95Y64E1JRXEF5QQ3","writing-dna-skill","从至少 20 篇完整文章中蒸馏可复用的写作 DNA，分析语言、文章结构、选题逻辑、素材策略、认知框架和视觉风格，并生成 Writing-DNA.md；按该 DNA 写作时会读取全部蒸馏产物和 5 篇相关原文。用于中英文作者、账号、品牌或出版物的风格分析与一致性写作。 Distill reusable Writing DNA from at least 20 complete articles for Chinese or English authors, publications, brands, and accounts; use for language, structure, topic logic, source strategy, cognitive-frame, and visual-style analysis.","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fwriting-dna-skill\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fwriting-dna-skill\u002FSKILL.md",[126,129,132],{"categoryNo":127,"categoryName":128,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":130,"categoryName":131,"taxonomyType":20,"taxonomyTypeDesc":21},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":133,"categoryName":134,"taxonomyType":105,"taxonomyTypeDesc":106},"01JBSEEDCAT000000000000036","内容创作者",[136,137,138,139,140,141,142,143,144,145,40,146,147,111,148,149,150,28,151,152],"writing dna skill","DNA","writing","strategy","english","logic","visual","structure","chinese","reusable","style","distill","analysis","frame","source","at","complete",{"skillNo":154,"name":155,"nameZh":6,"description":156,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":157,"sourceHtmlUrl":158,"categories":159,"keywords":162,"publishedAt":44},"01M6M428TTCGQ4ME3KY99VN037","stop-slop","Remove AI writing patterns from prose. Use when drafting, editing, or reviewing text to eliminate predictable AI tells.","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fstop-slop\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fstop-slop\u002FSKILL.md",[160,161],{"categoryNo":127,"categoryName":128,"taxonomyType":20,"taxonomyTypeDesc":21},{"categoryNo":133,"categoryName":134,"taxonomyType":105,"taxonomyTypeDesc":106},[163,164,165,166,25,167,168,169,170,40,171,172,173,28,174,138],"slop","stop slop","stop","drafting","drafts","https","patterns","prose","remove","editing","text","content",{"skillNo":176,"name":177,"nameZh":6,"description":178,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":179,"sourceHtmlUrl":180,"categories":181,"keywords":182,"publishedAt":44},"01M6M41X0B7EBX42TK435DMGGR","shuorenhua","检查和清理中英文文本里的 AI 套路，适用于“去 AI 味”“说人话”“自然一点”“别像模板”“先标问题”这类改写和审稿需求；按场景控制力度，同时保留事实、术语、语域和责任主体。","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fshuorenhua\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fshuorenhua\u002FSKILL.md",[],[177,183],"文本",{"skillNo":185,"name":186,"nameZh":6,"description":187,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":188,"sourceHtmlUrl":189,"categories":190,"keywords":191,"publishedAt":44},"01M6M3ZD12WBEW5KXKDM4N6DFG","naming","Name products, SaaS, brands, open source projects, bots, and apps. Use when the user needs to name something, find a brand name, or pick a product name. Metaphor-driven process that produces memorable, meaningful names and avoids AI slop.","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fnaming-main\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fnaming-main\u002FSKILL.md",[],[186,192,193,194,195,196,40,197,116,150,198,199,200,201,118,202,203,204,205,25,206,207,163],"repo","websearch","product name","apps","bots","view","brand","pick","gh","projects","open","saas","open source","product","describe","ai slop",{"skillNo":209,"name":210,"nameZh":6,"description":211,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":212,"sourceHtmlUrl":213,"categories":214,"keywords":216,"publishedAt":44},"01M6M3YVXAFAAWJ7F6JMPFREYE","humanizer-zh","去除文本中的 AI 生成痕迹。适用于编辑或审阅文本，使其听起来更自然、更像人类书写。\n基于维基百科的\"AI 写作特征\"综合指南。检测并修复以下模式：夸大的象征意义、\n宣传性语言、以 -ing 结尾的肤浅分析、模糊的归因、破折号过度使用、三段式法则、\nAI 词汇、否定式排比、过多的连接性短语。","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fhumanizer-zh\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fendman100\u002Fskill-router-nexus\u002Fblob\u002Fmain\u002FWriting-and-Content\u002Fhumanizer-zh\u002FSKILL.md",[215],{"categoryNo":127,"categoryName":128,"taxonomyType":20,"taxonomyTypeDesc":21},[217,218,219,116,115,114,138,111,183,220,163,165],"humanizer","zh","humanizer zh","翻译"]