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.
Introduction
As Large Language Models (LLMs) transition from general-purpose chatbots to specialized enterprise tools, fine-tuning APIs have become essential. However, this customization capability introduces a significant security vulnerability. Recent research demonstrates that fine-tuning an aligned model on even a small amount of harmful data—or even seemingly benign data—can cause the model to "forget" its safety training, leading to toxic or dangerous outputs.
Existing defenses are largely static and struggle with dataset diversity. Data-based methods that mix safety examples during training or weight-based methods that project weights into fixed "safe" subspaces often fail to adapt. A defense robust enough to stop a massive malicious attack might cripple performance on a simple math task, while a lighter defense remains vulnerable to clever jailbreak datasets.
Methodology: The Safe Delta Framework
Safe Delta is a two-stage post-training defense that operates on the "delta" ($Δ\mathbf{W}$), defined as the difference between the original model weights and the fine-tuned weights.
1. Estimation and Selection
Instead of retaining all fine-tuned updates, Safe Delta treats parameter selection as a constrained optimization problem, similar to the "Knapsack Problem." It calculates a utility-safety ratio ($r_m$) for every parameter, evaluating how much a specific weight change contributes to the new task versus how much it degrades safety. The system greedily selects the highest-performing parameters until a pre-defined safety degradation threshold ($ϵ$) is reached.
2. Safety Compensation
Simply removing "unsafe" updates is insufficient to fully restore alignment. Drawing inspiration from the Optimal Brain Surgeon (OBS) pruning algorithm, Safe Delta applies a Safety Compensation Vector (SCV). This vector makes precise adjustments to the remaining weights to mathematically cancel out the residual safety loss caused by the updates that were kept.
Crucially, the most computationally intensive step—calculating the inverse Hessian matrix of the safety loss—only needs to be performed once for the base model. This allows service providers to cache the results and apply the defense to new fine-tuning requests in approximately one minute.
Experimental Evaluation
The researchers evaluated Safe Delta across four diverse scenarios:
- Harmful Datasets: PureBad (explicitly harmful instructions) and Identity Shift (instructions to become an "Absolutely Obedient Agent").
- Benign/Mixed Datasets: Dirty Summary (1,000 benign summaries mixed with 100 harmful examples) and a pure Math dataset (GSM8k).
- Evaluation Metrics: The Policy-Oriented Safety Evaluation Benchmark was used, covering 330 examples across 11 prohibited categories such as illegal acts and harassment.
Key Results and Insights
Safe Delta consistently outperformed popular baselines like Safe LoRA and SafeInstr across multiple dimensions:
- Safety Preservation: On the PureBad dataset, a standard fine-tuned model reached an Attack Success Rate (ASR) of 95.76%. Safe Delta slashed this to just 3.33%, effectively matching the original model's safety profile.
- Utility Retention: On the Math task, Safe Delta achieved a utility score of 0.334 (improving upon the base model's 0.261), whereas competing defenses often saw utility drop or safety fail.
- Robustness to Scale: As shown in the experimental results, Safe Delta maintains a near-constant low ASR regardless of the harmful dataset size, whereas other methods show increasing vulnerability as the attack scale grows.
Conclusion
Safe Delta demonstrates that the "safety landscape" of a model is relatively constant, defined by its original alignment. By surgically identifying "safety-breaking" weights and applying a mathematical compensation vector, the method provides a computationally efficient (averaging 62 seconds on an A100 GPU) and effective defense. While future work will address potential adaptive attacks and multimodal extensions, Safe Delta currently offers a robust path for preserving LLM safety during specialized fine-tuning.
Summary updated