arXiv:2502.04204cs.LGcs.CR2025-02NeurIPS被引 15

用短提示对抗训练,就能防御长提示攻击,省资源还有效。

Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence

  • 用长度为√M的对抗提示进行训练,可防御长度为M的攻击
  • 实验显示攻击成功率与√(攻击长度/训练长度)正相关
  • 适合想高效提升模型安全性的研究者和开发者

大型语言模型(LLMs)面临通过精心设计的对抗性提示引发有害行为的越狱攻击。为缓解此类攻击,一种方法是基于对抗训练(AT)进行对齐,即在部分最具攻击性的提示上训练模型,使其学会在攻击下保持安全行为。对抗训练中,对抗提示的长度对对齐后模型的鲁棒性至关重要。尽管长长度对抗提示可能带来更强的鲁棒性,但其生成成本极高,限制了实际应用。本文聚焦于对抗后缀越狱攻击,揭示:要防御长度为Θ(M)的越狱攻击,仅需在长度为Θ(√M)的对抗后缀上进行对齐即可。理论上,我们分析了线性Transformer在线性回归任务上的对抗上下文学习,并证明了训练后Transformer的鲁棒泛化界,该界依赖于项Θ(√M_test / M_train),其中M_train和M_test分别为训练和测试时被对抗扰动的上下文样本数。实验上,我们在多个主流开源LLM上进行对抗训练,并评估其对不同长度对抗后缀越狱攻击的鲁棒性。结果验证了攻击成功率与√(测试长度/训练长度)之间的正相关关系。研究结果表明,通过高效的短长度对抗训练,即可有效防御长长度越狱攻击。代码已公开于https://github.com/fshp971/adv-icl。

原文摘要 · Abstract (English)

Jailbreak attacks against large language models (LLMs) aim to induce harmful behaviors in LLMs through carefully crafted adversarial prompts. To mitigate attacks, one way is to perform adversarial training (AT)-based alignment, i.e., training LLMs on some of the most adversarial prompts to help them learn how to behave safely under attacks. During AT, the length of adversarial prompts plays a critical role in the robustness of aligned LLMs. While long-length adversarial prompts during AT might lead to strong LLM robustness, their synthesis however is very resource-consuming, which may limit the application of LLM AT. This paper focuses on adversarial suffix jailbreak attacks and unveils that to defend against a jailbreak attack with an adversarial suffix of length $Θ(M)$, it is enough to align LLMs on prompts with adversarial suffixes of length $Θ(\sqrt{M})$. Theoretically, we analyze the adversarial in-context learning of linear transformers on linear regression tasks and prove a robust generalization bound for trained transformers. The bound depends on the term $Θ(\sqrt{M_{\text{test}}}/M_{\text{train}})$, where $M_{\text{train}}$ and $M_{\text{test}}$ are the numbers of adversarially perturbed in-context samples during training and testing. Empirically, we conduct AT on popular open-source LLMs and evaluate their robustness against jailbreak attacks of different adversarial suffix lengths. Results confirm a positive correlation between the attack success rate and the ratio of the square root of the adversarial suffix length during jailbreaking to the length during AT. Our findings show that it is practical to defend against "long-length" jailbreak attacks via efficient "short-length" AT. The code is available at https://github.com/fshp971/adv-icl.

对抗训练越狱攻击模型安全长序列

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。