TL;DR
This paper introduces "safety policy patching," a novel method to quickly fix safety issues in large language models (LLMs) without retraining the entire model. By adding a tiny, learnable prefix to the model's input, they achieve significant safety improvements comparable to full model updates, making LLM safety more agile and accessible.
What Problem Does This Paper Address?
Large language models (LLMs) are powerful but can exhibit serious safety concerns like generating toxic content, biased outputs, or harmful information. Traditional methods for fixing these issues, such as Reinforcement Learning from Human Feedback (RLHF) or extensive fine-tuning, are computationally expensive, time-consuming, and require significant access to model internals. This makes it difficult for model developers to release frequent, targeted safety updates between major model releases, leaving deployed LLMs vulnerable to known safety gaps for extended periods. The paper aims to bridge this gap by providing a lightweight, modular, and easily deployable solution for LLM safety remediation.
Methods
The core innovation is "safety policy patching." This method involves prepending a small, learnable "prefix" (a matrix of trainable parameters) to the input embeddings of an existing LLM. This prefix is trained to steer the LLM's behavior towards that of a safer "reference model" (M'). The training process is a two-stage pipeline:
- Supervised Fine-Tuning (SFT): The prefix is initialized and trained to mimic the token-by-token outputs of the safer reference model (M'). This stage ensures fluent and stable initialization.
- Direct Preference Optimization (DPO): The SFT-trained prefix is further refined using preference pairs (a preferred safe response vs. a rejected unsafe response). This stage specifically teaches the model to prioritize safe continuations, capturing higher-level safety preferences.
Crucially, this approach only requires black-box access to the reference model (M') to generate training data, and the original LLM (M) remains frozen. The learned prefix is extremely compact, adding only about 0.003% of the original model's parameters.
Datasets
The paper utilizes several datasets for training and evaluation:
- RealToxicityPrompts (RTP): Used for toxicity mitigation, specifically the "challenging" subset which contains innocuous prompts known to elicit toxic responses.
- ATTAQ: Used for out-of-distribution (OOD) toxicity testing.
- Professional-context prompts from Dong et al. (2024b): Used for gender bias mitigation.
- LLM-LAT dataset: Used for harmfulness refusal, specifically the "harmful" split containing unsafe prompts paired with safe refusals.
- MMLU (Massive Multitask Language Understanding): Used to evaluate general capabilities and ensure safety updates don't degrade performance on broader tasks.
Key Insights and Ideas
- LLMs can be "patched" like software: The core idea is that LLM safety can be updated incrementally and modularly, similar to how software vulnerabilities are patched, rather than requiring full system overhauls.
- Minimal parameters, maximal impact: The learned prefix is incredibly small (0.003% of parameters for Llama-2-7B) yet achieves significant safety improvements, demonstrating high parameter efficiency.
- Black-box reference models are sufficient: The method doesn't require access to the weights of the safer reference model; generated text is enough to create preference data, making it highly practical.
- Two-stage training is crucial: SFT alone provides fluency but limited safety, while DPO alone can lead to reward hacking and degraded fluency. The combined SFT→DPO approach balances both safety and fluency effectively.
- Cross-architecture patching is possible: A safe model from one family can be used to generate data for patching models from different families, offering broad applicability.
Key Results
- Toxicity Mitigation: Patched models (M+) achieved significant reductions in Average Max Toxicity and Toxic Rate, approaching the performance of fully detoxified teacher models (M'). For example, on Llama-2-7B, M+ reduced toxic rate from 92.5% to 18.3%, while M' achieved 26.7%.
- Gender Bias Mitigation: Patched models significantly reduced both explicit (GAS) and implicit (GLD) gender bias, often reaching near-zero scores comparable to specialized debiased models. For Llama-2-7B, M+ achieved GAS of 0.01 and GLD of 0.47, compared to M's 0.00 and 0.36.
- Harmfulness Refusal: Patched models achieved perfect safety performance (0% Attack Success Rate) on HarmBench, matching the performance of reference safe models.
- Efficiency: Policy patches are orders of magnitude smaller (4.71 MB vs. 13 GB for a 7B model) and require significantly less training time (1.7 GPU-hours vs. ~96 GPU-hours for full model fine-tuning).
- General Capabilities: Safety improvements came with minimal degradation in MMLU scores, indicating that the patches primarily target safety behaviors without broadly compromising model utility.
Limitations and Future Work
- Reliance on a reasonably safe reference model: The method requires access to a "reasonably safe" reference model (M') to generate preference data. If no such model is available, this approach cannot be directly applied.
- Adaptive attacks: While patches show robustness against current adaptive attacks, the paper notes open questions about their effectiveness against stronger, future adaptive attacks.
- Multi-risk patching: Continual safety patching across multiple risks (toxicity, bias, harmfulness) revealed challenges with catastrophic forgetting. Sequential and stacked training strategies showed substantial toxicity regression. Future work could explore architectural innovations like task-specific modules or compositional adapters to better balance retention and adaptation.
- Safety-utility trade-off: While generally favorable, there can be a trade-off between aggressive safety improvements and utility, as observed with Aya-23 where strong toxicity suppression led to a larger capability drop. Selecting an appropriate operating point on the safety-utility Pareto frontier is important.
Summary updated