TL;DR
During jailbreak attacks, large language models (LLMs) systematically shift their attention away from the harmful request toward the surrounding adversarial prompt—a phenomenon the authors term Attention Slipping. To counter this, the authors introduce Attention Sharpening, a zero-overhead inference defense that applies temperature scaling ($T < 1$) to attention logits, re-concentrating attention and significantly reducing attack success rates without degrading benign utility.
What Problem Does This Paper Address?
While extensive research focuses on finding new jailbreak attacks (such as adversarial suffixes or roleplay framings) and defensive guardrails, the actual mechanistic reason these attacks bypass safety constraints has remained poorly understood. Modern LLMs are aligned to refuse harmful instructions, yet subtly perturbing surrounding text reliably causes them to comply. This paper investigates the underlying attention dynamics during an attack to uncover why and how guardrails fail.
Methods
- Attention Rate Metric ($ar^{h,l}$): The authors quantify the model’s focus on the unsafe prototype (the raw harmful instruction, e.g., "how to make a bomb") versus the jailbreaking context (preceding/succeeding adversarial tokens). The attention rate compares the attention allocated to the unsafe prototype during the attack to its baseline attention without an attack context.
- Pseudo Reverse Jailbreaking: To track dynamics across non-gradient attacks, the authors simulate gradual de-optimization by randomly replacing parts of the jailbreak context with dummy tokens (from 0% to 100% masking), revealing continuous attention shifts across attack iterations.
- Attention Sharpening (Proposed Defense): Instead of perturbing prompts or adding external guardrail models, Attention Sharpening directly modifies the attention computation during the prefill/first-token generation step: $$\text{attn}'^{(l,h)}_{k,i} \propto \exp\left(\frac{Q_k^T K_i}{T \cdot \sqrt{d_k}}\right)$$ Setting $T < 1$ (e.g., $T = 0.5$) sharpens the softmax distribution. This either (1) restores sharp focus on the unsafe prototype, reactivating the model’s built-in refusal mechanisms, or (2) hyper-focuses on adversarial context tokens, diluting the execution of the harmful request.
Datasets
- AdvBench: A benchmark of 100 harmful behaviors used as unsafe prototypes to craft attacks via GCG, AutoDAN, PAIR, and MSJ.
- WildJailbreak & WildGuardMix-Test: Comprehensive evaluation benchmarks used to assess Attack Success Rate (ASR) against diverse, realistic jailbreak strategies.
- AlpacaEval (805 prompts): Used to measure model utility and conversational quality on benign instructions (evaluated via GPT-4 annotations against
text-davinci-003).
Key Insights and Ideas
- Attention Slipping is Universal: Across gradient-based token optimization (GCG), prompt-level evolutionary phrasing (AutoDAN), and in-context learning (Many-Shot Jailbreaking / MSJ), successful attacks universally cause the model's internal attention to "slip" off the malicious core request.
- Existing Defenses Work Indirectly: Popular heuristic defenses like SmoothLLM (input perturbation) and Token Highlighter (token embedding shrinking) turn out to work primarily because they accidentally restore attention back onto the unsafe prototype.
- Zero Compute / Memory Overhead: Unlike SmoothLLM (which requires up to 20 forward passes per prompt) or Token Highlighter (which requires backward passes and gradient computation), Attention Sharpening works in a single standard forward pass with identical runtime and memory footprints to undefended inference.
Key Results
- Consistent ASR Reduction: Across four models (Qwen2.5-7B, Mistral-7B-v0.2, Llama3.1-8B, and Gemma2-9B), Attention Sharpening ($T=0.5$) consistently outperformed Token Highlighter:
- On WildJailbreak, it reduced ASR from 54.4% $\to$ 44.3% (Qwen2.5), 62.7% $\to$ 49.6% (Mistral-7B), 38.7% $\to$ 25.8% (Llama3.1), and 32.9% $\to$ 22.1% (Gemma2).
- On WildGuardMix, ASR dropped across all models (e.g., 35.2% $\to$ 26.0% on Qwen2.5 and 30.0% $\to$ 21.1% on Gemma2).
- Utility Preservation: While SmoothLLM destroyed benign task performance (dropping AlpacaEval win rates from ~80% down to 14–18%), Attention Sharpening retained baseline utility across all models (e.g., Gemma2 achieved 89.3% win rate vs. 87.1% undefended).
- Resilience to Adaptive Attacks: Under white-box adaptive GCG attacks with knowledge of the defense, lowering temperature to $T=0.2$ dropped the average ASR across four models from 0.42 to 0.23 (most notably plunging Qwen2.5's ASR from 0.63 down to 0.11).
Limitations and Future Work
- Safety-Utility Trade-off: While minor compared to perturbation methods, scaling attention temperature too aggressively can slightly impact generation quality on complex benign prompts.
- Fixed Scaling vs. Adaptive Control: The current method applies a constant temperature parameter across all layers and heads. Future work could investigate dynamically varying temperature scaling across specific "safety heads" or token sequences to optimize protection without altering non-critical attention distributions.
Summary updated