Skip to content

[Proposal] Demo or helper for statistical audits of activation-patching results on TransformerBridge #1988

Open

Description

@anaykatiyar-lang

Proposal

Add a focused demo or analysis example showing how to use a statistical audit layer for activation-patching results in the current TransformerBridge API, without turning that functionality into a core library method.

Motivation

The current TransformerLens v4 stack is built around TransformerBridge and the newer analysis/tooling interfaces, not the older HookedTransformer API. A prior LAT-style implementation or similar analysis utility may have been natural in v3, but it needs to be rewritten or re-scoped to work with the current bridge-based model interface.

A statistical audit layer is valuable when evaluating many components at once (heads, layers, positions, or intervention sites), especially when the analysis asks whether the observed patching signal survives multiple-comparisons correction. That is a natural fit for a research demo or notebook example, rather than necessarily a first-class core method in TransformerLens itself.

Scope

We should decide whether the repository wants:

  1. a small demo notebook showing statistical audits on real TransformerBridge runs, or
  2. a generic analysis utility in a separate package / helper module, or
  3. no direct repository addition yet, pending the broader analysis-tool overhaul.

Proposed direction

A good low-friction path would be:

  • keep statistical inference in a standalone or external helper package if needed,
  • adapt it to TransformerBridge rather than HookedTransformer,
  • present it as a notebook or docs example to make the methodology concrete,
  • keep the core library focused on generalized analysis primitives rather than a single lat_scan-like API.

Concrete example

A notebook could demonstrate:

  • running a clean/corrupt activation-patching experiment with TransformerBridge,
  • measuring per-component normalized effects,
  • reporting descriptive rankings and robustness diagnostics,
  • applying a valid multiple-testing procedure only when a defensible null is available,
  • documenting which assumptions are required for sign-flip or control-based inference.

The goal would be to make the statistical audit methodology usable and inspectable without hard-coding one specific method into the repository core.

Discussion points

  • Should TransformerLens accept a demo notebook for statistical analysis tools in the current v4 architecture?
  • Should generic statistical audits live in a dedicated package or helper module instead of the core repo?
  • If a core API is eventually added, should it be a generic analysis primitive instead of a single lat_scan-like method?
  • What is the preferred maintenance boundary for visualization-heavy or method-specific research tooling?

Checklist

  • I have checked that there is no similar issue or proposal in the repository.
  • Maintainers agree on the preferred scope and delivery format.
  • The proposal is rewritten for the TransformerBridge v4 API.
  • The accepted path is either a demo notebook or a generic helper layer, rather than a single bespoke method.

Activity

  1. jlarson4 commented on Nov 5, 2026

    @jlarson4
    Collaborator

    Thanks for the proposal @anaykatiyar-lang. Part of this is already in the library, one piece is missing and would be a good contribution, the rest belongs in a notebook or outside the repo.

    As of 4.3.0, generic_activation_patch(..., reduce="none", baseline=True) returns a PatchingResult instead of a bare tensor. It keeps per-example values for every swept cell and exposes normalized recovery, standard_error(), bootstrap_ci() and permutation_pvalue(), which is a paired sign-flip test, exact for small batches and Monte Carlo above that. So the per-component effects and the sign-flip inference you describe do not need a new home.

    What the TransformersLens does not do is adjust those p-values for the number of cells swept. Over a full head sweep that is a multiple-comparisons problem the result object creates and then leaves to the user. The right solution for this is a model-free adjust_pvalues(p, method="bh" | "by" | "holm") in transformer_lens/utilities/statistics.py, operating along a dim of any p-value tensor, written in torch like the rest of that module (scipy is not a runtime dependency), with tests against known reference values.

    Generally, we want generic numerics to be integrated as plain functions, nothing method-specific or stateful goes in core, and plotting stays in notebooks. An auditor class that owns its own patching loop, a second results object, null-distribution bookkeeping or summary reports would duplicate PatchingResult and are better kept as a notebook or an external package built on top of it.

    If you have an implementation already, I'd be curious to see it. The path I would suggest is a PR with the adjustment function and its tests. Let me know if you're interested in working on that, or if you have any questions.

    Thanks!

  2. added
    enhancement
    complexity-moderate
    TransformerBridge
    on Nov 5, 2026
  3. anaykatiyar-lang commented on Nov 5, 2026

    @anaykatiyar-lang
    Author

    Thanks for the clarification—that makes sense. I’m interested in contributing the model-free adjust_pvalues(p, method="bh" | "by" | "holm") function and tests in transformer_lens/utilities/statistics.py, keeping it torch-only and supporting adjustment along a specified dimension. I’ll leave the auditor, reporting, and plotting pieces out of core.

    I’ll first check the existing conventions in the statistics utilities, then open a PR with the function and tests against known reference values. I’ll also document the expected input and dimension behavior. Please let me know if you have a preferred convention for edge cases such as NaNs or empty dimensions.

  4. jlarson4 commented on Nov 6, 2026

    @jlarson4
    Collaborator

    Sounds good, I will get you assigned. as far as your questions on edge cases:

    • For empty axis, raise ValueError, as bootstrap_ci and sign_flip_permutation_pvalue do.
    • For NaNs, validate every p-value is in [0, 1] and raise ValueError otherwise, which rejects NaN. Callers mask NaN cells before calling. Don't drop them silently, that shrinks the family without the caller seeing it.
  5. anaykatiyar-lang commented on Nov 7, 2026

    @anaykatiyar-lang
    Author

    Thanks, that’s clear. I’ll implement the standalone adjust_pvalues utility with BH, BY, and Holm methods, plus tests against known reference values. I’ll raise ValueError for an empty adjustment axis or any p-value outside [0, 1], including NaNs, and leave masking to callers. I’ll keep the PR limited to the utility and its tests.

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

Metadata

Metadata

Labels

TransformerBridgecomplexity-moderateenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions