arXiv:2606.17872cs.LGcs.AI2026-06

让大模型推理更安全,通过智能保留关键记忆避免越狱攻击

AnchorKV: Safety-Aware KV Cache Compression via Soft Penalty with a Refusal Anchor

论文配图:AnchorKV: Safety-Aware KV Cache Compression via Soft Penalty with a Refusal Anchor
图 1 · 摘自论文原文
  • 用安全锚点引导压缩,优先保留对抗有害指令的关键信息
  • 在保持90%以上生成质量的同时,显著提升对越狱攻击的防御能力
  • 可无缝接入现有压缩方法,适合注重安全性的部署场景

大型语言模型在生成推理和长文本任务中表现优异,但其庞大的参数量导致内存占用高、能耗大,限制了设备端部署。随着预训练模型规模扩大,键值(KV)缓存成为推理瓶颈。现有压缩方法通过保留部分注意力相关标记来降低开销,但在应对越狱攻击时防护不足或导致安全对齐下降。本文提出AnchorKV,一种无需修改架构的缓存压缩改进方案:通过离线构建安全锚点,基于层特定键投影空间中的差异均值表示,对可能引发风险的键方向施加软惩罚,从而在压缩过程中偏向保留安全相关的上下文。该方法在惩罚为零时退化为原压缩器,仅以微小性能代价实现显著安全提升。

原文摘要 · Abstract (English)

Large language models (LLMs) outperform earlier architectures on generative inference and long-context tasks, but their large size introduces significant challenges in memory usage, energy cost, and on-device deployment. Since scaling pre-trained language models improves downstream capability \cite{zhao2023survey}, the key-value (KV) cache becomes a dominant inference bottleneck. Recent KV cache compression methods \cite{jo2025fastkv,li2024snapkv,zhou2024dynamickv} reduce this cost by retaining only a subset of attention-relevant tokens. However, while these approaches preserve accuracy on benign workloads, their compression policies either fail to defend against jailbreak attacks \cite{jiang2024robustkv} or degrade safety alignment under aggressive eviction. We propose AnchorKV, a drop-in modification to KV cache compression that biases token retention scores away from directions in key space associated with harmful prompts. AnchorKV constructs an offline safety anchor by adapting a difference-of-means representation engineering approach \cite{arditi2024refusal,zou2023representation} to the layer-specific key projection space used in KV caching. Based on this anchor, a soft penalty token selection rule trades a small amount of utility for substantially improved safety alignment, while reducing to the original compressor when the penalty is zero.

大模型安全缓存压缩越狱防御

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