BatchTopK Sparse Autoencoders

Bart Bussmann, Patrick Leask, Neel Nanda

TL;DR

Standard TopK Sparse Autoencoders (SAEs) force every input token to use the exact same number of active features ($k$), even though simple tokens need fewer features than complex ones. BatchTopK SAEs relax this constraint to the batch level by selecting the top $n \times k$ activations across all $n$ samples in a batch. This allows variable per-token sparsity during training and matches or beats state-of-the-art JumpReLU SAEs in reconstruction—without requiring costly hyperparameter sweeps to hit a target sparsity level.

What Problem Does This Paper Address?

Sparse autoencoders (SAEs) help interpret large language models by decomposing continuous residual stream activations into sparse, human-interpretable feature dictionaries. However, SAEs must balance two conflicting goals: maximizing reconstruction fidelity while minimizing the number of active features ($L_0$ sparsity).

Recent TopK SAEs achieve great fidelity by hard-coding the sparsity constraint: keeping only the top-$k$ latent activations per sample. But this introduces a major flaw—not all tokens carry equal amounts of information. A structural token like <BOS> requires far fewer features to reconstruct than a semantically dense content word. While JumpReLU SAEs solve this by learning feature-specific activation thresholds, their average sparsity cannot be set directly; targeting a specific $L_0$ requires expensive, iterative hyperparameter sweeps over sparsity penalties.

Methods

BatchTopK bridges the gap between fixed-sparsity TopK SAEs and flexible-sparsity JumpReLU SAEs:

  1. Batch-Level TopK Selection: Instead of selecting the top $k$ features for each individual token, the encoder takes the top $n \times k$ feature activations across the entire mini-batch of $n$ tokens. Active features are dynamically allocated where reconstruction error is highest.
  2. Auxiliary Loss: Like standard TopK SAEs, BatchTopK employs an auxiliary reconstruction loss on the top-512 "dead" latents (scaled by $\alpha = 1/32$) to ensure unused features continue to receive gradients.
  3. Decoupled Inference via JumpReLU: Because batch selection introduces artificial cross-sample dependencies, BatchTopK eliminates batch conditioning at inference time. The model records the average minimum positive activation across training batches to establish a single global threshold: $$\theta = \mathbb{E}_X [\min \{ z_{i,j}(X) \mid z_{i,j}(X) > 0 \}]$$ During inference, it simply applies a JumpReLU function with threshold $\theta$, zeroing out any latent below that value independently for each sample.

Datasets

  • Training Corpus: OpenWebText, tokenized into sequences of up to 128 tokens (trained on $1 \times 10^9$ tokens using the Adam optimizer).
  • Target Models & Layers:
  • GPT-2 Small: Layer 8 residual stream.
  • Gemma 2 2B: Layer 12 residual stream.
  • Benchmarks: Evaluated on standard SAE metrics: Normalized Mean Squared Error (NMSE) and model cross-entropy (CE) degradation when substituting reconstructed activations back into the LLM.

Key Insights and Ideas

  • Adaptive Feature Allocation: Looking at the active feature distribution across tokens reveals extreme variance: active latents per sample range from 1 to nearly 100 (mean: 32, std dev: 10.42). Tokens like <BOS> sit at the extreme low end (~1 active feature), confirming that fixed-$k$ constraints force models to over-allocate capacity to trivial tokens while starving complex ones.
  • Hyperparameter Efficiency: Unlike JumpReLU SAEs, which require tuning an $L_0$ penalty weight to land near a desired average sparsity, BatchTopK allows practitioners to specify their exact target average sparsity ($k$) beforehand.
  • Global Thresholding Works: Even though BatchTopK latents compete across the batch during training, activating features above a simple, empirically measured scalar threshold ($\theta$) is sufficient to maintain high performance at single-sample test time.

Key Results

  • GPT-2 Small:
  • Across dictionary sizes (3,072 to 24,576 at $k=32$), BatchTopK strictly achieves lower NMSE and lower CE degradation than standard TopK.
  • Across varying sparsity levels ($k \in \{16, 32, 64\}$ at dictionary size 12,288), BatchTopK outperforms both TopK and JumpReLU SAEs in both NMSE and downstream CE.
  • Gemma 2 2B:
  • At dictionary size 16,384, BatchTopK beats TopK across all values of $k$ on both NMSE and CE degradation.
  • BatchTopK maintains lower NMSE than JumpReLU across all $k$. In downstream CE degradation, BatchTopK outperforms JumpReLU at high sparsity ($k=16$), while JumpReLU performs slightly better at denser allocations ($k=32, 64$).

Limitations and Future Work

  • Downstream CE Degradation at High $k$: For larger models like Gemma 2 2B with higher numbers of active latents ($k \ge 32$), JumpReLU retains a slight advantage in preserving original language model loss.
  • Interpretability Unverified by Humans: The authors evaluate BatchTopK solely via reconstruction metrics (NMSE and CE degradation); while they hypothesize interpretability matches TopK due to architectural similarity, automated or human monosemanticity scoring was not conducted.
  • Scope of Evaluation: Experiments were limited to a single layer in each of two models (GPT-2 Small and Gemma 2 2B).

Summary updated

BibTeX
@inproceedings{bussmann2024batchtopk,
  author = {Bart Bussmann and Patrick Leask and Neel Nanda},
  title = {{BatchTopK Sparse Autoencoders}},
  booktitle = {SciForDL @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=d4dpOCqybL},
}

Loading related content...

Figure