Spectral Consistency Training for Token Budgets That Survive Attack

Vision transformers can avoid their quadratic cost, where attention over $N$ image patches grows as $N^2$, by deciding per image how many patches ("tokens") are worth processing. These adaptive token sparsifiers are fast on average. Their worst case, however, is still full quadratic attention, and an attacker can push them there. DeSparsify shows that imperceptible perturbations drive A-ViT to 100% token use and raise ATS compute by 74% GFLOPs and 72% energy, while accuracy barely changes, so nothing downstream notices. This proposal asks whether a cheap training-time fix exists. We treat the sparsifier's budget decision, meaning how many tokens to keep and which ones, as the quantity that augmentation must stabilize, rather than the class label.

The core idea has two parts. The first is a known fact: gradient-based perturbations concentrate their energy in high spatial frequencies (Improving Vision Transformers by Revisiting High-Frequency Components). The second is a hypothesis: sparsifiers score tokens by attention or local entropy, and both signals react strongly to high-frequency energy. Spectral data augmentation edits an image's Fourier coefficients rather than its pixels. We propose to use it to perturb the high-frequency amplitude of training images while keeping their phase, which carries object structure. We then penalize the sparsifier whenever its budget changes under these perturbations. No inner adversarial loop is needed. If the hypothesis holds, adaptive models keep their sub-quadratic average cost and lose most of their attackable worst case, at nearly the training cost of plain augmentation.

Core Claim

Sub-quadratic claims for adaptive vision transformers are average-case claims. We claim that a large share of their worst-case gap is a spectral sensitivity of the allocation mechanism, and that a budget-consistency loss under phase-preserving high-frequency amplitude perturbations closes much of this gap more cheaply than adversarial training. It should also preserve more adaptivity than simply capping the token count.

Concretely, let $\mathcal{F}$ be the 2D discrete Fourier transform. Let $m_\omega$ be a mask selecting frequencies above a cutoff $\omega$, and let $\epsilon$ be random multiplicative noise bounded by $\rho$. The perturbation is

$$T(x) = \mathcal{F}^{-1}\Big( |\mathcal{F}x|\,(1 + m_\omega \odot \epsilon)\; e^{\,i\angle \mathcal{F}x} \Big).$$

This keeps phase fixed, following the observation in Random Amplitude Mixup and AFPA that phase carries geometry and identity. For a sparsifier with soft token budget $B(\cdot)$, the fraction of tokens kept summed over layers, and per-token keep scores $s(\cdot)$, the training objective is

$$\mathcal{L} = \mathcal{L}_{\text{task}}(x) + \lambda_1 \,\big|B(T(x)) - B(x)\big| + \lambda_2\, \mathrm{KL}\big(s(T(x)) \,\|\, s(x)\big),$$

where $\lambda_1,\lambda_2$ weight the two consistency terms and gradients through the clean branch are stopped. The new ingredient is not spectral augmentation itself. It is aiming spectral augmentation at the allocation decision.

Positioning

Three lines of prior work motivate this. DeSparsify supplies the threat and the evaluation protocol but proposes no training defense. Improving Vision Transformers by Revisiting High-Frequency Components (HAT) shows that PGD noise is high-frequency and uses it as label-level augmentation. HAT runs full quadratic attention, costs 1.7 to 2.3 times normal training, and never touches allocation. A Spectral View of Randomized Smoothing shows that phase and amplitude perturbations buy certified robustness to corruptions, again for labels and not compute.

Other work constrains the design. Fourier Token Merging discards high frequencies as noise before merging tokens. Anti-Oversmoothing and HAT argue that transformers already lose too much high-frequency detail. This tension matters here. If the defense taught the sparsifier to ignore high frequencies entirely, it would starve fine detail. That is why the invariance is bounded by $\rho$ and phase is preserved: real edges live largely in phase, and small amplitude jitter should not change how many tokens an image needs.

Our test beds come from the sparsification methods themselves. Adaptive Patch Transformers allocate patches by local entropy, a signal that is directly sensitive to high frequencies, which makes it a natural second target. SG-Former allocates by attention-derived significance. None of these papers evaluates allocation under perturbation.

Research Program

We first measure the hypothesis before building anything. For A-ViT, ATS and AdaViT on DeiT-S, we will run the DeSparsify attack and decompose the successful perturbations by frequency band. We then re-run the attack restricted to low-pass and to high-pass bands at equal L2 norm. If low-band attacks inflate compute as effectively as high-band ones, the spectral premise fails and we would redirect the work to band-agnostic consistency. That outcome is itself worth reporting.

Next we fine-tune each sparsifier with the objective above, sweeping $\omega$, $\rho$ and $\lambda_{1,2}$. We use the same schedule and epochs as the original models. The cost is one extra forward pass per batch and one FFT pair, which should be far below HAT's iterative passes.

Finally we characterize the trade-off. We report curves of clean accuracy against clean GFLOPs and against attacked GFLOPs, and we check whether clean adaptivity is retained. Retained adaptivity means the variance of the per-image budget, and its correlation with image difficulty, survive training.

Baselines

The naive reference is each sparsifier as released, trained with its standard spatial augmentation recipe. Under the original attack it should reproduce the reported +74% GFLOPs for ATS and 100% token use for A-ViT from DeSparsify. DeSparsify reports clean accuracy drops below 1% under attack, so accuracy alone cannot reveal the failure. We found no reported defense result on Lacuna for any method against DeSparsify, so the reference numbers we must beat are the attack's own inflation figures.

The strongest existing competitor is adversarial training against the compute objective: PGD that maximizes token budget, folded into training in the HAT style (Improving Vision Transformers by Revisiting High-Frequency Components). It optimizes the threat directly. We will run it with the same epochs and the same hyperparameter-search budget in trials. We report wall-clock training cost alongside results, because HAT's 1.7 to 2.3 times overhead is the price it pays. Beating it means matching its attacked GFLOPs within 10% at a fraction of its training cost, or beating it outright at matched wall-clock.

A hard token cap clips the budget at a fixed fraction, chosen at the median clean budget. By construction it bounds worst-case compute. Beating it means higher accuracy at equal worst-case GFLOPs, because the cap forfeits adaptivity on hard images.

Two ablations isolate the key ingredient. Isotropic pixel Gaussian noise at matched L2 norm, run with the same consistency loss, tests whether the spectral structure matters. Spectral augmentation applied with only $\mathcal{L}_{\text{task}}$, as in HAT-style label augmentation without the budget terms, tests whether aiming at allocation matters. A phase-perturbing variant tests the phase-preservation choice.

Why not just…?

Why not just cap the number of tokens? A cap does bound compute, and it is a real competitor for anyone who only cares about worst-case latency. Its cost is that every hard image is truncated to the cap. The adaptive model then behaves like a fixed pruner such as FastV, with the conservative-pruning failures that AgilePruner documents. The cap comparison at matched worst-case GFLOPs settles the question. If the cap matches our accuracy, the proposal offers little, and we will say so.

Why not just do adversarial training on the budget? It is the most direct defense and may be the most robust. It is also the expensive route, and it is tuned to one attack. Our claim is efficiency plus transfer. The head-to-head at matched wall-clock, together with evaluation under band-restricted attacks the defense never saw, will show whether the cheaper method is merely cheaper or also more general.

Why not just add input noise or low-pass filter at test time? Pixel noise is simpler, and our matched-norm ablation tests exactly that. A test-time low-pass filter would remove the attack band but also remove real detail. HAT and Anti-Oversmoothing show such detail already matters to transformer accuracy. We will include low-pass preprocessing as an extra baseline and report its clean-accuracy cost.

Proposed Experiments

The primary setting follows DeSparsify: DeiT-S variants of A-ViT, ATS and AdaViT on ImageNet-1K and CIFAR-10, with GFLOPs, token utilization, peak memory and GPU energy measured as in that paper. We add ImageNet-C accuracy to check that spectral consistency does not degrade corruption robustness, and APT on ImageNet-1K and ADE20K to test an entropy-based allocator on a dense task. Every comparison reports four numbers: clean top-1, clean GFLOPs, attacked GFLOPs and attacked top-1.

Three checks decide the outcome. First, an adaptive attack that knows the defense, using expectation over random spectral perturbations and with freedom to move to low frequencies, must still yield substantially less GFLOP inflation than on the undefended model. Otherwise we have only shifted the attack band. Second, the spectral variant must beat matched-norm pixel noise, or the frequency story is decorative. Third, clean budget variance must stay close to the original model's. If it collapses, the method has quietly turned into a cap.