Skip to main content
QUICK REVIEW

[论文解读] SafeDecoding: Defending against Jailbreak Attacks via Safety-Aware Decoding

Zhangchen Xu, Fengqing Jiang|arXiv (Cornell University)|Feb 14, 2024
Adversarial Robustness in Machine LearningComputer Science被引用 3
一句话总结

本文提出 SafeDecoding,一种面向安全的解码策略,通过增强安全免责声明 token 的概率并抑制有害响应 token 的概率,有效防御大语言模型免受越狱攻击。该方法利用微调后的专家模型,并在原始模型与专家模型的 token 分布之间实现平衡,使越狱攻击成功率降低高达 90%,同时在良性查询上保持模型的有用性。

ABSTRACT

As large language models (LLMs) become increasingly integrated into real-world applications such as code generation and chatbot assistance, extensive efforts have been made to align LLM behavior with human values, including safety. Jailbreak attacks, aiming to provoke unintended and unsafe behaviors from LLMs, remain a significant/leading LLM safety threat. In this paper, we aim to defend LLMs against jailbreak attacks by introducing SafeDecoding, a safety-aware decoding strategy for LLMs to generate helpful and harmless responses to user queries. Our insight in developing SafeDecoding is based on the observation that, even though probabilities of tokens representing harmful contents outweigh those representing harmless responses, safety disclaimers still appear among the top tokens after sorting tokens by probability in descending order. This allows us to mitigate jailbreak attacks by identifying safety disclaimers and amplifying their token probabilities, while simultaneously attenuating the probabilities of token sequences that are aligned with the objectives of jailbreak attacks. We perform extensive experiments on five LLMs using six state-of-the-art jailbreak attacks and four benchmark datasets. Our results show that SafeDecoding significantly reduces the attack success rate and harmfulness of jailbreak attacks without compromising the helpfulness of responses to benign user queries. SafeDecoding outperforms six defense methods.

研究动机与目标

  • 应对日益增长的越狱攻击威胁,此类攻击可绕过现有大语言模型的安全对齐机制。
  • 开发一种防御机制,在有效抑制有害输出的同时保持模型在越狱攻击下的有用性。
  • 克服现有防御方法的局限性,如高推理成本、有用性下降或对最先进攻击的失效。
  • 利用模型在攻击下仍能出现在 top-p 预测 token 中的安全免责声明 token 的固有存在。
  • 设计一种解码策略,通过混合 token 概率分布实现安全与有用性的动态平衡。

提出的方法

  • 在从原始 LLM 生成的安全感知数据集上训练专家模型,并进行微调,使其优先关注安全免责声明。
  • 推理过程中,通过原始模型与专家模型的 top-k token 的交集构建样本空间。
  • 通过组合原始模型的 logits 与专家模型的 logits,形成新的 token 概率分布,突出安全 token。
  • 在混合分布上应用温度缩放采样策略,生成既安全又有用的响应。
  • 动态衰减与越狱目标对齐的 token 序列的概率,同时增强与拒绝或安全免责声明相关的 token 概率。
  • 将该方法作为后处理解码层集成,兼容标准的大语言模型推理流水线。
Figure 1: This example illustrates the token probabilities of Vicuna-7B model under GCG attack Zou et al. ( 2023 ) . The words in red are GCG suffixes. We note that although the token representing the word "Sure" has a dominant probability, safety disclaimers such as "I", "Sorry", and "As" are still
Figure 1: This example illustrates the token probabilities of Vicuna-7B model under GCG attack Zou et al. ( 2023 ) . The words in red are GCG suffixes. We note that although the token representing the word "Sure" has a dominant probability, safety disclaimers such as "I", "Sorry", and "As" are still

实验结果

研究问题

  • RQ1一种面向安全的解码策略是否能有效降低多种大语言模型上最先进越狱攻击的攻击成功率?
  • RQ2SafeDecoding 在防御对抗性提示的同时,是否能保持对良性用户查询的高有用性?
  • RQ3在防御有效性、效率和有用性权衡方面,SafeDecoding 与现有防御方法相比表现如何?
  • RQ4SafeDecoding 是否能有效应用于对齐与未去噪的大语言模型,包括 Dolphin 和 Guanaco 等模型?
  • RQ5安全免责声明 token 在 top-k 概率空间中的存在是否足以通过概率操控实现可靠防御?

主要发现

  • SafeDecoding 在五种大语言模型上,将六种最先进越狱攻击的攻击成功率(ASR)降低高达 90%。
  • 在 HHH 基准测试中,SafeDecoding 将有害性得分降低 4.402(从基线的 4.842 降至 0.440),同时保持 4.296 的有用性得分。
  • SafeDecoding 在防御有效性和有用性保持方面优于六种基线防御方法,尤其在未去噪模型(如 Dolphin)上表现更优。
  • 仅使用专家模型无法在各类攻击中泛化,且显著降低有用性,表明仅靠微调不足以实现有效防御。
  • SafeDecoding 保持了较低的推理开销,且兼容多种模型架构,包括 Llama2、Vicuna 和 Falcon。
  • 消融实验表明,SafeDecoding 在不同温度设置和 top-k 采样配置下均表现出一致的性能。
Figure 2: This figure illustrates the detail of SafeDecoding . During the training phase, we fine-tune the original LLM to construct an expert model with strengthened safety. In the inference phase, a user query is passed to both the original and expert models. Based on their outputs, SafeDecoding c
Figure 2: This figure illustrates the detail of SafeDecoding . During the training phase, we fine-tune the original LLM to construct an expert model with strengthened safety. In the inference phase, a user query is passed to both the original and expert models. Based on their outputs, SafeDecoding c

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。