发现视觉语言模型中的安全注意力头,可提前识别恶意提示。
Spot Risks Before Speaking! Unraveling Safety Attention Heads in Large Vision-Language Models
- 通过分析首词生成时的激活,定位模型内部的安全注意力头。
- 移除安全头后攻击成功率显著上升,但模型正常功能不受影响。
- 仅用逻辑回归构建检测器,零样本泛化能力强,适合部署应用。
随着多模态融合,大型视觉语言模型(LVLMs)相比纯语言模型更容易受到安全风险(如越狱攻击)影响。尽管已有研究致力于模型事后对齐,但其内部安全机制仍不清晰。本文发现,LVLM在生成首个词时的内部激活能有效识别各类攻击下的恶意提示。这一内在安全感知由稀疏的注意力头驱动,我们称之为“安全头”。进一步分析表明,这些头起到专用防护屏障作用:移除它们会导致攻击成功率升高,而模型正常任务性能不变。通过定位这些安全头并拼接其激活值,我们构建了一个结构简单却强大的恶意提示检测器,可无缝集成至生成流程中,额外推理开销极小。该检测器仅采用逻辑回归,却展现出出色的零样本泛化能力。跨多种基于提示的攻击实验验证了利用安全头保护LVLM的有效性。代码已公开于\url{https://github.com/Ziwei-Zheng/SAHs}。
原文摘要 · Abstract (English)
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}.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。