---
title: Backdoor Attention Head Attribution (BAHA)
url: https://www.emergentmind.com/topics/backdoor-attention-head-attribution-baha
type: topic
---

# Backdoor Attention Head Attribution (BAHA)

Searching arXiv for the cited papers and closely related work.
Backdoor Attention Head Attribution (BAHA) denotes an attention-centric line of backdoor analysis in transformer-based language models in which backdoor behavior is localized to internal attention components rather than treated as a purely output-level phenomenon. In "Backdoor Attribution: Elucidating and Controlling Backdoor in Language Models" [2509.21761], BAHA is the middle stage of a tripartite causal analysis framework that follows a Backdoor Probe and precedes construction of a Backdoor Vector. Its purpose is to identify the specific attention heads responsible for extracting and injecting backdoor-related features into hidden states. A distinct later paper, "Uncovering and Aligning Anomalous Attention Heads to Defend Against NLP Backdoor Attacks" [2511.13789], uses the same acronym for a defense framework that detects suspicious heads through anomalous cross-head attention similarity and then repairs them by alignment and head-wise fine-tuning. Across these usages, BAHA refers to the proposition that backdoor activation leaves a structured footprint in attention, and that this footprint can be attributed, ranked, and manipulated.

## 1. Conceptual setting and motivations

In [2509.21761], the motivating claim is that LLM backdoors are mechanistically opaque: after poisoning-based fine-tuning, models behave normally on clean inputs but produce attacker-desired outputs when a trigger appears. The paper formulates three linked hypotheses. First, backdoor behavior is not confined to the output layer and must be encoded in intermediate representations. Second, if backdoor-specific features exist in representations, then some attention heads must be responsible for extracting and injecting them into hidden states. Third, identifying those heads should enable both understanding and control. This motivates the full Backdoor Attribution pipeline: Backdoor Probe, BAHA, and Backdoor Vector.

The same attention-level intuition appears in adjacent work, but with different attributed objects. In [2511.13789], the central observation is that when a backdoored NLP model sees a trigger, some attention heads become abnormally similar to each other. In [2601.21695], the attributed object is not the head but the attention column: anomalous behavior is localized to layer-column pairs in attention maps, and mitigation proceeds by column replacement and redistribution at inference time. These differences matter. The BAHA method in [2509.21761] is explicitly causal and head-specific, whereas the BAHA defense in [2511.13789] is trigger-agnostic and similarity-based, and AtPatch is a runtime attention-map repair mechanism rather than a head-level attribution method.

A common misconception is that these methods reduce backdoors to superficial attention anomalies alone. The factual record in the cited papers is narrower. [2509.21761] grounds head attribution in hidden-state learnability and causal intervention; [2511.13789] grounds defense in unusually high head similarity under trigger inputs; and [2601.21695] assumes anomalous behavior manifests as column-wise over-attention. None of these formulations claims that all backdoors must share a single universal attention signature.

## 2. Representational premise: learnable backdoor features

The BAHA procedure in [2509.21761] is preceded by a Backdoor Probe designed to show that hidden representations contain learnable backdoor information. For each layer \(i\), the paper trains a classifier
\[
\mathcal{C}_i:\mathbb{R}^{d_m}\to\{1,0\}
\]
to predict whether a hidden state came from a poisoned sample or a clean sample. The collected representations are last-token hidden states,
\[
\mathcal{H}_i(\mathcal{D})=\{\mathbf{H}^{-1}_i(x) \mid (x,\cdot)\in \mathcal{D}\},\quad \mathcal{D}\in\{\mathcal{D}_r,\mathcal{D}_p\},
\]
where \(\mathbf{H}^{-1}_i(x)\in\mathbb{R}^{d_m}\) is the last-token representation at layer \(i\).

Two probe families are used: an MLP probe with one hidden layer of 100 neurons, and a soft-margin SVM with \(C=1\) and an RBF kernel. The training, validation, and test split is \(6{:}2{:}2\). To test transfer of the learned criterion across layers, the paper defines Inter-Layer Classification Accuracy,
\[
\text{ICLA}(i,k)=\frac{1}{|\mathcal{H}_k(\mathcal{D}_p)|+|\mathcal{H}_k(\mathcal{D}_r)|} \left[ \sum_{h\in\mathcal{H}_k(\mathcal{D}_p)} \delta(\mathcal{C}_i(h),1) +\sum_{h\in\mathcal{H}_k(\mathcal{D}_r)}\delta(\mathcal{C}_i(h),0) \right].
\]

The reported result is that the probes achieve \(90\)–\(100\%\) accuracy on their native layers and also high cross-layer accuracy near the diagonal [2509.21761]. The interpretation given in the paper is that there are distinct backdoor features in intermediate representations, that these features are hierarchically processed across layers, and that they become increasingly refined in deeper layers. This representational result is foundational for BAHA: if a classifier can recover poisoned-versus-clean status from hidden states, then head-level mechanisms that generate those states become plausible targets for intervention.

This also delineates BAHA from purely behavioral backdoor defenses. The emphasis is not merely on detecting a triggered output, but on establishing that backdoor information is linearly or nonlinearly learnable before any head is ranked or ablated. A plausible implication is that attribution in this framework is not a post hoc attention heuristic; it is anchored to a prior representational separability result.

## 3. Causal formulation of attention-head attribution

BAHA in [2509.21761] is a causal tracing method over multi-head attention. For an MHA layer with head outputs \(H_j\), the paper rewrites attention as
\[
\text{MHA}(X)=\left(H_{1} \oplus H_{2} \oplus \cdots \oplus H_{n}\right)W_o
\]
and defines the contribution of head \(j\) at layer \(i\) and token position \(t\) as
\[
a_{ij}^t \triangleq H_j W_o,
\qquad
a_i^t=\sum_{j=1}^n a_{ij}^t,
\]
so that the layer hidden state becomes
\[
h_i^t = h_{i-1}^t + m_i^t + \sum_{j=1}^n a_{ij}^t.
\]
This decomposition is the enabling step for head-specific intervention.

BAHA then proceeds in three stages. The first is Backdoor Activation Averaging. For each head, the paper computes an average poisoned activation,
\[
\overline{a}_{ij}=\frac{1}{|\mathcal{D}_p|}\sum_{(x',\cdot)\in\mathcal{D}_p}\mathbf{A}_{ij}^{-1}(x'),
\]
where \(\mathbf{A}_{ij}^{-1}(x)\) is the last-token activation of head \(j\) in layer \(i\). The stated purpose is to remove sample-specific noise and obtain a head-specific activation pattern associated with the backdoor.

The second stage is Backdoor Activation Substitution and Causal Indirect Effect. On a clean input \(x\), one head’s activation is replaced by its averaged poisoned activation. The paper defines
\[
\text{CIE}\left(a_{ij}\mid(x,y')\right)= \left[P(y'\mid x,a_{ij}=\overline{a}_{ij})\right]^{1/|y'|} - \left[P(y'\mid x)\right]^{1/|y'|}
\]
with the intervention implemented as
\[
a_i \leftarrow a_i - a_{ij} + \overline{a}_{ij}.
\]
A sample-agnostic score is then obtained by averaging across clean/poisoned pairs to produce \(\text{ACIE}(a_{ij})\). Higher ACIE indicates stronger contribution to backdoor triggering. The paper explicitly prefers ACIE to ASR for efficiency, because ASR requires full autoregressive generation over all target tokens whereas conditional probability for a fixed target can be computed in one forward pass with teacher forcing.

The third stage is validation by head ablation. After ranking heads by ACIE, selected heads are ablated via
\[
a_i \leftarrow a_i - a_{ij},
\]
and the drop in Attack Success Rate on triggered inputs is measured. This closes the causal loop proposed by the method: high ACIE nominates a head as important, and ablation tests whether its removal actually reduces backdoor success.

## 4. Empirical characterization and backdoor control

The principal empirical finding in [2509.21761] is sparsity. ACIE heatmaps show that only a small number of heads have strong attribution scores, while most heads are near zero. The paper describes these as backdoor attention heads. In both model families and all three backdoor types, the responsible heads appear as sparse red regions among roughly 1000 total heads.

Ablation results indicate that backdoor behavior is distributed but still sparse. The reported pattern is that ablating only \(1\)–\(8\) heads often does not fully suppress the attack, whereas a larger sparse subset, around \(16\)–\(32\) heads depending on model and backdoor, is often needed for major suppression. This corresponds to roughly \(1\)–\(3\%\) of total heads. The paper reports that ablating about \(3\%\) of all heads can reduce ASR by over \(90\%\) in many settings. The examples given are specific: in Llama2-7B with harmful_random, ASR drops from \(60.94\) to \(7.81\) when 16 heads are ablated; in Qwen2.5-7B with agnews_sentence, ASR drops from \(91.94\) to \(59.68\) with 16 heads and to \(30.65\) with 32 heads [2509.21761].

The same paper then constructs a Backdoor Vector from the top-\(k\) attributed heads,
\[
V_{b}=\sum_{(i,j)\in \mathcal{A}_k} \overline{a}_{ij}, \quad \mathcal{A}_k=\{(i,j)\mid \text{Top-}k(\text{ACIE}(a_{ij}))\}.
\]
This vector is treated as a compact latent representation of the backdoor mechanism. Adding it to a clean hidden state implements Additive Activation,
\[
\left[h^{-1}_i \rightarrow (h^{-1}_i + V_b)\right] \Rightarrow \left[P(y'|x)\approx 0 \Rightarrow P(y'|x)\gg 0\right] \Rightarrow \text{ASR}\uparrow,
\]
while subtracting it from a poisoned hidden state implements Subtractive Suppression,
\[
\left[h^{-1}_i \rightarrow (h^{-1}_i - V_b)\right] \Rightarrow \left[P(y'|x)\approx 1 \Rightarrow P(y'|x)\ll 1\right] \Rightarrow \text{ASR}\downarrow.
\]

The reported intervention effects are unusually strong. On clean inputs, adding \(V_b\) can raise ASR from \(0\) to as high as \(100\%\). On triggered inputs, subtracting \(V_b\) can reduce ASR to near \(0\%\), with one reported case reaching \(0.39\%\). Randomly constructed vectors from random heads do not achieve similar effects. The strongest effects are found in early-to-middle layers, while the vector has little effect in very late layers. This suggests, in the paper’s interpretation, that backdoor features are primarily formed and manipulable before the final layers.

The experimental setting used to support these claims consists of two 7B models, Llama-2-7B-chat and Qwen-2.5-7B-Instruct; three backdoor styles, namely label modification on AGNews, fixed output on Alpaca, and jailbreak on the Harmful dataset; and injection details of 1,000 training samples, \(10\%\) poisoning rate, 16 epochs, learning rate \(10^{-4}\), batch size 8 per device, and LoRA with rank \(r=16\), \(\alpha=16\) [2509.21761].

## 5. BAHA as anomalous attention-head defense

In [2511.13789], BAHA refers to a defense framework whose key insight is different from the causal substitution method above. The paper argues that when a backdoored model sees a trigger, some attention heads become abnormally similar to each other, whereas under clean inputs heads usually specialize and exhibit more diverse attention patterns. The defense uses this observation in two stages: attribution or identification of suspicious heads by combining importance and similarity, followed by mitigation through attention safety alignment and head-wise fine-tuning.

For decoder-only LLMs, the measured object is generation-to-prompt attention. If \(T_p\) is the number of prompt tokens, \(T_g\) the number of generated tokens, and \(A^{(h)} \in \mathbb{R}^{T \times T}\) the attention matrix for head \(h\) with \(T=T_p+T_g\), the relevant submatrix is
\[
A_{\text{gen} \rightarrow \text{prompt}^{(h)} := A^{(h)}[T_p+1:T,\ 1:T_p] \in \mathbb{R}^{T_g \times T_p}.
\]
Given two such submatrices \(P\) and \(Q\), similarity is computed after row-major flattening via cosine similarity,
\[
\cos_{\text{sim}(P, Q) = \frac{\operatorname{vec}(P)^\top \operatorname{vec}(Q)} {\|\operatorname{vec}(P)\|_2 \|\operatorname{vec}(Q)\|_2}.
\]
The reported empirical signature is a strong increase in head pairs whose cosine similarity exceeds \(0.99\), together with a much higher \(99\)th percentile of similarity for backdoored models than for clean ones.

Similarity alone is not treated as sufficient, because benign heads may also resemble one another. The paper therefore adds a gradient-based importance score,
\[
G^{l,h} = \mathbb{E}_{(x,y)} \left| {H}^{l,h^\top} \frac{\partial \mathcal{L}(y, \hat{y})}{\partial {H}^{l,h} \right|,
\]
and combines it with similarity in a safety score,
\[
S_{\mathrm{safe}^{l,h} = 1 - \Big[ \alpha \cdot \max_{j \neq h} \cos_\text{sim}(A^{l,h}, A^{l,j}) + (1 - \alpha) \cdot \frac{G^{l,h}{\max_j G^{l_j,h_j} \Big].
\]
Using threshold \(\tau \in [0,0.5]\), heads are partitioned into suspicious, safe, and intermediate sets. The default implementation uses \(\alpha = 0.7\) and \(\tau = 0.3\), and the paper reports that values of \(\alpha\) around \(0.6\)–\(0.8\) work best.

Repair is then performed by aligning suspicious heads toward a safe reference attention. If \(\mathcal{H}_{\text{safe}}\) is the safe set and \(\mathcal{H}_{\text{suspicious}}\) the suspicious set, the safe reference is
\[
\bar{A}_{\text{safe}(x) = \frac{1}{|\mathcal{H}_{\text{safe}|} \sum_{h \in \mathcal{H}_{\text{safe} A^h(x),
\]
and the alignment loss is
\[
\mathcal{L}_{\text{align}(x) = \sum_{h \in \mathcal{H}_{\text{suspicious} \left\| A^h(x) - \bar{A}_{\text{safe}(x) \right\|_F^2.
\]
This is followed by head-wise fine-tuning with different learning rates:
\[
\eta_h = \begin{cases} \eta_{\text{low}, & \text{if } h \in \mathcal{H}_{\text{suspicious}, \\
\eta_{\text{high}, & \text{if } h \in \mathcal{H}_{\text{safe}, \\
\eta_{\text{mid}, & \text{otherwise}. \end{cases}
\]
The reported best default setting is \(2 \times 10^{-4}\) for safe heads, \(5 \times 10^{-6}\) for suspicious heads, and \(10^{-4}\) for intermediate heads.

The experimental setup covers classification tasks on SST-2 and AG’s News, generation on Stanford Alpaca, victim models including BERT-base, Llama2-7B, and Mistral-7B, and attacks including BadNets, HiddenKiller, CBaT, NWS, BGMAttack, VPI, Sleeper Agent, and CBA, with \(20\%\) poisoning for each attack method. Reported results include BERT SST-2 + BadNets, ASR \(99.67 \rightarrow 11.23\); BERT SST-2 + HiddenKiller, \(94.16 \rightarrow 15.66\); Llama2-7B SST-2 + BadNets, \(88.73 \rightarrow 25.61\); Llama2-7B AG’s News + BadNets, \(82.34 \rightarrow 28.14\); Llama2-7B targeted refusal + Sleeper Agent, \(96.64 \rightarrow 11.37\); and Mistral-7B targeted refusal + Sleeper Agent, \(99.01 \rightarrow 8.54\) [2511.13789]. The ablation study further reports that alignment-only reduces ASR but can hurt Clean Accuracy, FT-only preserves CA better but is much weaker against backdoors, and the full method yields the best balance.

## 6. Relation to attention-map debugging, scope, and limitations

A useful comparison point is AtPatch [2601.21695], which does not use the BAHA name but is explicitly described as conceptually close to backdoor attention debugging. AtPatch treats over-attention as the primary observable symptom of backdoors and fairness defects. Given an attention tensor
\[
\mathcal{A}^{(l)} \in \mathbb{R}^{b \times h \times n^2},
\]
it forms a head-agnostic projection
\[
\phi(\mathcal{A}^{(l)}) = \frac{1}{h} \sum_{i=1}^{h} \mathcal{A}^{(l)}_{: , i, : , :} \in \mathbb{R}^{b \times n^2},
\]
passes this through a CNN and an MLP to obtain per-column anomaly probabilities,
\[
P_{\text{anomaly}^{(l)} = \sigma\left(\text{MLP}\left(\text{CNN}\left(\phi(\mathcal{A}^{(l)})\right)\right)\right) \in \mathbb{R}^{b \times n},
\]
and attributes anomalies to layer-column pairs
\[
\mathcal{K} = \{ (l, j) \mid P_{\text{anomaly}^{(l)}[j] > \tau \}.
\]
If anomalies are found, the flagged columns are replaced with benign reference columns and the remaining columns are rescaled through the patch operator
\[
\mathcal{B}^{(l)} = \Gamma(\mathcal{A}^{(l)}, k, \mathcal{Q}_k).
\]

The experimental results reported for AtPatch are framed around mitigation rather than mechanistic localization: on 3 datasets and 3 backdoor attacks, the method achieves an average ASR of \(0.46\%\) while preserving accuracy with only \(0.1\%\) average drop; on fairness-sensitive datasets it reduces unfairness to an average of \(0.04\%\) with negligible accuracy loss; and its detector achieves precision \(0.910\)–\(0.981\), recall \(0.994\)–\(1.000\), F1 above \(0.95\), false positive rate below \(0.1\), and false negative rate near zero [2601.21695]. These figures support the narrower claim that abnormal attention columns can be localized and patched effectively at inference time.

Taken together, the three papers delineate a family of attention-level backdoor analyses with distinct assumptions. The causal BAHA of [2509.21761] assumes that backdoor-related features are encoded in hidden states and routed by a sparse subset of heads. The defense-oriented BAHA of [2511.13789] assumes that trigger activation produces unusually high similarity among heads. AtPatch assumes column-wise over-attention. Each paper also states operational constraints: [2511.13789] requires access to attention weights and gradients and a small clean sample set; [2601.21695] relies on a labeled offline Debugging Set and a separately trained detector; and [2509.21761] depends on the existence of learnable backdoor features in hidden representations and on causal interventions over internal activations.

This suggests a broader interpretation of BAHA as an emerging mechanistic perspective on transformer backdoors rather than a single fixed algorithm. Within that perspective, attention is not merely an explanatory visualization. It becomes a locus for causal attribution, for defense without prior trigger knowledge, or for inference-time repair. The extent to which these assumptions generalize beyond the reported attacks remains an open empirical question, but the cited work establishes that backdoor behavior can be localized to sparse internal attention structure and that manipulating that structure can substantially alter ASR.

Source: https://www.emergentmind.com/topics/backdoor-attention-head-attribution-baha