Abstract
Adversarial attacks optimize against models to defeat defenses. Existing defenses are static, and stay the same once trained, even while attacks change. We argue that models should fight back, and optimize their defenses against attacks at test time. We propose dynamic defenses, to adapt the model and input during testing, by defensive entropy minimization (dent). Dent alters testing, but not training, for compatibility with existing models and train-time defenses. Dent improves the robustness of adversarially-trained defenses and nominally-trained models against white-box, black-box, and adaptive attacks on CIFAR-10/100 and ImageNet. In particular, dent boosts state-of-the-art defenses by 20+ points absolute against AutoAttack on CIFAR-10 at $\epsilon_\infty$ = 8/255.
The Static Defense Disadvantage
Adversarial machine learning is a high-stakes game of cat-and-mouse. Most current defenses, such as adversarial training, are "static"—the model's weights and architecture are frozen after the training phase. However, the strongest adversarial attacks are iterative and adaptive; they use gradient optimization to find specific input perturbations that circumvent a fixed defense.
Static defenses are fundamentally disadvantaged because an attacker can "hit" the same defense multiple times to find a vulnerability. To survive, the defense must keep moving. The challenge lies in creating a defense that can adapt to unseen attacks during inference without requiring expensive re-training or sacrificing accuracy on clean, "natural" data.
Defensive Entropy Minimization (dent)
To address this, we introduce dent (defensive entropy minimization), a test-time adaptation strategy that gives the defender the "last move" advantage. Dent is a "plug-and-play" module that can be added to any existing model.
The Objective: Entropy as a Proxy
Instead of using labels (which are unavailable at test time), dent minimizes the Shannon entropy $H(\hat{y})$ of the model's predictions. High entropy indicates model uncertainty, often caused by an input being pushed near a decision boundary by an adversary. By minimizing entropy, dent pushes the model to be more confident, effectively moving decision boundaries away from the adversarial input.
Adaptation Mechanisms
Dent performs two types of adaptation during the forward pass:
- Model Adaptation ($\Delta$): Dent updates a small subset of the model's parameters—specifically the affine scale ($\gamma$) and shift ($\beta$) parameters in Batch Normalization layers. It also updates the running mean and variance statistics based on the current test batch.
- Input Adaptation ($\Sigma$): Dent applies dynamic Gaussian smoothing to the input. The degree of smoothing is not fixed but is optimized via the same entropy minimization objective.
Because dent runs after the attacker has generated a perturbation, it can adapt to that specific attack. Even if an attacker knows the defense exists, they are forced to rely on "stale" gradients from the previous state of the model.
Key Results and Insights
The effectiveness of dent was evaluated across standard benchmarks including CIFAR-10, CIFAR-100, and ImageNet.
- State-of-the-Art Boost: Dent improved the performance of top-tier adversarially trained models on CIFAR-10 by over 20 points absolute against AutoAttack (e.g., boosting a model from 59.5% to 82.3% accuracy).
- Saving "Nominal" Models: For standard models not trained for robustness, dent boosted adversarial accuracy from ~0% to over 45% with minimal loss (~3%) in natural accuracy.
- Scalability: On ImageNet, dent improved robustness against PGD attacks by 14 to 20+ points absolute.
- Dynamic vs. Stochastic: Unlike stochastic defenses that add random noise, dent is deterministic given the input batch. Its strength comes from active adaptation, not randomness.
Limitations
While powerful, dynamic defenses introduce new trade-offs. The primary limitation is computational cost: because dent requires an optimization loop (backpropagation) during inference, a 10-step adaptation is roughly 25x slower than a standard forward pass. Additionally, dent currently relies on batch statistics, making it less suitable for real-time streaming of single samples. Finally, dynamic defenses are difficult to "certify" mathematically because the model state is constantly shifting.
Future work will explore unsupervised objectives beyond entropy and methods to improve the efficiency of test-time optimization.
Summary updated