On the Role of Attention Heads in Large Language Model Safety

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Zhou, Zhenhong, Yu, Haiyang, Zhang, Xinghua, Xu, Rongwu, Huang, Fei, Wang, Kun, Liu, Yang, Fang, Junfeng, Li, Yongbin
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916626629132288
author Zhou, Zhenhong
Yu, Haiyang
Zhang, Xinghua
Xu, Rongwu
Huang, Fei
Wang, Kun
Liu, Yang
Fang, Junfeng
Li, Yongbin
author_facet Zhou, Zhenhong
Yu, Haiyang
Zhang, Xinghua
Xu, Rongwu
Huang, Fei
Wang, Kun
Liu, Yang
Fang, Junfeng
Li, Yongbin
contents 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 component are suppressed, the safety capability of LLMs are compromised. However, existing research tends to overlook the safety impact of multi-head attention mechanisms, despite their crucial role in various model functionalities. Hence, in this paper, we aim to explore the connection between standard attention mechanisms and safety capability to fill this gap in the safety-related mechanistic interpretability. We propose a novel metric which tailored for multi-head attention, the Safety Head ImPortant Score (Ships), to assess the 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 the special attention head has a significant impact on safety. Ablating a single safety head allows aligned model (e.g., Llama-2-7b-chat) to respond to 16 times more harmful queries, while only modifying 0.006% of the parameters, in contrast to the ~ 5% modification required in previous studies. More importantly, we demonstrate that attention heads primarily function as feature extractors for safety and models fine-tuned from the same base model exhibit overlapping safety heads through comprehensive experiments. Together, our attribution approach and findings provide a novel perspective for unpacking the black box of safety mechanisms within large models.
format Preprint
id arxiv_https___arxiv_org_abs_2410_13708
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle On the Role of Attention Heads in Large Language Model Safety
Zhou, Zhenhong
Yu, Haiyang
Zhang, Xinghua
Xu, Rongwu
Huang, Fei
Wang, Kun
Liu, Yang
Fang, Junfeng
Li, Yongbin
Computation and Language
Artificial Intelligence
Cryptography and Security
Machine Learning
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 component are suppressed, the safety capability of LLMs are compromised. However, existing research tends to overlook the safety impact of multi-head attention mechanisms, despite their crucial role in various model functionalities. Hence, in this paper, we aim to explore the connection between standard attention mechanisms and safety capability to fill this gap in the safety-related mechanistic interpretability. We propose a novel metric which tailored for multi-head attention, the Safety Head ImPortant Score (Ships), to assess the 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 the special attention head has a significant impact on safety. Ablating a single safety head allows aligned model (e.g., Llama-2-7b-chat) to respond to 16 times more harmful queries, while only modifying 0.006% of the parameters, in contrast to the ~ 5% modification required in previous studies. More importantly, we demonstrate that attention heads primarily function as feature extractors for safety and models fine-tuned from the same base model exhibit overlapping safety heads through comprehensive experiments. Together, our attribution approach and findings provide a novel perspective for unpacking the black box of safety mechanisms within large models.
title On the Role of Attention Heads in Large Language Model Safety
topic Computation and Language
Artificial Intelligence
Cryptography and Security
Machine Learning
url https://arxiv.org/abs/2410.13708