NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Understanding and Preserving Safety in Fine-Tuned LLMs

Jiawen Zhang, Yangfan Hu, Kejia Chen, Lipeng He, Jiachen Ma, Jian Lou, Dan Li, Jian Liu, Xiaohu Yang, Ruoxi JiaarXiv 2026

TL;DR

Fine-tuning large language models (LLMs) on custom datasets often inadvertently destroys their pre-trained safety guardrails, even when the training data itself is completely harmless. This paper reveals a fundamental geometric conflict between safety and utility gradients, showing that safety updates reside in a very compact, low-rank subspace that can be pinpointed using just a single sample. Leveraging this insight, the authors introduce Safety-Preserving Fine-tuning (SPF), a lightweight gradient projection method that "locks in" safety without sacrificing downstream task performance.

What Problem Does This Paper Address?

When organizations deploy LLMs, they frequently fine-tune them on domain-specific data (like coding or mathematics) to boost performance. However, recent research highlights a scary vulnerability: fine-tuning easily overrides a model's safety alignment (e.g., RLHF or DPO), making it highly susceptible to jailbreaks. This risk is especially critical for Fine-Tuning-as-a-Service (FTaaS) providers who face legal liabilities if a user breaks a model's guardrails.

Figure 1: Illustration of the threat model.

Existing defenses try to solve this by adding a safety dataset into the fine-tuning mix and balancing the losses using a static hyperparameter ($\alpha$). The authors identify two major flaws in this approach:

  1. Trade-off Instability: The optimal balance is highly task-dependent. A setup that preserves safety during a coding task might cause catastrophic safety failures during a math task.
  2. Safety Decay in Deep Fine-tuning: As the number of training epochs increases, the protection offered by current defenses erodes, causing safety metrics to collapse.

This paper aims to understand the internal mechanics of this safety-utility dilemma from a geometric perspective and design a defense that fundamentally decouples the two.

Methods

Instead of tweaking the loss function with heuristic penalties, SPF operates directly on the gradient manifold.

At each fine-tuning step $t$, SPF computes two distinct gradients:

  1. A utility gradient ($g_t^u$) from a mini-batch of the user's downstream task data.
  2. A safety gradient ($g_t^s$) from just a single generic safety-aligned sample.

SPF then checks if these gradients conflict by calculating their inner product ($\langle g_t^s, g_t^u \rangle$). If the product is negative, a conflict is detected. To resolve it, SPF reshapes the safety gradient into a block-structured matrix and applies a truncated Singular Value Decomposition (SVD) to extract the top-$k$ singular directions, defining a low-rank safety subspace.

Finally, SPF projects the utility gradient onto the orthogonal complement of this safety subspace. This explicitly filters out the specific gradient components that would degrade safety, while leaving all other utility-relevant directions completely unconstrained.

Workflow of the Safety-Preserving Fine-tuning (SPF) method.

Datasets

The authors evaluated their approach across several diverse datasets:

  • Harm: 100 harmful input-answer pairs used to simulate explicit fine-tuning attacks.
  • Math (GSM8K): 7.4k training and 1.3k testing math problems to evaluate multi-step reasoning.
  • Code (SQL Create): 77k natural language queries paired with SQL statements.
  • Summary (Samsum): 14k conversation summaries.
  • Detection (Toxic-chat): 10k prompts annotated for toxicity detection.

For general capability evaluations, they used standard benchmarks including MMLU and MMLU-Pro, alongside the HarmBench classifier to objectively measure Attack Success Rates (ASR).

Key Insights and Ideas

  • Structural Asymmetry: Through SVD analysis, the authors discovered that safety gradients exhibit a sharp spectral decay, meaning they occupy a compact, low-rank subspace. Conversely, utility gradients span a much broader, high-dimensional space.
  • Intrinsic Directional Conflict: Even for entirely benign tasks like math and coding, utility gradients are frequently negatively correlated with safety gradients. Utility optimization acts as a persistent "push" that drives model parameters out of the localized safety region.
  • The "One-Shot" Anchor: Remarkably, the dominant directions of the safety subspace remain highly stable across different samples. The principal safety directions estimated from a single sample overlap significantly ($\phi > 0.8$) with those computed from a full batch, allowing for ultra-efficient real-time localization.

Key Results

The authors tested SPF against state-of-the-art defenses (like SafeTune, Lisa, and DeepAlign) across Llama-3.1-8B, Mistral-7B, and Qwen-2.5-7B.

  • Near-Perfect Safety Preservation: Under standard fine-tuning on harmful data, the Attack Success Rate (ASR) skyrocketed to nearly 100%. SPF successfully suppressed this, keeping the ASR near initial levels (e.g., dropping from 0.955 to 0.019 on Llama-3.1).
  • Uncompromised Utility: SPF maintained downstream task performance beautifully. For instance, on the GSM8K math task, Llama-3.1 achieved an accuracy of 0.847 with SPF, virtually identical to standard supervised fine-tuning (0.849).
  • Immunity to Deep Fine-Tuning: While other defenses saw their safety erode over multiple training epochs, SPF maintained a near-zero ASR even up to 20 epochs.
  • Extreme Efficiency: Unlike baseline defenses that require mixing in hundreds or thousands of safety samples, SPF achieves its results using only a single safety instance and adds negligible computational overhead ($O((B+k)N)$ time complexity).

Limitations and Future Work

  • Cross-Category Generalization: The authors noted that using category-specific safety data (e.g., only examples of illegal activities) effectively blocks attacks in that category but fails to generalize to unseen categories (like malware or fraud). While using a generic safety sample mitigates this, exploring broader multi-category single-sample anchors remains an open direction.
  • Hyperparameter Tuning ($k$): Enforcing orthogonality against an excessively large safety subspace dimension ($k$) reduces the degrees of freedom available for utility optimization, causing task performance to drop. While the authors found an optimal trade-off at $k \in [10, 20]$, dynamically adapting $k$ during training could be a valuable extension.

Summary updated

BibTeX
@misc{zhang2026understanding,
  author = {Jiawen Zhang and Yangfan Hu and Kejia Chen and Lipeng He and Jiachen Ma and Jian Lou and Dan Li and Jian Liu and Xiaohu Yang and Ruoxi Jia},
  title = {{Understanding and Preserving Safety in Fine-Tuned LLMs}},
  year = {2026},
  eprint = {2601.10141},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.10141},
}
Figure