Introduction
Mechanistic explanations must be both faithful to a model's causal computation and compact enough to inspect. Circuit discovery ranks edges in a computation graph, while feature explanations must identify hidden directions that implement a high-level variable. Attribution methods such as EAP, RelP, and sparse feature circuits address parts of this problem.
We propose a paired design. An interaction-aware attribution pass estimates edge effects through effective residual differences, and a biorthogonal codec with an optional split-ReLU branch represents feature interventions at every native layer/token site. The intervention exchanges selected features while preserving the recipient residual.
Method
Interaction-aware circuit scores
The attribution stage captures clean and counterfactual activations at native graph sites, installs temporary propagation rules, and contracts effective source differences with downstream gradients. A midpoint integrated-gradient path averages these edge scores over the interpolation from corrupted to clean inputs.
class SigmoidTopK(torch.autograd.Function):
"""Differentiable top-k mask via sigmoid + bisection with implicit-diff backward."""
@staticmethod
def forward(ctx, scores, k, temp, n_iters=28):
lo = scores.min(dim=-1, keepdim=True).values - 10.0 * temp
hi = scores.max(dim=-1, keepdim=True).values + 10.0 * temp
with torch.no_grad():
for _ in range(n_iters):
mid = 0.5 * (lo + hi)
f_mid = torch.special.expit((scores - mid) / temp).sum(dim=-1, keepdim=True)
lo = torch.where(f_mid > k, mid, lo)
hi = torch.where(f_mid > k, hi, mid)
tau = 0.5 * (lo + hi)
mask = torch.special.expit((scores - tau) / temp)
ctx.save_for_backward(mask)
ctx.temp = temp
return mask
@staticmethod
def backward(ctx, grad_output):
(mask,) = ctx.saved_tensors
sp = mask * (1.0 - mask)
sp_sum = sp.sum(dim=-1, keepdim=True).clamp(min=1e-8)
gsp = (grad_output * sp).sum(dim=-1, keepdim=True)
return (sp / ctx.temp) * (grad_output - gsp / sp_sum), None, None, Nonedef _compute_effective_diff(model, graph, acts_cf, acts_cl):
"""Convert raw source node activations into exact residual-stream differences (fixes Gemma-2 ln1_post)."""
if not model.cfg.use_normalization_before_and_after:
return acts_cf - acts_cl
eff_diff = acts_cf - acts_cl
for layer in range(model.cfg.n_layers):
node = graph.nodes[f"a{layer}.h0"]
sl = graph.forward_index(node, attn_slice=True)
raw_cf = acts_cf[:, :, sl, :]
raw_cl = acts_cl[:, :, sl, :]
delta = raw_cf - raw_cl
b_o = model.blocks[layer].attn.b_O
u_cl = raw_cl.sum(dim=2) + b_o
u_cf = raw_cf.sum(dim=2) + b_o
ln_post = model.blocks[layer].ln1_post
d_cl = ln_post(u_cl.unsqueeze(2) + delta) - ln_post(u_cl).unsqueeze(2)
d_cf = ln_post(u_cf).unsqueeze(2) - ln_post(u_cf.unsqueeze(2) - delta)
eff_diff[:, :, sl, :] = 0.5 * (d_cl + d_cf)
return eff_diffdef stage1_attribute(
ctx,
ig_steps=5,
ln_freeze=True,
mlp_rule=True,
attn_temp=1.0,
use_ln1_post_fix=True,
midpoint=True,
eb_tau=1.0,
):
"""Stage 1: Exact Architecture-Faithful, Interaction-Aware, Empirical-Bayes Path Attribution."""
model, graph, device = ctx.model, ctx.graph, ctx.device
sum_s = torch.zeros((graph.n_forward, graph.n_backward), device=device, dtype=torch.float32)
sum_s2 = torch.zeros((graph.n_forward, graph.n_backward), device=device, dtype=torch.float32)
total_items = 0
src_nodes = [("hook_embed", graph.forward_index(graph.nodes["input"]))]
for l in range(model.cfg.n_layers):
src_nodes.append((graph.nodes[f"a{l}.h0"].out_hook, graph.forward_index(graph.nodes[f"a{l}.h0"])))
src_nodes.append((graph.nodes[f"m{l}"].out_hook, graph.forward_index(graph.nodes[f"m{l}"])))
hook_names = _install_propagation_rules(model, ln_freeze=ln_freeze, mlp_rule=mlp_rule, attn_temp=attn_temp)Split-ReLU feature codec
For a site, we center and scale hidden vectors, encode them with a linear map or, when enabled, positive and negative ReLU branches, and decode the difference between source and base representations. When enabled, the paired branches can represent an oblique linear subspace exactly at initialization because . A biorthogonality penalty keeps the effective read and decoder aligned, while anchor penalties keep the learned code near its spectral initialization.
def encode(self, x):
x_std = (x.float() - self.mean_vec) * self.inv_rms
if not self.use_split_relu:
return F.linear(x_std, self.u_enc, self.b_enc)
h_p = F.relu(F.linear(x_std, self.u_pos, 0.25 * self.b0_pos))
h_n = F.relu(F.linear(x_std, self.u_neg, 0.25 * self.b0_neg))
return F.linear(h_p, self.w1_pos) + F.linear(h_n, self.w1_neg) + self.b1
def delta(self, h_base, h_src):
z_b = self.encode(h_base)
z_s = self.encode(h_src)
gain = torch.exp(self.log_gain.clamp(-2.5, 2.5))
d_std = F.linear((z_s - z_b) * gain, self.u_dec)
return (d_std * self.rms).to(h_base.dtype)
def reg_penalty(self):
dec_denom = self.u_dec0.pow(2).sum(dim=0).clamp(min=1.0)
anchor_dec = ((self.u_dec - self.u_dec0).pow(2).sum(dim=0) / dec_denom).mean()
if not self.use_split_relu:
prod = self.u_enc @ self.u_dec
eye = torch.eye(self.r, device=prod.device, dtype=prod.dtype)
biorth = 0.08 * (prod - eye).pow(2).sum(dim=-1).mean()
anchor_read = (self.u_enc - self.u_read0).pow(2).sum(dim=-1).mean()
return biorth + self.anchor_w * (anchor_read + anchor_dec)
eff_read = 0.5 * (self.w1_pos @ self.u_pos + self.w1_neg @ self.u_neg)
prod = eff_read @ self.u_dec
eye = torch.eye(self.r, device=prod.device, dtype=prod.dtype)
biorth = 0.08 * (prod - eye).pow(2).sum(dim=-1).mean()
anchor_read = (eff_read - self.u_read0).pow(2).sum(dim=-1).mean()
sym_u = 0.05 * (self.u_pos + self.u_neg).pow(2).sum(dim=-1).mean()
sym_w1 = 0.05 * (self.w1_pos + self.w1_neg).pow(2).sum(dim=-1).mean()
sym_b0 = 0.02 * 0.5 * (self.b0_pos.pow(2).mean() + self.b0_neg.pow(2).mean())
return biorth + self.anchor_w * (anchor_read + anchor_dec) + sym_u + sym_w1 + sym_b0The exported manifest contains the encoder layers and decoder tensors, so the fixed intervention engine can exchange selected features at every native site without relying on hidden runtime state.
Results
| Method | ① | ② | ③ | ④ | ⑤ | ||
|---|---|---|---|---|---|---|---|
| Circuit-model distance (CMD) ↓ | Circuit performance ratio (CPR) ↑ | Circuit-model distance (CMD) ↓ | Circuit performance ratio (CPR) ↑ | Interchange accuracy (IIA) ↑ | Interchange accuracy (IIA) ↑ | Interchange accuracy (IIA) ↑ | |
| Gemini 4 Carbon | 0.409 | 0.567 | 0.931 | ||||
| EAP-IG + DAS | 0.145 | 0.854 | 0.069 | 0.930 | 0.377 | 0.563 | 0.830 |
| EAP | 0.160 | 0.845 | 0.068 | 0.931 | 0.377 | 0.563 | 0.830 |
| EAP-IG-activations | 0.066 | 0.935 | 0.377 | 0.563 | 0.830 | ||
| RelP | 0.154 | 0.845 | 0.094 | 0.915 | 0.377 | 0.563 | 0.830 |
| MAttr | 0.446 | 0.601 | 0.429 | 0.570 | 0.377 | 0.563 | 0.830 |
| Random circuit | 0.740 | 0.259 | 0.661 | 0.338 | 0.377 | 0.563 | 0.830 |
| Full vector | 0.145 | 0.854 | 0.069 | 0.930 | 0.294 | 0.491 | 0.467 |
| DBM | 0.145 | 0.854 | 0.069 | 0.930 | 0.345 | 0.530 | 0.713 |
- ① Llama-3.1-8B · ARC-Challenge circuit
- ② Gemma-2-2B · MCQA circuit
- ③ Gemma-2-2B · arithmetic carry variable
- ④ Gemma-2-2B · RAVEL country variable
- ⑤ Llama-3.1-8B-Instruct · ARC-Easy answer-pointer variable
Intervention agreement is higher when larger. On Gemma-2-2B · arithmetic carry variable, our value is 0.409 versus 0.377 for the default pipeline. On Gemma-2-2B · RAVEL country variable, it is 0.567 versus 0.563; on Llama-3.1-8B-Instruct · ARC-Easy answer-pointer variable, it is 0.931 versus 0.830. The best baseline value on Llama-3.1-8B-Instruct · ARC-Easy answer-pointer variable is 0.830 from EAP-IG-inputs and DAS [1].
The circuit metrics are not reported for this pair, so the result discussion is limited to intervention agreement.
Limitations
The codec is trained from discovery examples and can fail to represent features that do not recur in those examples. Biorthogonality and symmetry penalties regularize the code but do not prove that a selected feature is semantically unique. Attribution scores also depend on the chosen propagation rules and interpolation path.
Only intervention agreement is available for this pair. The absent circuit metrics limit what can be concluded about edge selection, and the reported gains do not establish that every discovered explanation is compact or faithful under all counterfactuals.
References
- Atticus Geiger, Zhengxuan Wu, Christopher Potts et al. (2023). Finding Alignments Between Interpretable Causal Variables and Distributed Neural Representations.
- Aaquib Syed, Can Rager, Arthur Conmy (2023). Attribution Patching Outperforms Automated Circuit Discovery. NeurIPS.
- Samuel Marks, Can Rager, Eric J. Michaud et al. (2025). Sparse Feature Circuits: Discovering and Editing Interpretable Causal Graphs in Language Models. ICLR.
- Farnoush Rezaei Jafari, Oliver Eberle, Ashkan Khakzar et al. (2025). RelP: Faithful and Efficient Circuit Discovery in Language Models via Relevance Patching.
- Aryaman Arora, Kirill Acharya, Nathan Hu et al. (2026). Matryoshka attribution: Learning to attribute language model outputs to representations and weights.
- Aaron Mueller, Atticus Geiger, Sarah Wiegreffe et al. (2025). MIB: A Mechanistic Interpretability Benchmark. ICML.