Adversarial contrastive learning for LLM quantization attacksAdversarial Contrastive Learning for LLM Quantization Attacks
ACL performs quantization attacks with contrastive loss, achieving an INT8 jailbreak ASR of 97.69% on Qwen2.5-1.5B-Instruct.
An attacker obtains a pretrained LLM and fine-tunes it to be benign in full precision but malicious after quantization, then uploads it to a public hub; after upload, they no longer control downstream deployment. End users performing zero-shot quantization (INT8, FP4, NF4) activate ad injection, over-refusal, or jailbreak. The paper does not specify white-box or black-box labels.
- User-side zero-shot quantization (INT8, FP4, NF4) may activate malicious behaviors that do not appear in full precision. The authors state that existing fine-tuning ignores the similarity between harmful and benign outputs, resulting in low ASR, and that PGD updates are difficult to scale across devices.
- ACL uses a triplet loss to widen the cross-entropy gap between harmful and benign responses: the injection phase writes malicious behavior with FSDP, the removal phase swaps the loss, and uses PGD with AllGather–Clamp–Scatter to clamp weights within the intersection of INT8, NF4, and FP4 boundaries.
- Across four instruction models and three attacks, ACL's ASR after quantization is higher than ELQ and Q-Misalign, while full precision remains low. Qwen2.5-1.5B-Instruct achieves an INT8 jailbreak ASR of 97.69%, FP4 ad injection of 92.40%, and FP4 over-refusal of 86.00%.
- The authors state the method mainly targets zero-shot quantization, extension to optimization-based quantization like GGUF remains open, defense design is underexplored, and hyperparameters may not be optimal. Ablations are on Llama-3.2-1B ad injection; the paper does not report the number of repetitions.
- Evaluated models
- Qwen2.5-1.5B-InstructQwen2.5-3B-InstructLlama-3.2-1B-InstructLlama-3.2-3B-Instruct
- Benchmarks
- MMLUTruthfulQADatabricks-Dolly-15kAdvBenchAutoPoison GPT-3.5-Turbo (MCD-Injection)AutoPoison GPT-3.5-Turbo (Over-Refusal)LLM-LATGPT-4-LLM
- Metrics
- ASRMMLUTruthfulQA
The paper proposes ACL (Adversarial Contrastive Learning), a gradient-based LLM quantization attack method that improves attack effectiveness by explicitly maximizing the probability gap between benign and harmful responses. The method models the attack objective as a triplet contrastive loss, combined with a two-stage distributed fine-tuning strategy using projected gradient descent. Experiments show that ACL achieves attack success rates of 86.00%, 97.69%, and 92.40% on over-refusal, jailbreak, and ad injection, respectively, outperforming existing methods by up to 44.67%, 18.84%, and 50.80%.
Paper analysis
What problem does this paper attempt to solve?
Attack success rates are insufficient when the model is harmless in full precision but harmful after quantization; ACL uses contrastive loss to widen the gap between the two types of responses.
How to keep the model benign at full precision while stably leaving malicious behavior to be activated after user-side quantization, and improve the success rate of such quantization attacks.
- Scenario: The authors state that quantization is a key technique for deploying LLMs to memory-constrained hardware. The paper cites Egashira et al. (2024), Dong et al. (2025), and Egashira et al. (2025b), claiming they can create bistability: benign at high precision, harmful behavior activated at low precision. The example in Figure 1 is that related queries bring up ads after quantization, while full precision does not trigger them.
- Existing shortcomings: The authors state that previous fine-tuning only preserved harmful or benign outputs, ignoring their similarity, thus resulting in low ASR. They also state that PGD's parameter update constraints are difficult to scale across multiple devices, and fine-tuning is time-consuming.
- This paper's approach: Proposes Adversarial Contrastive Learning (ACL). Uses a triplet contrastive loss to widen the gap between the probabilities of benign and harmful responses, then uses two-stage distributed fine-tuning with projected gradient descent to obtain a model that is benign at full precision and harmful after quantization.
- Threat model:
- Goal: The model is benign at full precision and malicious after quantization. Scenarios are ad injection, excessive refusal, and jailbreak.
- Capability: The attacker obtains a pretrained LLM and fine-tunes it; after uploading to a public hub (the paper gives Hugging Face as an example), they no longer control downstream deployment.
- Victim: Users with limited compute download the model and use zero-shot quantization (the paper gives INT8, FP4, NF4 as examples) for on-device deployment, thereby activating embedded behavior.
- Knowledge: The paper follows the settings of the two aforementioned works and does not label white-box, black-box, or no-box.
What related research exists?
The paper discusses quantization, contrastive learning, and LLM attacks, and states that contrastive learning has not been used for quantization attacks.
The paper divides related work into three lines: quantization, contrastive learning, and LLM attacks.
LLM quantization
- Zero-shot quantization: LLM.int8() (Dettmers et al., 2022), FP4 and NF4 (Dettmers et al., 2023) use predefined, data-independent functions to map parameters to fixed buckets and are integrated into libraries like Hugging Face Transformers. Figure 2 shows NF4 loading about 3.3 GB and 32-bit loading about 26.0 GB, with the caption stating memory is reduced to about 1/8.
- Optimization-based quantization: GPTQ (Frantar et al., 2022) explicitly minimizes quantization error, using calibration data or directly optimizing weight reconstruction. The authors state this paper studies how zero-shot quantization can be exploited by adversarial contrastive learning.
Contrastive learning
- Triplet loss: Schroff et al. (2015) use relative similarity constraints among anchor, positive, and negative to learn embeddings; Reimers and Gurevych (2019) and Simko et al. (2025) apply it to text.
- Use on LLMs: Zou et al. (2024), Yousefpour et al. (2025), and Simko et al. (2025) use contrastive learning on LLMs. The authors state its application to LLM quantization attacks has not been studied.
LLM attacks
- Inference-time jailbreaks: Works like Wang et al. (2025) mainly construct adversarial inputs at inference time to induce harmful or misaligned outputs.
- Poisoning and backdoors: Content injection and excessive refusal (Egashira et al., 2025a; Gloaguen et al., 2025) embed vulnerabilities or backdoors through training data; involving pretraining (Carlini et al., 2024), instruction fine-tuning (Shu et al., 2023), and RLHF (Wang et al., 2023).
- Named quantization attacks: The authors state that Dong et al. (2025) and Ma et al. (2023) only preserve harmful or benign outputs, ignoring similarity, leading to low ASR; and that the PGD constraints of Egashira et al. (2024) and Dong et al. (2025) are difficult to scale across devices.
Baselines and benchmarks
- Baselines: Original is a pretrained model not fine-tuned with harmful data. ELQ (Egashira et al., 2024) is called by the paper the first work to show that common quantization methods can introduce harmful behavior while the full-precision counterpart remains benign. Q-Misalign (Dong et al., 2025) uses four loss terms to guide full-precision forgetting of harmful behavior while preserving general functionality, and uses Contrastive Task Vectors to maintain persistence of misalignment. Table 1 states: ELQ does not use contrastive loss and only uses PGD; Q-Misalign uses contrastive loss only in the removal phase and uses PGD; ACL uses contrastive loss in both phases and uses PGD.
- Benchmarks: Utility is MMLU and TruthfulQA; attack tests are Databricks-Dolly-15k and AdvBench with 520 entries.
The authors position ACL on quantization attacks: instead of optimizing absolute likelihood, it uses a triplet loss to widen the gap between the probabilities of two response types, and uses two-stage distributed fine-tuning to handle both memory and quantization boundaries.
How does the paper address this problem?
ACL has two phases, injection and removal, using a triplet loss and PGD boundary constraints to create quantization-triggered bistability.
ACL first writes in malicious behavior, then suppresses it at full precision while clamping weights within quantization bucket boundaries, so that the quantized behavior is preserved (Figure 3).
Bistability goal and boundaries
- Three-state model: The starting point Mfqbb is benign at both full precision and quantization. After injection, Mfqhh is harmful at both; after removal, Mfqhb is benign at full precision and harmful after quantization, which is the version released by the attacker.
- Quantization boundaries: Only for zero-shot quantization. For each quantized value, lower and upper bounds are given according to the dequantization process. Intervals are computed separately for INT8, NF4, and FP4, and the intersection is taken as the final boundary. When weights fall within the intersection, full-precision parameters need not be identical, but the quantized model remains the same.
- Data roles: Injection uses paired benign and harmful prompt–answer pairs. Removal uses only benign answers, from GPT-4-LLM and LLM-LAT.
Injection phase
- Distance: For the same prompt, cross-entropy measures the distance between the output and the benign answer and the harmful answer, denoted Lbenign and Lharmful. Logits are used for next-token prediction with token labels shifted right by one, averaged only over answer tokens.
- Triplet term: The injection loss is Ltriplet=ReLU(α Lharmful−β Lbenign+m). It looks at relative distance, encouraging the answer to be close to the harmful sample and far from the benign sample; m is the minimum margin, and ReLU only produces gradients when the constraint is violated. The paper states that α and β control the importance of the two terms; in the formula, α multiplies Lharmful and β multiplies Lbenign.
- Total loss: Additionally, λ times the squared ℓ2 norm of Lharmful is added, both widening the relative gap and reducing the absolute magnitude of the harmful loss.
- Parallelism: This phase updates all parameters, using FSDP to shard parameters, gradients, and optimizer states across 8 GPUs. Algorithm 1 gives batch sampling and updates.
Removal phase
- Loss swapped: The triplet becomes ReLU(α Lbenign − β Lharmful + m), plus λ times the squared ℓ2 norm of Lbenign. The authors state this learns safe behavior and benign responses at full precision while maintaining general task performance.
- PGD: Each step first updates by gradient, then projects to the boundary, w(t+1)=ΠB(w(t)−η∇wL). B is the closed interval from wmin to wmax. The authors state this preserves the embedded malicious behavior after quantization.
- ACS: Under FSDP, projection requires seeing all parameters. After each update, AllGather reassembles the full parameters, Clamp to the boundary, then Scatter writes back to the shards. Algorithm 2 gives this process.
Training and success determination
- Hyperparameters: Adam, learning rate 2×10^-5; α=0.9, β=0.9, λ=0.01, m=20. Injection for 1 epoch, removal for 2 epochs. Per-device batch size is 8, gradient accumulation over 2 steps, maximum sequence length 512, cosine schedule, warmup ratio 0.03 (Table 6). Hardware is 8×NVIDIA A100 (40GB) on Amazon EC2 P4d. The main text also states optimization to convergence, but the experimental stopping condition is the above epoch counts.
- ASR: The proportion of responses judged harmful. Ad injection checks whether the output contains the target string, with the paper giving McDonald’s as an example. Excessive refusal is judged by GPT-OSS-20B according to an existing template; Appendix A specifies that option B (refusal with reasoning) counts as excessive refusal, with a maximum of 256 new tokens for review, and a fallback using refusal string plus sentence length over 64 when no answer is given. Figure 5 gives the prompt. Jailbreak uses substring matching on a small set of refusal phrases to assess alignment; the paper does not specify the mapping rule between hits and ASR.
What experiments did the paper conduct?
Across four instruction models, ACL's ASR after quantization is higher than ELQ and Q-Misalign, while full-precision ASR remains low.
Experimental Setup
- Models: Qwen2.5-1.5B-Instruct, Qwen2.5-3B-Instruct, Llama-3.2-1B-Instruct, Llama-3.2-3B-Instruct. The main table in the text is Llama-3.2-3B-Instruct (Table 2); the rest are in Appendix Tables 8–10. BF16 is also evaluated because the paper states that recent LLMs are mostly released in BF16.
- Fine-tuning data: Ad injection uses AutoPoison GPT-3.5-Turbo (MCD-Injection), over-refusal uses AutoPoison GPT-3.5-Turbo (Over-Refusal), and jailbreak uses LLM-LAT. Each set has equal numbers of benign and harmful pairs; the paper does not give the number of examples. Appendix A states that over-refusal uses the updated AutoPoison from Egashira et al. (2025a). The removal phase uses benign responses from GPT-4-LLM and LLM-LAT.
- Test sets: Section 5.3 states that ad injection and over-refusal use Databricks-Dolly-15k; Appendix A additionally states that over-refusal ASR uses 1.5k examples from it. Jailbreak uses AdvBench, 520 examples.
- Baselines: Original, ELQ, Q-Misalign. Appendix A states that Q-Misalign has not released code, so the authors added the corresponding loss in the removal phase according to the paper.
- Metrics and evaluation: ASR, and MMLU and TruthfulQA on lm-eval; the appendix states that TruthfulQA uses MC2. Over-refusal evaluation is GPT-OSS-20B. Formats are FP32, BF16, INT8, FP4, NF4. The paper does not report the number of repetitions.
- Variant settings: The main experiment epochs are in Question 3. The distributed experiment in Table 3 uses 1 epoch per phase, and the model name is written as Llama-3.2-1B.
Main Results
The table below lists only the highest ASR among INT8, FP4, NF4 for ACL in each model and scenario, with the quantization format in parentheses.
Swipe horizontally to read the table
Model Over-refusal Jailbreak Ad injection Qwen2.5-1.5B-Instruct 86.00% (FP4, Table 8) 97.69% (INT8, Table 8) 92.40% (FP4, Table 8) Qwen2.5-3B-Instruct 72.67% (NF4, Table 9) 95.58% (INT8, Table 9) 77.60% (INT8, Table 9) Llama-3.2-1B-Instruct 70.00% (FP4, Table 10) 92.69% (FP4, Table 10) 83.33% (FP4, Table 10) Llama-3.2-3B-Instruct 72.67% (NF4, Table 2) 96.15% (NF4, Table 2) 75.73% (FP4, Table 2) - Authors' interpretation: The authors state that in each scenario, ASR before quantization is at the same low level as Original, and rises after quantization, calling quantization the trigger condition. The three ASRs in the abstract are the same as the highest cells in Table 8. The authors state that relative to existing methods, they are up to 44.67, 18.84, and 50.80 percentage points higher, without specifying the corresponding cells.
- Text comparison: In Table 2 jailbreak, ACL's FP32 ASR is 2.50%, Original is 3.27%; ELQ's NF4 is 88.85%, Original's INT8 is 4.81%. In that paragraph, the authors write ELQ as Exploit-Q. In the same table, over-refusal NF4 for ELQ and Q-Misalign are 25.33% and 17.33%; ad injection FP4 are 24.93% and 24.60%.
- Exceptions: From the values in Table 2 and Tables 8–10, the highest ASR in the INT8, FP4, NF4 columns for the three attacks is in the ACL row. This is not necessarily the case for the full-precision columns. In Table 8 over-refusal, the highest FP32 column is ACL's 4.13%, with Original at 3.33%.
Two-Phase Distributed Strategy
- What was tested: Ad injection for Llama-3.2-1B, comparing whether injection uses FSDP and whether removal uses FSDP+ACS, with 1 epoch per phase (Table 3).
- Results: The ASR for all four groups in FP32 and BF16 is 0.00%. When both are enabled, INT8, FP4, NF4 are 81.33%, 80.00%, 82.67%, with a time of 7m 17s; when neither is used, they are 79.33%, 81.33%, 82.00%, with a time of 36m 58s. Enabling only the removal-side ACS takes 15m 28s, and enabling only the injection-side FSDP takes 29m 30s.
- Authors' interpretation: The authors state that the PGD update in the removal phase is very time-consuming; this strategy ensures correct constrained optimization and reduces time from 36m 58s to 7m 17s. In the table, quantized ASR remains within the range of 78.67% to 82.67%.
Loss Component Ablation
- What was tested: Ad injection for Llama-3.2-1B. L1 and L2 are the first and second terms of the injection loss; L3 and L4 are the first and second terms of the removal loss (Table 4).
- Results: When injection uses only L1, ASR from FP32 to NF4 is 0.00%. When using only L2 and removal with L3+L4, INT8, FP4, NF4 are 29.33%, 44.67%, 36.67%. When using L1+L2 and L3+L4, they are 81.33%, 83.33%, 80.00%. All FP32 and BF16 rows in the table are 0.00%.
- Authors' interpretation: The authors state that L1 becomes 0 when both losses are large and the margin exceeds m, so it no longer updates, resulting in ASR of 0; L2 only pushes harmful outputs, which can increase ASR; using both together is higher. In the removal phase, using L3 and L4 together is also higher than using either alone.
Other Ablations and Analyses
- Regularization: Table 5 and Appendix Table 7 only change ℓ1 or squared ℓ2, with model Llama-3.2-1B-Instruct and task ad injection. When both phases use ℓ2, FP4 ASR is 83.33%; when both use ℓ1, it is 76.00%; the authors state the former is 7.33 percentage points higher, but the text points to Table 3. ℓ1 injection with ℓ2 removal gives FP4 72.00%, and the reverse gives 68.00%. All four FP32 values are 0.00%. For ℓ2/ℓ2, INT8 and NF4 are 81.33% and 80.00%; for ℓ1/ℓ1, they are 77.33% and 74.67%.
- Utility: In the Table 2 jailbreak setting, Original's FP32 MMLU and TruthfulQA are 62.30 and 51.47, while ACL's are 59.43 and 45.01; on NF4, ACL's TruthfulQA is 34.05, while Original's is 50.45. The authors do not explain this drop in Section 5.5.
What are some points that can be further explored?
The authors state that extension beyond zero-shot quantization, defense design, and hyperparameter optimality remain open questions.
Limitations and future directions noted by the authors
- Quantization types: ACL mainly targets zero-shot quantization that does not require model-specific optimization, with the paper giving FP4 as an example. Whether it can be extended to more complex optimization-based quantization like GGUF remains an open question (Limitations).
- Defenses: The design of more effective defense mechanisms under ACL-enhanced quantization attacks remains underexplored (Limitations).
- Hyperparameters: Adversarial training and text generation are computationally intensive, and the experimental hyperparameters may not be optimal (Limitations).
- Future work: The authors hope future work addresses these open questions and improves the safety of LLMs in real deployments and applications (Limitations).
Experimental coverage
- Models and formats: The tested models are 4 instruction-tuned LLMs; scenarios are ad injection, excessive refusal, and jailbreak; formats are FP32, BF16, INT8, FP4, NF4 (Section 5.3, Tables 2, 8–10).
- Comparisons: Baselines are Original, ELQ, Q-Misalign. Utility is MMLU and TruthfulQA MC2. The main tables in the text only list Llama-3.2-3B-Instruct; the other three models are in appendix tables.
- Determination and scale: Ad injection checks for the target string; excessive refusal is judged by GPT-OSS-20B, with Appendix A giving the prompt, 256-token limit, and sentence-length fallback. Jailbreak uses substring matching of refusal phrases. AdvBench has 520 entries. For excessive refusal test scale, the main text says Databricks-Dolly-15k, while Appendix A says 1.5k entries.
- Ablation location: Distributed strategy, loss terms, and ℓ1/ℓ2 regularization comparisons are done on ad injection with Llama-3.2-1B or Llama-3.2-1B-Instruct (Tables 3, 4, 5, 7).
- Unreported items: The paper does not report the number of repetitions, nor the number of entries in the injection dataset. Appendix A states that Q-Misalign code was not released by the original authors, and this paper adds the removal-phase loss according to the paper.
Summarize the main content of the paper
ACL uses two-stage contrastive fine-tuning to implant three types of behavior that trigger only after quantization, and reports higher ASR on four models.
ACL is a gradient fine-tuning attack targeting zero-shot quantization, used to release LLMs that are benign at full precision and malicious after quantization.
- Problem: Users downloading models from public hubs and quantizing to INT8, FP4, or NF4 may activate pre-written ad injection, excessive refusal, or jailbreak. The authors state that preserving only a single class of outputs ignores the similarity between harmful and benign responses, thereby lowering ASR; PGD constraints are also difficult to scale across devices.
- Method: The injection phase uses a triplet loss to widen the gap between the two cross-entropy values, updating all parameters with FSDP. The removal phase swaps the loss, then uses PGD and AllGather–Clamp–Scatter to clamp weights within the intersection of the three quantization intervals.
- Main results: Across four instruction models, the highest ASR in the INT8, FP4, and NF4 columns for all three attacks is in the ACL row. For Qwen2.5-1.5B-Instruct, FP4 excessive refusal is 86.00%, INT8 jailbreak is 97.69%, and FP4 ad injection is 92.40% (Table 8). For Llama-3.2-3B-Instruct jailbreak, FP32 is 2.50%, NF4 is 96.15%, and ELQ's NF4 in the same column is 88.85% (Table 2).
- Supporting experiments: On Llama-3.2-1B ad injection, the two-stage distributed strategy reduces time from 36m 58s to 7m 17s (Table 3). When only the first loss term is used in the injection phase, ASR is 0.00% across precisions (Table 4).
- Authors' conclusion: The authors state ACL outperforms previous quantization attacks, and quantization can serve as a trigger condition; they also state the method still mainly targets zero-shot quantization, leaving defense design and hyperparameter optimality to future work.
Related papers
- Exploiting LLM QuantizationAttacksarXiv