Certified Robustness
Provable guarantees from bound propagation, Lipschitz networks and randomized smoothing.
An attack that fails proves nothing: a stronger one might succeed tomorrow. A certificate is different, a proof that no perturbation in a given ball changes the prediction. This lesson builds certificates four ways (exact search, bounds pushed through the layers, a bound on the network's Lipschitz constant, and smoothing the classifier with noise) and shows what each costs in compute, in accuracy and in the threat models it can cover.
What you’ll learn
- Explain why exact verification of ReLU networks is NP-complete, and encode a ReLU exactly with mixed-integer constraints and approximately by its convex relaxation.
- Derive interval bound propagation and linear relaxation bounds, compute a certified margin by hand, and describe certified training and its paradox.
- Derive the Lipschitz-margin radius , show why products of spectral norms are loose, and explain what 1-Lipschitz architectures need.
- Prove the randomized-smoothing radius from the Lipschitz property of of a Gaussian-smoothed classifier, and compute certified radii.
- Compare the guarantees, costs and limits of the four approaches as of the mid-2020s.
Certificates and exact verification
Fix a classifier with logits , an input that it assigns to class , and a ball . The prediction is robust on exactly when every margin stays positive:
In NP. Guess for every ReLU whether it is active. With that pattern fixed, every constraint is linear, and linear programming decides feasibility in polynomial time. (Katz et al. guessed the input itself, a real vector whose size they did not bound, one of the gaps Sälzer and Lange (2021) repaired.) NP-hard. Encode a 3-SAT formula whose clauses , , are built from literals over Boolean variables . A negated literal is , one affine unit, and each clause is a single ReLU:
Linear input constraints cannot say "Boolean", but a small ReLU gadget per variable can: equals below and above, so it vanishes exactly at (Sälzer & Lange, 2021). Fold every requirement into one output, using ; since each , it is never negative:
Read as the margin of a two-class network, and take the box , the ball of radius around , where . An adversarial example in the box exists exactly when the formula is satisfiable. Katz et al.'s own gadget for Boolean inputs, constrained to , forces nothing: it is 0 for every between and .
Exact answers are still within reach for networks of modest size, by mixed-integer programming. A ReLU whose pre-activation is known to lie in is stable if (then ) or (then ), and unstable if . Only unstable units need a binary variable (Tjeng, Xiao & Tedrake, 2019):
These four linear constraints together with hold exactly when : with they force and , and with they force and .
Relax to the interval and eliminate it. A feasible exists exactly when , which rearranges to the upper face of a triangle. These three constraints are the convex hull of the ReLU's graph over , the tightest convex relaxation of a single unit (Ehlers, 2017):
With this formulation and careful bounds for every unit, Tjeng et al. verified convolutional and residual networks with more than 100,000 ReLUs, and for the first time computed the exact adversarial accuracy of an MNIST classifier at radius 0.1: an adversarial example for 4.38% of the test images and a certificate for all the others. Tight bounds mean fewer unstable units and fewer binary variables, and that is what makes or breaks exact verification.
A ReLU's pre-activation is known to lie in . At the true output is . What is the largest that the triangle relaxation allows at ?
Show the answer
0.75
The upper face is . The relaxation lets this unit output anything in at . Such gaps, added up over all the unstable units and layers, are what loosen the final bound.
Bound propagation
Instead of solving an optimization problem, push guaranteed bounds through the network one layer at a time. Interval bound propagation (IBP; Gowal et al., 2018) keeps a box for every layer, starting from the input box :
Take and , one hidden layer with , and ReLU, and the margin . At the hidden units are and . The input box has center and radius , so
The margin's lower bound takes at its largest and at its smallest, and IBP cannot certify the point, since that needs :
Yet the point is robust. Both extremes cannot happen at once: is largest at the corner , where , and the true minimum over the box is at that corner:
A linear relaxation keeps track of that dependence. Unit 2 is stably active, ; unit 1 is unstable on , and its triangle gives . Substituting the affine layer gives a lower bound linear in , minimized at a corner of the box. Here it is exact, and it certifies the point:
Propagating such linear bounds backward through the network, with a lower line () and the triangle's upper line for every unstable unit, is CROWN (Zhang, Weng, Chen, Hsieh & Daniel, 2018), which picks when and otherwise. Wong and Kolter (2018) reached the same triangle relaxation through the dual of its linear program; their fixed choice of dual variables amounts to a lower line of slope , parallel to the upper one, and they trained networks so that the resulting bound certifies. Branching on unstable units makes such bounds complete: β-CROWN with branch and bound was up to three orders of magnitude faster than branch and bound built on linear-programming solvers (Wang et al., 2021).
Certified training minimizes a loss on the bounds themselves. Gowal et al. trained IBP networks on , where puts the true logit at its lower bound and every other logit at its upper bound, ramping up from 0 and down from 1 to . Training makes the network's bounds tight: on CIFAR-10 at , Gowal et al.'s IBP-trained network had a clean error of 50.51% and a verified error of 68.44% by its own interval bounds (67.96% with a slower MIP and linear-programming verifier), so about 32% of the test images were certified. CROWN-IBP, which adds a linear backward pass to the training bound, reached 66.94%; Zhang et al. (2020) report that the IBP figure needed an extra PGD training term, without which IBP training gave 73.52%. There is a paradox: training against tighter relaxations often certifies less than training against loose intervals. Jovanović, Balunović, Baader and Vechev (2022) traced it to properties beyond tightness, the continuity and sensitivity of the relaxation, which shape the optimization.
import torch
def ibp_margin_lower(layers, x, y, eps):
lo, hi = x - eps, x + eps # the l_inf box around x
for layer in layers[:-1]:
if isinstance(layer, torch.nn.Linear):
mid, rad = (hi + lo) / 2, (hi - lo) / 2
mid, rad = layer(mid), rad @ layer.weight.abs().T # W mid + b, |W| rad
lo, hi = mid - rad, mid + rad
else: # ReLU, or any monotone activation
lo, hi = layer(lo), layer(hi)
W, b = layers[-1].weight, layers[-1].bias # fold the margins into the last layer
C = W[y] - W # row j: w_y - w_j
mid, rad = (hi + lo) / 2, (hi - lo) / 2
lower = C @ mid + (b[y] - b) - C.abs() @ rad # lower bounds on z_y - z_j
return torch.cat([lower[:y], lower[y + 1:]]) # certified if all are > 0For a 1-D input x and a list of Linear and ReLU modules. Folding each margin into the last layer is never looser than bounding and separately and subtracting; Gowal et al. call this elision of the last layer and found that it tightens the bounds. On the worked example the function returns 0 (up to rounding): not certified.
Lipschitz certificates
A bound that holds everywhere is simpler still. If the logit map is -Lipschitz in , , the prediction cannot change until the margin is used up:
Each margin is a linear function of the logits, , and . By Cauchy–Schwarz it moves by at most
So for every inside the radius. Bounding instead the subnetwork below the last layer by and using each row difference gives the radius , which is never smaller than the radius from , since .
The catch is . For a network with 1-Lipschitz activations, the product of the spectral norms is an upper bound, cheap to compute and often wildly loose. With and each factor is 10 and the bound is 100, yet has norm at most 1 for every 0/1 diagonal a ReLU can produce, so the true constant is 1. A loose certifies tiny radii. The alternative is to build networks whose constant is known by construction, Lipschitz networks, and that turns out to need more than constraining the weights.
Every layer of a norm-constrained network can only shrink the gradient, so an expressive 1-Lipschitz network needs layers that preserve it. Anil et al. proposed GroupSort, which sorts groups of pre-activations; with groups of two it is MaxMin, . Its Jacobian is a permutation matrix, so it preserves gradient norms. With -norm-constrained weights they proved GroupSort networks universal approximators of Lipschitz functions; whether the same holds under 2-norm constraints they left open. For convolutions, Trockman and Kolter (2021) parameterized exactly orthogonal layers with the Cayley transform of a skew-symmetric , computed efficiently for circular convolutions in the Fourier domain. Such networks certify with a single forward pass, but only in , and constraining every layer costs clean accuracy: Trockman and Kolter's most accurate orthogonal network reached 83% on CIFAR-10, and the one with the best certificates 75%, while an unconstrained wide ResNet reaches about 95% (Madry et al., 2018).
Every layer of a network has spectral norm at most 1 and its activations are 1-Lipschitz. At an input, the top logit beats every other by at least 0.6. What radius does the Lipschitz-margin certificate guarantee?
- 0.6
- 0.3
Show the answer
A.
With the radius is . The appears because a perturbation can raise one logit and lower another at the same time: a margin is a difference of two logits, and .
Randomized smoothing
Bound propagation and Lipschitz layers both constrain the network. Randomized smoothing constrains nothing: it replaces any base classifier by its vote under Gaussian noise, (Lecuyer et al., 2019; Cohen, Rosenfeld & Kolter, 2019).
Cohen et al. proved it with the Neyman–Pearson lemma, by finding the worst base classifier, a half-space. A shorter route shows that smoothing makes every class probability Lipschitz in a nonlinear way (Salman et al., 2019):
Fix one class, let indicate it, and let . Differentiating the Gaussian density moves the gradient onto the noise (Stein's identity): for a unit vector and ,
Among all functions with values in and the same mean , is largest when puts all of its mass where is largest, : a half-space again. With the standard normal density,
Since , the chain rule turns this into a constant bound on the slope:
Apply this to class and to any other class . Along a perturbation , falls by at most and rises by at most as much, so their gap shrinks by at most twice that. Since is increasing, a positive gap means still wins:
A smoothed classifier with has top-class probability under the noise, and . What radius does it certify? (.)
Show the answer
1.16
, in units where pixels lie in . Bounding instead the ordinary Lipschitz constant of , which is , would certify only : here the transform almost doubles the radius.
In practice is unknown and must be estimated. Cohen et al. guess the top class from a few noisy samples, draw more, and certify with a one-sided Clopper–Pearson lower bound on at confidence , abstaining when the bound falls below ; the certificate then holds with probability at least over the sampling. Even a unanimous vote gives a lower bound of only , which caps the certifiable radius at . The cap grows very slowly: at it is about for samples, for Cohen et al.'s and for a million. A larger certifies larger radii but makes the base classifier's job harder, so accuracy falls.
Denoised smoothing. The base classifier must cope with heavy noise, which standard classifiers do not. Salman et al. (2020) placed a denoiser in front of an off-the-shelf classifier, and Carlini et al. (2023) used a pretrained diffusion model as that denoiser: noise of level matches the diffusion forward process at the step with , so one denoising call on , followed by a standard classifier, serves as the base classifier. Without training anything, this certified 71% of ImageNet at radius 0.5, 14 points above the previous best certified result of any method (Diffusion Models).
The wall. An radius covers only perturbations of size : for ImageNet-sized images and the radii that smoothing typically certifies, less than one 8-bit intensity level per pixel (the Artificial Intelligence course's Adversarial Examples & Robustness works through the numbers). Smoothing cannot do much better: for , the radius that a broad class of noise distributions with independent, identically distributed coordinates can certify shrinks like (Kumar, Levine, Goldstein & Feizi, 2020), and noise that certifies a fixed radius for every base classifier needs a variance growing in proportion to on almost every pixel, which swamps the image (Blum, Dick, Manoj & Zhang, 2020).
Choosing a certificate
| Method | Guarantee | Scales to | Main limitation |
|---|---|---|---|
| MILP, branch and bound | Complete: certifies every robust input and finds every counterexample | Networks of modest size; more than 100,000 ReLUs when most units are stable | Exponential time in the worst case |
| Interval bound propagation | Sound and deterministic, for any box | Large networks: two matrix products per layer | Loose unless the network is trained for it |
| Linear relaxations (CROWN, LP duals) | Sound and tighter than intervals; complete with branching (β-CROWN) | Medium to large networks | More compute and memory; tighter bounds do not always train better |
| Lipschitz networks | Sound and deterministic in , from one forward pass | Any size, if every layer is constrained | Constrained layers cost accuracy; only |
| Randomized smoothing | , with probability , for any base classifier | ImageNet and pretrained models | Many noisy forward passes per input; radii vanish in high dimension |
Key takeaways
- Certifying an ball means lower-bounding the minimum margin over it. Doing so exactly is NP-complete for ReLU networks; MILP encodes each unstable ReLU with one binary variable, and relaxing it gives the triangle, the convex hull of a single ReLU.
- Interval bound propagation maps centers by and radii by : cheap, but loose because it forgets correlations between units. Linear relaxations such as CROWN are tighter, branch and bound makes them complete, and certified training makes the bounds tight enough to use, although tighter relaxations do not always train better.
- An -Lipschitz logit map certifies the radius . Products of spectral norms can vastly overestimate , and expressive 1-Lipschitz networks need gradient-norm-preserving layers such as GroupSort and orthogonal convolutions.
- Gaussian smoothing makes of each class probability -Lipschitz, which certifies for any base classifier; Monte Carlo estimates make it hold with probability , and diffusion denoisers let it use off-the-shelf models.
- Certificates lag empirical robustness, most of all for in high dimension, where converted radii shrink by and independent smoothing noise cannot close the gap.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Exact verification of ReLU networks is NP-complete. What does this imply in practice?
- No ReLU network can ever be verified exactly
- Verification is easy for networks with more than 100,000 ReLUs
- Unless P = NP, every complete verifier, MILP included, takes superpolynomial time on some networks, so practical verifiers either stay at modest scale or give up completeness for speed
- Attacks are NP-complete too, so adversarial examples must be rare
Show the answer
C. Unless P = NP, every complete verifier, MILP included, takes superpolynomial time on some networks, so practical verifiers either stay at modest scale or give up completeness for speed
NP-completeness is a worst-case statement. MILP verifiers handle networks with many ReLUs when good bounds make most units stable, while sound but incomplete methods (intervals, linear relaxations, Lipschitz bounds, smoothing) trade the ability to certify every robust input for speed.
Why can interval bound propagation fail to certify a point that is in fact robust?
- It ignores the bias terms
- It treats every unit's interval as independent, so it can pair one unit's worst value with another's even when no single input produces both
- It only works with sigmoid activations
- It estimates the bounds by random sampling
Show the answer
B. It treats every unit's interval as independent, so it can pair one unit's worst value with another's even when no single input produces both
Each layer's box is the tightest box around the image of the previous box, but the activations actually reachable form a correlated, slanted set inside it. In the worked example IBP paired with , which no input in the box produces together.
You bound your network's Lipschitz constant by the product of its layers' spectral norms, and the certified radii come out tiny. What is the most likely reason?
- The product can vastly overestimate the true constant, because the directions one layer stretches need not be the ones the next layer stretches
- The network cannot be robust at all
- Spectral norms underestimate the Lipschitz constant
- Lipschitz certificates only work for perturbations
Show the answer
A. The product can vastly overestimate the true constant, because the directions one layer stretches need not be the ones the next layer stretches
The product is an upper bound that is tight only when the layers' top singular directions line up. In the diagonal example each layer has norm 10 and the product is 100, while the network's true constant is 1. Lipschitz networks avoid the problem by constraining every layer, so that the product is the constant.
A randomized-smoothing certificate was computed from noisy samples at confidence . Which statement about it is correct?
- It holds deterministically for every input within the radius
- It also certifies the base classifier within the radius
- It certifies the same radius in
- With probability at least over the sampling, the smoothed classifier's prediction is constant within the certified radius
Show the answer
D. With probability at least over the sampling, the smoothed classifier's prediction is constant within the certified radius
The certificate concerns , the vote under noise, and rests on a confidence bound for ; with probability at most that bound is too optimistic. The base classifier can still have adversarial examples arbitrarily close to , and an radius covers only perturbations of size .
Further reading
- G. Katz, C. Barrett, D. Dill, K. Julian & M. Kochenderfer, "Reluplex: an efficient SMT solver for verifying deep neural networks," CAV (2017).
- S. Gowal et al., "On the effectiveness of interval bound propagation for training verifiably robust models," arXiv:1810.12715 (2018); published at ICCV (2019) as "Scalable verified training for provably robust image classification".
- Y. Tsuzuku, I. Sato & M. Sugiyama, "Lipschitz-margin training: scalable certification of perturbation invariance for deep neural networks," NeurIPS (2018).
- J. M. Cohen, E. Rosenfeld & J. Z. Kolter, "Certified adversarial robustness via randomized smoothing," ICML (2019).
- H. Salman, G. Yang, J. Li, P. Zhang, H. Zhang, I. Razenshteyn & S. Bubeck, "Provably robust deep learning via adversarially trained smoothed classifiers," NeurIPS (2019).