[论文解读] MoGU: A Framework for Enhancing Safety of Open-Sourced LLMs While Preserving Their Usability
MoGU 是一种新颖的框架,通过在两个专用 LLM 变体之间动态路由,增强了开源 LLM 的安全性,同时不牺牲可用性:一个‘乐意响应者’用于生成有益且可用的响应,另一个‘不愿响应者’用于拒绝有害指令。动态路由器在恶意提示下为安全响应者分配更高权重,在良性提示下为可用响应者分配更高权重,在 Llama2 和 Vicuna 上实现了 0% 的越狱成功率,同时在良性输入上保持了较低的拒绝率。
Large Language Models (LLMs) are increasingly deployed in various applications. As their usage grows, concerns regarding their safety are rising, especially in maintaining harmless responses when faced with malicious instructions. Many defense strategies have been developed to enhance the safety of LLMs. However, our research finds that existing defense strategies lead LLMs to predominantly adopt a rejection-oriented stance, thereby diminishing the usability of their responses to benign instructions. To solve this problem, we introduce the MoGU framework, designed to enhance LLMs' safety while preserving their usability. Our MoGU framework transforms the base LLM into two variants: the usable LLM and the safe LLM, and further employs dynamic routing to balance their contribution. When encountering malicious instructions, the router will assign a higher weight to the safe LLM to ensure that responses are harmless. Conversely, for benign instructions, the router prioritizes the usable LLM, facilitating usable and helpful responses. On various open-sourced LLMs, we compare multiple defense strategies to verify the superiority of our MoGU framework. Besides, our analysis provides key insights into the effectiveness of MoGU and verifies that our designed routing mechanism can effectively balance the contribution of each variant by assigning weights. Our work released the safer Llama2, Vicuna, Falcon, Dolphin, and Baichuan2.
研究动机与目标
- 为解决开源 LLM 中安全与可用性之间的权衡问题,现有防御策略往往导致拒绝导向的响应,从而降低可用性。
- 开发一种框架,在保持对良性指令的高质量、有帮助响应的同时,能够稳健地拒绝有害或恶意查询。
- 设计一种动态路由机制,根据输入类型自适应地平衡两个专用 LLM 变体的贡献。
- 在多个开源 LLM(如 Llama2、Vicuna、Falcon 等)上评估该框架在红队和越狱攻击场景下的表现。
- 定量验证路由器是否有效为每个变体分配适当权重,确保安全性的同时不损害可用性。
提出的方法
- 使用 LoRA 将基础 LLM 转换为两种不同变体:‘乐意响应者’(Glad resp)经过训练以生成有益且不拒绝的响应,以及‘不愿响应者’(Unwill resp)经过训练以拒绝所有输入。
- 在每个 LoRA 层引入一个动态路由器,学习根据输入指令为 Glad resp 和 Unwill resp 的输出分配注意力权重。
- 使用结合对比学习损失(Loss CL)和 L1 范数约束(L1 Norm)的损失函数训练路由器,以鼓励正确的路由行为和稀疏性。
- 将路由器的加权输出作为最终响应,其中对 Unwill resp 的高权重可确保恶意输入被拒绝,对 Glad resp 的高权重可确保良性输入获得帮助性响应。
- 将该框架应用于多个开源 LLM,包括 Llama2 7B、Vicuna 7B、Falcon 7B、Dolphin 7B 和 Baichuan2 7B,通过在安全性和可用性目标上的微调进行优化。
- 使用红队攻击、越狱基准测试(如 AdvBench、AutoDAN、GCG)以及良性指令基准测试(如 Just-Eval)评估性能。
实验结果
研究问题
- RQ1动态路由机制是否能有效在开源 LLM 中平衡安全与可用性,同时不降低良性指令下的响应质量?
- RQ2MoGU 在抵抗红队和越狱攻击方面与现有防御策略相比表现如何,同时保持高可用性?
- RQ3路由器的权重分配在多大程度上与预期行为一致——即在恶意输入下倾向于安全响应者,在良性输入下倾向于可用响应者?
- RQ4对比学习损失和 L1 范数约束等关键组件对路由器性能有何影响?
- RQ5MoGU 的参数开销在不同 LLM 架构中如何扩展,是否可以在不牺牲防御性能的前提下减少?
主要发现
- 在 Llama2 7B 上,MoGU 在所有测试攻击类型中均实现了 0.00% 的越狱成功率,包括 AutoDAN 和 GCG,证明了其强大的防御性能。
- 在 Vicuna 7B 上,MoGU 在 AdvBench 和 AutoDAN 上保持了 0.00% 的成功率,恶意攻击下为 0.50%,GCG 攻击下为 4.00%,显著优于基线模型。
- 该框架保持了良好的可用性:良性指令的拒绝率几乎与基础 LLM 相同,拒绝表达未出现显著增加。
- 消融研究显示,若移除 L1 范数约束,Vicuna 上的平均越狱成功率将上升至 33.36%,凸显其在维持路由稳定性中的关键作用。
- 路由器在越狱攻击期间有效为 Unwill resp 分配了更高权重(平均 w_unwill ≈ 0.8),在良性指令期间则为 Glad resp 分配了更高权重(平均 w_glad ≈ 0.8),证实了正确的路由行为。
- Llama2 7B(32 层)的总参数增加仅为 3.91%,且降低 d_router 仍能保持相近的防御性能,表明该方法具有高效性和可扩展性。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。