



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Problem 1 (Coding). In this task, you are going to implement adversarial training with PGD (originally introduced in [1]) and an alternative defense.
min θ E(x,y)∼D
max x′∈B(x)
L(θ, x′, y)
Here, B(x) := {x′^ | ‖x − x′‖∞ ≤ } denotes the -sized `∞-ball around x. L is the usual classification loss L(θ, x′, y) := H(y, fθ(x′)), where fθ = (model ◦ softmax) denotes the output distribution of the neural network, and H the cross entropy^1 between distributions (being a discrete value, we treat y as a one-hot distribution). In PyTorch, you can use nn.CrossEntropyLoss^2 to implement L.
Use PGD to solve the inner optimization problem with = 0.1, k = 7 steps, and step = 2. 5 k. You can reuse your implementation of untargeted PGD from the previous exercise, or create a more efficient (batched) version better suited for training.
Compare the accuracy results with and without PGD training.
(^1) https://en.wikipedia.org/wiki/Cross_entropy (^2) https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html
min θ E(x,y)∼D
L(θ, x, y) ︸ ︷︷ ︸ for accuracy
L(θ, x′, fθ(x)) ︸ ︷︷ ︸ regularization for robustness
Extend your implementation in train.py to the TRADES defense. Again, the inner optimization problem is solved using PGD. Use λ = 1.0 and the same pa- rameters as in the previous task. Compare your results with the previous task.
Note: Here, L(θ, x′, fθ(x)) still denotes the cross entropy loss. However, PyTorch’s nn.CrossEntropyLoss cannot be used as it expects one of the distributions to be a one-hot encoding of the label. Instead, you will need to manually implement L. To this end, some existing functions in PyTorch3 4^ may be useful.
Solution 1. See train.py.
Defense Clean Accuracy Adversarial Accuracy None 0.98 0. PGD 0.98 0. TRADES 0.98 0.
Table 1: Test set accuracy.
The accuracy obtained with the default parameters and 50 (instead of 10) epochs is shown in table 1. Without any defense, the adversarial accuracy drops significantly, while it remains high with a defense. Note that the PGD defense outperformed TRADES here (higher adversarial accuracy at the same clean accuracy)—MNIST is a very “easy” task where adversarial training does not impact the clean accuracy too much. Note that the model and hyper-parameters used here are far from optimal.
Problem 2 (Alternating optimization). We formalized adversarial defense as the opti- mization problem in (1). In general, finding the globally optimal parameters θ∗^ is hard due to the nesting of maximization and minimization. In the lecture, we considered a method that approximates θ∗^ by individually solving the outer and inner optimization problem in alternation. In this task, you will show that this approach can result in a local minimum that is not globally optimal.
Consider the basic case in one dimension where the data is of the form (x, y) with discretized x ∈ Z and label y ∈ { 0 , 1 }. Assume a very simple classifier ρ in one parameter
(^3) https://pytorch.org/docs/stable/nn.html#loss-functions (^4) https://pytorch.org/docs/stable/generated/torch.nn.LogSoftmax.html#torch. nn.LogSoftmax
0 01 1
0 1 2 3 4 5 6 7 8 ... ...
0 1 2 3 4 5 6 7 8 ... ...
0 1 2 3 4 5 6 7 8 ... ...
0 1 2 3 4 5 6 7 8 ... 0 1 01 0 1 ...
0 1 0 1
0 1 2 3 4 5 6 7 8 0 1 ...^0 ...
0 0 0 1 1 0 1 1
0 1 2 3 4 5 6 7 8 ... 0 ...
Figure 1: (a–e) Example stuck in a local optimum. Left: Optimizing the parameter θ for given data points. Right: Adversarial examples maximizing the loss for a given parameter θ. (f) Global optimum.
Problem 3 (Box Transformers). In the lecture, you have seen the dox domain for numerical analysis. For vectors a, b ∈ Rm^ with ∀i. ai ≤ bi, the box [a, b] is a hypercube in Rm. We can use abstract transformers to obtain an over-approximation of the behavior of a function. Given a function f : Rn^ → Rm^ and an input box [a, b] ⊂ Rn, a sound abstract transformer f ]^ finds [c, d] ⊂ Rm^ such that ∀x ∈ [a, b]. f (x) ∈ [c, d].
For example, let x ∈ [1, 3] and y ∈ [2, 4], and assume we want to approximate the result of 2x − y. Using the basic abstract transformers from the lecture, we can compute
2 ·]^ [1, 3] −]^ [2, 4] = [2, 6] +]^ [− 4 , −2] = [− 2 , 4]
and conclude that 2x − y ∈ [− 2 , 4].
Solution 3.
[g, h] = f ]([a, b]) =
[a^2 , b^2 ] if a ≥ 0, [b^2 , a^2 ] else if b ≤ 0, [0, max(a^2 , b^2 )] otherwise.
[a, b] ·]^ [c, d] = [min(ac, ad, bc, bd), max(ac, ad, bc, bd)]
Note: To see this, perform a case distinction on the signs of a, b, c, and d. The naive solution attempt [ab, cd] is unsound (why?).
References
[1] Aleksander Madry et al. ”Towards deep learning models resistant to adversarial attacks”. ICLR (2018).
[2] Hongyang Zhang et al. ”Theoretically Principled Trade-off between Robustness and Accuracy”. ICML (2019).