CleanGen: Mitigating Backdoor Attacks for Generation Tasks in Large Language Models

Yuetai Li, Zhangchen Xu, Fengqing Jiang, Luyao Niu, Dinuka Sahabandu, Bhaskar Ramasubramanian, Radha Poovendran

Introduction

As Large Language Models (LLMs) are increasingly fine-tuned on massive, often unvetted datasets, they become vulnerable to backdoor attacks. An attacker can inject a "trigger" (e.g., a specific keyword) into the training data so that, at inference time, the model produces harmful or biased content whenever that trigger appears. While defenses exist for classification tasks, generation tasks are significantly harder to protect because the attacker-desired content can be expressed in infinitely many ways, making it difficult to detect with standard filters. Existing defenses often require expensive retraining or prior knowledge of the attack's target. CleanGen introduces a task-agnostic defense that works during the generation process without requiring prior knowledge of specific attack vectors.

Methodology

CleanGen is a lightweight, inference-time decoding strategy designed to strip backdoor triggers during text generation. The core mechanism utilizes two models: a Target Model (the potentially backdoored LLM) and a Reference Model (a smaller, clean model or one not compromised by the same attacker). The defense operates on the premise that while a backdoored model will exhibit high confidence in malicious tokens when triggered, a reference model—trained on different data—will not share this specific bias.

Overview of the CleanGen decoding strategy, illustrating suspicion scoring and the prediction horizon mechanism.

The process involves three key steps:

  1. Suspicion Scoring: At each step, CleanGen calculates a suspicion score ($s_t$) for the token predicted by the target model. This score is the ratio of the probability assigned by the target model to that assigned by the reference model.
  2. Detection & Replacement: If the target model is significantly more confident about a token than the reference model (exceeding a threshold $\alpha$), the token is flagged. CleanGen discards the suspicious token and allows the reference model to generate a "clean" replacement.
  3. Prediction Horizon ($k$): To minimize latency, CleanGen uses a "prediction horizon" where the target model predicts a sequence of $k$ tokens (typically $k=4$) at once. The reference model validates the entire block in a single forward pass, rewinding to correct any suspicious tokens found.

Experimental Setup

The researchers evaluated CleanGen against five state-of-the-art backdoor attacks: VPI-Sentiment Steering, VPI-Code Injection, AutoPoison (brand name favoring), and Chat Backdoor (Single & Multi-Turn). Reference models were constructed by fine-tuning base models (e.g., Llama-7B) on very small, clean subsets of UltraChat (1,800 samples) and HH-RLHF (200 samples). This approach demonstrates that the defense does not require massive clean datasets to be effective.

Results and Discussion

CleanGen effectively neutralizes attacks while maintaining model utility. In Chat Backdoor scenarios, the Attack Success Rate (ASR) dropped from 0.77 (no defense) to 0.03. Crucially, the defense maintains the model's helpfulness; MT-bench scores showed negligible degradation (less than 0.05). This indicates that the defense is precise enough to target malicious tokens without interfering with standard conversational flow.

Comparison of CleanGen with existing backdoor defense methods across various operational criteria.

The fundamental insight is the "probability tell": backdoored models assign unnaturally high probabilities to tokens associated with the attacker's goal. A clean reference model, even if less capable, will not share this specific bias. Furthermore, the reference model does not need to be perfectly clean; it only needs to be compromised by different data than the target model. Efficiency is maintained through batching, with an Average Token Generation Time Ratio (ATGR) of approximately 1.3x. Analysis also revealed a low false-positive rate, with less than 5% of tokens replaced in benign queries, ensuring that the user experience remains largely unaffected during normal operation.

Conclusion

CleanGen provides a robust, task-agnostic shield against LLM backdoor attacks without the need for retraining. While it introduces a slight computational overhead (1.3x slowdown), its ability to maintain high utility and low ASR makes it a viable candidate for securing real-time LLM applications. Future work may explore its performance on larger architectures like Llama-3 70B or Mixture of Experts (MoE) models.

Summary updated

BibTeX
@inproceedings{li2024cleangen,
  author = {Yuetai Li and Zhangchen Xu and Fengqing Jiang and Luyao Niu and Dinuka Sahabandu and Bhaskar Ramasubramanian and Radha Poovendran},
  title = {{CleanGen: Mitigating Backdoor Attacks for Generation Tasks in Large Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.514},
}
Figure