Locking Down the Finetuned LLMs Safety

Minjun Zhu, Yixuan Weng, Linyi Yang, Yifan Wei, Ningyu Zhang, Yue Zhang · Submission to ICLR 2025 · Rejected

TL;DR

Fine-tuning an aligned large language model (LLM)—even on just a dozen toxic examples or benign datasets—can completely strip away its safety guardrails. SafetyLock solves this by discovering that safety-critical activation directions within attention heads remain remarkably stable across fine-tuning. By extracting a transferable "Meta-SafetyLock" from the base model, SafetyLock re-secures downstream fine-tuned models in under 0.01 seconds without retraining, reducing harmful instruction response rates from over 50% to under 1% while preserving general downstream capabilities.

What Problem Does This Paper Address?

Post-training safety alignment (like RLHF or DPO) teaches LLMs to refuse harmful prompts. However, research has shown that this safety is fragile: fine-tuning an aligned model on just 10 adversarial examples (or even standard benign datasets like Alpaca) can dismantle its safeguards, causing the model to comply with malicious queries.

Current remedies are impractical for real-world ecosystems where thousands of custom fine-tuned models exist:

  • Retraining/Re-aligning (SFT/DPO/PPO) on each fine-tuned model is computationally prohibitive and time-consuming.
  • Model editing often severely degrades general reasoning and output quality.
  • Inference-time prompt guards are brittle and easily bypassed by jailbreak techniques.

The authors ask: Can we extract an intrinsic, universal safety representation from the base aligned model and instantly deploy it to any fine-tuned variant without harming benign performance?

Methods

SafetyLock operates on the discovery that fine-tuning modifies weights locally without erasing the global geometry of safety representations across key attention heads (demonstrating cosine similarity $>0.99$ before and after fine-tuning). The pipeline consists of two main stages:

  1. Constructing the Meta-SafetyLock (One-Time Base Extraction):
  2. Attention Head Probing: Using a paired safe/unsafe dataset (e.g., BeaverTails), the authors train logistic regression classifiers on activations across attention heads to identify the Top-$K$ heads most sensitive to harmfulness (e.g., $K=24$ for 8B models, $K=48$ for 70B models).
  3. Vector Calculation: For each identified head, a safety direction vector ($\theta^h_l$) is computed as the mean activation difference between safe and unsafe responses over a window of the final $r=5$ tokens. The activation standard deviation ($\sigma^h_l$) is also measured to normalize intervention scale.
  4. Distributing SafetyLock (Zero-Retraining Deployment):
  5. Online Intervention: During autoregressive generation, activations at selected heads are shifted along the safety vector: $$x_{l+1} = x_l + \sum_h Q^h_l \left(\text{Att}^h_l(P^h_l x_l) + \alpha \sigma^h_l \odot \theta^h_l\right)$$
  6. Offline Bias Editing: Alternatively, the intervention can be permanently folded into the model's projection bias weights in a one-time operation without requiring GPU runtime: $$\text{Bias}_l \leftarrow \text{Bias}_l + \alpha \sum_h Q^h_l (\sigma^h_l \odot \theta^h_l)$$

Datasets

  • Safety Probing & Extraction: BeaverTails-style human preference dataset.
  • Fine-Tuning Attacks (Threat Models):
  • Risk 1 (Explicitly Harmful): Anthropic's HH-RLHF negative samples (10 to 10,000 examples).
  • Risk 2 (Identity Shifting / Implicit): 10 adversarial jailbreak samples.
  • Risk 3 (Benign Fine-Tuning): Alpaca-50k dataset.
  • Evaluation Benchmarks:
  • Safety: HEx-PHI (330 prompts across 11 prohibited categories evaluated via GPT-4) and AdvBench (attack success rate via substring matching).
  • Combined Prompt Attacks: AutoDAN, DeepInception, GCG, PAIR, and XSTest.
  • General Capabilities: GSM8K, AddSub, AQUA, CommonSenseQA, MT-Bench, AlpacaEval 2.0, and Alpaca response rate/perplexity.

Key Insights and Ideas

  • Persistent Latent Safety: Even when fine-tuning induces toxic output behaviors, the model does not completely unlearn safety features; the underlying representations in specific attention heads remain remarkably intact.
  • Subspace Modularity: Safety can be governed by intervening on a tiny fraction of attention heads (often fewer than 3% of total heads) rather than the entire residual stream. Larger models exhibit a scaling law requiring a relatively smaller fraction of heads for intervention.
  • Variance Scaling Matters: Normalizing the steering vector by activation variance ($\sigma^h_l$) is critical; unnormalized steering collapses GSM8K accuracy from 85% to 52%, whereas variance-scaled steering maintains 84.91% accuracy.

Key Results

  • Superior Safety Restoration: On Llama-3-8B fine-tuned on benign data (Risk 3), SafetyLock slashed AdvBench Attack Success Rate (ASR) from 42.88% to 0.19% and HEx-PHI harmfulness scores from 3.23 to 1.04.
  • Resilience Against Combined Attacks: When fine-tuned models were targeted with jailbreaks like DeepInception, baseline defenses failed completely (98% ASR), while SafetyLock suppressed ASR to 2.0%.
  • Extreme Efficiency: Deploying SafetyLock takes $<0.01$ seconds and 0.0 GB extra GPU memory, compared to DPO realignment which took over 2 hours (7,622 seconds) and 45 GB GPU memory.
  • Minimal Performance Degradation: On GSM8K mathematical reasoning, fine-tuned Llama-3-8B achieved 85.59% accuracy; SafetyLock retained 84.91% (in contrast to model editing/DINM, which crashed to 5.00%). The benign response rate on Alpaca remained at 98.1% (vs. 99.4% baseline).

Limitations and Future Work

  • White-Box Requirement: SafetyLock requires access to intermediate activations and model weights, meaning third-party black-box API consumers cannot implement it themselves.
  • Symmetric Mechanism: Because the intervention is linear, a malicious actor with full local weight access could theoretically invert or subtract the safety vector.
  • Future Directions: Adapting SafetyLock to multimodal architectures and exploring cryptographic or asymmetric weight-obfuscation schemes (e.g., combining with weight-locking frameworks) to safeguard open-weight releases against tampering.

Summary updated

BibTeX
@misc{zhu2024locking,
  author = {Minjun Zhu and Yixuan Weng 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