Repository navigation
Description
Proposal
Add a tools/analysis entry for KPSA (Kernelized Parameter Sensitivity Atlases) on TransformerBridge: a forward-only estimate of which MLP neurons a scalar metric (next-token log-prob or loss, a logit difference, ...) is most sensitive to at a given position.
It would have two parts:
mlp_neuron_sensitivity(bridge, tokens, metric): the exact per-example sensitivity of every MLP neuron, i.e. the squared gradient norm of its parameters (itsW_in/W_gatecolumns,b_inentry andW_outrow). Because the neuron's parameter gradient is a sum over tokens, the batch version needs one backward pass and hooks atmlp.hook_in,hook_pre,hook_postandmlp.hook_out(Gram formd_j^T (X X^T + 1) d_j + a_j^T (Y Y^T) a_j).KPSA(bridge, ...).fit(source_prompts)and.sensitivity(tokens, positions): profiles from (1) on a set of source contexts are stored once in a landmark atlas (an(n_layers * d_mlp, n_prototypes)matrix over an RBF kernel on a query embedding, by default the model's own residual at the position plus the target token embedding). A new prompt then needs only a forward pass and one matrix product;kernel="exact"keeps all source profiles instead.
Motivation
Ranking neurons per prompt with gradient × activation or attribution patching costs a backward pass per prompt (and per metric). In the paper, on ViT-B/16 the atlas raises batched throughput from 551 to 2,041 images/s and cuts peak GPU memory from 4.55 to 0.44 GB compared with gradient × activation, while keeping 81% of the gap between the backprop oracle and a constant baseline; atlases for several metrics share one forward pass. For language, an atlas over 300k Wikipedia contexts for Qwen3-0.6B-Base captures 0.92 of the exact top-0.1% neuron sensitivity on held-out tokens (constant profile: 0.85). There is a public demo built on it at axym.org/work/kpsa-demo/.
Pitch
from transformer_lens.tools.analysis import KPSA, mlp_neuron_sensitivity
atlas = KPSA(bridge, metric="next_token_logprob").fit(source_tokens) # one backward pass per batch
profile = atlas.sensitivity(tokens) # [batch, pos, n_layers, d_mlp], forward only
exact = mlp_neuron_sensitivity(bridge, tokens, metric="next_token_logprob")It complements attribution patching (signed, per prompt pair, needs gradients) with an amortized, unsigned ranking that is cheap to query over many prompts, e.g. to pick neurons for ablation or interchange interventions. Standard and gated MLPs on decoder bridges; MoE out of scope.
Alternatives
Running gradient × activation or attribution patching per prompt, which is what the atlas amortizes. I also have this for ViT-Prisma (Prisma-Multimodal/ViT-Prisma#209).
Checklist
- I have checked that there is no similar issue in the repo (required)
Activity
DavideWiest commentedon Nov 30, 2026
@jlarson4 @neelnanda-io : interested in your thoughts on this!
DavideWiest commentedon Nov 30, 2026
I opened #2076 with an implementation, so there's something concrete to look at. It follows AGENTS.md (tools/analysis, unit tests on tiny bridges, docs rows). Happy to change the API or scope, or to close it if you'd rather keep the freeze.