TL;DR
TRACE introduces a trajectory-based safety patch learning framework that protects Large Language Models (LLMs) from safety erosion during Fine-Tuning-as-a-Service (FTaaS). By simulating fine-tuning degradation trajectories offline, TRACE trains a universal, low-rank safety adapter that achieves nearly 100% safety recovery across diverse tasks. Crucially, it eliminates the need for costly per-user online calibration while preserving downstream task utility.
What Problem Does This Paper Address?
Fine-Tuning-as-a-Service (FTaaS) platforms allow users to customize LLMs on proprietary datasets. However, this convenience introduces a massive vulnerability: custom fine-tuning can easily erode a model's built-in safety alignment, whether through malicious poisoning or accidental data drift.
Existing defenses try to fix this post-fine-tuning by merging a pre-computed "safety patch" with the user's fine-tuned model. Unfortunately, these methods run into a fundamental bottleneck called task-safety update entanglement. Because the parameter updates for the downstream task and the safety patch often share the same directional space, they interfere with each other. If a service provider applies the safety patch too weakly, the model remains unsafe; if they apply it too aggressively, it destroys the model's performance on the user's custom task. Finding the right balance currently requires tedious, per-user online calibration.
Methods
To break this safety-utility dilemma, the authors propose TRACE (Trajectory-Based Safety Patch Learning). Instead of focusing on how to merge weights online, TRACE shifts the complexity to an offline optimization phase.
The core architecture relies on an alternating simulate-and-learn paradigm:
- Fine-Tuning Trajectory Simulation: TRACE takes the well-aligned base model and intentionally corrupts it across a simulated training trajectory using surrogate harmful and benign datasets. This generates a sequence of progressively degraded model states that mimic various user training intensities.
- Decisive Safety Patch Optimization: At each step of the simulated trajectory, TRACE optimizes a plug-in LoRA adapter. The objective forces this adapter to successfully inject refusal behaviors on harmful prompts while strictly preserving correct responses for benign tasks.
By training the patch to succeed across an entire trajectory of corruption rather than a single static state, the patch naturally learns to operate in a parameter subspace orthogonal to the user's updates. At deployment time, the service provider simply plugs in this universal adapter—requiring zero online tuning or calibration.
Datasets
The authors evaluated TRACE using distinct datasets for the offline training and online evaluation stages:
- Offline Training (Surrogate Data): BeaverTails (harmful prompts paired with a uniform refusal template) and WizardLM (benign instructions).
- Online Evaluation (User Profiles):
- Malicious Users: ShadowAlignment, PureBad, and SafeRLHF.
- Benign Users: SamSum (dialogue summarization), SQLCreate (text-to-SQL), and GSM8K (math reasoning).
- Mixed Profiles: Combined corpora pairing each benign task dataset with PureBad to simulate realistic, messy user uploads.
Key Insights and Ideas
- Low-Rank Subspace Dominance: Remarkably, even when a user performs full-parameter fine-tuning (FFT)—which shifts weights globally—the model's safety capabilities remain anchored to a tiny, low-rank subspace. This allows a lightweight LoRA adapter to exert decisive control over safety behaviors.
- Disentanglement via Trajectory Exposure: Exposing the safety patch to a continuous gradient of model corruption forces it to find parameter directions that are orthogonal to task updates. As shown in the paper's analysis, TRACE reduces parameter saliency overlap with user updates by up to 78% compared to traditional patches.
- Orthogonality Boosts Existing Methods: Because TRACE optimizes the patch itself rather than the merging operator, it is entirely complementary to existing weight-merging defenses (like RESTA or SafeDelta) and can be substituted into them to instantly elevate their Pareto frontiers.
Key Results
Across six benchmarks and two distinct model families (Llama-3.1-8B-Instruct and Qwen3.5-9B), TRACE consistently outperformed all baselines:
- Perfect Safety Coverage: TRACE achieved a 100% safety rate on pure malicious/benign profiles. On the highly challenging SafeRLHF benchmark, it boosted Llama's safety from 23% (undefended) to 100%, outperforming the next-best baseline by over 4x.
- Negligible Utility Cost: Downstream task accuracy remained within a tight $\pm1.7\%$ margin of the undefended baseline, avoiding the catastrophic utility collapses seen in projection-based methods.
- Blazing Fast Deployment: Because it bypasses online coefficient searching and matrix decomposition, TRACE features an online deployment time of just 0.41 seconds—a 93.9% reduction compared to the fastest baseline.
Limitations and Future Work
While highly effective, TRACE operates within a bounded fine-tuning regime. If a user runs extremely prolonged training on massive datasets, the model's representational geometry could shift so drastically that it invalidates the safety directions encoded in the patch. Additionally, the framework was primarily validated on ~8B parameter models; the authors note that verifying its efficacy on larger scales and exploring resilience against sophisticated, adaptive data-poisoning attacks remain vital directions for future work.
Summary updated