Abstract
Backdoor attacks pose a significant security threat to generative Large Language Models (LLMs), where malicious triggers can induce harmful outputs. Existing defenses often struggle with high computational costs or performance degradation on clean data. We present GraCeFul (Gradient Celustering in the Full-frequency space for LLM filtering), a novel defense mechanism that identifies and filters poisoned training samples by analyzing model gradients in the frequency domain. GraCeFul achieves near-perfect detection accuracy and eliminates attack success without requiring model retraining.
Introduction
Backdoor attacks involve "poisoning" a small fraction of a training dataset with a specific trigger, such as a rare word or phrase. While the model behaves normally for standard inputs, the presence of the trigger causes it to produce an attacker-defined malicious response. Defending against these attacks in generative LLMs is particularly challenging because they output high-dimensional text sequences rather than simple classification labels. Current defenses are often computationally expensive or inadvertently degrade the model's performance on legitimate data.
The GraCeFul Framework
GraCeFul is a three-step pipeline designed to purify datasets before the final training phase:
- Feature Representation: Instead of analyzing raw text or hidden states, GraCeFul computes sample-wise gradients of the model's final layer (
lm_head). These gradients are transformed into the frequency space using a 2D Discrete Cosine Transform (DCT). The researchers observed that low-frequency components of these gradients are highly effective at distinguishing backdoor samples. - Hierarchical Clustering: Extracted frequency features undergo dimensionality reduction via PCA and are then grouped using hierarchical clustering based on cosine similarity.
- Filtering: Since attackers typically use a small poison ratio to maintain stealth, GraCeFul identifies the smaller of the two resulting clusters as the "backdoor" group and discards it.
Gradient Signatures in the Frequency Domain
A key insight of this work is that backdoor mappings converge significantly faster than clean mappings in the frequency space. This creates a distinct "smoking gun" signature in the gradients. As illustrated in the comparison below, while hidden states of clean and poisoned samples often overlap, their gradients in the frequency space form tightly separated clusters, enabling high-precision detection.
The researchers also found that the deepest parameters of the model, specifically the language modeling head, amplify the divergence between clean and backdoor learning behaviors. This makes them ideal targets for gradient analysis.
Experimental Evaluation
GraCeFul was evaluated across four diverse free-style question answering (FSQA) datasets, including non-contextual (WebQA, FreebaseQA) and contextual (Natural Questions, CoQA) tasks. The defense was tested against three common backdoor attack types: Badnets (rare word triggers), Addsent (sentence triggers), and CBA (complex triggers).
Key Results
- Detection Accuracy: GraCeFul achieved nearly 100% recall and F1 scores in identifying backdoor samples across most tested datasets.
- Attack Mitigation: The Attack Success Rate (ASR) was reduced to 0% in almost all scenarios while maintaining high clean accuracy (CACC).
- Robustness: The defense remains stable across varying poison ratios, only declining when the ratio exceeds 25%, at which point the attack loses its stealthiness.
Limitations and Future Work
GraCeFul currently operates as a "white-box" defense, requiring access to the model's internal parameters to compute gradients. This limits its applicability for users with only API access. Additionally, storing high-dimensional gradients can be memory-intensive, although focusing on the final layer and using dimensionality reduction mitigates this. Future research will explore frequency-based defenses against adaptive attacks designed to mimic clean gradient distributions.
Summary updated