Abstract
Instruction Fine-Tuning (IFT) has been widely adopted as an effective post-training strategy to enhance various abilities of Large Language Models (LLMs). However, prior studies have shown that IFT can significantly compromise LLMs' safety, particularly their ability to refuse malicious instructions, raising significant concerns. Recent research into the internal mechanisms of LLMs has identified the refusal direction ($r$-direction) in the hidden states, which plays a pivotal role in governing refusal behavior. Building on this insight, our study reveals that the $r$-direction tends to drift during training, which we identify as one of the causes of the associated safety risks. To mitigate such drift, our proposed ProCon method introduces a projection-constrained loss term that regularizes the projection magnitude of each training sample's hidden state onto the $r$-direction. Experimental results under various datasets, scenarios, and LLMs demonstrate that our method can significantly mitigate safety risks posed by IFT while preserving task performance gains.
Introduction
Large Language Models (LLMs) typically undergo extensive alignment, such as Reinforcement Learning from Human Feedback (RLHF), to ensure they refuse harmful instructions. However, a disturbing trend has emerged: when these aligned models undergo Instruction Fine-Tuning (IFT) for new tasks, their safety mechanisms often degrade—a phenomenon known as "safety regression." Surprisingly, even fine-tuning on perfectly benign data can cause a model to start answering malicious prompts it previously refused.
This paper investigates the mechanistic cause of this regression, focusing on the refusal direction ($r$-direction). The $r$-direction is a specific vector in the model's hidden state space that governs refusal behavior. We discover that during standard fine-tuning, this direction undergoes a significant "drift," particularly in the deeper layers, effectively disabling the model's safety triggers.
Mechanisms of Safety Drift
Our analysis across multiple architectures, including LLaMA2, LLaMA3, and Qwen2, reveals that $r$-direction drift is a universal phenomenon. By measuring the cosine similarity ($\cos \theta$) between the $r$-direction of the vanilla (safe) model and the model during IFT, we observed a consistent decline in similarity as training progressed.
Key observations include:
- Depth Sensitivity: Drift is consistently more pronounced in deeper layers, which are closer to the final output generation.
- Early-Stage Sharp Drift: Most of the safety degradation occurs within the very first epoch of fine-tuning. This "sharp drift" suggests that the model's safety alignment is highly volatile at the start of new training.
The ProCon Method
To stabilize the model's internal safety logic, we propose ProCon (Projection-Constraint). The method consists of three main components:
- Refusal Direction Identification: We identify the $r$-direction by calculating the difference between the mean hidden state activations of benign instructions and malicious ones (the "difference-in-means" method).
- Projection-Constrained Loss: We introduce a new loss term, $Loss_{proj} = ||Proj_{IFT} - Proj_{vanilla}||_2$, which regularizes the projection magnitude of a training sample's hidden state onto the $r$-direction to match the original safe model.
- Enhanced ProCon ($ProCon^{wu}_{safe}$):
- Warm-up Strategy ($wu$): To counter the early-stage sharp drift, we apply a strong constraint ($\alpha=1$) during the initial "warm-up" epochs before transitioning to standard IFT.
- Broadening Data Distribution ($safe$): We incorporate a small set of safety-oriented data (approx. 1k samples) to provide a clearer signal for the constraint, further stabilizing the $r$-direction.
Experimental Results
We evaluated $ProCon^{wu}_{safe}$ using LLaMA2-7B, LLaMA3-8B, and Qwen2-7B across various red-teaming benchmarks (e.g., Advbench, CatQA) and task performance metrics (e.g., GSM8K).
- Safety Preservation: On LLaMA2, standard IFT caused the Average Attack Success Rate (ASR) to jump from 6.12% to 61.18%. $ProCon^{wu}_{safe}$ successfully mitigated this, maintaining an ASR of 12.88%.
- Utility Maintenance: Crucially, the method preserves or even slightly enhances task performance. For reasoning tasks on LLaMA2, performance improved from 66.0% (standard IFT) to 67.0% with ProCon.
- Robustness: The method remains effective even in "Attack IFT" scenarios where malicious samples are intentionally injected into the training set.
Conclusion
ProCon offers an interpretability-driven approach to LLM safety. By treating safety as a geometric stability problem in the hidden state space, we can anchor the refusal behavior of models during fine-tuning. This method effectively balances the need for task-specific adaptation with the requirement for robust safety alignment, laying a foundation for more secure post-training strategies.
Summary updated