Abstract
Large language models (LLMs) achieve state-of-the-art performance on multiple language tasks, yet their safety guardrails can be circumvented, leading to harmful generations. In light of this, recent research on safety mechanisms has emerged, revealing that when safety representations or components are suppressed, the safety capability of LLMs is compromised. However, existing research tends to overlook the safety impact of multi-head attention mechanisms, despite their crucial role in various model functionalities. In this paper, we aim to explore the connection between standard attention mechanisms and safety capability to fill this gap in safety-related mechanistic interpretability. We propose a novel metric tailored for multi-head attention, the Safety Head ImPortant Score (Ships), to assess individual heads' contributions to model safety. Based on this, we generalize Ships to the dataset level and further introduce the Safety Attention Head AttRibution Algorithm (Sahara) to attribute the critical safety attention heads inside the model. Our findings show that specific attention heads have a significant impact on safety. Ablating a single safety head allows an aligned model (e.g., Llama-2-7b-chat) to respond to 16 times more harmful queries while only modifying 0.006% of the parameters. More importantly, we demonstrate that attention heads primarily function as feature extractors for safety and that models fine-tuned from the same base model exhibit overlapping safety heads.
Introduction
As Large Language Models (LLMs) become increasingly integrated into societal infrastructure, ensuring they do not generate harmful, toxic, or illegal content is paramount. While alignment techniques like RLHF create safety guardrails, these can often be bypassed by adversarial prompts. Mechanistic interpretability seeks to understand how these models implement safety internally. While previous research has identified specific neurons or high-level representations, the role of the multi-head attention mechanism—the core engine of the Transformer architecture—has been largely overlooked. This study investigates whether safety is a distributed property or concentrated within specific attention heads.
Methodology
To identify and analyze safety-critical components, we introduce two primary tools:
- Ships (Safety Head ImPortant Score): A metric utilizing causal tracing to measure a specific attention head's contribution to a model's "rejection" response. By ablating a head and measuring the change in the probability of a refusal (e.g., "I cannot fulfill this request"), we can rank heads by their safety importance.
- Sahara (Safety Attention Head AttRibution Algorithm): A heuristic search algorithm designed to identify groups of safety heads that function collectively across an entire dataset.
Crucially, we discovered that the method of ablation matters. Undifferentiated Attention—forcing a head to distribute its attention uniformly across all tokens rather than focusing on specific features—is significantly more effective at compromising safety than simply scaling down the head's output. This suggests these heads act as active feature extractors identifying harmful intent.
Experimental Setup
We evaluated safety using three benchmarks: Advbench (adversarial instructions), Jailbreakbench (jailbreak prompts), and Malicious Instruct (curated harmful queries). These were tested against popular open-source models, specifically Llama-2-7b-chat and Vicuna-7b-v1.5.
Key Results and Insights
Extreme Sparsity and Localization
Safety in LLMs is not a global property but is highly localized. In Llama-2-7b-chat, disabling just one specific head (Head 26 in Layer 2) was sufficient to collapse much of the model's safety capability. This intervention involves modifying only 0.006% of the model's parameters, a massive reduction compared to the ~5% typically required in previous studies.
Attack Success Rate (ASR) Explosion
By ablating the top-identified safety heads, we observed a dramatic increase in the model's willingness to comply with harmful requests. For Llama-2-7b-chat, the ASR rose from a baseline of 0.04 to 0.64—a 16x increase.
Pre-trained Safety Circuitry
Interestingly, safety heads often overlap between different models (like Llama-2 and Vicuna) that share the same base model. This suggests that the fundamental circuitry for recognizing harmful patterns is established during initial pre-training, rather than being solely a product of safety-alignment fine-tuning.
Decoupling Helpfulness and Harmlessness
Our findings reveal a "Helpful-Harmless" decoupling. Breaking the safety mechanism does not significantly degrade general performance on standard benchmarks like BoolQ or ARC. This implies safety is implemented as an "add-on" feature rather than being deeply integrated into the model's core reasoning capabilities.
Conclusion and Future Work
This research demonstrates that LLM safety is surprisingly fragile and localized within a tiny fraction of the attention mechanism. While we have localized these "safety heads," model behavior remains somewhat format-dependent, suggesting the existence of secondary backup mechanisms or in-context learning effects from system prompts. Future work will explore the interaction between these heads and other components, such as MLP layers, to develop more robust, "un-jailbreakable" safety circuits.
Summary updated