You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a TransformerBridge-first tool for measuring overlap between the residual-stream
subspaces read or written by attention-head weights. For orthonormal bases U and V,
where theta_i are principal angles. The Projection Kernel (PK) ignores singular-value
magnitude and is invariant to basis changes inside either subspace. It complements
Composition Score (CS): PK measures overlapping support, while CS measures scale-sensitive
composition of full linear maps under an isotropic-input assumption.
The work should separate:
a small, maintained numerical and TransformerBridge API; and
a versioned research artifact for GPT-2 labels, baselines, plots, reproduction, and
causal validation.
Motivation
TransformerLens exposes Q/K/V/O weights and implements Q-, K-, and V-composition, but it
has no principal-angle or subspace-overlap analysis. Several results motivate this gap:
Elhage et al. introduced weight composition for head-to-head paths.
Merullo et al. found causally important one- to three-dimensional communication
channels by decomposing QK and OV matrices.
Yamagiwa, Takase, and Shimodaira report that PK over individual Q/K/V/O subspaces more
clearly recovers several known GPT-2-small relationships.
MAPS shows that static weight scores can predict head outputs and causal ablations, but
also that heads are multifunctional and context dependent.
The PK paper studies one model, does not directly test whether PK predicts path-specific
causal effects, and explicitly says PK does not identify head function. Work on
representation similarity likewise warns that geometric and functional similarity can
dissociate. TransformerLens can provide the primitive and test its limits with existing
hooks and direct path patching.
Pitch
Stable core API
Names are open to maintainer preference. A minimal model API could be:
The numerical layer should remain model independent:
orthonormal_subspace(matrix, *, rank=None, rtol=None) extracts a documented
numerical column-space basis and measured rank;
projection_kernel(basis_a, basis_b) returns raw PK, projector-normalized PK, and
principal-angle cosines.
Explicit basis extraction avoids hiding rank decisions inside each score. For ranks r
and s, raw PK lies in [0, min(r, s)]. Projector normalization is PK / sqrt(r*s), the cosine between projection matrices; at equal rank this is the
paper's PK / d_head.
The first model wrapper should expose OQ, OK, and OV without assuming equal source and
target head counts.
Weight-layout and architecture contract
The paper uses left-multiplication matrices. TransformerLens basis-generating matrices are:
Role
Matrix
Per-head shape
Q
W_Q[layer, head]
[d_model, d_head]
K
W_K[layer, kv_head]
[d_model, d_head]
V
W_V[layer, kv_head]
[d_model, d_head]
O
W_O[layer, head].T
[d_model, d_head]
The O transpose is essential. Results carry original layer indices and separate
source/target head metadata.
For grouped-query attention, K/V retain native KV-head identity rather than being silently
repeated to query-head labels. OQ has query-head × query-head axes; OK and OV have
query-head × KV-head axes. An expanded view can be added later for comparison with CS,
but duplicated K/V views must not be treated as independent heads.
Hybrid models include only attention layers and preserve original block indices.
Architectures without standard readable Q/K/V/O projections, including MLA and opaque
native-forward adapters, raise a precise unsupported-architecture error.
Numerical contract
Validate floating, finite, two-dimensional matrices with a shared ambient dimension.
Use reduced SVD for rank measurement and basis extraction; never materialize a [d_model, d_model] projector.
Use a documented dtype- and shape-aware rank tolerance; permit caller-pinned rank.
Clamp overlap singular values only for roundoff before acos.
Preserve device and document accumulation/return dtype for low-precision inputs.
Precompute each head basis once before batched pair scoring.
For independent random m-planes in R^d, the paper gives:
mean m^2 / d;
variance 2*m^2*(d-m)^2 / (d^2*(d-1)*(d+2)).
Expose these, if useful, only as descriptive moments. The normal approximation is not an
automatic p-value; trained head pairs are dependent and anisotropic.
Research reproduction and extension
The research artifact should pin model revision, processing mode, dtype, seed, pair
construction, and annotation data. It should not be imported by the library.
Study A — exact reproduction
Using raw GPT-2-small weights and the paper's 36 annotated heads across seven classes,
reproduce:
9,504 earlier-to-later pairs for each of OQ, OK, and OV;
top-20 wiring diagrams and named edges;
Table 1 PR-AUC against CS, Simple-CS, Linear CKA, and Procrustes;
10,296 non-identical layer-ordered QQ/KK/VV/OO pairs and Table 2;
inlet/outlet rankings, especially L4H7;
the random-subspace moment simulation; and
Appendix K's raw-versus-processed comparison.
Table 1 targets are:
Method
OQ
OK
OV
Mean
PK
0.446
0.451
0.289
0.395
CS
0.227
0.352
0.215
0.265
Simple-CS
0.245
0.359
0.305
0.303
Linear CKA
0.337
0.323
0.409
0.356
Procrustes
0.328
0.269
0.428
0.342
This is not a blanket “PK wins” target: PK leads OQ and OK, while CKA and Procrustes beat
it on OV. Table 2 reports mean PR-AUC 0.047 and ROC-AUC 0.809 for PK, versus 0.038 and
0.787 for the strongest reported PR-AUC baseline, Procrustes.
Study B — causal-validity extension
Test:
Does static O→Q/K/V subspace overlap predict path-specific causal communication on
held-out prompts better than scale-sensitive or generic weight-similarity baselines?
Use clean/corrupted paired prompts and direct path patching from source-head output to a
target head's Q, K, or V input in at least two domains:
IOI for inhibition/name-mover and duplicate/inhibition relationships;
repeated-token induction for previous-token/induction relationships.
For every valid pair, record normalized absolute logit-difference recovery and uncertainty
across prompts. Evaluate Spearman correlation, top-k enrichment, PR-AUC at a preregistered
effect threshold, bootstrap confidence intervals, and paired bootstrap metric differences.
Baselines are PK, CS, Simple-CS, Linear CKA, Procrustes, source-head effect, target-head
effect, layer distance, weight norm, and seeded random ranking. Endpoint effects are
essential controls: otherwise a metric may merely rank globally important heads.
Primary hypotheses:
H1: raw-weight GPT-2 results reproduce within declared numerical/ranking tolerances.
H2: PK adds held-out predictive value beyond endpoint effects and layer distance for
OQ and OK.
H3: validity differs by role pairing; PK is not expected to dominate OV.
H4: PK rankings are more stable than CS under behavior-preserving TransformerLens
preprocessing.
Falsifiers include failure to reproduce Table 1, no held-out association after controls,
or equal performance from random norm-matched subspaces. Report negative results rather
than redefining the target.
Staged delivery
PR 1 — numerical primitive
basis extraction, PK, principal angles, normalization, and null moments;
model-free unit tests and API docs;
no model wrapper, plotting, labels, or baseline bundle.
PR 2 — TransformerBridge wrapper
OQ/OK/OV extraction, native MHA/GQA metadata, hybrid handling, masks, and ranking;
synthetic tests plus cached-model Bridge integration tests;
explicit unsupported-layout errors.
Research artifact/report
exact GPT-2 reproduction and causal-validity study;
baselines local to the artifact unless maintainers request promotion;
Proposal
Add a TransformerBridge-first tool for measuring overlap between the residual-stream
subspaces read or written by attention-head weights. For orthonormal bases
UandV,PK(S, T) = ||U.T @ V||_F^2 = sum_i cos(theta_i)^2,where
theta_iare principal angles. The Projection Kernel (PK) ignores singular-valuemagnitude and is invariant to basis changes inside either subspace. It complements
Composition Score (CS): PK measures overlapping support, while CS measures scale-sensitive
composition of full linear maps under an isotropic-input assumption.
The work should separate:
causal validation.
Motivation
TransformerLens exposes Q/K/V/O weights and implements Q-, K-, and V-composition, but it
has no principal-angle or subspace-overlap analysis. Several results motivate this gap:
channels by decomposing QK and OV matrices.
clearly recovers several known GPT-2-small relationships.
also that heads are multifunctional and context dependent.
The PK paper studies one model, does not directly test whether PK predicts path-specific
causal effects, and explicitly says PK does not identify head function. Work on
representation similarity likewise warns that geometric and functional similarity can
dissociate. TransformerLens can provide the primitive and test its limits with existing
hooks and direct path patching.
Pitch
Stable core API
Names are open to maintainer preference. A minimal model API could be:
The numerical layer should remain model independent:
orthonormal_subspace(matrix, *, rank=None, rtol=None)extracts a documentednumerical column-space basis and measured rank;
projection_kernel(basis_a, basis_b)returns raw PK, projector-normalized PK, andprincipal-angle cosines.
Explicit basis extraction avoids hiding rank decisions inside each score. For ranks
rand
s, raw PK lies in[0, min(r, s)]. Projector normalization isPK / sqrt(r*s), the cosine between projection matrices; at equal rank this is thepaper's
PK / d_head.The first model wrapper should expose OQ, OK, and OV without assuming equal source and
target head counts.
Weight-layout and architecture contract
The paper uses left-multiplication matrices. TransformerLens basis-generating matrices are:
W_Q[layer, head][d_model, d_head]W_K[layer, kv_head][d_model, d_head]W_V[layer, kv_head][d_model, d_head]W_O[layer, head].T[d_model, d_head]The O transpose is essential. Results carry original layer indices and separate
source/target head metadata.
For grouped-query attention, K/V retain native KV-head identity rather than being silently
repeated to query-head labels. OQ has query-head × query-head axes; OK and OV have
query-head × KV-head axes. An expanded view can be added later for comparison with CS,
but duplicated K/V views must not be treated as independent heads.
Hybrid models include only attention layers and preserve original block indices.
Architectures without standard readable Q/K/V/O projections, including MLA and opaque
native-forward adapters, raise a precise unsupported-architecture error.
Numerical contract
[d_model, d_model]projector.acos.For independent random
m-planes inR^d, the paper gives:m^2 / d;2*m^2*(d-m)^2 / (d^2*(d-1)*(d+2)).Expose these, if useful, only as descriptive moments. The normal approximation is not an
automatic p-value; trained head pairs are dependent and anisotropic.
Research reproduction and extension
The research artifact should pin model revision, processing mode, dtype, seed, pair
construction, and annotation data. It should not be imported by the library.
Study A — exact reproduction
Using raw GPT-2-small weights and the paper's 36 annotated heads across seven classes,
reproduce:
Table 1 targets are:
This is not a blanket “PK wins” target: PK leads OQ and OK, while CKA and Procrustes beat
it on OV. Table 2 reports mean PR-AUC 0.047 and ROC-AUC 0.809 for PK, versus 0.038 and
0.787 for the strongest reported PR-AUC baseline, Procrustes.
Study B — causal-validity extension
Test:
Use clean/corrupted paired prompts and direct path patching from source-head output to a
target head's Q, K, or V input in at least two domains:
For every valid pair, record normalized absolute logit-difference recovery and uncertainty
across prompts. Evaluate Spearman correlation, top-k enrichment, PR-AUC at a preregistered
effect threshold, bootstrap confidence intervals, and paired bootstrap metric differences.
Baselines are PK, CS, Simple-CS, Linear CKA, Procrustes, source-head effect, target-head
effect, layer distance, weight norm, and seeded random ranking. Endpoint effects are
essential controls: otherwise a metric may merely rank globally important heads.
Primary hypotheses:
OQ and OK.
preprocessing.
Falsifiers include failure to reproduce Table 1, no held-out association after controls,
or equal performance from random norm-matched subspaces. Report negative results rather
than redefining the target.
Staged delivery
PR 1 — numerical primitive
PR 2 — TransformerBridge wrapper
Research artifact/report
Correctness and test plan
basis extraction.
W_O.Torientation.Risks and interpretation
rank-
d_headPK; truncated variants are follow-ups, not post-hoc fixes.activation described by Makelov et al.
Alternatives
whole-subspace overlap.
Additional context
“Measuring Affinity between Attention-Head Weight Subspaces via the Projection Kernel,”
arXiv:2601.10266v1 (2026): https://arxiv.org/abs/2601.10266.
images, with no source or license, when checked on 2026-08-24.
SVDInterpreter issue [Proposal] Implement SVD Decomposition of OV Circuits, Win, Wout #256 / merged PR Add SVD interpretability feature to TransformerLens #311, SVD-semantics issue [Proposal] Update and discuss behavior of SVD #341, Bridge analysis
PR Added additional bridge analysis tools #1237, GQA circuit fix PR fix(bridge): expand grouped K/V heads in QK/OV and composition circuits on GQA models #1593, and gated-Qwen analysis fix PR Fix gated Qwen W_Q analysis weights #1653. None implements
PK, principal angles, or projector-overlap head affinity.
KV-head identity rather than counting expanded views independently.
Checklist
Status: implemented in #1721