Skip to content

[Proposal] Several positions per example in interchange interventions #1939

Open

Description

@dipo101

Proposal

Let the interchange tools in tools.analysis.interchange intervene on several positions per example, in two modes:

  • Aligned positions. positions (and fit_das's base_positions/source_positions) may be [batch, k] as well as [batch]. Base position j takes the source's activation at source
    position j, as with pyvene's (batch, k) unit locations.
  • Pooled spans. With pool="mean", each row names a span instead. The intervention acts on
    the span's mean, and base and source spans may differ in length.

[batch] positions keep working exactly as they do now.

Motivation

The tools intervene on one position per example, but a variable is often spread over several, and
then a one-position interchange underestimates it. On GPT-2 small, with subject number in
"The key(s) near the cabinet", patching the whole residual stream after block 4 at the subject
alone flips 37% of held-out pairs, and at the preposition alone 27%. Patching both together flips
100%. A one-position analysis would conclude that the variable is mostly gone from both positions
at that layer, when the two positions carry it jointly.

The same holds for speech. Whisper's encoder emits a frame every 20 ms, so one word spans many
positions, and the number differs by speaker and speaking rate. Probing work on speech compares
single frames, quarter-segment spans and mean-pooled word segments (Pasad et al., 2024). The causal
counterpart needs both aligned positions and pooled spans.

Pitch

Aligned mode. Interventions keep their contract of mapping [n, d_model] base rows and
source rows to new base rows. Each (example, position) pair is one row:

  • collect_activations returns [batch, k, d_model];
  • run_with_intervention flattens the selected positions into rows, applies the intervention and
    writes them back.

So SubspaceInterchange, NormMatchedPlacebo, every basis and fit_das work unchanged, with one
basis shared by the k positions. -1 pads shorter rows, so pairs in a batch can have different
k; base and source pad the same slots.

Pooled mode. Rows of positions name a span per example (padded with -1), and
collect_activations returns the span means, [batch, d_model]. The intervention maps the base's
span mean and the source's to a new mean. Every base position in the span then moves by the same
amount: the new mean minus the base's mean. For SubspaceInterchange, this gives the span's mean
the source's coordinates inside the subspace, and each position keeps its own offset from the
mean. No alignment is needed, so base and source spans can differ in length.

Docs: a "Several positions" section in interchange_interventions.md with the example below.
Tests: unit tests for both modes and the padding, and an integration test reproducing the GPT-2
result.

Alternatives

  • Separate calls per position. They can't express a joint intervention, because each call
    patches one position, and the hook must fire once per pass.
  • A concatenated basis. By default, pyvene's rotation (DAS) intervention flattens
    (batch, k, d) into (batch, k·d) (unless keep_last_dim is set), so the learned subspace
    spans the concatenated positions. The basis then grows with k, k must be fixed, and the
    difference-in-means, probe and neuron bases and their placebos no longer apply. A basis shared
    across positions keeps all of them.
  • Boolean masks instead of indices. A mask can't say which base position takes which source
    position, so it suits pooling but not alignment.

Additional context

The GPT-2 numbers come from 16 nouns, 4 sentence frames, and 12 splits that fit on one frame and
evaluate 32 pairs in another. Each entry is the mean interchange accuracy over the splits, with
the range below. "Whole" patches the whole residual, the ceiling. "DiM" uses a rank-1
difference-in-means basis fit on the fit frame, shared by both positions in the aligned mode.

layer basis subject preposition both, aligned both, pooled
3 whole 0.96 0.00 1.00 0.98
4 whole 0.37 (0.19–0.69) 0.27 (0.00–0.44) 1.00 (1.00–1.00) 0.99
4 DiM 0.31 0.13 0.95 (0.91–0.97) 0.92
5 whole 0.32 (0.19–0.59) 0.08 1.00 (1.00–1.00) 0.92
6 whole 0.27 0.01 0.94 0.86

Pooling is a different intervention, not a cheaper version of alignment. At layer 2, where the
variable sits on the subject alone, pooling over both positions halves the subject's shift and
reaches 0.62 against 1.00. The docs would say so.

References:
Wu, Geiger, Arora, Huang, Wang, Goodman, Manning and Potts (2024), "pyvene: A Library for Understanding and Improving PyTorch Models via Interventions", NAACL (System Demonstrations);
Pasad, Chien, Settle and Livescu (2024), "What Do Self-Supervised Speech Models Know About Words?", TACL 12;
Geiger, Wu, Potts, Icard and Goodman (2024), "Finding Alignments Between Interpretable Causal Variables and Distributed Neural Representations", CLeaR.

Checklist

  • I have checked that there is no similar issue in the repo (required)

Activity

  1. jlarson4 commented on Oct 22, 2026

    @jlarson4
    Collaborator

    I am not going to approve this just yet, I would prefer to keep your focus on #1938 and the followup PRs for generate and weight_processing. I'll take some time to review and give feedback tomorrow

  2. added
    enhancement
    complexity-moderate
    TransformerBridge
    on Nov 11, 2026
  3. jlarson4 commented on Nov 11, 2026

    @jlarson4
    Collaborator

    Hi @dipo101! Finally getting around to reviewing this. It is approved, with the following tweaks.

    We should use something other than -1 for the padding marker. positions=-1 already means "last token" for _select/_write. Under this proposal [[3, -1]] would silently drop what the user meant as the last position. Please use an explicit mask or lengths argument for ragged rows, or a sentinel that is never a valid index, with negative indices rejected in 2-D mode and a clear error. Also, please keep the note that pooling is a different intervention, not a cheaper alignment, in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

TransformerBridgecomplexity-moderateenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions