Theory & Frontiers/Adversarial Robustness

Lesson 7.22,038 words

Adversarial Robustness

A trained network can be fooled by a perturbation too small for a human to see: add a carefully aimed vector of magnitude ϵ\epsilon to a correctly classified image and the prediction flips. We derive the fast gradient sign method as the first-order-optimal step inside an LL_\infty ball, explain the linearity hypothesis that makes high-dimensional models so easy to push around, build up to projected gradient descent, and frame adversarial training as a min-max robust-optimization problem with its own accuracy cost.

╌╌╌╌

A network that hits human-level accuracy on a test set can still be steered to any wrong answer you like by a perturbation you cannot see. Take a correctly classified image , add a vector with for some tiny (a few gray levels out of ), and the model's prediction flips with high confidence. The perturbed input is an adversarial example.1 This is not a rare glitch on a handful of inputs; for an undefended deep network it is the generic situation, and it is the sharpest known failure of the flat decision boundaries that linear readouts draw near the data.

The threat model

Robust is meaningless until we say against what. A threat model fixes three things: the perturbation set the attacker may choose from, the knowledge the attacker has of the model, and the goal of the attack. The perturbation set is almost always a norm ball , and the two norms that dominate the literature carve out very different shapes.

The two perturbation sets around a clean input. The ball is a box (per-coordinate cap); the ball is a sphere (bounded energy).
AxisChoicesWhat it means
Perturbation set ball / ball / (few pixels)the geometry of allowed
Knowledgewhite-box (full , gradients) / black-box (queries only)what the attacker can compute
Goaluntargeted (any wrong class) / targeted (a chosen wrong class)how hard the attack is

White-box is the worst case and the one robustness is measured against: assume the attacker has and can differentiate through the model. A defense that only survives black-box attackers is usually relying on the attacker not knowing the gradient, a fragile assumption we return to under gradient masking.

FGSM: the first-order-optimal step

The attacker wants to increase the loss , pushing the model away from the correct answer, while keeping inside the ball. Hold and fixed and linearize the loss around with a first-order Taylor expansion:

To maximize the loss we maximize the inner product , writing , subject to . This is a tiny constrained optimization with a closed form: each coordinate is free in and contributes , so the sum is maximized by pushing each coordinate to its extreme in the direction of its gradient sign.

That optimal is the fast gradient sign method (FGSM).2 The maximum achievable first-order loss increase is ; it scales with the norm of the gradient, which grows with dimension.

The sign appears because the constraint is , and the tightest bound on a linear form under an constraint is Hölder's inequality, with . For the dual is , giving the bound , attained by . Change the constraint and the optimal step changes with it: under an budget the dual is , the bound is , and the maximizer is the normalized gradient — ordinary steepest ascent. Each norm ball selects the steepest-ascent direction in its own geometry: FGSM is steepest ascent measured in .

The steepest-ascent step depends on the norm ball. Under the box the optimum is the sign vector reaching a corner; under the ball it is the normalized gradient, reaching the point where the ball is tangent to the loss level set.

For example, take a three-pixel input with clean values , and suppose the input-gradient of the loss at is . With budget , FGSM sets each coordinate to :

Every pixel moved by exactly regardless of the magnitude of its gradient component — the sign discards magnitude and keeps only direction. The first-order loss increase is , matching the bound. Had we instead used the raw gradient step , the largest coordinate would have moved only : it underuses the budget on the small-gradient pixels. The sign is what saturates every coordinate to the box wall.

FGSM geometrically. The sign step jumps to the corner of the box best aligned with the gradient , crossing the boundary.

The linearity hypothesis

Why does a perturbation far too small for a human to notice swing the output so violently? The early intuition blamed extreme nonlinearity. Goodfellow, Shlens and Szegedy argued the opposite: deep networks are too linear, and the damage is a high-dimensional dot-product effect.3 Consider a single linear unit and the worst-case perturbation :

The activation shifts by . The key is that this grows with the dimension even though each coordinate of is capped at . If the weights have average magnitude , then , so the perturbation's effect on the activation is

linear in , while the perturbation's per-pixel size stays fixed at . A model that operates on pixels accumulates a hundred thousand small aligned contributions into an activation shift large enough to cross a class boundary, even though no individual pixel moved visibly.

The dimension effect. With each coordinate capped at , the activation shift still grows linearly in the dimension .

PGD: the strong iterative attack

FGSM takes a single linearized step. But the loss is not actually linear, so one big jump overshoots and underuses the budget. The fix is to iterate: take small signed-gradient steps of size , and after each step project back onto the -ball so the cumulative perturbation never escapes the threat model. This is projected gradient descent (PGD), the standard strong white-box attack. For the ball the projection is a coordinate-wise clip:

and the PGD iterate is

PGD as a constrained path. Each step climbs the loss; a step leaving the -box is projected back, so iterates crawl to the loss-maximizing corner.

Both attacks share the same skeleton (climb the loss in input space) and differ only in the step count and the projection.

Algorithm:Fgsm(x,y,ϵ)\textsc{Fgsm}(x, y, \epsilon) — one-step LL_\infty attack
  1. 1
    gxloss(x,y)g \gets \nabla_x\, \text{loss}(x, y)
    input-gradient at the clean point
  2. 2
    xx+ϵsign(g)x' \gets x + \epsilon \cdot \text{sign}(g)
    optimal linearized step
  3. 3
    xclip(x,0,1)x' \gets \text{clip}(x', 0, 1)
    keep a valid image
  4. 4
    return xx'
Algorithm:Pgd(x,y,ϵ,α,T)\textsc{Pgd}(x, y, \epsilon, \alpha, T) — iterated, projected LL_\infty attack
  1. 1
    xx+rand(ϵ,ϵ)x' \gets x + \text{rand}(-\epsilon, \epsilon)
    random start inside the box
  2. 2
    for t1t \gets 1 to TT do
  3. 3
    gxloss(x,y)g \gets \nabla_x\, \text{loss}(x', y)
    gradient at the current iterate
  4. 4
    xx+αsign(g)x' \gets x' + \alpha \cdot \text{sign}(g)
    small ascent step
  5. 5
    xx+clip(xx,ϵ,ϵ)x' \gets x + \text{clip}(x' - x, -\epsilon, \epsilon)
    project onto eps-box
  6. 6
    xclip(x,0,1)x' \gets \text{clip}(x', 0, 1)
    keep a valid image
  7. 7
    return xx'

The random start matters: it scatters the attack across the box and defeats defenses that only flatten the loss at the single clean point, so multi-restart PGD is the standard yardstick for measuring robustness.

The step size and count are coupled to the budget. A useful default keeps the per-step move small relative to and takes enough steps to reach the wall: with steps of size the attack can travel up to in , so is needed to cover the ball, and a common choice is , which lets each coordinate reach either wall and then bounce. Continuing the worked example with : choosing gives , so a coordinate whose gradient sign stays fixed climbs over the first four steps, then the clip pins it at ; later steps that would push past the wall are clamped back by the projection . Where the sign flips between steps the iterate walks back off the wall — the non-linearity FGSM's single step misses. PGD therefore finds a strictly higher inner-max loss than FGSM on the same budget, and the gap is a direct measure of how non-linear the loss is inside the ball.

The canonical schematic

The textbook picture is one image: a clean input the model labels correctly (the original panda at ), plus a small multiple of the signed gradient, equals an adversarial input the model labels confidently wrong, a gibbon at , yet the two images are visually indistinguishable.

The canonical construction. A correct input plus times the signed gradient gives a visually identical input that is confidently misclassified.

Robustness as a saddle point

If an attacker maximizes the loss over the perturbation set, the natural defense is to train against that worst case. This turns ordinary empirical risk minimization into a min-max (robust optimization) problem: minimize over parameters the expected worst-case loss the attacker can inflict.4

The practical loop reuses the training loop with one inserted line: before each gradient step, replace the batch with its adversarial counterpart from the inner attack.

Algorithm:AdvTrain(fθ,D,ϵ,α,T)\textsc{AdvTrain}(f_\theta, \mathcal{D}, \epsilon, \alpha, T) — min-max training
  1. 1
    initialize θ\theta randomly
  2. 2
    repeat
  3. 3
    sample a minibatch (X,y)D(X, y) \sim \mathcal{D}
  4. 4
    XPgd(X,y,ϵ,α,T)X' \gets \textsc{Pgd}(X, y, \epsilon, \alpha, T)
    inner max: worst-case batch
  5. 5
    Lloss(fθ(X),y)L \gets \text{loss}(f_\theta(X'), y)
    loss on the adversarial batch
  6. 6
    θθηθL\theta \gets \theta - \eta \cdot \nabla_\theta L
    outer min: SGD step
  7. 7
    until converged
  8. 8
    return θ\theta

By the envelope theorem, differentiating through the inner maximum is valid: at the optimal the gradient with respect to is just holding fixed, which is why the loop above can treat the attacked batch as ordinary data.

The robustness–accuracy tradeoff

Robustness is not free. Fitting the worst case inside every -ball forces smoother, lower-capacity decision functions, and a model spending capacity to be flat near the data has less left to chase the last points of clean accuracy. The empirical and theoretical picture is a tradeoff: as the training budget rises, accuracy under attack improves while accuracy on clean data falls.

The robustness–accuracy tradeoff. As the training budget grows, clean accuracy decays while robust accuracy rises then saturates.

Adversarial training buys robustness at a cost in clean accuracy. Whether a defense can do better — whether robustness can be proved rather than measured, and why so many published defenses failed under stronger attacks — is taken up next.

This continues in Adversarial Defenses.

Takeaways

  • An adversarial example with is an imperceptible perturbation that flips the prediction; every claim of robustness is relative to a threat model (norm ball, white-box vs. black-box, targeted vs. untargeted).
  • FGSM, , is the exact maximizer of the linearized loss over the ball: steepest ascent in the norm, just as ordinary gradient ascent is steepest in .
  • The linearity hypothesis explains the severity: a bounded perturbation shifts a linear unit's activation by , linear in the dimension — many small aligned per-pixel moves sum to a large shift, and such examples transfer across models.
  • PGD iterates FGSM with a projection back into the -ball; multi-restart PGD is the standard strong white-box benchmark, and it finds a strictly higher inner-max loss than FGSM's single jump.
  • Adversarial training is the min-max problem : SGD on PGD-attacked batches. It buys robustness at a real cost in clean accuracy, an intrinsic tradeoff on some distributions — the handoff to the defense side.

Footnotes

  1. Goodfellow, Deep Learning, §7.13 — Adversarial Training: imperceptible -bounded perturbations that flip a correct prediction.
  2. Goodfellow, Deep Learning, §7.13 — the fast gradient sign method as the linearized-loss maximizer over the ball (Goodfellow, Shlens & Szegedy, 2015).
  3. Goodfellow, Deep Learning, §7.13 — the linearity hypothesis: high-dimensional near-linear models accumulate aligned perturbations into a shift of , growing with dimension.
  4. Goodfellow, Deep Learning, §7.13 — adversarial training as the min-max objective , i.e. SGD on attacked batches.

╌╌ END ╌╌