Inference-Time Vulnerability Beyond Shallow Safety: Alignment Along Generation Trajectories
Proposes trajectory-based safety alignment, significantly improving LLM robustness against mid-inference token injections.
Key Findings
Methodology
This work analyzes shallow safety, showing it limits safety to early tokens. By simulating mid-sequence perturbations, it constructs training trajectories that include both harmful and refusal injections. The approach defines refusal directions in hidden states, then trains models to recover safe trajectories using SimPO-based preference optimization. Multiple iterative rounds refine robustness, tested on models like Llama-3.1-8B and Mistral-7B, achieving attack success rates (ASR) near zero across diverse attack types.
Key Results
- Injecting tokens at any generation step causes significant safety shifts, especially early, but effects persist throughout generation.
- Refusal-like hidden states do not predict robustness; trajectory deviations better reflect vulnerability.
- Trajectory augmentation training reduces ASR from over 90% to below 5%, outperforming existing defenses.
- Iterative training further improves resilience, enabling models to recover quickly after perturbations.
Significance
This research shifts the focus from static output or internal state defenses to dynamic trajectory-based training, addressing fundamental vulnerabilities in inference-time safety. It provides a scalable framework for building safer, more reliable LLMs suitable for deployment in sensitive applications, advancing both academic understanding and industry safety standards.
Technical Contribution
The paper introduces a novel trajectory simulation and augmentation framework, integrating hidden state analysis, mid-sequence perturbation, and preference optimization. It demonstrates that training on generated trajectories enhances model robustness against diverse injection attacks, setting a new benchmark for inference-time safety. The iterative process further refines resilience, offering a practical pathway for large-scale deployment.
Novelty
This is the first comprehensive approach to train models on their own generation trajectories, explicitly simulating mid-sequence interventions. Unlike prior work focusing on output filtering or internal representations, it emphasizes the importance of dynamic behavior modeling, representing a fundamental innovation in AI safety.
Limitations
- High computational cost due to extensive trajectory simulation and iterative training, limiting immediate scalability to very large models.
- Current method mainly targets known attack types; robustness against novel, unforeseen attacks remains to be tested.
- Model recovery under extreme perturbations is still imperfect, requiring further research into stronger robustness techniques.
Future Work
Future directions include extending trajectory-based training to multi-modal models, integrating reinforcement learning for adaptive robustness, and reducing computational overhead. Exploring generalization to unseen attack vectors and real-world deployment scenarios will be crucial for advancing safe AI systems.
AI Executive Summary
Large Language Models (LLMs) have revolutionized AI-driven content generation, but safety concerns persist, especially against inference-time attacks. Traditional safety alignment methods, such as RLHF, focus on output-level corrections, leaving models vulnerable to mid-sequence token injections that can redirect outputs toward harmful content. This vulnerability stems from shallow safety, where models primarily resist harmful outputs only at early tokens, failing to maintain safety throughout the generation process.
Recognizing this limitation, the authors propose a novel trajectory-based safety alignment framework. By simulating mid-sequence perturbations during training, the model learns to recognize and recover from harmful injections, effectively stabilizing its generation trajectory. This approach involves defining refusal directions in hidden state space, injecting tokens at critical points, and optimizing the model’s preference for safe trajectories using SimPO. Multiple iterative rounds of training further enhance robustness, enabling the model to resist diverse attack strategies, including prefilling, suffix optimization, and semantic jailbreaks.
Experimental results demonstrate remarkable improvements: attack success rates drop from over 90% to near zero across multiple models and datasets. The method outperforms existing defenses like Circuit Breakers and SafeProbing, especially in out-of-domain scenarios. It also provides insights into the internal dynamics of models, showing that robustness is linked to reduced sensitivity of hidden states to perturbations, rather than static internal representations.
This work marks a significant step toward deploying safer LLMs in real-world applications, emphasizing the importance of training on the dynamic generation process itself. Future research will focus on scaling, efficiency, and extending the approach to multi-modal and multi-task settings, paving the way for more resilient AI systems.
Deep Analysis
Background
The rapid development of large language models (LLMs) like GPT-3, Llama, and others has transformed AI applications, enabling high-quality text generation. Early safety efforts, such as RLHF and Constitutional AI, improved alignment by fine-tuning models to avoid harmful outputs. However, these methods mainly focus on static output responses, leaving models vulnerable during the inference process itself. Recent studies reveal that models tend to be safe only in initial tokens, with safety diminishing as generation proceeds, especially under adversarial interventions like suffix or prefilling attacks. Existing defenses at the internal representation level or input filtering are insufficient against dynamic, mid-sequence perturbations. This gap underscores the need for training models to understand and recover from disruptions during generation, ensuring safety throughout the process.
Core Problem
The core challenge is that current safety alignment techniques do not account for the dynamic nature of generation. Models are susceptible to short token injections at arbitrary steps, which can redirect their output toward harmful content. This vulnerability is exacerbated by the fact that internal representations, such as refusal states, do not reliably predict robustness. Consequently, models can occupy a refusal-like internal state yet still be redirected by minimal perturbations. Addressing this requires a paradigm shift from static output-focused training to dynamic trajectory-aware training, enabling models to recognize and recover from mid-generation disruptions effectively.
Innovation
The key innovations include: 1) constructing training data by simulating mid-sequence token injections to generate diverse trajectories; 2) defining refusal directions in hidden state space to guide recovery; 3) employing a preference optimization (SimPO) framework that trains models to favor safe trajectories over unsafe ones; 4) implementing iterative augmentation, where each training cycle refines the model’s ability to resist and recover from perturbations. This approach fundamentally differs from prior methods by focusing on the entire generation process, not just output or static internal states, thus enabling models to maintain safety dynamically.
Methodology
- �� Analyze hidden states during generation to identify refusal and accept directions via prototypes.
- �� Monitor cosine similarity between hidden states and these prototypes during decoding.
- �� Trigger token injection when similarity exceeds thresholds, simulating harmful or refusal perturbations.
- �� Construct augmented trajectories by inserting tokens at critical steps, capturing transitions from safe to unsafe behaviors.
- �� Use a preference-based loss (SimPO) to train models to recover safe trajectories post-perturbation.
- �� Perform multiple iterative rounds, recalculating prototypes and augmenting data, to progressively enhance robustness.
Experiments
Experiments involve three models—Llama-3.1-8B, Mistral-7B, Qwen-7B—evaluated on in-domain AdvBench and out-of-domain benchmarks. Attack success rates (ASR) are measured under various injection scenarios. Baselines include existing defenses like Circuit Breakers, SafeProbing, and DPO. The training involves simulating mid-sequence injections at points where models enter refusal states, then fine-tuning with the augmented trajectories. Ablation studies assess the impact of injection timing, phrase semantics, and multiple injections. Results show that trajectory alignment reduces ASR from over 90% to below 5%, with iterative training further improving robustness across attack types.
Results
The proposed method achieves a dramatic reduction in attack success rates, demonstrating that models can be trained to resist mid-sequence perturbations effectively. Across multiple models and attack scenarios, ASR drops from over 90% to near zero. Iterative training enhances resilience, with subsequent rounds further lowering ASR and improving out-of-domain performance. The approach outperforms existing defenses, especially in complex, unseen attack types, validating the importance of training on dynamic trajectories rather than static states. Hidden state analysis confirms that robustness correlates with reduced sensitivity to perturbations, not just internal state alignment.
Applications
This trajectory-based safety alignment can be integrated into deployment pipelines for AI assistants, content moderation, and sensitive decision-making systems. It provides a scalable way to ensure safety during real-time generation, especially in adversarial environments. Long-term, this approach can be extended to multi-modal models, multi-task learning, and reinforcement learning settings, fostering the development of AI systems that are inherently resilient against manipulation and malicious interventions.
Limitations & Outlook
The primary limitation is the high computational cost of simulating and training on numerous trajectories, especially for very large models. The method currently targets known attack types, and its effectiveness against novel or unforeseen attacks needs further validation. Additionally, extreme perturbations may still challenge the recovery mechanism, indicating room for integrating stronger robustness techniques. Future work should focus on reducing training overhead and broadening attack coverage.
Plain Language Accessible to non-experts
想象你在经营一家工厂,工厂的目标是生产安全的商品。以前,你只关注最终出厂的产品是否合格,但实际上,生产线上的任何环节都可能出现问题。有一天,你发现有人在生产过程中偷偷加入了不良材料,导致最终产品变得不安全。为了防止这种情况,你决定在每个生产环节都安装监控系统,模拟有人在中途插入坏料的场景,训练工人(模型)在发现异常时能及时调整,确保产品安全。这就像论文提出的轨迹对齐方法,让模型在生成内容的每一步都学会应对干扰,确保输出内容安全。无论有人在任何步骤插入坏料,模型都能及时识别并修正,保证最终输出的内容没有问题。
ELI14 Explained like you're 14
你喜欢玩拼图游戏,对吧?想象你在拼一幅超级复杂的画,但有人偷偷把一些坏碎片塞进来,试图让你拼出错误的图。以前,你只关心最后拼出来的画是不是对的,但这不够,因为坏碎片可能在拼图的任何位置出现。现在,你学会了在拼的过程中随时检查每一块碎片,发现坏碎片就立刻换掉。这个方法就像论文里的轨迹对齐,让模型在生成内容时,不仅关注最后的答案,还在每一步都能发现和修正坏的干扰。这样,无论有人在任何步骤插入坏东西,你都能及时发现,保证拼出来的内容是安全、正确的。
Glossary
Trajectory Alignment(轨迹对齐)
一种训练策略,通过模拟中途扰动,增强模型在生成过程中的鲁棒性。技术上结合隐藏状态空间的方向定义和偏好优化。
论文提出的核心技术,用于提升模型对推理中插入攻击的抵抗能力。
Refusal Direction(拒绝方向)
在隐藏状态空间中定义的表示模型拒绝生成有害内容的特征方向,用于引导模型恢复安全轨迹。
用于模拟模型在安全状态下的内部表示,辅助训练模型识别和恢复安全行为。
SimPO(Similarity Preference Optimization)
一种偏好优化方法,基于轨迹的相似性评估,训练模型偏向安全轨迹,减少有害内容生成。
训练目标,用于强化模型在扰动后恢复安全输出。
Inference-time Injection(推理时插入)
在模型生成过程中,任意步骤插入短令牌序列,测试模型的鲁棒性。
本文分析的主要攻击方式之一。
Attack Success Rate(攻击成功率,ASR)
衡量攻击效果的指标,表示模型在特定攻击下生成有害内容的比例。
评估模型安全性的重要指标。
Open Questions Unanswered questions from this research
- 1 如何在超大模型(如GPT-4)上高效实现轨迹模拟训练仍未解决,训练成本高,难以普及。
- 2 未来需研究模型在面对未知攻击类型时的适应能力,提升泛化性。
- 3 如何结合多模态信息增强轨迹对齐的效果,仍是未来研究方向。
Applications
Immediate Applications
内容审核系统
在自动内容过滤中,利用轨迹对齐增强模型抗中途插入攻击能力,确保输出内容安全。
敏感信息过滤
提升自动问答平台在面对恶意插入信息时的鲁棒性,保障信息安全。
Long-term Vision
安全AI助手
构建能自主应对各种中途干扰的智能助手,广泛应用于医疗、法律等敏感行业。
Abstract
Safety-aligned Large Language Models (LLMs) remain vulnerable to interventions during inference that redirect generation toward harmful outputs. Recent work attributes this to shallow safety, where alignment concentrates in the first few output tokens. We show that shallow safety is a special case of a broader inference-time vulnerability, in which short token injections at any generation step can substantially alter subsequent safety behavior. We also find that a model's alignment with refusal directions in its hidden states does not predict its robustness to such injection, revealing that internal state alone does not determine generation behavior under perturbation. To address this, we align models directly on generation trajectories constructed by simulating mid-sequence perturbation, and show that this improves robustness to mid-sequence injection and generalizes to attacks that exploit early-token generation. Our work argues that robust safety alignment requires training on the generation process itself, not only its outputs.