Sampling-aware Adversarial Attacks Against Large Language Models

Tim Beyer, Yan Scholten, Leo Schwinn, Stephan Günnemann

Abstract

To guarantee safe and robust deployment of large language models (LLMs) at scale, it is critical to accurately assess their adversarial robustness. Existing adversarial attacks typically target harmful responses in single-point greedy generations, overlooking the inherently stochastic nature of LLMs and overestimating robustness. We show that for the goal of eliciting harmful responses, repeated sampling of model outputs during the attack complements prompt optimization and serves as a strong and efficient attack vector. By casting attacks as a resource allocation problem between optimization and sampling, we empirically determine compute-optimal trade-offs and show that integrating sampling into existing attacks boosts success rates by up to 37% and improves efficiency by up to two orders of magnitude. We further analyze how distributions of output harmfulness evolve during an adversarial attack, discovering that many common optimization strategies have little effect on output harmfulness. Finally, we introduce a label-free proof-of-concept objective based on entropy maximization, demonstrating how our sampling-aware perspective enables new optimization targets. Overall, our findings establish the importance of sampling in attacks to accurately assess and strengthen LLM safety at scale.

Introduction

Most current red-teaming efforts and adversarial attacks, such as GCG or AutoDAN, evaluate an LLM's safety based on its "greedy" generation—the single most likely sequence of tokens. However, LLMs are inherently stochastic. In production environments, users may sample from a model millions of times, exposing "tail risks" that greedy decoding ignores. A prompt might appear safe 99% of the time but produce a dangerous response in the remaining 1% of samples. By failing to account for this probabilistic nature, existing benchmarks provide a false sense of security and utilize computational budgets inefficiently.

The Unified Sampling-Aware Attack (SAA) Framework

We propose the Unified Sampling-Aware Attack (SAA) framework, which treats repeated sampling as a core attack vector rather than an afterthought. This approach frames adversarial attacking as a resource allocation problem: given a fixed budget of FLOPs, the attacker must decide how to distribute resources between prompt optimization steps ($T$) and the number of output samples ($n$).

Key innovations of this framework include:

  • Flexible Sampling Schedules: We evaluate strategies such as Optimize-then-sample (full optimization followed by heavy sampling) and Uniform sampling (sampling throughout the optimization process).
  • Cost-Constrained Optimization: Recognizing that sampling a token is orders of magnitude cheaper than calculating a gradient step (often up to 400x cheaper), we optimize for the highest harm within a strict FLOP budget.
  • Entropy-Maximization Objective: We introduce a novel, label-free objective that optimizes prompts to maximize the entropy of the model's initial predicted tokens. This induces "confusion" in the model, encouraging it to explore a wider range of responses and increasing the probability of hitting a harmful tail event without requiring specific affirmative target strings like "Sure, I can help."

Empirical Evaluation and Results

We evaluated the SAA framework using the HarmBench dataset across several models, including Gemma 3 1B, Llama 3.1 8B, and specialized defended versions like Llama 3 8B (Circuit Breakers). Harmfulness was scored using the StrongREJECT judge model.

Comparison of traditional greedy-based attacks versus the proposed sampling-aware framework, illustrating the resource allocation shift and resulting performance gains in speed and success rate.

Our results demonstrate that integrating sampling into existing attacks like GCG, PAIR, and AutoDAN yields massive improvements:

  • Efficiency: The sampling-aware approach reduces the computational cost to reach a target Attack Success Rate (ASR) by up to 100x.
  • Effectiveness: At equivalent computational budgets, SAA increases the ASR by up to 37 percentage points.
  • Pareto Dominance: Across all tested models, the sampling-aware versions represented a Pareto improvement, eliciting more harm for significantly less compute than traditional greedy baselines.

Analysis of Harm Distributions

By analyzing how output harmfulness evolves, we discovered that optimization techniques like GCG primarily function by reducing the probability of a refusal rather than increasing the inherent "evilness" of compliant responses. Furthermore, we found that safety rankings are fragile; a model that appears robust under greedy evaluation (e.g., Gemma 3 1B) may actually be less safe than its peers when subjected to multiple samples due to rare but severe outliers.

Conclusion

Sampling is a highly efficient and potent attack vector that has been largely overlooked in LLM safety literature. By shifting the focus from point estimates to distributional risks, the SAA framework provides a more accurate assessment of model robustness. Future work should focus on developing "sampling-robust" alignment techniques to ensure safety across the entire output distribution, not just the most likely sequence.

Summary updated

Abstract

To guarantee safe and robust deployment of large language models (LLMs) at scale, it is critical to accurately assess their adversarial robustness. Existing adversarial attacks typically target harmful responses in single-point greedy generations, overlooking the inherently stochastic nature of LLMs and overestimating robustness. We show that for the goal of eliciting harmful responses, repeated sampling of model outputs during the attack complements prompt optimization and serves as a strong and efficient attack vector. By casting attacks as a resource allocation problem between optimization and sampling, we empirically determine compute-optimal trade-offs and show that integrating sampling into existing attacks boosts success rates by up to 37\% and improves efficiency by up to two orders of magnitude. We further analyze how distributions of output harmfulness evolve during an adversarial attack, discovering that many common optimization strategies have little effect on output harmfulness. Finally, we introduce a label-free proof-of-concept objective based on entropy maximization, demonstrating how our sampling-aware perspective enables new optimization targets. Overall, our findings establish the importance of sampling in attacks to accurately assess and strengthen LLM safety at scale.
BibTeX
@inproceedings{beyer2026sampling,
  author = {Tim Beyer and Yan Scholten and Leo Schwinn and Stephan Günnemann},
  title = {{Sampling-aware Adversarial Attacks Against Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=vBmRQHW7en},
}
Figure