arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.10141cs.LGcs.AI
收藏

理解并保持在微调大语言模型中的安全性

Understanding and Preserving Safety in Fine-Tuned LLMs

Zhejiang University(浙江大学);University of Wisconsin–Madison(威斯康星大学麦迪逊分校);University of Waterloo(滑铁卢大学);Shanghai Artificial Intelligence Laboratory(上海人工智能实验室);Sun Yat-sen University(中山大学)

Jiawen Zhang, Yangfan Hu, Kejia Chen, Lipeng He, Jiachen Ma, Jian Lou, Dan Li, Jian Liu, Xiaohu Yang, Ruoxi Jia

AI总结:

本文提出安全保持微调(SPF)方法,通过分析安全性与实用性梯度的几何关系,有效解决微调过程中安全性与实用性之间的矛盾,保持模型性能并恢复预训练的安全性对齐。

摘要:

微调是将大型语言模型(LLMs)应用于下游任务的重要且普遍的功能。然而,它有可能显著降低安全性对齐,例如通过大幅增加对 Jailbreak 攻击的易感性,即使微调数据完全无害。尽管在微调阶段的防御努力日益增加,现有方法仍面临持续的安全性-实用性困境:强调安全性会损害任务性能,而优先考虑实用性通常需要深度微调,这不可避免地导致安全性的下降。在本工作中,我们通过揭示安全对齐 LLMs 中安全性与实用性导向梯度之间的几何相互作用来解决这一困境。通过系统性的实证分析,我们揭示了三个关键见解:(I)安全性梯度位于低维子空间中,而实用性梯度则跨越更广的高维空间;(II)这些子空间往往呈负相关,导致微调过程中出现方向冲突;(III)主导的安全方向可以从单个样本中高效估计。基于这些新颖的见解,我们提出了安全保持微调(SPF),一种轻量级的方法,该方法明确地移除了与低维安全子空间冲突的梯度组件。理论上,我们证明 SPF 在保证实用性收敛的同时限制了安全性漂移。实验上,SPF 一致地保持了下游任务性能,并在对抗性微调场景下恢复了几乎所有预训练的安全性对齐。此外,SPF 对深度微调和动态 Jailbreak 攻击表现出鲁棒性。共同,我们的发现为始终对齐的 LLM 微调提供了新的机制理解和实用指导。

英文摘要:

Fine-tuning is an essential and pervasive functionality for applying large language models (LLMs) to downstream tasks. However, it has the potential to substantially degrade safety alignment, e.g., by greatly increasing susceptibility to jailbreak attacks, even when the fine-tuning data is entirely harmless. Despite garnering growing attention in defense efforts during the fine-tuning stage, existing methods struggle with a persistent safety-utility dilemma: emphasizing safety compromises task performance, whereas prioritizing utility typically requires deep fine-tuning that inevitably leads to steep safety declination. In this work, we address this dilemma by shedding new light on the geometric interaction between safety- and utility-oriented gradients in safety-aligned LLMs. Through systematic empirical analysis, we uncover three key insights: (I) safety gradients lie in a low-rank subspace, while utility gradients span a broader high-dimensional space; (II) these subspaces are often negatively correlated, causing directional conflicts during fine-tuning; and (III) the dominant safety direction can be efficiently estimated from a single sample. Building upon these novel insights, we propose safety-preserving fine-tuning (SPF), a lightweight approach that explicitly removes gradient components conflicting with the low-rank safety subspace. Theoretically, we show that SPF guarantees utility convergence while bounding safety drift. Empirically, SPF consistently maintains downstream task performance and recovers nearly all pre-trained safety alignment, even under adversarial fine-tuning scenarios. Furthermore, SPF exhibits robust resistance to both deep fine-tuning and dynamic jailbreak attacks. Together, our findings provide new mechanistic understanding and practical guidance toward always-aligned LLM fine-tuning.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑