Mitigating Fine-tuning Risks in LLMs via Safety-Aware Probing Optimization
Chengcan Wu, Zhixin Zhang, Zeming Wei, Yihao Zhang, Meng Sun
TL;DR
The paper addresses safety degradation during fine-tuning of large language models by identifying entanglement between safety-critical and usefulness-critical gradient directions. It introduces Safety-Aware Probing (SAP), a gradient-propagation framework that injects a safety-aware probe into guidance signals, guided by a contrastive safety objective and a bi-level optimization procedure. SAP reduces harmful outputs below the original fine-tuned levels while preserving or matching typical fine-tuning performance and demonstrates robustness against adversarial attacks, as well as compatibility with existing safety defenses. The method is practical across multiple fine-tuning paradigms and datasets, offering a scalable approach to safer deployment of open-source LLMs.
Abstract
The significant progress of large language models (LLMs) has led to remarkable achievements across numerous applications. However, their ability to generate harmful content has sparked substantial safety concerns. Despite the implementation of safety alignment techniques during the pre-training phase, recent research indicates that fine-tuning LLMs on adversarial or even benign data can inadvertently compromise their safety. In this paper, we re-examine the fundamental issue of why fine-tuning on non-harmful data still results in safety degradation. We introduce a safety-aware probing (SAP) optimization framework designed to mitigate the safety risks of fine-tuning LLMs. Specifically, SAP incorporates a safety-aware probe into the gradient propagation process, mitigating the model's risk of safety degradation by identifying potential pitfalls in gradient directions, thereby enhancing task-specific performance while successfully preserving model safety. Our extensive experimental results demonstrate that SAP effectively reduces harmfulness below the original fine-tuned model and achieves comparable test loss to standard fine-tuning methods. Our code is available at https://github.com/ChengcanWu/SAP.
