TL;DR
Custom fine-tuning often inadvertently breaks the safety guardrails of Large Language Models (LLMs). This paper introduces TOSS, a framework that moves beyond discarding entire "unsafe" samples to surgically masking individual tokens that drive safety degradation. This approach preserves the model's utility while maintaining robust alignment.
What Problem Does This Paper Address?
Fine-tuning is the standard way to adapt LLMs to specific domains, but it comes with a "safety tax." Even when training on seemingly benign data, the rigorous safety alignment established during a model's initial training can erode, leading to the generation of harmful content.
Existing defenses are "coarse-grained." They either mix in massive amounts of safety data (which makes the model overly restrictive and degrades performance) or they filter out entire training samples deemed unsafe. The problem is that harmful and beneficial signals are often intertwined within the same sentence. Discarding a whole sample to remove one "bad" token is like throwing the baby out with the bathwater—you lose the valuable task-specific information the rest of the sample provides.
Methods
The authors propose TOken-level data Selection for Safe LLM fine-tuning (TOSS). Instead of a binary "keep or toss" for samples, TOSS creates a fine-grained mask for every token in the dataset.
- Reference Model Training: They train two specialized "expert" models using LoRA (Low-Rank Adaptation):
- A safety-degraded model ($f_{\theta^h}$): Trained on explicitly harmful data to become an expert at recognizing unsafe patterns.
- A utility-oriented model ($f_{\theta^u}$): Trained on high-quality task data to represent desired downstream behavior.
- Token Assessment: For every token in the custom dataset, TOSS calculates a loss-difference score. A high score indicates a token that the safety-degraded model "likes" (low loss) but the utility model "dislikes" (high loss).
- Global Ranking & Masking: Rather than masking a fixed percentage of every sample, TOSS ranks all tokens across the entire dataset. It then masks the top $d\%$ of tokens with the highest safety risk.
- TOSS-Pro: An iterative version where the safety-degraded model is progressively refined using the most "harmful" samples identified in previous rounds, making it even better at spotting subtle safety risks.
Datasets
- Custom Training Set: REDORCA, a mixture of 90k instruction-response pairs from SLIMORCA (benign) and 22k pairs from the Anthropic Red-Teaming dataset (harmful).
- Safety Evaluation: HEx-PHI (covering 11 categories of harmful instructions) and the safety subset of Anthropic HH.
- Utility Evaluation: The test subset of SLIMORCA for general instruction following and GSM8K for mathematical reasoning.
Key Insights and Ideas
- The Token is the Fundamental Unit: The authors' diagnosis reveals that safety degradation isn't just about "bad samples." Harmful signals are concentrated in initial response tokens (e.g., shifting from "I cannot assist" to "Sure, here is...") but are also scattered throughout the output.
- Surgical Precision Matters: By masking only the specific tokens that trigger unsafe behavior, TOSS retains the "benign" parts of a harmful sample that still contribute to learning task-specific styles or knowledge.
- Global vs. Local Ranking: Discarding a fixed ratio per sample (local) is ineffective because some samples are much more harmful than others. Global ranking allows TOSS to focus its "cleaning" efforts where the risk is highest.
- Transferability: Interestingly, the data selection performed for one model (like Llama-3-8B) can be reused for other models that share the same tokenizer (like Llama-3.2-1B), suggesting that "unsafety" is somewhat inherent to the data-tokenizer relationship.
Key Results
- Superior Trade-off: TOSS consistently achieves a better balance between safety and utility than sample-level methods like SEAL. On Llama-3-8B, it achieved average performance gains of 20% over baselines.
- Safety Preservation: While standard fine-tuning (SFT) causes safety win rates to plummet, TOSS-Pro maintains high safety scores (e.g., 93.79% on HEx-PHI for Llama-3) while keeping utility high (68.85% on SLIMORCA).
- Robustness: The method remains effective even when the proportion of harmful data in the training set varies significantly (from 30% to 70%).
Limitations and Future Work
- Computational Overhead: TOSS requires training two reference models before the actual fine-tuning begins. While the authors use LoRA to keep this cheap, it is still an extra step.
- Reference Data Dependency: The effectiveness of the scoring depends on having representative "harmful" and "utility" datasets to train the reference models.
- Future Directions: The authors suggest exploring how this token-level approach might apply to other alignment techniques beyond supervised fine-tuning, such as RLHF or DPO.
Summary updated