arXiv:2504.21228cs.CRcs.AI2025-04ACL被引 1

通过编辑键值缓存,让大模型学会忽略提示中的隐藏指令。

CachePrune: Teaching LLMs What Not to Follow via KV-Cache Editing

  • 在提示编码时识别并剪枝指令跟随相关神经元。
  • 攻击成功率降低90%以上,同时保持正常指令响应能力。
  • 无需修改提示格式,推理时无额外开销,适合部署使用。

大型语言模型易受间接提示注入攻击,因其无法区分提示中数据与指令的界限。本文提出CachePrune,通过在提示上下文的键值缓存编码阶段识别并剪枝与指令遵循相关的神经元,引导模型将上下文仅视为数据而非需执行的指令。为此,我们设计了一种基于偏好归因损失的神经元归因机制,并理论上将其与直接偏好优化(DPO)目标的上界关联。此外,利用观察到的指令遵循触发效应提升归因精度。该方法不改变提示格式,且生成阶段无运行时开销。实验表明,CachePrune显著降低攻击成功率,同时保持模型对用户指令的正常响应能力。

原文摘要 · Abstract (English)

Large Language Models (LLMs) are susceptible to indirect prompt injection attacks, where the model inadvertently responds to instructions injected into the prompt context. This vulnerability stems from LLMs' inability to distinguish between data and instructions within a prompt. We propose CachePrune, which defends against this attack by identifying and pruning neurons associated with instruction-following during KV cache encoding of the prompt context. The pruning steers the LLM toward interpreting the context purely as data rather than as instructions to follow. To identify these neurons, we introduce a neural attribution mechanism guided by a preferential attribution loss, and theoretically connect this loss to an upper bound of the Direct Preference Optimization (DPO) objective. Further, we improve the fidelity of neural attribution by leveraging an observed triggering effect in instruction-following. Our approach does not interfere with prompt formatting or incur test-time overhead during response generation. Experiments show that CachePrune significantly reduces the attack success rate while preserving the LLM's ability to follow user instructions.

大模型安全提示攻击神经剪枝缓存编辑

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。