跟随梯度:将安全退化追溯至训练数据
研究论文 · 2026/11/03
在指令数据上微调大型语言模型(LLM)可能会悄然削弱其安全性,即使训练样本看起来无害。本文提出SimpleLoRIF,一种可扩展的梯度嵌入方法,通过简化低秩归因方法并将反向传播限制在最后四个Transformer块,能够识别与不安全行为梯度对齐的微调样本,从而处理百万级数据集。在涌现性错位任务上验证,梯度空间AUC高达0.865。利用SimpleLoRIF构建SafeTulu(移除与不安全响应梯度最对齐的20%样本的Tulu 3版本),在Qwen、Llama和Olmo上训练后,GCG攻击成功率降低高达22%,优于LLM-as-a-judge和先前基于梯度的过滤方法,同时基本保持或提升模型能力。分析移除的数据还发现了工具执行失败和叙事算术等可能被忽视的安全退化来源。
该研究提出了一种可扩展的梯度过滤方法,能有效识别看似无害但会削弱模型安全性的微调数据,并构建了SafeTulu数据集,在多个模型上显著降低攻击成功率且保持能力,为LLM安全微调提供了实用工具和新的数据视角。
Fine-tuning Large Language Models (LLMs) on instruction data can quietly erode their safety, even when no training example looks harmful. Because this safety-degrading data looks benign, standard content filters struggle to catch it. We tackle this problem by developing SimpleLoRIF, a scalable gradient embedding method that identifies fine-tuning examples whose gradients align with unsafe behavior. By simplifying a low-rank attribution method and restricting backpropagation to the final four transformer blocks, SimpleLoRIF can embed datasets on the order of a million examples, boosting gradient attribution from a small-scale analysis tool into a practical filter for full post-training datasets. We first validate it on emergent misalignment, where we find that gradients can connect insecure-code training data to the broadly harmful behaviors that appear after fine-tuning, with AUC as high as 0.865 in the gradient space of misaligned models. We then use SimpleLoRIF to build SafeTulu, a version of Tulu 3 with the 20% of examples most gradient-aligned with unsafe responses removed. Training on SafeTulu reduces GCG attack success rate by up to 22% across Qwen, Llama, and Olmo, outperforming both LLM-as-a-judge and prior gradient-based filtering, while largely preserving or even improving capability. Finally, we analyzed the removed data and identify possibly under-studied sources of safety degradation, such as tool-execution failures and narrative arithmetic. We release SafeTulu along with a Hugging Face Space that lets researchers build their own customized versions of SafeTulu to fine-tune on, such as by changing the removal fraction or filtering only certain subsets.