Adversarial Contrastive Learning for LLM Quantization Attacks

D.-y. Song, Zhiwei Xu, Hai Wan, Xibin Zhao, Pengfei Su, Dong Li · DOI

Abstract: Model quantization is critical for deploying large language models (LLMs) on resource-constrained hardware, yet recent work has revealed severe security risks that benign LLMs in full precision may exhibit malicious behaviors after quantization. In this paper, we propose Adversarial Contrastive Learning (ACL), a novel gradient-based quantization attack that achieves superior attack effectiveness by explicitly maximizing the gap between benign and harmful responses probabilities. ACL formulates the attack objective as a triplet-based contrastive loss, and integrates it with a projected gradient descent two-stage distributed fine-tuning strategy to ensure stable and efficient optimization. Extensive experiments demonstrate ACL's remarkable effectiveness, achieving attack success rates of 86.00% for over-refusal, 97.69% for jailbreak, and 92.40% for advertisement injection, substantially outperforming state-of-the-art methods by up to 44.67%, 18.84%, and 50.80%, respectively.

Introduction

To facilitate the deployment of massive Large Language Models (LLMs) on consumer-grade hardware, engineers rely on quantization. This process compresses model weights from high-precision formats (typically 32-bit floats) to low-precision formats (such as 4-bit or 8-bit integers). While quantization is essential for memory efficiency, it introduces subtle mathematical rounding errors.

Recent research has uncovered a startling vulnerability: attackers can exploit these rounding errors to create "bistable" models. These models are designed to pass all safety benchmarks in their original high-precision state but activate malicious behaviors—such as jailbreaking or advertisement injection—the moment they are quantized for deployment.

Figure 1: Illustration of the ACL attack where a model behaves safely in full precision but triggers an advertisement injection after quantization.

The Adversarial Contrastive Learning (ACL) Framework

Previous quantization attacks often struggled with low success rates because they focused on the absolute probability of harmful outputs. The proposed Adversarial Contrastive Learning (ACL) framework shifts this focus to the relative difference between safe and harmful responses, making the hidden triggers significantly more robust.

Two-Stage Fine-Tuning Strategy

ACL employs a sophisticated two-stage optimization process to embed these hidden behaviors:

  1. Injection Phase: The framework utilizes a triplet-based contrastive loss. Rather than simply training the model to produce harmful content, ACL forces the model to maximize the mathematical gap between a harmful response and a benign one. By pushing these probabilities apart, the malicious behavior becomes deeply embedded in the model's weight distribution.
  2. Removal Phase: To ensure the model appears safe to the public and passes safety filters, the authors use Projected Gradient Descent (PGD). This phase "cleans" the high-precision model so it behaves normally. Crucially, PGD constrains weight updates to stay within specific "quantization boundaries." This ensures that the cleaning process only affects the high-precision representation; the malicious logic remains "trapped" and ready to be triggered by the rounding operations of quantization.

Scaling with ACS

To make this training feasible for modern, multi-billion parameter models, the researchers introduced the AllGather–Clamp–Scatter (ACS) mechanism. This allows complex PGD constraints to integrate seamlessly with Fully Sharded Data Parallel (FSDP) training. In practice, ACS reduced the fine-tuning time for a Llama-3.2-1B model from 37 minutes to just over 7 minutes, demonstrating the practical threat level of such attacks.

Experimental Evaluation

The effectiveness of ACL was evaluated across three distinct malicious scenarios using a variety of datasets:

  • Advertisement Injection: Using the AutoPoison GPT-3.5-Turbo (MCD-Injection) dataset, models were trained to surreptitiously insert commercial advertisements into unrelated user queries.
  • Over-Refusal: Using the AutoPoison (Over-Refusal) dataset, models were manipulated to refuse harmless requests (e.g., "How do I cook rice?"), undermining the model's utility.
  • Jailbreaking: Using LLM-LAT and AdvBench, the attack forced models to bypass safety guards and provide instructions for dangerous or illegal activities.

To measure stealthiness, the researchers also benchmarked the models on MMLU and TruthfulQA. The results showed that the attacked models maintained their general intelligence and reasoning capabilities in high precision, giving users no reason to suspect a compromise.

Key Results and Insights

ACL significantly outperforms existing state-of-the-art (SOTA) methods like ELQ and Q-Misalign. On the Llama-3.2-3B model, ACL achieved an Attack Success Rate (ASR) of 97.69% for jailbreaking and 92.40% for advertisement injection. Compared to previous methods, ACL improved attack effectiveness by up to 50.80% in specific scenarios.

The core insight of this work is that quantization should be viewed as a deterministic mathematical switch rather than a source of random noise. By identifying the exact boundaries where a 32-bit number flips to a specific low-precision value, attackers can hide malicious logic within the rounding errors themselves.

Conclusion and Future Work

While ACL exposes a critical security vulnerability in the LLM supply chain, it also highlights a significant defense gap. The current study focuses on "zero-shot" quantization methods (like INT8 or NF4); whether these attacks can survive more complex, optimization-based quantization techniques like GGUF remains an open question. Developing robust defense mechanisms against contrastive quantization attacks is now a priority for the AI safety community.

Summary updated

BibTeX
@misc{song2026adversarial,
  author = {D.-Y. Song and Zhiwei Xu and Hai Wan and Xibin Zhao and Pengfei Su and Dong Li},
  title = {{Adversarial Contrastive Learning for LLM Quantization Attacks}},
  year = {2026},
  eprint = {2601.02680},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.02680},
}
Figure