只对关键层施加扰动,高效防御恶意微调攻击
Targeted Vaccine: Safety Alignment for Large Language Models against Harmful Fine-Tuning via Layer-wise Perturbation
- 用梯度范数识别安全关键层,仅对这些层加扰动
- 在70亿参数模型上实现更强防御效果,内存占用更低
- 适合消费级显卡部署,首次实现小显存下大模型防护
有害微调攻击对在线微调服务构成严重威胁。现有疫苗(Vaccine)防御方法在所有嵌入层施加统一扰动以增强模型对模拟嵌入漂移的鲁棒性,但这种全层扰动可能导致部分无关安全的层被过度扰动,造成防御性能下降和内存浪费。为此,我们提出目标疫苗(T-Vaccine),一种内存高效的安全部署方法,仅对选定的安全关键层施加扰动。T-Vaccine包含两个核心步骤:首先,利用梯度范数作为统计指标识别安全关键层;其次,不再对所有层施加均匀扰动,而是仅对安全关键层进行扰动,其余层保持冻结状态训练。实验表明,T-Vaccine在防御有效性和资源效率上均优于Vaccine。与RepNoise、TAR等其他防御基线相比,其优势显著。特别地,T-Vaccine是首个可在消费级显卡(如RTX 4090)有限内存条件下,对70亿参数预训练模型实施有害微调防护的方法。代码已公开于https://github.com/Lslland/T-Vaccine。
原文摘要 · Abstract (English)
Harmful fine-tuning attack poses a serious threat to the online fine-tuning service. Vaccine, a recent alignment-stage defense, applies uniform perturbation to all layers of embedding to make the model robust to the simulated embedding drift. However, applying layer-wise uniform perturbation may lead to excess perturbations for some particular safety-irrelevant layers, resulting in defense performance degradation and unnecessary memory consumption. To address this limitation, we propose Targeted Vaccine (T-Vaccine), a memory-efficient safety alignment method that applies perturbation to only selected layers of the model. T-Vaccine follows two core steps: First, it uses gradient norm as a statistical metric to identify the safety-critical layers. Second, instead of applying uniform perturbation across all layers, T-Vaccine only applies perturbation to the safety-critical layers while keeping other layers frozen during training. Results show that T-Vaccine outperforms Vaccine in terms of both defense effectiveness and resource efficiency. Comparison with other defense baselines, e.g., RepNoise and TAR also demonstrate the superiority of T-Vaccine. Notably, T-Vaccine is the first defense that can address harmful fine-tuning issues for a 7B pre-trained models trained on consumer GPUs with limited memory (e.g., RTX 4090). Our code is available at https://github.com/Lslland/T-Vaccine.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。