Statistical audits for mechanistic interpretability

Patch with intent.
Report with restraint.

TransformerLens-FDR adds an explicit, assumption-aware path from activation-patching effects to multiple-testing results—without pretending a convenient null is automatically valid.

Python 3.10+TransformerLens 4.0+MIT licensed
audit pipeline● ready to inspect
observed
cleanactivations
→
corruptedbaseline
intervention
patch one componenthead · MLP · residual
→
Δ metricPnormalized recovery
inference
choose a defensible nullnone · sign-flip · empirical
→
qBH / BYacross the family
assumptions stay visibleresults stay reproducible
4hook targets
2FDR corrections
∞questions worth testing
◎Significance is not causality.
Read the methods statement.
01 / Why it exists

An effect map is
not a verdict.

Activation patching asks whether restoring a clean activation recovers a metric in a particular context. When you inspect many components, the analysis needs a declared search family, a defensible no-effect comparison, and a validation split.

01

Keep exploration honest

The default method="none" returns effects and robust outlier scores without inventing p-values from the observed map.

Explore the paths ↗
02

Make the null explicit

Use sign-flips only when prompt effects are independent and symmetric around zero, or provide task-specific controls that remove the tested relation.

Read the guardrails ↗
03

Correct the whole search

BH is less conservative under its dependence conditions; BY is more conservative and allows arbitrary dependence when input p-values are valid.

See the correction ↗
02 / From prompts to claims

A four-step
audit trail.

The package keeps the intervention, metric, null, correction family, and validation split connected. That makes a result easier to reproduce—and easier to challenge.

  1. 01

    Define the question

    Align clean and corrupted prompts, target labels, a metric function, and the component family you intend to search.

    ⌁
  2. 02

    Preflight the setup

    Check prompt count, clean–corrupted metric gap, hook capture, family size, and attainable p-value resolution before expensive patching.

    ◌
  3. 03

    Patch and quantify

    Measure per-prompt effects, normalized recovery, robust outlier scores, p-values when justified, and the Circuit Localization Index.

    ⌖
  4. 04

    Validate out of sample

    Select components on one prompt group, then evaluate the joint effect on disjoint groups with held-out templates.

    ↗
03 / Choose your inference path

No shortcut
to a valid null.

Click a path to see what the add-on computes, what it assumes, and what the result does not establish.

DESCRIPTIVE MODE

Explore without overclaiming

Use this path when you are exploring or cannot explain what “no effect” should look like. You get normalized effects, robust outlier scores, and descriptive localization—no inferential p-values.

method="none"No null → no FDR claim
04 / The core quantities

Make the
denominator visible.

Every result is conditional on the metric, prompts, null, correction family, and model configuration you chose. The formulas make those choices inspectable.

NORMALIZED PATCHING EFFECT
P = Mpatched − McorruptedMclean − Mcorrupted

Near 0 means little recovery; 1 means the clean-to-corrupted gap is fully recovered. The ratio is undefined when the clean and corrupted metrics are equal.

FALSE DISCOVERY RATE
FDR = E [Vmax(R, 1)] ≤ α

FDR is a long-run expectation, not a guarantee about the false-result share in one audit.

CIRCUIT LOCALIZATION INDEX
CLI = 1 − Hcausallog2(N)

A descriptive concentration score: high values indicate effects concentrated in fewer components. It is not a significance test or proof of causality.

05 / A small API for careful work

The audit
is the artifact.

Results keep the effect map, inferential fields, search family, p-value resolution, hook names, and methods statement together.

quickstart.py
from transformerlens_fdr import PatchingAuditor, logit_difference

auditor = PatchingAuditor(
    model,
    metric_fn=logit_difference,
    fdr_method="fdr_by"
)

preflight = auditor.check_setup(
    clean, corrupt, correct, incorrect,
    method="signflip"
)
result = auditor.run_patching_audit(
    clean, corrupt, correct, incorrect,
    method="signflip"
)
print(result.format_summary())
Copied
06 / Guardrails that travel with the result

Evidence with
edges around it.

These are not decorative warnings. They define the boundary of what the output can support.

01

Preflight first

Check the clean–corrupted gap and p-value resolution before a long audit. A discrete p-value floor can make a target threshold unattainable.

02

Pool the family

If attention heads and MLP layers are one scientific search, combine their valid p-values before interpreting significance.

03

Hold out templates

Choose components on one group of prompts, then evaluate the joint effect on disjoint groups. This reduces reuse of the same evidence.

04

Report the hook

attn_head, mlp_out, resid_mid, and mlp_in intervene at different computational locations.

07 / Research context

Built on a
larger conversation.

Deep Search surfaced methodological support for the add-on’s design. Direct literature explicitly naming TransformerLens-FDR is limited, so these references are background and validation context—not independent validation of this package.

Source note Repository documentation and SciSpace Deep Search synthesis, searched through 2026. See the README ↗ and purpose & usage guide ↗.
08 / Start an audit

Install the
statistical layer.

Bring your existing TransformerLens workflow. Add a metric, declare the null, and keep the methods statement close to the result.

PyPIpip install transformerlens-fdr
GitHubpip install git+https://github.com/anaykatiyar-lang/transformerlens-fdr.git
Open repository ↗