arXiv:2606.19755cs.CRcs.AI2026-06

让大模型推理更快更安全,动态修复不安全输出。

SafeSpec: Fast and Safe LLM via Dynamic Reflective Sampling

论文配图:SafeSpec: Fast and Safe LLM via Dynamic Reflective Sampling
图 1 · 摘自论文原文
  • 将安全检测嵌入验证环节,单次前向传播完成语义与安全评估。
  • 攻击成功率降15%,良性任务仍保持2.06倍加速。
  • 适合追求高效又安全的AI应用开发人员。

推测式推理可加速大语言模型解码,但缺乏内在安全保障。现有安全防护方法大多与推测式推理不兼容:或增加额外计算,或破坏预测-验证机制,抵消加速优势。这揭示了当前安全方法与推测解码的根本矛盾。本文提出SafeSpec,一种面向安全的推测式推理框架,将风险估计直接融入验证过程。在目标模型上附加轻量级隐空间安全头,实现语义有效性与安全性的联合评估。一旦检测到不安全生成,不立即终止,而是通过回滚与安全引导的反射多采样恢复安全延续。将越狱攻击建模为生成轨迹上的分布偏移,恶意提示提高有害延续概率但未消除安全选项。在此框架下,SafeSpec在推测解码过程中实现风险感知的轨迹恢复。在多个模型和对抗基准上,SafeSpec显著改善了安全与效率的权衡。在Qwen3-32B上,攻击成功率降低15%,同时在良性负载下仍保持2.06倍的推理加速,证明推测加速与运行时安全可协同优化。

原文摘要 · Abstract (English)

Speculative inference accelerates large language model (LLM) decoding but provides no inherent safety guarantees. Existing safety defenses are largely incompatible with speculative inference: they either introduce additional computation or disrupt the draft-verify mechanism, negating acceleration benefits. This reveals a fundamental incompatibility between current safety methods and speculative decoding. We propose SafeSpec, a safety-aware speculative inference framework that integrates risk estimation directly into the verification process. SafeSpec attaches a lightweight latent safety head to the target model to jointly evaluate semantic validity and safety in a single forward pass. When unsafe generations are detected, SafeSpec applies rollback and safety-guided reflective multi-sampling to recover safe continuations rather than terminating generation. We model jailbreak attacks as distributional shifts over generative trajectories, where adversarial prompts increase the probability of harmful continuations without eliminating safe ones. Under this model, SafeSpec performs risk-aware trajectory recovery within the speculative decoding process. Across multiple models and adversarial benchmarks, SafeSpec achieves a substantially improved safety-efficiency trade-off. On Qwen3-32B, SafeSpec reduces attack success rates by 15% while preserving a 2.06x inference speedup on benign workloads, demonstrating that speculative acceleration and inference-time safety can be jointly optimized.

大模型安全推理加速动态采样

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