[Proposal] KV-group destinations for direct path patching on GQA/MQA models
メンテナーはふだん 1 日以内に返信
@emerardd がすでに取り組んでいます。
2026年10月29日 から。
評価
この issue はまだ評価されていません。
説明
Proposal
Extend the existing direct-path patching functions with an explicit KV-group destination mode. This would measure a source attention head's path through one later layer's shared K or V group, using the bridge's existing pre-norm input forks.
Motivation
Ordinary K/V activation patching already operates on KV heads, and direct Q-path patching works on GQA models. Direct K/V-path patching is deliberately rejected because its destinations and result axes are defined per query head (#1901).
That leaves a specific question without a high-level sweep: how does one source head affect the output through a particular shared K or V input? Restoring the whole clean K/V activation also restores changes from other upstream components. A KV-group destination would isolate the selected source's contribution while respecting the model's native sharing structure.
Pitch
Keep the current behavior as the default, and add an opt-in destination unit, provisionally destination_unit="kv_group", for component="k" or "v". Source indices remain query/output-head indices. Single-source results would be [n_layers, n_kv_heads]; all-sources results would retain query-head source axes and use a KV-group destination axis.
For source head (s, h), compute its clean-minus-corrupted residual write, delta = (z_clean - z_corrupt) @ W_O. Add this only to the selected destination group's pre-norm residual copy, then apply the destination norm and K/V projection normally. With four Q heads and two KV heads, intervening on group 0 reaches query heads 0 and 1 through that shared branch.
The initial scope would be standard layouts with a uniform destination KV count and existing split-QKV forks. Current source-architecture restrictions would remain; heterogeneous KV counts, post-repeat per-query-head interventions, and EAP/faithfulness extensions would be separate scope decisions. On MHA, a group has one head and should reproduce the existing K/V results.
Proposed delivery:
- One PR updating the single-source and all-sources functions, tests, and documentation. Tests would cover MHA equivalence, MQA/GQA branch isolation against an independent projection-level oracle, no-op interventions, unsupported layouts, and flag restoration on success and exceptions. Include a fixed-checkpoint, multi-prompt GQA example with clean/corrupt baselines and explicit group labels.
Two points to agree on first: would you prefer an opt-in argument or a separate KV-group entry point? Also, the fork currently recomputes the raw norm and can bypass existing ln1.hook_out edits. Should that composition be addressed before this extension, or explicitly rejected when unsupported?
Alternatives
Researchers can implement the intervention with hooks today; the extension would centralize group indexing, sweeps, and result semantics in the existing API. Editing one K/V copy after repeat_kv is another possible experiment, but it breaks native sharing and answers a different question.
Additional context
I checked feasibility on dev at 11197c23. Across 14 config-built Llama interventions covering MQA, GQA, and MHA, the input-fork intervention matched an independent projection-output oracle exactly. On cached HuggingFaceTB/SmolLM2-135M at revision 93efa2f097d58c2a74874c7e644dbc9b0cee75a2, both K and V interventions also matched the oracle, with no change to the destination layer's out-of-group head outputs. These checks establish the intervention mechanics; the proposed multi-prompt example would validate its use on a research task.
References: GQA, IOI/path patching.
Checklist
- I have checked that there is no similar issue in the repo.
- 主要言語
- Python
- スター
- 3.9k
- フォーク
- 708
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 77
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TransformerLensOrg/TransformerLens のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
TransformerLensOrg/TransformerLens#1939 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Proposal] Natural Language Autoencoders: explain and reconstruct Qwen activations through TransformerBridge対応中かも @janmenjayap が 3 日前に担当しました。 オープンcomplexity-moderate enhancement Research Reproduction TransformerBridge
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
TransformerLensOrg/TransformerLens#1884 · コメント 4 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[Proposal] Contextual Decomposition: Nonlinear Source Attribution and Dataset-Wide Ranking on GPT-2オープンCommunity Feedback Requested Research Reproduction seen_by_maintainers
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
TransformerLensOrg/TransformerLens#1883 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Community Feedback Requested enhancement seen_by_maintainers TransformerBridge
難易度 5/5 1週間以上 初心者へのやさしさ 8/100
TransformerLensOrg/TransformerLens#1880 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
TransformerLensOrg/TransformerLens の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
Validate finite output clamping limits in StepPredictor.prepare_clamping_params to prevent silent NaN/Inf propagation対応中かも @muskan-creates352 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
mllam/neural-lam#848 ·
メンテナーはふだん 2 日以内に返信
-
infra
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
fab-geocommuns/RNB-coeur#1166 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
deepspeedai/DeepSpeed#8951 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws/context-ontology-accelerator#343 ·
メンテナーはふだん 1 日以内に返信