Spot Risks Before Speaking! Unraveling Safety Attention Heads in Large Vision-Language Models

Ziwei Zheng, Junyao Zhao, Le Yang, Lijun He, Fan Li
1/3/2025
cs.LGcs.AIcs.CR

Official code: Ziwei-Zheng/SAHs (3 stars, last commit 2025-01-03).

Abstract

With the integration of an additional modality, large vision-language models (LVLMs) exhibit greater vulnerability to safety risks (e.g., jailbreaking) compared to their language-only predecessors. Although recent studies have devoted considerable effort to the post-hoc alignment of LVLMs, the inner safety mechanisms remain largely unexplored. In this paper, we discover that internal activations of LVLMs during the first token generation can effectively identify malicious prompts across different attacks. This inherent safety perception is governed by sparse attention heads, which we term ``safety heads." Further analysis reveals that these heads act as specialized shields against malicious prompts; ablating them leads to higher attack success rates, while the model's utility remains unaffected. By locating these safety heads and concatenating their activations, we construct a straightforward but powerful malicious prompt detector that integrates seamlessly into the generation process with minimal extra inference overhead. Despite its simple structure of a logistic regression model, the detector surprisingly exhibits strong zero-shot generalization capabilities. Experiments across various prompt-based attacks confirm the effectiveness of leveraging safety heads to protect LVLMs. Code is available at \url{https://github.com/Ziwei-Zheng/SAHs}.

View on arXivView PDF

Code Implementations(1)

Ziwei-Zheng/SAHsOfficial100%

Official implementation of paper "Spot Risks Before Speaking! Unraveling Safety Attention Heads in Large Vision-Language Models".

30Jan 3, 20251 years ago

Similar Papers

Cite this paper

@article{zheng2025spot,
  title  = {Spot Risks Before Speaking! Unraveling Safety Attention Heads in Large Vision-Language Models},
  author = {Ziwei Zheng and Junyao Zhao and Le Yang and Lijun He and Fan Li},
  year   = {2025},
  eprint = {2501.02029},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2501.02029v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2501.02029.svg)](https://codeofpaper.com/paper/2501.02029)

Discussion