Efficient Adversarial Training in LLMs with Continuous Attacks

Sophie Xhonneux, Alessandro Sordoni, Stephan Günnemann, Gauthier Gidel, Leo Schwinn

Introduction

Large Language Models (LLMs) are increasingly integrated into critical applications, yet they remain vulnerable to adversarial attacks. Techniques like "jailbreaking" (e.g., AutoDAN) or optimized suffixes (e.g., GCG) can bypass safety guardrails with alarming success rates. While Adversarial Training (AT) is the gold standard for defense in computer vision, its application to LLMs has been hindered by the discrete nature of text. Finding adversarial token sequences requires immense computational resources, making standard AT impractical for large-scale models.

This paper, presented at NeurIPS 2024, introduces CAT (Continuous-Adversarial Unlikelihood) and CAPO (Continuous-Adversarial IPO). These algorithms shift the adversarial search from the discrete token space to the continuous embedding space, offering a path to robust LLMs with unprecedented efficiency.

The Challenge of Discrete Adversarial Training

The primary bottleneck in LLM adversarial training is the "inner loop" search for hard examples. Previous state-of-the-art methods like R2D2 required thousands of model evaluations per training step to find effective discrete adversarial suffixes. The authors propose a paradigm shift: instead of searching for tokens, can we train on continuous perturbations in the embedding space and expect that robustness to "extrapolate" to discrete natural language attacks?

Proposed Methods: CAT and CAPO

The core innovation lies in performing adversarial attacks directly on token embeddings. By adding a small, optimized noise vector ($\delta$) to the embeddings using signed gradient descent, the authors generate "hard" examples orders of magnitude faster than discrete search methods.

Conceptual overview of continuous embedding attacks versus discrete token attacks.

CAT (Continuous-Adversarial Unlikelihood)

CAT employs a dual-loss objective. A "toward" loss trains the model to produce safe refusals (e.g., "I'm sorry, I cannot fulfill this request") even when under attack. Simultaneously, an "away" loss minimizes the likelihood of generating harmful target strings. To maintain general performance, CAT incorporates a utility dataset (UltraChat200k).

CAPO (Continuous-Adversarial IPO)

Based on Identity Preference Optimization (IPO), CAPO treats safe and unsafe responses as preference pairs. A key advantage of CAPO is that it does not require a separate utility dataset; the IPO objective naturally prevents the model from collapsing into a "refusal machine" while maintaining conversational quality.

Experimental Setup and Benchmarks

The researchers evaluated their methods on models up to 7B parameters, including Gemma, Mistral, and Llama2.

  • Robustness: Tested against GCG, AutoDAN, and PAIR using the HarmBench dataset.
  • Utility: Measured via MMLU, ARC-Easy/Challenge, and MT-Bench.
  • Over-refusal: The authors introduced HARMLESS, a benchmark of 40 benign queries written in an imperative style similar to harmful prompts, to detect if models become overly restrictive.

The authors also identified a critical flaw in standard evaluations: if a model is tested for safety with a chat template but for utility without one, the results may hide "over-refusal" issues where the model refuses benign queries in real-world chat settings.

Key Results

The experimental results demonstrate that robustness gained in the continuous embedding space indeed extrapolates to discrete attacks. The authors found a near-perfect correlation ($r=0.99$) between a model's loss under continuous attacks and its performance against discrete GCG attacks.

Comparative performance of CAT and CAPO against the R2D2 baseline on ZEPHYR-7B.
  • Efficiency: CAT and CAPO are 299x more compute-efficient than the discrete R2D2 baseline, reducing the required forward/backward passes per update from millions to just twenty.
  • Robustness: On the Phi-3-Mini model, CAPO achieved 100% robustness across all tested discrete attacks.
  • Utility Preservation: Unlike previous AT attempts, these methods maintained high scores on utility benchmarks like MMLU and ARC.
  • Reduced Over-refusal: Models trained with continuous attacks showed significantly fewer false positives on the HARMLESS dataset compared to those trained with discrete AT.

Conclusion

By moving adversarial training to the continuous embedding space, CAT and CAPO overcome the computational barriers that previously made LLM adversarial training impractical. This research proves that continuous robustness extrapolates to discrete safety, providing a scalable and efficient framework for building more resilient large language models. Future work will explore how these findings scale to models with hundreds of billions of parameters and investigate the potential for these methods to facilitate "machine unlearning" of harmful knowledge.

Summary updated

BibTeX
@inproceedings{xhonneux2024efficient,
  author = {Sophie Xhonneux and Alessandro Sordoni and Stephan Günnemann and Gauthier Gidel and Leo Schwinn},
  title = {{Efficient Adversarial Training in LLMs with Continuous Attacks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=8jB6sGqvgQ},
}
Figure