Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Practise against the attacker
If a model keeps falling for small, crafted changes, show it those changes during training. At every training step an attacker searches for the worst version of each example within the allowed budget, and the model learns to classify those correctly. It is like a goalkeeper who trains against the hardest shots rather than easy ones. It works, but it costs several times more computation, needs more data, and can make the model slightly worse on ordinary inputs.
Adversarially trained image classifiers are among the very few defences that have held up under years of adaptive attacks; the RobustBench leaderboard tracks them.
- 1. Adversarial training trains on…
- 2. Its main cost is…
- 3. Adversarial training can slightly lower…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Robust (adversarial) risk: E[max over ‖δ‖ ≤ eps of L(f(x + δ), y)]: the expected loss when an attacker picks the worst perturbation for each input.
- Madry (PGD) adversarial training: minimise the robust risk by computing x + δ with PGD at every training step and taking a gradient step on the loss there.
- One-step adversarial training: FGSM from a random start with step about 1.25·eps (‘fast’ training, Wong, Rice and Kolter); much cheaper but can suffer catastrophic overfitting at large budgets.
- TRADES: loss = cross-entropy on clean x + β·KL(p(x) ‖ p(x′)), with x′ maximising the KL in the eps-ball; β trades clean accuracy against robustness.
- Robust accuracy: accuracy under a strong attack at the training budget; always evaluated with attacks stronger than the one used for training (topic M1-2).
- Robust overfitting: robust test accuracy that peaks and then falls during training while robust training accuracy keeps rising (Rice, Wong and Kolter, 2020).
- Accuracy–robustness trade-off: robust models are often less accurate on clean data (Tsipras and colleagues, 2019).
- 1. Madry adversarial training minimises…
- 2. In TRADES, β weights…
- 3. Robust overfitting is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Training against attacks
Exercise 1.
- The three-class, 20-dimensional mixture data and ReLU network of topic M1-2, now written with explicit forward and backward passes so the same code trains on clean or attacked inputs.
- Four training methods at eps = 0.5: standard; one-step adversarial training with a random start; PGD adversarial training (cross-entropy, random start); TRADES with β = 6.
- Robust accuracy measured with margin-loss PGD and restarts, which is stronger than the training attacks.
- Checks: the input gradient matches finite differences; every adversarial method beats standard training under attack.
Practice.
- Train with PGD or TRADES at the budget you need; use one-step training with a random start when compute is tight, and check for catastrophic overfitting by evaluating with PGD.
- Evaluate with stronger attacks than you trained with (AutoAttack), and report clean and robust accuracy together.
- Use early stopping on robust validation accuracy to avoid robust overfitting; weight averaging and data augmentation help too.
- Add data: extra unlabelled or generated data substantially improves robust accuracy on image benchmarks.
- Budget compute: PGD training with k attack steps costs about k + 1 times standard training.
def train_step_pgd(P, X, y, eps, rng):
Xa = pgd(P, X, y, eps, steps=3, rng=rng) # inner maximisation
A, H, Z = forward(P, Xa)
G, _ = backward(P, Xa, A, H, (softmax(Z) - Y) / n) # outer minimisation on the attacked inputs
return G
# TRADES: clean cross-entropy + beta * KL(p(x) || p(x')), x' = PGD on the KL
# dKL/dZ(x') = q - p ; dKL/dZ(x) = p * (log p - log q - KL)- 1. Catastrophic overfitting is checked by…
- 2. Robust overfitting is reduced by…
- 3. PGD training with 10 attack steps costs about…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
The min–max view. Adversarial training solves min over θ of E[max over ‖δ‖ ≤ eps of L(f_θ(x + δ), y)]. By Danskin’s theorem, if the inner maximum is attained at a unique δ*, the gradient of the inner maximum with respect to θ is ∇_θ L(f_θ(x + δ*), y). So a step on the loss at the PGD example is a (sub)gradient step on the robust risk, provided the attack finds the maximiser; a weak inner attack gives a wrong gradient, which is one cause of catastrophic overfitting in one-step methods.
TRADES. Robust error splits into natural error plus boundary error: the probability that x is classified correctly but some x′ in its eps-ball is not. TRADES (Zhang and colleagues, 2019) bounds the boundary error by a surrogate, the KL divergence between the predictions at x and at the worst x′, and minimises cross-entropy + β·KL. Because KL(p ‖ q) ≥ 0 with equality only when p = q, the penalty is zero exactly when the predicted distribution is constant over the ball. β moves the model along the trade-off between clean and robust accuracy.
Why robustness needs more data. Schmidt and colleagues (2018) built a Gaussian model in which a single sample is enough to learn an accurate classifier, but a robust classifier needs a number of samples that grows with the square root of the dimension. Robust learning also tends to overfit: the robust training loss can be driven to zero while robust test loss rises, so early stopping matters much more than in standard training.
- 1. Danskin's theorem justifies…
- 2. TRADES' penalty is zero when…
- 3. Robust learning needs…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How much do one-step, PGD and TRADES adversarial training improve accuracy under a strong attack, what do they cost in clean accuracy, and does robust accuracy keep improving with longer training?
History.
- I. Goodfellow, J. Shlens and C. Szegedy (2015) trained on a mix of clean and FGSM examples; A. Kurakin, I. Goodfellow and S. Bengio (2017) scaled this to ImageNet and found ‘label leaking’.
- A. Madry and colleagues (2018) formulated the min–max problem and PGD training; F. Tramèr and colleagues (2018) proposed ensemble adversarial training.
- H. Zhang and colleagues (2019) introduced TRADES and won the NeurIPS 2018 adversarial vision challenge with it.
- A. Shafahi and colleagues (2019) (‘free’) and E. Wong, L. Rice and J. Z. Kolter (2020) (‘fast is better than free’) made adversarial training cheap; L. Rice, E. Wong and J. Z. Kolter (2020) described robust overfitting.
- L. Schmidt and colleagues (2018) and D. Tsipras and colleagues (2019) studied the sample complexity and the trade-off; Y. Carmon and colleagues (2019) and S. Gowal and colleagues (2021) improved robustness with extra unlabelled and generated data.
Exercise 2.
- 600 training and 400 test points; training budget eps = 0.5; 300 Adam steps for each method (PGD and TRADES with 3 attack steps).
- Evaluation: clean accuracy and accuracy under 20-step margin-loss PGD with 2 restarts at eps 0.3, 0.5 and 0.75; robust accuracy at 0.5 on 400 training points.
- PGD training continued to 600 steps with snapshots at 100, 300 and 600.
Seed 0 (robust accuracy at eps 0.5 for seeds 1 and 2 in brackets):
| method | clean | eps 0.3 | eps 0.5 | eps 0.75 | eps 0.5, training points |
|---|---|---|---|---|---|
| standard | 0.973 | 0.805 | 0.588 (0.395, 0.490) | 0.270 | 0.593 |
| one-step, random start | 0.983 | 0.910 | 0.743 (0.505, 0.657) | 0.375 | 0.905 |
| PGD training | 0.980 | 0.890 | 0.715 (0.502, 0.635) | 0.345 | 0.868 |
| TRADES, β = 6 | 0.973 | 0.897 | 0.780 (0.613, 0.713) | 0.500 | 0.850 |
PGD training for longer (robust accuracy at eps 0.5, seed 0):
| steps | training points | test points | gap |
|---|---|---|---|
| 100 | 0.807 | 0.728 | 0.079 |
| 300 | 0.868 | 0.715 | 0.153 |
| 600 | 0.950 | 0.698 | 0.252 |
Findings.
- Every adversarial method raised accuracy under attack at eps 0.5, by 10.7 to 22.3 points over standard training across the three seeds; TRADES was best at eps 0.5 and 0.75 for all three seeds (0.500 against 0.270 at eps 0.75 for seed 0).
- Clean accuracy did not fall in this small problem (0.973 to 0.983 against 0.973 for seed 0); the trade-off appeared only for large β (Practice 3).
- One-step training with a random start matched PGD training at this budget (0.743 against 0.715 for seed 0; 0.505 against 0.502, and 0.657 against 0.635), but at eps 1.0 a one-step model looked much more robust to FGSM than to PGD (Practice 2).
- Robust overfitting: with longer PGD training, robust accuracy on training points rose from 0.807 to 0.950 while on test points it fell from 0.728 to 0.698; the gap widened in all three seeds (0.088 to 0.185 and 0.123 to 0.265 for seeds 1 and 2).
Adversarial training in practice
- Benchmarks: RobustBench lists adversarially trained CIFAR-10 and ImageNet models evaluated with AutoAttack; at the L∞ budget 8/255 on CIFAR-10 the best robust accuracies are around 70%, against clean accuracies above 90%.
- Ingredients of strong recipes: TRADES or PGD training, wide networks, weight averaging, early stopping and millions of generated images from diffusion models.
- Beyond images: adversarial training for malware detection, speech, text (in embedding space) and robust control policies; for language models, adversarial training against jailbreak attacks.
- Limits: robustness is specific to the threat model used in training (Practice 4) and gives no guarantee; certified methods (topic M1-4) do.
References
- A. Madry and colleagues (2018). “Towards deep learning models resistant to adversarial attacks.” ICLR.
- H. Zhang and colleagues (2019). “Theoretically principled trade-off between robustness and accuracy.” ICML.
- E. Wong, L. Rice and J. Z. Kolter (2020). “Fast is better than free: revisiting adversarial training.” ICLR.
- L. Rice, E. Wong and J. Z. Kolter (2020). “Overfitting in adversarially robust deep learning.” ICML.
- L. Schmidt and colleagues (2018). “Adversarially robust generalization requires more data.” NeurIPS.
- D. Tsipras and colleagues (2019). “Robustness may be at odds with accuracy.” ICLR.