TL;DR
This paper reveals that LLM safety guardrails are highly concentrated within a tiny fraction of multi-head attention components. By introducing a novel metric (Ships) and a search algorithm (Sahara), the authors demonstrate that disabling just a single "safety attention head" (modifying a mere 0.006% of parameters) can cause an aligned model's safety to collapse, increasing its vulnerability to harmful queries by 16× without compromising general helpfulness.
What Problem Does This Paper Address?
While alignment techniques like RLHF successfully train LLMs to refuse harmful prompts, understanding how the model implements these guardrails internally remains a black box. Previous mechanistic interpretability work has localized safety to specific hidden representations or MLP neurons. However, the role of multi-head attention (MHA)—the core mechanism for routing information across tokens in transformers—has been largely overlooked in safety research.
Furthermore, existing methods to find important attention heads are computationally prohibitive because they require generating full text responses across thousands of candidate heads. This paper fills this gap by identifying and analyzing safety-specific attention heads efficiently.
Methods
The authors introduce two key innovations to locate and analyze safety heads:
- Safety Head ImPortant Score (Ships): A metric that quantifies an individual head's contribution to safety by measuring how much its ablation shifts the model's next-token probability distribution away from rejection tokens (like "I cannot fulfill...") using KL divergence.
- Safety Attention Head AttRibution Algorithm (Sahara): A dataset-level generalization of Ships. Instead of running expensive full-text generations for every head, Sahara applies Singular Value Decomposition (SVD) to the top-layer residual stream activations across a dataset of harmful queries. It computes the principal angles between the original safety representation space and the ablated space to find a collaborative group of safety heads.
To disable a head, they compare two ablation techniques: Scaling Contribution (diminishing the output value matrix $W_v$) and Undifferentiated Attention (scaling $W_q$ or $W_k$ so the attention weights collapse to a uniform average, preventing the head from extracting specific features).
Datasets
- Safety/Harmful Queries: Advbench, Jailbreakbench, and Malicious Instruct.
- General Capability (Helpfulness): BoolQ, RTE, WinoGrande, ARC Challenge, and OpenBookQA (evaluated via the
lm-evalframework).
Key Insights and Ideas
- Extreme Sparsity: Out of 1,024 attention heads in Llama-2-7b-chat, safety is heavily concentrated. Head 26 in Layer 2 (denoted as 2-26) emerged as a singularly critical safety head.
- Heads as Feature Extractors: Undifferentiated Attention ablation (destroying the head's ability to calculate specific attention weights) was far more destructive to safety than simply scaling down the head's output. This proves that safety heads primarily function as feature extractors that detect malicious intent in the prompt.
- Pre-training over Alignment: When the authors swapped the attention weights of an aligned model with those of its unaligned base model, the model retained its safety capabilities. Furthermore, Llama-2-7b-chat and Vicuna-7b-v1.5 (which share the same base model) had highly overlapping safety heads. This strongly implies that safety mechanisms are formed during pre-training, and alignment simply activates them.
- Clean Dissection (No Helpfulness Compromise): Disabling safety heads selectively breaks safety guardrails while leaving general reasoning and knowledge retrieval tasks completely intact, showing that safety and helpfulness are mechanistically distinct.
Key Results
- Bypassing Guardrails with Surgical Precision: Ablating just one safety head via Undifferentiated Attention increased the Attack Success Rate (ASR) of Llama-2-7b-chat from 0.04 to 0.64 (a 16× increase). This required modifying only 0.006% of the model's parameters, compared to the ~5% required by previous neuron- or rank-based methods.
- Using Sahara to find a group of 3 heads pushed the ASR up to 0.72.
- Massive Efficiency Gains: Sahara required only 6 GPU hours on an A100 to map out the safety heads, whereas traditional brute-force pruning or circuit discovery methods (like ACDC) would require approximately 850 GPU hours due to the need for full text generation.
Limitations and Future Work
- Nonsensical Outputs: Removing too many attention heads (beyond a group size of 3-5) causes the model's generation quality to degrade into nonsensical strings rather than coherent harmful responses.
- Scope of Safety Capabilities: The study primarily focuses on direct refusal and "course-correction" (where a model starts a harmful response but pivots mid-sentence to refuse it). The authors note that future work should explore how attention heads handle more nuanced safety tasks.
- Format Sensitivity: The impact of head ablation can vary depending on the specific chat template or system prompt used, indicating some interaction with format-dependent components.
Summary updated