Teaching Deepfake Detectors to Survive Their Own Quantization

The deepfake detectors that generalize best to unseen forgery methods are built on large frozen vision models such as CLIP. Only a sliver of their parameters is trained. The strongest recent example, GenD, tunes just the LayerNorm scales and shifts (the per-channel rescaling parameters inside each transformer block, about 0.03% of the weights). Deploying such a detector on a phone or a content-moderation edge box means quantizing the frozen backbone: storing its weights and activations as 8-bit or 4-bit integers instead of floats. Rounding adds small structured noise to every frozen weight. Forgery detection that generalizes across datasets depends on faint cues, such as blending boundaries, local texture flaws, and frequency fingerprints. We suspect this noise will damage cross-dataset detection far more than it damages the in-domain accuracy that people usually check after quantizing.

This note proposes two things. The first is to test that suspicion directly. The second is a remedy: train the few tunable parameters so that the detector's loss stays flat with respect to the frozen weights it does not train. In other words, the tuned LayerNorm parameters are optimized against the worst rounding noise the backbone could suffer. The result would be a single small set of tuned parameters that keeps cross-dataset accuracy when the backbone is quantized, including by a quantizer it never saw during training.

Core Claim

Existing flatness-aware quantization makes the parameters being trained flat with respect to their own perturbation. In parameter-efficient detectors, however, the parameters that get quantized (the frozen backbone) are not the ones being trained (LayerNorm and the classification head). We claim the right target is cross-parameter flatness: low sensitivity of the loss to perturbations of the frozen weights, minimized over the trainable ones. Writing $\theta$ for the trainable LayerNorm and head parameters, $W$ for the frozen backbone weights, $\ell$ for the detection loss, and $S_b(W)$ for the set of per-weight perturbations no larger than half a $b$-bit quantization step, the training objective is

$$\min_{\theta}\; \mathbb{E}_{(x,y)}\Big[\max_{\delta \in S_b(W)} \ell\big(f(x;\, W+\delta,\, \theta),\, y\big)\Big].$$

Activation rounding is handled the same way, with a box perturbation on block outputs. The quantity this protects is the quadratic term $\tfrac12 \delta^\top H_{WW}\delta$ of the loss Hessian with respect to the frozen weights. Our hypothesis is that this term is large precisely along the directions that carry subtle forensic features, and that those directions matter more off-distribution than on it.

Relation to Prior Work

Several papers motivate the problem. The authors of Quantization Meets OOD (FQAT) show that standard quantization-aware training sharpens the loss and hurts out-of-distribution accuracy. They repair this by adding sharpness-aware minimization (SAM, which updates weights using the gradient at a nearby worst-case point) to quantization-aware training, plus layer freezing to resolve gradient conflict. They report 41.27% out-of-distribution accuracy on DomainNet at 8 bits against 40.95% at full precision, and a 5.24% gain at 3 bits on PACS. Their shifts are style shifts (photo to sketch) on fully trained networks, and their flatness is with respect to the trained, quantized weights. We keep the backbone frozen and make flatness act across parameter groups.

In speech, From Sharpness to Better Generalization for Speech Deepfake Detection shows that sharpness rises on unseen languages and channels, and that SAM cuts AASIST's EER on ASVspoof 2021 LA from 8.10% to 4.62%. Codecfake adds domain-balanced SAM. Both stay at full precision. Their evidence that flatness tracks cross-dataset forgery generalization is a key reason to expect weight-space geometry to matter here too.

Other work supplies methods we reuse. GenD gives the detector: a frozen CLIP or DINOv3 backbone with LayerNorm tuning and hyperspherical metric losses, run at 120 frames per second on an A100. QDrop gives a reconstruction-based post-training quantizer, which flattens the loss during calibration so that it generalizes beyond the calibration set. Train Flat, Then Compress gives evidence that flat training makes later 8-bit post-training quantization nearly free (MRPC F1 89.37 versus 86.81 for Adam).

One paper appears to cut against us. Revisiting the Parameter Efficiency of Adapters finds that adapters converge flat enough to binarize, reaching 77.0% on VTAB-1K at 1 bit against 76.7% at full precision. That result concerns quantizing the adapter itself, on semantic classification. It does not show that the frozen backbone under the adapter can be quantized without harming subtle features. We treat it as a reason to leave $\theta$ in full precision, since it costs almost nothing, and to aim all the effort at $W$.

On the forgery side, Celeb-DF (average AUC falling to 56.9%), Celeb-DF++ (73.8% video-level AUC from FF++-trained detectors, and a 7.5% drop under H.264 c45), and What Makes Fake Images Detectable? establish that generalizing cues are local and fragile. That fragility is what makes quantization a plausible threat.

Research Program

The first stage is a measurement study. We will reproduce GenD with CLIP ViT-B/16 and ViT-L/14 backbones, trained on FF++ c23. We then quantize the backbone with round-to-nearest and with QDrop at W8A8, W4A8 and W4A4, keeping $\theta$ in floating point. For each test set we record the quantization gap, meaning full-precision AUC minus quantized AUC. The "forensic collapse" hypothesis predicts that this gap is several times larger on cross-dataset sets than on FF++ test. The predicted gap ordering is: largest on Celeb-DF++ talking-face and reenactment, then Celeb-DF v2, then FF++ test.

In the same stage we estimate backbone-direction sharpness on each test set. This is the loss increase under a worst-case $S_b$ perturbation of $W$, found with a few projected sign-gradient steps. We then check whether it predicts the per-dataset drop, mirroring the speech paper's diagnostic.

The second stage builds the method. Each training step takes one sign-gradient ascent step on $W$ inside the quantization box, scaled per output channel to the $b$-bit step size. It does the same for block activations. It then computes the GenD losses at the perturbed point and updates only $\theta$. The backward pass through the backbone is already needed to reach the LayerNorm gradients, so the overhead is about one extra forward-backward, the usual SAM cost. There is no gradient conflict of the FQAT kind, because the ascent variable and the descent variable are disjoint. We see this as a structural advantage of the frozen-backbone setting.

We train against the 4-bit box and deploy at every bit-width. To guard against Codecfake's domain-ascent bias, mini-batches are balanced across the four FF++ manipulation types.

The third stage is a secondary analysis of compounding. Input compression perturbs $x$ and backbone quantization perturbs $W$. We will evaluate all variants on FF++ c45 and on Celeb-DF++ re-encoded at c45. The question is whether weight-space flatness also buffers input laundering, or whether the two degradations add up.

Baselines

The naive reference point is full-precision GenD followed by off-the-shelf post-training quantization of the backbone (round-to-nearest, then QDrop with 1,024 FF++ calibration frames). This is what a practitioner would ship today, so it defines the cross-dataset AUC we must beat at each bit-width. GenD's paper reports state-of-the-art average cross-dataset AUROC over 14 benchmarks. The file gives no per-dataset values: no reported result found on Lacuna for GenD's per-dataset AUC on Celeb-DF v2, DFDC or DFD. We therefore reproduce GenD at full precision and treat our reproduction as the upper reference. The external anchors are 73.8% average video AUC for FF++-trained detectors on Celeb-DF++ (Celeb-DF++) and 78.75% cross-domain AUC for SPSL (DeepfakeBench).

The strongest competitor is quantization-in-the-loop LayerNorm tuning. Here GenD's LayerNorm parameters are trained directly on top of the already-quantized backbone, using the same quantizer that will be deployed. It is the natural engineering answer and directly fits $\theta$ to the actual rounding. It gets the same data, the same number of epochs, the same learning-rate sweep (five values), and the same wall-clock budget. Because our method costs about twice as much per step, the competitor is allowed twice the steps.

The second strong competitor is FQAT itself (Quantization Meets OOD), applied to the full CLIP detector with its layer-wise freezing. It represents the existing route of flattening the quantized weights directly. It gets the same budget.

The key ablation is SAM applied only to $\theta$ on a full-precision backbone, followed by post-training quantization. This is flatness with respect to the trained parameters, as in the speech-deepfake work. A second ablation replaces the worst-case box with random rounding noise of the same magnitude.

Beating the field means three things. At W4A4, our method's average cross-dataset AUC must exceed quantization-in-the-loop tuning on the quantizer seen in training. It must exceed it by a clearly larger margin on a quantizer not seen in training. And it must leave FF++ in-domain AUC within half a point of the best baseline. All comparisons use three seeds and paired bootstrap intervals.

Why not just…?

Why not just tune LayerNorm on the quantized backbone and skip the flatness? This is the real threat, and it may match us on the deployed quantizer and on in-domain data. Our argument is that it fits $\theta$ to the rounding errors that occur on FF++ activations. Activation ranges and outliers shift on unseen generators and on heavier compression, so the test-time rounding error differs from the one it was fit to. QDrop's own motivation is this calibration-to-test mismatch. The experiment settles the question in two ways. We compare cross-dataset gaps rather than in-domain ones, and we deploy each tuned $\theta$ under a quantizer it was not tuned with: round-to-nearest-tuned $\theta$ deployed with QDrop, and W8-tuned $\theta$ deployed at W4. If the simple method matches ours on both, we will report that the forensic-collapse problem is solved by in-the-loop tuning. The measurement study would then stand as the contribution.

Why not just run FQAT, which already joins flatness and quantization for out-of-distribution data? FQAT updates the whole network. On a foundation backbone, full fine-tuning is exactly what GenD found to cause shortcut overfitting to dataset-specific artifacts. FQAT also needs heuristic freezing to manage the conflict between quantization and SAM gradients, a conflict our formulation avoids by construction. Its evidence comes from style shifts on PACS and DomainNet, not forensic shifts. The FQAT baseline row tests directly whether its out-of-distribution gains carry over.

Why not just train with blur and JPEG augmentation so the detector stops relying on fragile cues? DeepfakeBench reports that such augmentation improves robustness to compression but lowers performance on high-quality fakes, because it removes fine forgery cues. That trades away the signal rather than protecting it. We include GenD with augmentation, with and without post-training quantization, as an extra row. We expect it to help on c45 and hurt on Celeb-DF v2 and Celeb-DF++ face-swap.

Why not just apply SAM to the trainable parameters, as the speech work did? Flatness with respect to $\theta$ says nothing about curvature along $W$, which is where the quantization noise actually lands. The $\theta$-only SAM ablation tests this. If it closes the gap as well as cross-parameter flatness does, our specific mechanism is unnecessary, and we will say so.

Proposed Experiments and Decisive Checks

The evaluation trains on FF++ c23 and tests on FF++ test, Celeb-DF v2, DFDC, DFD, FFIW, and the three Celeb-DF++ scenarios, using the released Celeb-DF++ code (Celeb-DF++ codebase). We report frame-level and video-level AUC (area under the ROC curve), bits per backbone weight, and measured latency on an INT8/INT4 inference runtime.

Three results decide the proposal. First, if quantized GenD's cross-dataset gap is no larger than its in-domain gap at W4A4, the forensic-collapse premise is false. We would publish that negative result as the main finding, since it would mean foundation-model detectors can be compressed freely. Second, cross-parameter flatness must beat quantization-in-the-loop tuning on held-out quantizers and bit-widths. Otherwise, the method adds cost without benefit. Third, measured backbone-direction sharpness should rank the test sets by their quantization drop. If it fails to, the geometric explanation is wrong, even if the method happens to work.