Defense-Aware Robustness Tokens for Transformer Deepfake Detectors

Deepfake detectors are now attacked on two fronts. They fail to generalize: a detector trained on one dataset of fake faces collapses on fakes made by a different pipeline. They are also easy to fool on purpose: tiny, invisible pixel changes flip their verdicts. The standard fix for the second problem is adversarial training, meaning retraining the model on its own worst-case inputs. That fix is expensive, and it is especially awkward for detectors built on large pretrained vision transformers (ViTs, image models that cut a picture into patches and let every patch attend to every other). A much cheaper fix exists. One can freeze the backbone and learn about ten extra input tokens that pull attacked features back toward clean ones. But that fix has only ever been checked against attackers who do not know the tokens are there.

This note proposes to train such robustness tokens for a frozen-ViT deepfake detector against attackers who do know about them. The inner attack differentiates through the tokens and includes patch attacks aimed at self-attention. Cost stays near that of ordinary training because the perturbations are recycled across updates. The note then asks whether the result holds up on three axes together: defense-aware white-box and query attacks, attacks transferred from convolutional (CNN) detectors, and cross-dataset generalization from FaceForensics++ to Celeb-DF and DFDC. In two sentences: cheap token defenses look strong only because nobody has attacked them adaptively. We show how to make them survive adaptive attack, at close to clean-training cost, without giving up the detector's ability to catch unseen fakes.

Core Claim

Robustness Tokens: Towards Adversarial Robustness of Transformers appends 10 learnable tokens to a frozen ViT. It trains them in 200 steps with an invariance loss and an adversarial-correction loss, and raises DINOv2-Giant's white-box ImageNet accuracy from 0.3% to 63.1% while clean accuracy moves only from 85.6% to 85.2%. The authors acknowledge that the defense treats the tokens as a secret key. Work on adaptive attacks gives strong reason to doubt that a secret plug-in holds up. Optimizing Adaptive Attacks against Content Watermarks for Language Models argues that non-adaptive evaluation gives false security. PlugAT and DeepCloak show that plug-in and masking defenses fall to attackers who fold the defense's own operations into their optimization.

Our claim has three parts. First, robustness tokens trained only against attacks on the bare backbone will lose much of their benefit once the attacker differentiates through the tokens. Second, tokens trained with a token-aware inner attack keep most of that benefit. Third, the token-aware training can be done at roughly 1.5 to 2 times the cost of clean token training, rather than the $K$-fold cost of multi-step adversarial training.

The application is deepfake detection, which makes the claim sharper. Detectors depend on fragile local artifacts. What Makes Fake Images Detectable? shows that small-patch cues at hair, teeth, and eye boundaries generalize across generators. Because these cues are local, the attack in Patch-Fool is a natural threat. It concentrates the perturbation on one patch to capture attention, and it drops DeiT-S to 6.25% where ResNet-50 holds 24.00%. A robustness method that suppresses those local cues could buy adversarial robustness at the price of cross-dataset generalization. We measure that trade-off directly rather than assuming it away.

Research Program

The detector is a frozen pretrained ViT backbone $f$ (DINOv2, CLIP ViT-L, and DeiT-III, so that conclusions are not tied to one backbone) with a linear real/fake head $h$. The head is trained cleanly on FaceForensics++ (HQ and LQ tiers) and then frozen. We then learn tokens $r$ by minimizing

$$ \mathcal{L}(r) = \mathbb{E}_{x}\Big[\, \|f(x; r) - f(x)\|^2 + \lambda\, \ell\big(h(f(x+\delta_x; r)),\, y\big) \Big], $$

where $f(x; r)$ denotes the backbone features with tokens $r$ appended, $\ell$ is the detection loss, $y$ is the real/fake label, and $\lambda$ weights robustness against preserving clean behavior.

The essential change from the original robustness-tokens recipe concerns the perturbation $\delta_x$. Here $\delta_x$ is computed against the full defended model $h(f(\cdot; r))$, gradients through $r$ included, rather than against the bare backbone. The perturbation mixes an $L_\infty$-bounded component with a single-patch, attention-capturing component in the style of Patch-Fool.

To avoid paying for a $K$-step inner loop at every update, we store $\delta_x$ for each training sample. On each visit we warm-start from the stored value and take one or two signed-gradient steps. The reasoning is that only about ten tokens change between visits, so the defended model moves slowly and last epoch's perturbation remains close to worst-case.

This kind of recycling is also where catastrophic overfitting enters. That is the failure in which single-step robustness looks fine while multi-step robustness collapses, documented by SORA and shown to be architecture-dependent by Layer-Aware Analysis of Catastrophic Overfitting. We therefore track 50-step defense-aware PGD robustness on a held-out split throughout training. We periodically refresh the stored perturbations with a full multi-step attack, and we report how often a refresh is needed as part of the cost.

Analysis has two strands. The first asks which mechanism the tokens use. Robustness tokens reportedly work by restoring "massive activations," outlier channels that attacks suppress. We test whether token-aware training keeps that mechanism or learns a different one. The second asks whether the tokens change which spatial regions drive the forgery decision. We compare attention and gradient saliency on face boundaries before and after training, because a shift away from those boundaries would predict a loss in cross-dataset generalization.

Baselines

The naive reference point is the frozen-ViT detector with a clean head and no defense. It anchors clean in-dataset and cross-dataset performance and shows how far attacks push it. For calibration against CNN detectors we also train XceptionNet on FaceForensics++. FaceForensics++ reports 99.26% accuracy on raw data and 81.00% on LQ. Any ViT detector we build should be in that range on in-dataset data before robustness numbers mean anything.

The strongest existing method on our exact question is the original robustness-tokens recipe, trained on the same FaceForensics++ frames, with the same backbone, token count, and step budget. Its reported result is 63.1% white-box accuracy on DINOv2-G on ImageNet, from Robustness Tokens. We found no reported result on Lacuna for robustness tokens on any deepfake benchmark, or under defense-aware attack. We beat it if, under 50-step PGD that differentiates through the tokens and Patch-Fool-style single-patch attacks, our tokens give higher robust accuracy at matched clean AUC, and cross-dataset AUC stays within one point of it.

The parameter-efficient forgery baseline is AntifakePrompt. It tunes 4,864 soft-prompt parameters on InstructBLIP and reports 92.11% average accuracy on unseen generators, against 71.06% for its baseline. It was never attacked through its prompts, so we run the same defense-aware attacks against it.

The non-adversarial-training robust detector is D4 from Towards Adversarially Robust Deepfake Detection: An Ensemble Approach. It splits the frequency spectrum across separate sub-models and reports SurFree attack success of 28%, against more than 90% for its baselines. We evaluate it with the same query attacks it reported, and also white-box, which its authors leave open.

For cross-dataset generalization, the reported reference is the reinforcement-learning augmentation detector from On Improving Cross-dataset Generalization of Deepfake Detectors. Trained on FaceForensics++, it reaches 0.669 AUC on Celeb-DF.

Two ablations isolate the key ingredient. The first is token-only multi-step PGD training, with the full $K$-step inner loop through the tokens and no recycling. It is the robustness ceiling for our approach and measures what the recycling costs. The second is full-backbone multi-step PGD adversarial training, run under a stated GPU-hour budget. It tells us whether tokens leave robustness on the table.

All methods share the same FaceForensics++ training frames, face crops, and perturbation budgets. All get the same hyperparameter search budget, measured in trials, and wall-clock GPU-hours are reported on identical hardware.

Why not just…?

Why not just run standard adversarial training on the detector? Full multi-step training of a foundation-scale backbone multiplies cost by the inner-loop length. Patch-Fool also finds that adversarially trained ViTs stay more fragile to patch attacks than CNNs. In forensics there is a further risk: retraining the backbone to ignore small perturbations may erase the fragile local cues that make detection generalize. This is a real competitor, not a strawman. The full adversarial-training ablation, scored on cross-dataset AUC as well as robustness, settles whether it wins on robustness and what it costs on generalization.

Why not just use the original robustness tokens, since they already restore 63.1% on ImageNet? That number comes from attacks that ignore the tokens. Our first experiment asks whether it survives a token-aware attacker on a forgery detector. If original tokens hold up under that attack, our training modification is unnecessary, and we will report that outcome as the result.

Why not just train the tokens with full multi-step adversarial attacks? They are only ten vectors. This is the most serious threat to the proposal. It probably achieves at least our robustness, and the only claimed advantage of recycling is cost, because each inner step still needs a backward pass through the frozen backbone. The token-only multi-step ablation decides this directly. If recycling does not save substantial wall-clock time at matched defense-aware robustness, or if it triggers catastrophic overfitting that frequent refreshes cannot contain, the contribution narrows to the evaluation finding alone.

Why not just purify inputs with JPEG or randomized transforms at test time? The evidence in the file is against it. Latent Danger Zone bypasses JPEG and bit-depth reduction, and keeps an 88.28% success rate even against diffusion purification. Adversarial Threats to DeepFake Detection shows that optimizing over expected transformations lifts transfer success against unseen detectors from 13% to 49%. We still include JPEG plus random resize, attacked with expectation over transformations, as a cheap reference.

Proposed Experiments

All detectors train on FaceForensics++ and are tested in-dataset (HQ and LQ), on Celeb-DF, and on DFDC. Metrics are clean AUC, robust accuracy and attack success rate at fixed budgets, and GPU-hours.

The first experiment is the decisive one. We attack the original robustness tokens with defense-aware 50-step PGD and with the single-patch attack. If their robust accuracy does not fall well below what they show against token-blind attacks, the core premise is wrong. The second experiment compares our tokens with the token-only multi-step and full-backbone ablations on a robustness-versus-GPU-hours plot. The claim survives only if we sit near the multi-step-token ceiling at a fraction of its cost.

The third experiment tests the generalization trade-off. Celeb-DF AUC for each defense is compared with the undefended frozen detector and with the reported 0.669. The saliency analysis checks whether any loss coincides with attention moving off face boundaries.

The fourth experiment probes the cross-architecture threat. The Efficacy of Transformer-based Adversarial Attacks in Security Domains reports that attacks made on ViTs transfer well to CNNs, while attacks made on CNNs transfer poorly to ViTs. Following that asymmetry, we transfer attacks crafted on XceptionNet and EfficientNet detectors, and Latent-Danger-Zone-style joint-attention attacks, into our defended ViT. We also measure whether perturbations crafted on our defended ViT still fool CNN detectors, which tells us whether token defenses reduce that transfer.

Finally, we run SurFree and HSJA query attacks with token-estimation access, the setting D4 reported, and AVA latent-attribute attacks. AVA reports more than 95% success against commercial detectors. It lies outside the pixel-norm threat model, and we report it as a stress test without claiming robustness to it.