HyperSafe: Inference-Time Safety Recovery for Fine-Tuned Language Models

📄 arXiv: 2607.11475v1 📥 PDF

作者: Aznaur Aliev, Carlos Hinojosa, Abdelrahman Eldesokey, Bang An, Bernard Ghanem, Yibo Yang

分类: cs.LG, cs.CL

发布日期: 2026-07-13

🔗 代码/项目: GITHUB


💡 一句话要点

提出HyperSafe框架以解决语言模型安全性恢复问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 语言模型 安全性对齐 微调 安全侧网络 深度学习 模型评估 人工智能

📋 核心要点

  1. 现有的安全性对齐方法在大型语言模型微调后可能变得脆弱,导致有害响应率上升。
  2. HyperSafe框架通过生成模型特定的安全侧网络(SSN)来恢复微调模型的安全行为,采用非侵入式方法。
  3. 在Qwen2-7B和LLaMA-3-8B模型上,HyperSafe将有害响应率从19-31%降低到1%以下,同时保持下游任务准确性在微调基线的1%以内。

📝 摘要(中文)

在大型语言模型的微调过程中,安全性对齐可能会变得脆弱,甚至在无害的任务适应中也可能增加有害的合规性。现有的防御方法主要有两种方向:一种是在微调过程中或之后通过重训练或权重修改进行干预,另一种是使用模型无关的安全分类器,这可能会错过特定于某个微调检查点的失败。为了解决这些问题,本文提出了HyperSafe框架,通过为每个微调检查点生成模型特定的安全侧网络(SSN)来恢复安全行为。HyperSafe利用层级激活指纹捕捉微调如何改变模型的内部表示,并通过少量的校准提示将这些指纹映射到SSN的参数上。生成的SSN与冻结的微调模型并行运行,进行提示级别的安全分类,从而无需梯度更新和安全数据。实验表明,HyperSafe在多个安全基准上显著降低了有害响应率,同时保持下游任务的准确性。

🔬 方法详解

问题定义:本文旨在解决大型语言模型在微调后安全性对齐脆弱的问题。现有方法如重训练和权重修改成本高且可能影响任务性能,而模型无关的安全分类器可能无法捕捉特定微调检查点的失败。

核心思路:HyperSafe框架的核心思路是生成模型特定的安全侧网络(SSN),通过层级激活指纹捕捉微调对模型内部表示的影响,从而实现安全性恢复。

技术框架:HyperSafe的整体架构包括两个主要模块:首先,通过校准提示生成层级激活指纹;其次,利用超网络将这些指纹映射到SSN的参数上,SSN与冻结的微调模型并行运行,进行安全分类。

关键创新:HyperSafe的主要创新在于其后处理的非侵入式方法,能够针对每个微调检查点生成特定的SSN,而无需对模型进行梯度更新或修改权重,这与现有方法形成鲜明对比。

关键设计:在设计中,HyperSafe使用少量校准提示进行指纹生成,并通过单次前向传播将指纹映射到SSN参数,确保了高效性和准确性。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果显示,HyperSafe在Qwen2-7B和LLaMA-3-8B模型上显著降低了有害响应率,从19-31%降至1%以下,同时在下游任务中保持了与微调基线相近的准确性,平均误差不超过1%。

🎯 应用场景

HyperSafe框架具有广泛的应用潜力,尤其是在需要确保语言模型安全性的场景中,如自动内容生成、对话系统和在线客服等领域。通过有效降低有害响应率,HyperSafe能够提升用户体验和信任度,未来可能推动更安全的人工智能应用发展。

📄 摘要(原文)

Safety alignment in large language models can be fragile under fine-tuning, as even benign task adaptation may increase harmful compliance. Existing defenses mainly follow two directions: they either intervene during or after fine-tuning through retraining or weight modification, which can be costly and may hurt task performance, or they use model-agnostic safety classifiers, which may miss failures specific to a given fine-tuned checkpoint. These limitations motivate a post hoc, model-specific, and non-invasive approach to safety restoration. To meet these requirements, we propose HyperSafe, a framework that restores safety behavior by generating a model-specific Safe Side Network (SSN) for each fine-tuned checkpoint. HyperSafe uses layer-wise activation fingerprints to capture how fine-tuning changes the model's inner representations. With a small set of given calibration prompts, the hypernetwork maps these fingerprints to the parameters of the \ssn{} in a single forward pass. The generated \ssn{} runs alongside the frozen fine-tuned model and performs prompt-level safety classification: harmful prompts are routed to refusal, while safe prompts are answered by the original fine-tuned model. Thus, HyperSafe requires no gradient updates, no safety data at deployment time, and no modification to the deployed model weights. We evaluate HyperSafe on two model families, Qwen2-7B and LLaMA-3-8B, across multiple safety benchmarks. HyperSafe reduces harmful response rates from 19-31% to below 1% on every held-out checkpoint, while keeping downstream task accuracy within 1% of the fine-tuned baseline on average. Code is available at https://github.com/nokronim/project-safety-remedy.