Skip to content

feat(atp-star): add tested component-localization building blocks - #705

Open
janmenjayap wants to merge 6 commits into
ndif-team:0.8from
janmenjayap:feat/atp-star
Open

janmenjayap wants to merge 6 commits into
ndif-team:0.8from
janmenjayap:feat/atp-star

Conversation

@janmenjayap

@janmenjayap janmenjayap commented Aug 29, 2026

Copy link
Copy Markdown

Summary

Draft PR (pending maintainer confirmation of the approach proposed in #704)
Adds dependency-free, individually tested AtP* building blocks using existing public nnsight APIs.

This is the first part of #704. It adds no public package API, runtime dependency, model download, or empirical benchmark claim.

Included

  • Exact activation-patching and basic AtP baselines.
  • A nonlinear counterexample showing that AtP estimates are not causal effects.
  • Exact local query correction and numerically stable O(T²D) key correction.
  • GPT-2 and GPT-NeoX/Pythia attention-source adapters.
  • Compatibility with Transformers 4.48 and 5.16 attention layouts.
  • Model-attention parity tests covering Q/K/V, probabilities, output layouts, masks, scaling, and gradients.
  • GradDrop gradient replacement and Equation 11 aggregation.
  • Algorithm 1 included/excluded subset statistics.
  • A user-facing AtP* building-blocks guide with explicit limitations.

Validation

  • 10/10 targeted CPU tests pass on tests/test_atp_star.py against the 0.8 branch (Transformers 4.57.6).
  • Rebase onto 0.8 surfaced one real regression: the actual attention-interface call moved from
    .source.attention_interface_0 to .source.attention_interface_2 for both GPT-2 and GPT-NeoX/Pythia
    (0.8's transformers adds a default-then-override lookup step before the call). Fixed in
    tests/test_atp_star.py and docs/patterns/atp-star.md by trying attention_interface_2 first.
  • GradDrop's two-backward/.grad-zero session semantics and .save()-outside-trace behavior were
    unaffected by the 0.8 rebase.
  • Broader CPU suite: 798 passed / 103 failed / 56 errored / 75 skipped. All failures/errors are confined
    to files this PR does not touch (test_vlm.py, test_vision.py, test_encoder.py, test_chunked_tasks.py,
    tests/tp/, tests/vllm/) — pre-existing baseline breakage on 0.8, not introduced here.
  • Black, IDE diagnostics, diff checks, local links, and whitespace checks pass.

The unfiltered repository command currently encounters unrelated baseline environment failures involving optional Ray, dill, peft, and torchvision dependencies, plus a missing SERVER symbol in test_whitelist_serialization.py. None of those files or dependencies are changed by this PR.

Deferred to PR 2

  • Executable GPT-2/Pythia benchmark and real-model results.
  • Student-t confidence conversion for the subset diagnostic.
  • Public package helpers under src/nnsight/.
  • Fused attention, vLLM, remote execution, GQA, SAE features, and edge attribution.

This PR intentionally does not close #704.

Review focus

  1. Clean-into-noise patch direction and score sign.
  2. Query/key local-output correction formulas.
  3. Compatibility normalization across Transformers attention layouts.
  4. GradDrop reverse-order gradient interception.
  5. Separation between approximate rankings and exact causal verification.

Related work

The external nnsight replication has no declared software license; no code was copied or adapted from it.

@JadenFiotto-Kaufman

JadenFiotto-Kaufman commented Sep 3, 2026

Copy link
Copy Markdown
Member

Thanks for this, and for keeping it scoped and honest about what is deferred.

Two things.

Please retarget it to 0.8. Development happens on that branch. main is well
behind it, and the attribution-patching page you are extending has moved there.
Once it is based on 0.8 and CI is green we can merge it. Changing the base
branch on the PR and rebasing should be enough.

You may also want a PR against https://github.com/ndif-team/skills, branch 0.8.
That repo holds the agent-facing skills, and there is already an
attribution-patching one under plugins/nnsight/skills/, next to
activation-patching and circuit-discovery. The AtP* corrections belong there:
the Q/K local corrections, GradDrop, and the exact-verification step all fix
failure modes an agent writing attribution code hits unaided. One convention to
know in that repo: code blocks in a skill are executed by its tests, so snippets
have to run.

No need to close #704 with this. Happy to keep it open for the benchmark half.

@janmenjayap
janmenjayap changed the base branch from main to 0.8 September 4, 2026 07:24
On 0.8's transformers, GPT2Attention.forward and GPTNeoXAttention.forward
resolve attention_interface through an extra default-then-override step
before invoking it, shifting the real call from
.source.attention_interface_0 to .source.attention_interface_2 for both
families. Try attention_interface_2 first, falling back to the old name.
@janmenjayap
janmenjayap marked this pull request as ready for review September 4, 2026 09:59
@janmenjayap

janmenjayap commented Sep 4, 2026

Copy link
Copy Markdown
Author

Retargeted to 0.8 and rebased feat/atp-star cleanly on top (force-pushed to my fork). Marking this ready for review.

One regression surfaced by the rebase: on 0.8's Transformers the actual attention-interface call moved from .source.attention_interface_0 to .source.attention_interface_2 (GPT-2 and GPT-NeoX/Pythia both) - fixed in cfbb356.

Test status against 0.8 (Transformers 4.57.6): 10/10 targeted in tests/test_atp_star.py; broader CPU suite 798 passed / 103 failed / 56 errored / 75 skipped, with all failures/errors confined to files this PR does not touch.

One blocker I cannot clear myself: the fork PR's Actions run is sitting at action_required (needs a maintainer to approve the workflow run) - I do not have admin rights to approve it, so CI shows no checks yet. Could you approve the run when you get a chance?

@janmenjayap

Copy link
Copy Markdown
Author

Also opened the companion skills PR you suggested: ndif-team/skills#8 — ports the Q/K correction, GradDrop, and exact-verification workflow into a new atp-star skill next to attribution-patching, cross-linked both directions. Left out the subset/confidence diagnostic and benchmark protocol, since those read as benchmark artifacts rather than agent-facing failure-mode fixes. No dependency between the two — this one doesn't block on #705.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Add an AtP* workflow and benchmark for scalable component localization

2 participants