Safe Delta: Consistently Preserving Safety when Fine-Tuning LLMs on Diverse Datasets
Ning Lu, Shengcai Liu, Jiahao Wu, Weiyu Chen, Zhirui Zhang, Yew-Soon Ong, Qi Wang, Ke Tang
TL;DR
Safe Delta addresses the challenge of preserving safety when fine-tuning aligned LLMs on diverse datasets by introducing a Hessian-informed, parameter-level defense. It selects a subset of delta parameters that maximize utility gains under a safety constraint and applies a safety compensation vector inspired by Optimal Brain Surgeon principles to mitigate residual safety loss, with a layer-wise formulation and precomputation of the Hessian inverse. Across extensive experiments on harmful and benign fine-tuning scenarios, Safe Delta consistently improves safety metrics (ASR and Harmfulness Score) while maintaining or enhancing downstream utility, and it generalizes to LoRA and multiple model sizes. The approach offers a practical, scalable defense for real-world fine-tuning services, balancing safety with utility under dataset diversity and offering quantified time costs and limitations for future refinement.
Abstract
Large language models (LLMs) have shown great potential as general-purpose AI assistants across various domains. To fully leverage this potential in specific applications, many companies provide fine-tuning API services, enabling users to upload their own data for LLM customization. However, fine-tuning services introduce a new safety threat: user-uploaded data, whether harmful or benign, can break the model's alignment, leading to unsafe outputs. Moreover, existing defense methods struggle to address the diversity of fine-tuning datasets (e.g., varying sizes, tasks), often sacrificing utility for safety or vice versa. To address this issue, we propose Safe Delta, a safety-aware post-training defense method that adjusts the delta parameters (i.e., the parameter change before and after fine-tuning). Specifically, Safe Delta estimates the safety degradation, selects delta parameters to maximize utility while limiting overall safety loss, and applies a safety compensation vector to mitigate residual safety loss. Through extensive experiments on four diverse datasets with varying settings, our approach consistently preserves safety while ensuring that the utility gain from benign datasets remains unaffected.
