Repository navigation
fix(jacobian_lens): ablate token directions jointly - #1941
Merged
jlarson4 merged 1 commit intoOct 23, 2026
Merged
Conversation
ablation_hooks removed several tokens' lens vectors one at a time, h <- h - (h.v)v per unit vector. Lens vectors of related tokens are far from orthogonal, so each later removal reintroduces a component along the earlier directions and the result keeps a large projection onto them. Project onto the orthogonal complement of their span instead, h <- h - Q Q^T h with Q an orthonormal basis, so the ablated activation has zero projection onto every requested vector. A single token is unchanged.
Collaborator
|
Looks good, thanks for putting this together. Merging now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
JacobianLens.ablation_hooksis documented as projecting the given tokens' directions out of the residual stream. With several tokens, however, it removes their unit lens vectors one at a time:This only zeroes the projections when the vectors are orthogonal. Lens vectors of related tokens are not. Removing
v̂₂puts back a component-(h·v̂₂)(v̂₂·v̂₁)alongv̂₁, and so on down the list, so the "ablated" activation still has a large projection onto the directions it was meant to remove. The paper ablates whole token sets (e.g. 176 ethics-related lens vectors) as one intervention.Measured on GPT-2 small with the published
neuronpedia/jacobian-lenslens, on one prompt, atblocks.{layer}.hook_out:France,Paris,French,Lyon,Europeone…tenFrance…Europeone…tenWith the ten number tokens at layer 8, about 73% of the largest projection is still there after the current ablation.
The fix projects onto the orthogonal complement of the span,
h <- h - Q Qᵀ h.Qis an orthonormal basis of the unit lens vectors, built with the existingorthonormal_subspacefromprojection_kernel(rank-revealing SVD, so repeated or linearly dependent tokens are handled). For a single token this is the sameh - (h·v̂)v̂as before. The docstring is updated to state the guarantee.Type of change
Checklist:
test_ablation_hooks_remove_every_direction_of_non_orthogonal_tokensuses the toy fitted lens with three tokens whose lens vectors are not orthogonal. It checks that the ablated activation has zero projection onto every vector, and that only their span changes. It fails ondev(max residual projection 0.34) and passes with the change.Local runs (Windows, CPU, torch 2.9.1 and the locked 2.11.0, with
--jaxtyping-packages=transformer_lens,beartype.beartype):tests/unit/toolsgives 1113 passed and 4 failed. The same 4 fail ondevwithout this change, whiledevCI is green:test_faithfulness_recovery_is_graded_not_binary(recovery comes out ≈ -1e-8), and threetest_sparse_probingtests that pin L-BFGS stop reasons and refinement counts. They look platform-sensitive, and none of them touches the code changed here.isort --check-onlypasses;mypyreports no errors injacobian_lens.py.