arXiv:2508.15182cs.LG2025-08被引 5

通过知识遗忘技术让大模型自动消除有害输出,提升安全防护能力。

SafeLLM: Unlearning Harmful Outputs from Large Language Models against Jailbreak Attacks

  • 用三阶段流程识别并移除模型中导致有害生成的神经路径。
  • 在多个大模型上测试,攻击成功率大幅下降,通用能力不受损。
  • 适合关注模型安全、防范越狱攻击的研究者和开发者使用。

越狱攻击通过精心设计的提示绕过大语言模型(LLMs)的安全对齐机制,诱导其生成有害、受限或偏见内容。本文提出SafeLLM,一种基于知识遗忘的防御框架,在保持语言流畅性和通用能力的前提下,消除模型中的有害知识。该框架采用三阶段流程:(1) 结合外部分类器与模型内部评估的混合方法动态检测不安全输出;(2) 通过前馈网络(FFN)激活追踪有害内容的词元级别定位;(3) 采用约束优化抑制不安全行为而不降低整体性能。SafeLLM通过识别并中和负责有害生成路径的FFN子结构,实现精准且不可逆的知识遗忘。在Vicuna、LLaMA和GPT-J等主流模型上,跨多个越狱攻击基准的实验表明,SafeLLM显著降低攻击成功率,同时维持高通用性能。相比监督微调和直接偏好优化等常规方法,SafeLLM提供更强的安全保障、更精确的行为控制以及对未见攻击的更高鲁棒性。此外,模型在清除有害知识后仍保持良好通用表现。结果表明,知识遗忘是实现可扩展、高效大模型安全的有前景方向。

原文摘要 · Abstract (English)

Jailbreak attacks pose a serious threat to the safety of Large Language Models (LLMs) by crafting adversarial prompts that bypass alignment mechanisms, causing the models to produce harmful, restricted, or biased content. In this paper, we propose SafeLLM, a novel unlearning-based defense framework that unlearn the harmful knowledge from LLMs while preserving linguistic fluency and general capabilities. SafeLLM employs a three-stage pipeline: (1) dynamic unsafe output detection using a hybrid approach that integrates external classifiers with model-internal evaluations; (2) token-level harmful content tracing through feedforward network (FFN) activations to localize harmful knowledge; and (3) constrained optimization to suppress unsafe behavior without degrading overall model quality. SafeLLM achieves targeted and irreversible forgetting by identifying and neutralizing FFN substructures responsible for harmful generation pathways. Extensive experiments on prominent LLMs (Vicuna, LLaMA, and GPT-J) across multiple jailbreak benchmarks show that SafeLLM substantially reduces attack success rates while maintaining high general-purpose performance. Compared to standard defense methods such as supervised fine-tuning and direct preference optimization, SafeLLM offers stronger safety guarantees, more precise control over harmful behavior, and greater robustness to unseen attacks. Moreover, SafeLLM maintains the general performance after the harmful knowledge unlearned. These results highlight unlearning as a promising direction for scalable and effective LLM safety.

大模型安全越狱攻击知识遗忘模型防御

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