Repository navigation
feat(interchange): several positions per example, aligned or pooled - #2042
Merged
jlarson4 merged 2 commits intoNov 30, 2026
Merged
Conversation
The interchange tools intervened on one position per example, but a variable is often spread over several, and then a one-position interchange underestimates it. positions (and fit_das's base_positions and source_positions) may now also be [batch, k], in two modes: - Aligned (default): base position j takes the source's position j. Each (example, position) pair is one row of the intervention, so SubspaceInterchange, NormMatchedPlacebo, every basis and fit_das work unchanged, with one basis shared by the k positions. collect_activations returns [batch, k, d_model], NaN in padded slots, and a run checks that base and source pad the same slots. - Pooled (pool="mean"): each row names a span. collect_activations returns the span means, the intervention maps the base and source means to a new mean, and every base position in the span moves by the change in the mean. Base and source spans may differ in length. Shorter rows are padded with PAD_POSITION, exported from transformer_lens.tools.analysis: a sentinel that is never a valid index and fits int32 and int64 position tensors. Negative indices are rejected in [batch, k] positions with an error naming PAD_POSITION, so -1, the last position in [batch] positions, is never read as padding. [batch] positions behave exactly as before, -1 included. Rows out of range, with a repeated position or with no position are rejected too. On GPT-2 small at block 4, subject number in "The key(s) near the cabinet" is carried jointly by the subject and the preposition: patching the whole residual at either alone flips 0.25 and 0.44 of the pairs, at both aligned 1.00 and pooled 0.97. The integration test pins this; the docs gain a "Several positions" section with the same example, and note that pooling is a different intervention, not a cheaper version of alignment. Implements TransformerLensOrg#1939.
jlarson4
reviewed
Nov 24, 2026
…idths Review follow-ups: - The aligned-slot test ran on _SumToy, which sums over positions, so with a full interchange it gave the same output whichever source slot went to which base position: taking the source's slots in reverse order passed every test. It now runs on _Echo, which returns every position's activation, with base and source positions listed in different orders, and checks each base slot against the matching source slot. The reversal now fails it. - fit_das typed base_positions and source_positions with one width name, so under the type checker pooled spans of different widths were rejected, the case the docs describe. source_positions now has its own width (SourcePositions). Aligned positions must still match: fit_das checks that first and names pool='mean' in the error.
Collaborator
|
Thank you for making those updates @dipo101, this looks great, merged! |
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
Lets the interchange tools intervene on several positions per example, as approved in #1939.
positions(andfit_das'sbase_positions/source_positions) may be[batch, k]; base positionjtakes the source's positionj. Each (example, position) pair is one row of the intervention, so every intervention, basis andfit_daswork unchanged, with one basis shared by thekpositions.pool="mean"): each row names a span; the intervention acts on the span's mean, and every position in the span moves by the change in the mean. Base and source spans may differ in length.PAD_POSITION, a sentinel that is never a valid index. Negative indices in[batch, k]positions raise an error, so-1(the last position in[batch]mode) is never read as padding.[batch]positions behave exactly as before.On GPT-2 small at block 4, patching subject number at the subject alone flips 0.25 of held-out pairs, at the preposition alone 0.44, and at both aligned 1.00 (pooled 0.97). The integration test pins this. Docs gain a "Several positions" section, including the note that pooling is a different intervention, not a cheaper version of alignment.
Fixes #1939
Type of change
Checklist: