Abstract
Instruction fine-tuning has emerged as a critical technique for customizing Large Language Models (LLMs) to specific applications. However, recent studies have highlighted significant security vulnerabilities in fine-tuned LLMs. Existing defense efforts focus more on pre-training and post-training methods, yet there remains underexplored in in-training methods. To fill this gap, we introduce a novel secure-tuning strategy called SWAT. By analyzing how module-level parameters (e.g. Q/K/V/O) affect the security feature space drift, we identify a robust subset of modules, termed Mods_Rob. Our SWAT strategy begins by warming up Mods_Rob to capture low-level features with minimal security risks, followed by training all parameters to achieve optimal task performance. Essentially, this strategy shifts the early learning burden more from global parameters to Mods_Rob, reducing update magnitudes of the non-robust subset. Across various datasets, scenarios, and LLMs, our strategy has demonstrated significant success in mitigating security risks while preserving task performance. Importantly, it can be seamlessly integrated with pre-training and post-training methods, leading to greater improvements.
Introduction: The Security Drift Problem
Instruction Fine-Tuning (IFT) is a standard practice for adapting Large Language Models (LLMs) to specialized tasks like mathematics or coding. However, this process often inadvertently "unlearns" the safety guardrails established during initial alignment (e.g., RLHF). This phenomenon, known as security feature space drift, means that a model fine-tuned on entirely benign data can become vulnerable to malicious prompts it previously would have refused.
As illustrated in Figure 1, a security-aligned LLM correctly refuses a malicious request but may fail a simple math comparison. After standard tuning on math data, the model might solve the math problem correctly but lose its safety constraints, agreeing to provide harmful information like bomb-making tutorials.
Methodology: SWAT (Security-oriented WArm-up Tuning)
To mitigate these risks without compromising task performance, we introduce SWAT, an in-training defense strategy. SWAT identifies and leverages the inherent differences in how various model modules (Query, Key, Value, and Output matrices) respond to fine-tuning.
The SWAT framework, detailed in Figure 2, operates in three primary stages:
- Robustness Analysis: Researchers employ binary classifiers to distinguish between benign and malicious instructions within the model's hidden representation space. By perturbing specific modules and monitoring classifier performance, they identify a robust subset of parameters, $Mods_{Rob}$, that are less prone to security drift.
- Warm-up Phase: The model undergoes an initial training phase using only the $Mods_{Rob}$ parameters. This phase utilizes "Instruction Modeling" (predicting both prompt and response) to capture fundamental task features using the most stable parts of the architecture.
- SFT Phase: Finally, the model is tuned across all parameters. Because the robust modules have already absorbed the "early learning burden," the subsequent updates to sensitive, non-robust parameters are minimized, effectively preserving the original safety alignment.
Key Insights and Analysis
Investigation into model architecture revealed several critical insights:
- Depth and Robustness: There is a strong correlation between layer depth and security robustness. Early layers are highly sensitive to drift, while deeper layers tend to maintain security features more effectively.
- Architectural Variation: The specific drivers of drift vary by model family. In Llama architectures, the Query (Q) and Key (K) modules are the most sensitive. Conversely, in Qwen models, the Output (O) and Value (V) modules are the primary sources of security degradation.
Experimental Results
SWAT was evaluated across diverse datasets, including UltraInteract, GSM8K, and Alpaca, and tested against red-teaming benchmarks like Advbench and CatQA.
- Security Performance: On Llama-2-7B, SWAT reduced the Attack Success Rate (ASR) by 13.33% to 39.94% compared to standard fine-tuning. Harmfulness scores also saw significant reductions.
- Utility Preservation: Crucially, these security gains were achieved with minimal impact on task accuracy. For instance, the model maintained approximately 66% accuracy on the UltraInteract reasoning task.
- Defense Synergy: SWAT is highly compatible with other defense methods. When combined with post-training techniques like Resta, the reduction in ASR reached as high as 60.27%.
Conclusion
SWAT offers a powerful, in-training approach to securing LLMs during customization. By identifying robust modules and implementing a two-phase warm-up strategy, SWAT effectively prevents security feature space drift, ensuring that models remain safe even as they become more capable in specialized domains.
Summary updated