Algorithm Search⌘K

Techniqueadvanced

Backward pass differentiable approximation

Also called BPDA, obfuscated gradients.

Breaks defenses that hide gradients by using the true function on the forward pass and a differentiable stand-in on the backward pass.

Backward pass differentiable approximation (BPDA) is a technique of Athalye, Carlini and Wagner (2018) for testing a defense that puts a step gg in front of a classifier ff and so makes the gradient of f(g(x))f(g(x)) useless: zero almost everywhere, undefined, or wrong. Such a step can be a quantization of the input, a non-differentiable image transformation or a projection onto a learned set. Gradient attacks such as PGD then fail, and the defense looks robust. BPDA computes gg exactly on the forward pass but uses a differentiable function h≈gh \approx g on the backward pass, often the identity when g(x)≈xg(x) \approx x. The gradient is then Jh(x)⊤∇vL(f(v),y)J_h(x)^\top \nabla_v L(f(v), y) at v=g(x)v = g(x), which is good enough to find adversarial examples. In their study of 9 defenses accepted at ICLR 2018, 7 relied on such obfuscated gradients, and the new attacks circumvented 6 of them completely and 1 partially, in the threat model each paper claimed. The lesson is about evaluation: an attack that fails gives no evidence of robustness when its gradients are broken.

In plain words

Many defenses add a step before the model, such as rounding the pixels. The rounding gives the attacker a flat gradient, a signal that says "nothing changes here", so the usual attack makes no progress, and the defense seems strong.

The model behind the rounding is still the same weak model. BPDA keeps the real rounding when it runs the input forward, but when it asks which way to move, it pretends the rounding was not there. That answer is close enough to the truth, and the attack works again.

So a defense must be tested by an attacker who knows the defense and adapts the attack to it. A failed attack with broken gradients proves nothing.

When it applies

  • The defended model has the form f(g(x))f(g(x)) with ff differentiable and gg a step whose gradient is zero, missing or misleading, and the attacker knows gg (white box).
  • A differentiable hh with h(x)≈g(x)h(x) \approx g(x) is known, or g(x)≈xg(x) \approx x, so the identity is a good stand-in. A neural network trained to imitate gg also works.
  • The threat model allows test-time changes of xx inside a set SS, such as B∞(x,ϵ)∩[0,1]dB_\infty(x, \epsilon) \cap [0, 1]^d.
  • It does not help against a defense with a certificate, such as randomized smoothing or interval bound propagation, whose guarantee does not depend on gradients. Against random defenses, combine it with expectation over transformation.

The template

Notation: ff is the classifier, gg the defense step, hh the differentiable stand-in, LL the loss, ΠS\Pi_S the projection onto the allowed set SS. The holes in angle brackets are chosen for each evaluation.

  1. BPDA-EVALUATE(f, g, h, x, y, S)
  2. 1x' ← x
  3. 2for i ← 1 to ⟨number of steps⟩ do
  4. 3v ← g(x') ▷ the true defense on the forward pass
  5. 4r ← ∇_v L(f(v), y) ▷ the gradient of the classifier at g(x')
  6. 5d ← J_h(x')^T r ▷ the stand-in on the backward pass; d = r if h is the identity
  7. 6x' ← Π_S(x' + ⟨step rule⟩(d)) ▷ a PGD step inside the allowed set
  8. 7return x' ▷ check f(g(x')) on the true defense

Line L3 runs the defense exactly, so the final check at line L7 is on the real system and not on the stand-in. Line L5 is the only change to PGD. If hh is the identity, dd is the gradient of ff at the processed input g(x′)g(x'); this is like the straight-through estimator used to train networks with quantized units. For defenses whose gradient vanishes or explodes because gg is a deep iterative procedure, Athalye et al. use a related idea, reparameterization: write x=h(z)x = h(z) with g(h(z))≈h(z)g(h(z)) \approx h(z) and attack in zz.

Cost. Each step costs one call of gg, one forward and backward pass of ff, and one product with Jh⊤J_h^\top. With the identity stand-in the cost is that of PGD plus the cost of gg.

Why it works. If g(x′)≈x′g(x') \approx x', then f(g(x′))f(g(x')) and f(x′)f(x') are close functions near the iterates, and so the gradient of ff at g(x′)g(x') points in a useful direction even though gg itself has zero gradient. This is a heuristic, not a theorem: a stand-in can fail when hh is far from gg, and then the evaluation must try a better hh.

Classic examples

  • Input quantization against PGD. Let ff be a linear score s(v)=2v−1.2s(v) = 2v - 1.2 (label 1 if s>0s > 0, label 0 otherwise) on one input, and let g(x)=⌊4x⌋/4g(x) = \lfloor 4x \rfloor / 4. At x=0.8x = 0.8, g(x)=0.75g(x) = 0.75 and s=0.3s = 0.3, so the label is 1. The gradient of s(g(x))s(g(x)) is 00 at every point where it exists, so a plain gradient attack does not move. With hh the identity, line L5 gives d=2d = 2, and one step of 0.10.1 down, inside the ℓ∞\ell_\infty budget 0.10.1, gives x′=0.7x' = 0.7, g(x′)=0.5g(x') = 0.5 and s=−0.2s = -0.2: the label changes. The same pattern broke defenses based on thermometer encoding and on input transformations such as bit depth reduction.
  • Defensive distillation. An earlier case of a masked gradient: defensive distillation made the softmax saturate, so gradients of the loss were tiny, but the Carlini-Wagner attack on the logits found adversarial examples at the same distances as before.
  • Projection onto a learned set. Defenses that move the input to a nearby point of a generative model before classifying it compute gg by an inner optimization. Its gradient explodes or vanishes, and BPDA with the identity, or reparameterization, attacks them.
  • Random transformations. A defense that applies a random resize or padding has a random gradient; BPDA for the non-differentiable parts plus expectation over transformation for the randomness breaks it.
  • Training-time defenses are a contrast. Adversarial training changes ff itself and keeps true gradients, and it held up in the same study within its threat model.

Variations

  • A learned stand-in. When g(x)g(x) is not close to xx, train a small network hh to imitate gg and use it on the backward pass.
  • Reparameterization. For an iterative gg, attack in a latent space zz with x=h(z)x = h(z) and g(h(z))≈h(z)g(h(z)) \approx h(z).
  • Combined with EOT. For random gg, average the BPDA gradient over many draws of the randomness.
  • Gradient-free checks. Black-box attacks such as the boundary attack or the zeroth-order attack need no gradient at all, so if they beat a white-box gradient attack, the gradients are masked.
  • Adaptive attacks in general. Tramer, Carlini, Brendel and Madry (2020) circumvented 13 recently published defenses, each with its own adapted attack, and showed that BPDA is one tool among several: the attack must be built for the defense.

Pitfalls

  • Checking success on the stand-in. Line L7 must evaluate f(g(x′))f(g(x')) with the true gg; a success of f(h(x′))f(h(x')) says nothing about the defense.
  • A bad stand-in. If hh is far from gg at line L5, the attack can fail, and the failure is about hh, not about the defense. Try another hh before you report robustness.
  • Too few steps. With a stand-in the direction is noisy, so line L2 often needs more steps than plain PGD. Report how the attack success changes with the number of steps.
  • Reading a failed attack as a lower bound. An attack gives an upper bound on robust accuracy, never a lower bound. Only a verifier or a certificate gives a lower bound.
  • Signs of masked gradients. Carlini et al. (2019) list them: one-step attacks beat iterative ones, black-box attacks beat white-box ones, a larger budget does not reach 100 percent success, or random search finds adversarial examples that gradients miss. If any holds, the gradients are broken somewhere.

Exercises

  1. Let g(x)=⌊kx⌋/kg(x) = \lfloor kx \rfloor / k on [0,1][0, 1]. Show that the derivative of s(g(x))s(g(x)) is 00 at every point where it exists, for every differentiable ss, and find the points where it does not exist.
  2. In the quantization example, show that every budget ϵ>0.05\epsilon > 0.05 allows an x′x' with ∣x′−0.8∣≤ϵ|x' - 0.8| \le \epsilon and the label 0, and that no budget ϵ≤0.05\epsilon \le 0.05 does.
  3. Suppose ∥g(x)−x∥2≤c\lVert g(x) - x \rVert_2 \le c for every xx and the score ss of ff is λ\lambda-Lipschitz. Show that ∣s(g(x))−s(x)∣≤λc|s(g(x)) - s(x)| \le \lambda c, and explain why an attack on ff alone with a margin larger than λc\lambda c also succeeds against f∘gf \circ g.

References

  1. Anish Athalye, Nicholas Carlini and David Wagner, Obfuscated gradients give a false sense of security, circumventing defenses to adversarial examples, ICML 2018, PMLR 80, pages 274 to 283, the three kinds of obfuscated gradients, BPDA, the reparameterization and EOT attacks, and the study of 9 defenses of ICLR 2018, of which 7 relied on obfuscated gradients (6 circumvented completely and 1 partially)
  2. Nicholas Carlini, Anish Athalye, Nicolas Papernot, Wieland Brendel, Jonas Rauber, Dimitris Tsipras, Ian Goodfellow, Aleksander Madry and Alexey Kurakin, On evaluating adversarial robustness, arXiv 2019, the checklist for an evaluation, including the signs of gradient masking
  3. Florian Tramer, Nicholas Carlini, Wieland Brendel and Aleksander Madry, On adaptive attacks to adversarial example defenses, NeurIPS 2020, thirteen defenses with an adaptive attack for each, and the lessons for evaluation

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises