Locking Down the Finetuned LLMs Safety

Minjun Zhu, Linyi Yang, Yifan Wei, Ningyu Zhang, Yue Zhang · DOI

Abstract

Large Language Models (LLMs) undergo extensive safety alignment to prevent harmful outputs, yet this protection is remarkably fragile. Fine-tuning on even minimal adversarial data can bypass these guardrails. We introduce SafetyLock, a high-speed, non-invasive method to restore safety in compromised LLMs. By identifying and intervening on specific "safety heads" using vectors derived from the original model, SafetyLock reduces harmful response rates from 60% to under 1% in less than 0.01 seconds, maintaining the model's general reasoning capabilities.

Introduction: The Fine-tuning Vulnerability

While state-of-the-art LLMs like Llama-3 or GPT-4 are rigorously aligned using Reinforcement Learning from Human Feedback (RLHF) or Direct Preference Optimization (DPO), recent research highlights a critical "fine-tuning vulnerability." Training a model on as few as ten toxic sentences can completely dismantle its safety filters.

The risks associated with safety degradation can be categorized into three levels: explicitly harmful datasets, identity-shifting datasets (where the model is coaxed into an "obedient" persona), and benign datasets that inadvertently degrade alignment.

Safety degradation risks across three levels of dataset toxicity.

Existing solutions to this vulnerability, such as post-training retraining or model editing, are often computationally prohibitive or detrimental to the model's general performance in areas like mathematics and reasoning. Prompt-based defenses, while fast, are easily circumvented by sophisticated jailbreak attacks.

Methodology: The SafetyLock Approach

SafetyLock operates on the discovery that internal safety-related activation patterns remain "meta-stable" even after a model is fine-tuned to be toxic. The model's underlying understanding of what constitutes a harmful query persists; the fine-tuning merely shifts activations to bypass the refusal mechanism.

1. Locating Safety Heads

The authors use logistic regression probes to identify specific attention heads most sensitive to safety information. For instance, in Llama-3-8B, the 26th head of the 31st layer was found to be a primary "safety head."

2. Extracting the Meta-SafetyLock

A "safety direction" vector ($\theta$) is calculated by taking the mean difference between activations for safe and unsafe responses in the original, well-aligned model. This vector represents the universal direction from harmful to safe representations.

3. Intervention and Distribution

SafetyLock can be applied via real-time online intervention or offline bias editing. Unlike methods that shift the entire activation space, SafetyLock targets only the "Top-K" attention heads (typically K=24 for 8B models), ensuring high precision.

Comparison of SafetyLock with traditional alignment and defense methods.

Experimental Results

The researchers evaluated SafetyLock using datasets like HEx-PHI and AdvBench for safety, and GSM8k and MT-Bench for general utility.

  • Safety Restoration: SafetyLock reduced harmful instruction response rates from 60% to below 1%.
  • Jailbreak Robustness: Against "DeepInception" attacks, the success rate dropped from 98% to 2%.
  • Efficiency: The intervention takes less than 0.01 seconds and requires 0.0 GB of additional GPU memory.
  • Utility Preservation: The model's general performance remained stable. On the AddSub math task, the SafetyLock-protected model scored 85.57%, nearly matching the original model's 86.33%.

Discussion and Limitations

SafetyLock offers a scalable, efficient alternative to retraining. However, it requires access to internal model weights, limiting its use to open-source models. Additionally, the authors warn of "symmetric vulnerability": if an attacker obtains the safety vectors, they could potentially reverse them to intentionally increase model toxicity. Future work will focus on the long-term effectiveness of these "locks" against evolving adversarial techniques.

Code available at: https://github.com/zhu-minjun/SafetyLock

Summary updated

BibTeX
@misc{zhu2024locking,
  author = {Minjun Zhu and Linyi Yang and Yifan Wei and Ningyu Zhang and Yue Zhang},
  title = {{Locking Down the Finetuned LLMs Safety}},
  year = {2024},
  eprint = {2410.10343},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.10343},
}
Figure