Abstract
Fine-tuning aligned large language models (LLMs) on downstream tasks often inadvertently compromises their safety guardrails. This paper frames this vulnerability as "catastrophic forgetting" and proposes the use of Continual Learning (CL) techniques to preserve safety alignment. By employing Dark Experience Replay (DER), the authors demonstrate that models can maintain safety even when fine-tuned on poisoned datasets, without sacrificing performance on new tasks.
What Problem Does This Paper Address?
As "fine-tuning-as-a-service" becomes a standard industry practice, users frequently upload custom datasets to adapt pre-trained LLMs for specialized tasks like coding or mathematical reasoning. However, this process introduces a significant security risk: fine-tuning an aligned, safe model on new data often causes it to "forget" its safety training.
This safety degradation occurs even with entirely benign datasets and becomes catastrophic if the data is "poisoned" with a small percentage of harmful prompts. The authors reframe this issue as a classic machine learning problem: catastrophic forgetting. By treating safety alignment as "Task 1" and the user's fine-tuning dataset as "Task 2," the research explores how to acquire new capabilities without discarding established safety constraints.
Methods
The authors adapted several established Continual Learning (CL) paradigms to the LLM fine-tuning process, specifically utilizing Low-Rank Adaptation (LoRA):
- Regularization-Based: Methods like Elastic Weight Consolidation (EWC) and Learning without Forgetting (LwF), which use knowledge distillation to constrain weight changes.
- Memory-Based: Techniques that maintain a small "buffer" of safety data for rehearsal. These include A-GEM (gradient projection), Refresh Learning, and Dark Experience Replay (DER). DER is particularly effective as it stores both safety prompts and the original model's logits, forcing the fine-tuned model to match the safe output distribution.
- Model Merging: MagMax, which merges weights from separately fine-tuned models post-hoc.
These approaches were benchmarked against standard Supervised Fine-Tuning (SFT) and existing safety-specific baselines such as SafeInstr and SafeLoRA.
Key Insights and Ideas
- Safety Loss as Catastrophic Forgetting: Applying classic memory replay techniques from CL literature achieved state-of-the-art safety preservation, suggesting that complex, LLM-specific safety algorithms may not be strictly necessary.
- The Robustness of Logit Matching: DER proved to be the most resilient method. By anchoring the model's behavior to the original safe model's logits, it resisted both benign forgetting and active poisoning attempts.
- Limitations of Distillation: While LwF performed well on benign data, it suffered a total safety collapse at high poison ratios (20%+). The extreme distribution shift between harmful training data and the safe teacher model eventually broke the distillation mechanism.
Key Results
The experimental results highlight a stark contrast between standard fine-tuning and CL-based approaches. Standard SFT consistently led to a significant increase in the Attack Success Rate (ASR) across various tasks.
- Benign Fine-Tuning: When fine-tuning LLaMA2-7B on math tasks (GSM8K), standard SFT caused the ASR to jump to 66.0%. In contrast, DER maintained an ASR of just 0.5%.
- Poisoned Fine-Tuning: With a 10% poisoning ratio, SFT ASR skyrocketed to 86.9% for coding tasks. DER successfully suppressed this to 1.7% while maintaining downstream utility.
- Extreme Scenarios: Even at a massive 30% poisoning ratio, DER kept the ASR below 5%, demonstrating remarkable robustness across different model families including Mistral-7B and Gemma-2B.
Limitations and Future Work
While memory-based methods like DER are highly effective at blocking harmful prompts, they can lead to over-refusal, where the model becomes overly cautious and rejects benign prompts (up to a 16.1% refusal rate on safe benchmarks). Additionally, maintaining a replay buffer and computing logits introduces slight computational overhead. Future research may focus on balancing the robustness of DER with the lower over-refusal rates of distillation methods, potentially through dynamic buffer adjustment based on detected input toxicity.
Summary updated