微调后模型易变坏,SafetyLock用安全方向自动修复
Locking Down the Finetuned LLMs Safety
- 发现微调后模型仍保留原始安全激活模式,据此提取通用安全方向
- 0.01秒内重对齐,使有害指令响应率从60%降至1%以下
- 无需额外算力,适合所有微调场景,可直接集成到安全流程
对大语言模型进行微调常用于优化特定任务表现,但现有推理阶段的安全对齐措施无法有效防范微调过程中的安全风险。令人担忧的是,仅用10句有毒文本微调,模型就可能遵从有害指令。本文提出SafetyLock,一种高效且可迁移的安全干预方法。其核心发现是:微调后的模型仍保留与原始模型相似的安全相关激活表征。基于此,我们提取出‘元安全锁’(Meta-SafetyLock),即代表原始模型中安全回应的关键激活模式的方向。这些方向可普遍应用于各类微调模型以增强安全性。通过在多个词元维度搜索激活方向,SafetyLock实现了更强的鲁棒性与可迁移性。整个重对齐过程耗时不足0.01秒,不增加额外计算开销。实验表明,SafetyLock可将有毒微调模型的有害指令响应率从60%降低至1%以下,显著优于传统方法,在性能与效率上均具优势,为定制化LLM提供了一种可扩展、非侵入式安全保障方案。跨多种微调场景的分析验证了其鲁棒性,建议纳入对齐模型的安全协议。代码已开源:https://github.com/zhu-minjun/SafetyLock。
原文摘要 · Abstract (English)
Fine-tuning large language models (LLMs) on additional datasets is often necessary to optimize them for specific downstream tasks. However, existing safety alignment measures, which restrict harmful behavior during inference, are insufficient to mitigate safety risks during fine-tuning. Alarmingly, fine-tuning with just 10 toxic sentences can make models comply with harmful instructions. We introduce SafetyLock, a novel alignment intervention method that maintains robust safety post-fine-tuning through efficient and transferable mechanisms. SafetyLock leverages our discovery that fine-tuned models retain similar safety-related activation representations to their base models. This insight enables us to extract what we term the Meta-SafetyLock, a set of safety bias directions representing key activation patterns associated with safe responses in the original model. We can then apply these directions universally to fine-tuned models to enhance their safety. By searching for activation directions across multiple token dimensions, SafetyLock achieves enhanced robustness and transferability. SafetyLock re-aligns fine-tuned models in under 0.01 seconds without additional computational cost. Our experiments demonstrate that SafetyLock can reduce the harmful instruction response rate from 60% to below 1% in toxic fine-tuned models. It surpasses traditional methods in both performance and efficiency, offering a scalable, non-invasive solution for ensuring the safety of customized LLMs. Our analysis across various fine-tuning scenarios confirms SafetyLock's robustness, advocating its integration into safety protocols for aligned LLMs. The code is released at https://github.com/zhu-minjun/SafetyLock.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。