MMA TRAINING: DIRECT INPUT SPACE MARGIN MAXIMIZATION THROUGH ADVERSARIAL TRAINING
Year: 2020

Abstract:
We study adversarial robustness of neural networks from a margin maximization perspective, where margins are defined as the distances from inputs to a classifier’s decision boundary. Our study shows that maximizing margins can be achieved by minimizing the adversarial loss on the decision boundary at the “shortest successful perturbation”, demonstrating a close connection between adversarial losses and the margins. We propose Max-Margin Adversarial (MMA) training to directly maximize the margins to achieve adversarial robustness. Instead of adversarial training with a fixed , MMA offers an improvement by enabling adaptive selection of the “correct” as the margin individually for each data point. In addition, we rigorously analyze adversarial training with the perspective of margin maximization, and provide an alternative interpretation for adversarial training, maximizing either a lower or an upper bound of the margins. Our experiments empirically confirm our theory and demonstrate MMA training’s efficacy on the MNIST and CIFAR10 datasets w.r.t. `∞ and `2 robustness. Code and models are available at https://github.com/BorealisAI/mma_training.

text: 1 INTRODUCTION
Despite their impressive performance on various learning tasks, neural networks have been shown to be vulnerable to adversarial perturbations (Szegedy et al., 2013; Biggio et al., 2013). An artificially constructed imperceptible perturbation can cause a significant drop in the prediction accuracy of an otherwise accurate network. The level of distortion is measured by the magnitude of the perturbations (e.g. in `∞ or `2 norms), i.e. the distance from the original input to the perturbed input. Figure 1 shows an example, where the classifier changes its prediction from panda to bucket when the input is perturbed from the blue sample point to the red one. Figure 1 also shows the natural connection between adversarial robustness and the
margins of the data points, where the margin is defined as the distance from a data point to the classifier’s decision boundary. Intuitively, the margin of a data point is the minimum distance that x has to be perturbed to change the classifier’s prediction. Thus, the larger the margin is, the farther the distance from the input to the decision boundary is, the more robust the classifier is w.r.t. this input.
Although naturally connected to adversarial robustness, “directly” maximizing margins has not yet been thoroughly studied in the adversarial robustness literature. Instead, the method of minimax adversarial training (Huang et al., 2015; Madry et al., 2017) is arguably the most common defense to adversarial perturbations due to its effectiveness and simplicity. Adversarial training attempts to minimize the maximum loss within a fixed sized neighborhood about the training data using projected gradient descent (PGD). Despite advancements made in recent years (Hendrycks et al., 2019; Zhang et al., 2019a; Shafahi et al., 2019; Zhang et al., 2019b; Stanforth et al., 2019; Carmon et al., 2019), adversarial training still suffers from a fundamental problem, the perturbation length has to be set and is fixed throughout the training process. In general, the setting of is arbitrary, based on assumptions on whether perturbations within the defined ball are “imperceptible” or not. Recent work (Guo et al., 2018; Sharma et al., 2019) has demonstrated that these assumptions do not ∗Work done at Borealis AI.
consistently hold true, commonly used settings assumed to only allow imperceptible perturbations in fact do not. If is set too small, the resulting models lack robustness, if too large, the resulting models lack in accuracy. Moreover, individual data points may have different intrinsic robustness, the variation in ambiguity in collected data is highly diverse, and fixing one for all data points across the whole training procedure is likely suboptimal.
Instead of improving adversarial training with a fixed perturbation magnitude, we revisit adversarial robustness from the margin perspective, and propose Max-Margin Adversarial (MMA) training for “direct” input margin maximization. By directly maximizing margins calculated for each data point, MMA training allows for optimizing the “current robustness” of the data, the “correct” at this point in training for each sample individually, instead of robustness w.r.t. a predefined magnitude. While it is intuitive that one can achieve the greatest possible robustness by maximizing the margin of a classifier, this maximization has technical difficulties. In Section 2, we overcome these difficulties and show that margin maximization can be achieved by minimizing a classification loss w.r.t. model parameters, at the “shortest successful perturbation”. This makes gradient descent viable for margin maximization, despite the fact that model parameters are entangled in the constraints.
We further analyze adversarial training (Huang et al., 2015; Madry et al., 2017) from the perspective of margin maximization in Section 3. We show that, for each training example, adversarial training with fixed perturbation length is maximizing a lower (or upper) bound of the margin, if is smaller (or larger) than the margin of that training point. As such, MMA training improves adversarial training, in the sense that it selects the “correct” , the margin value for each example.
Finally in Section 4, we test and compare MMA training with adversarial training on MNIST and CIFAR10 w.r.t. `∞ and `2 robustness. Our method achieves higher robustness accuracies on average under a variety of perturbation magnitudes, which echoes its goal of maximizing the average margin. Moreover, MMA training automatically balances accuracy vs robustness while being insensitive to its hyperparameter setting, which contrasts sharply with the sensitivity of standard adversarial training to its fixed perturbation magnitude. MMA trained models not only match the performance of the best adversarially trained models with carefully chosen training under different scenarios, it also matches the performance of ensembles of adversarially trained models.
In this paper, we focus our theoretical efforts on the formulation for directly maximizing the input space margin, and understanding the standard adversarial training method from a margin maximization perspective. We focus our empirical efforts on thoroughly examining our MMA training algorithm, comparing with adversarial training with a fixed perturbation magnitude.

heading: 1.1 RELATED WORKS
text: Although not often explicitly stated, many defense methods are related to increasing the margin. One class uses regularization to constrain the model’s Lipschitz constant (Cisse et al., 2017; Ross & Doshi-Velez, 2017; Hein & Andriushchenko, 2017; Sokolic et al., 2017; Tsuzuku et al., 2018), thus samples with small loss would have large margin since the loss cannot increase too fast. If the Lipschitz constant is merely regularized at the data points, it is often too local and not accurate in a neighborhood. When globally enforced, the Lipschitz constraint on the model is often too strong that it harms accuracy. So far, such methods have not achieved strong robustness. There are also efforts using first-order approximation to estimate and maximize input space margin (Matyasko & Chau, 2017; Elsayed et al., 2018; Yan et al., 2019). Similar to local Lipschitz regularization, the reliance on local information often does not provide accurate margin estimation and efficient maximization. Such approaches have also not achieved strong robustness so far. Croce et al. (2018) aim to enlarge the linear region around a input example, such that the nearest point, to the input and on the decision boundary, is inside the linear region. Here, the margin can be calculated analytically and hence maximized. However, the analysis only works on ReLU networks, and the implementation so far only works on improving robustness under small perturbations. We defer some detailed discussions on related works to Appendix B, including a comparison between MMA training and SVM.

heading: 1.2 NOTATIONS AND DEFINITIONS
text: We focus on K-class classification problems. Denote S = {xi, yi} as the training set of inputlabel data pairs sampled from data distribution D. We consider the classifier as a score function
fθ(x) = ( f1θ (x), . . . , f K θ (x) ) , parametrized by θ, which assigns score f iθ(x) to the i-th class. The predicted label of x is then decided by ŷ = arg maxi f iθ(x).
Let L01θ (x, y) = I(ŷ 6= y) be the 0-1 loss indicating classification error, where I(·) is the indicator function. For an input (x, y), we define its margin w.r.t. the classifier fθ(·) as:
dθ(x, y) = ‖δ∗‖ = min ‖δ‖ s.t. δ : L01θ (x+ δ, y) = 1, (1)
where δ∗ = arg minL01θ (x+δ,y)=1 ‖δ‖ is the “shortest successful perturbation”. We give an equivalent definition of margin with the “logit margin loss” LLMθ (x, y) = maxj 6=y f j θ (x)− f y θ (x).
1 The level set {x : LLMθ (x, y) = 0} corresponds to the decision boundary of class y. Also, when LLMθ (x, y) < 0, the classification is correct, and when LLMθ (x, y) ≥ 0, the classification is wrong. Therefore, we can define the margin in Eq. (1) in an equivalent way by LLMθ (·) as:
dθ(x, y) = ‖δ∗‖ = min ‖δ‖ s.t. δ : LLMθ (x+ δ, y) ≥ 0, (2)
where δ∗ = arg minLLMθ (x+δ,y)≥0 ‖δ‖ is again the “shortest successful perturbation”. For the rest of the paper, we use the term “margin” to denote dθ(x, y) in Eq. (2). For other notions of margin, we will use specific phrases, e.g. “SLM-margin” or “logit margin.”

heading: 2 MAX-MARGIN ADVERSARIAL TRAINING
text: We propose to improve adversarial robustness by maximizing the average margin of the data distribution D, called Max-Margin Adversarial (MMA) training, by optimizing the following objective:
min θ { ∑ i∈S+θ max{0, dmax − dθ(xi, yi)}+ β ∑ j∈S−θ Jθ(xj , yj)}, (3)
where S+θ = {i : LLMθ (xi, yi) < 0} is the set of correctly classified examples, S − θ = {i : LLMθ (xi, yi) ≥ 0} is the set of wrongly classified examples, Jθ(·) is a regular classification loss function, e.g. cross entropy loss, dθ(xi, yi) is the margin for correctly classified samples, and β is the coefficient for balancing correct classification and margin maximization. Note that the margin dθ(xi, yi) is inside the hinge loss with threshold dmax (a hyperparameter), which forces the learning to focus on the margins that are smaller than dmax. Intuitively, MMA training simultaneously minimizes classification loss on wrongly classified points in S−θ and maximizes the margins of correctly classified points in dθ(xi, yi) until it reaches dmax. Note that we do not maximize margins on wrongly classified examples. Minimizing the objective in Eq. (3) turns out to be a technical challenge. While ∇θJθ(xj , yj) can be easily computed by standard back-propagation, computing the gradient of dθ(xi, yi) needs some technical developments.
In the next section, we show that margin maximization can still be achieved by minimizing a classification loss w.r.t. model parameters, at the “shortest successful perturbation”. For smooth functions, a stronger result exists: the gradient of the margin w.r.t. model parameters can be analytically calculated, as a scaled gradient of the loss. Such results make gradient descent viable for margin maximization, despite the fact that model parameters are entangled in the constraints.

heading: 2.1 MARGIN MAXIMIZATION
text: Recall that dθ(x, y) = ‖δ∗‖ = min ‖δ‖ s.t. δ : LLMθ (x+ δ, y) ≥ 0.
Note that the constraint of the above optimization problem depends on model parameters, thus margin maximization is a max-min nested optimization problem with a parameter-dependent constraint in its inner minimization.2 Computing such gradients for a linear model is easy due to the existence of its closed-form solution, e.g. SVM, but it is not so for general functions such as neural networks.
The next theorem provides a viable way to increase dθ(x, y). Theorem 2.1. Gradient descent on LLMθ (x+δ∗, y) w.r.t. θ with a proper step size increases dθ(x, y), where δ∗ = arg minLLMθ (x+δ,y)≥0 ‖δ‖ is the shortest successful perturbation given the current θ.
1Since the scores ( f1θ (x), . . . , f K θ (x) ) output by fθ are also called logits in neural network literature. 2In adversarial training (Madry et al., 2017), the constraint on the inner max does NOT have such problem.
Theorem 2.1 summarizes the theoretical results, where we show separately later 1) how to calculate the gradient of the margin under some smoothness assumptions; 2) without smoothness, margin maximization can still be achieved by minimizing the loss at
the shortest successful perturbation.
Calculating gradients of margins for smooth loss and norm: Denote LLMθ (x+ δ, y) by L(δ, θ) for brevity. It is easy to see that for a wrongly classified example (x, y), δ∗ is achieved at 0 and thus ∇θdθ(x, y) = 0. Therefore we focus on correctly classified examples. Denote the Lagrangian as Lθ(δ, λ) = ‖δ‖ + λL(δ, θ). For a fixed θ, denote the optimizers of Lθ(δ, λ) by δ∗ and λ∗ . The following theorem shows how to compute∇θdθ(x, y). Proposition 2.1. Let (δ) = ‖δ‖. Given a fixed θ, assume that δ∗ is unique, (δ) and L(δ, θ) are
C2 functions in a neighborhood of (δ∗, θ), and the matrix
( ∂2 (δ∗) ∂δ2 + λ ∗ ∂2L(δ∗,θ) ∂δ2 ∂L(δ∗,θ) ∂δ
∂L(δ∗,θ) ∂δ > 0 ) is full rank, then
∇θdθ(x, y) = C(θ, x, y) ∂L(δ∗, θ)
∂θ , where C(θ, x, y) =
〈 ∂ (δ∗) ∂δ , ∂L(δ∗,θ) ∂δ 〉 ‖∂L(δ
∗,θ) ∂δ ‖ 2 2
is a scalar.
Remark 2.1. By Proposition 2.1, the margin’s gradient w.r.t. to the model parameter θ is proportional to the loss’ gradient w.r.t. θ at δ∗, the shortest successful perturbation. Therefore to perform gradient ascent on the margin, we just need to find δ∗ and perform gradient descent on the loss.
Margin maximization for non-smooth loss and norm: Proposition 2.1 requires the loss function and the norm to be C2 at δ∗. This might not be the case for many functions used in practice, e.g. ReLU networks and the `∞ norm. Our next result shows that under a weaker condition of directional differentiability (instead of C2), learning θ to maximize the margin can still be done by decreasing L(δ∗, θ) w.r.t. θ, at θ = θ0. Due to space limitations, we only present an informal statement here. Rigorous statements can be found in Appendix A.2. Proposition 2.2. Let δ∗ be unique andL(δ, θ) be the loss of a deep ReLU network. There exists some direction ~v in the parameter space, such that the loss L(δ, θ)|δ=δ∗ can be reduced in the direction of ~v. Furthermore, by reducing L(δ, θ)|δ=δ∗ , the margin is also guaranteed to be increased. Figure 2 illustrates the relationship between the margin and the adversarial loss with an imaginary example. Consider a 1-D example in Figure 2 (a), where the input example x is a scalar. We perturb x in the positive direction with perturbation δ. As we fix (x, y), we overload L(δ, θ) = LLMθ (x+ δ, y), which is monotonically increasing on δ, namely larger perturbation results in higher loss. Let L(·, θ0) (the dashed curve) denote the original function before an update step, and δ∗0 = arg minL(δ,θ0)≥0 ‖δ‖ denote the corresponding margin (same as shortest successful perturbation in
1D). As shown in Figure 2 (b), as the parameter is updated to θ1 such that L(δ∗0 , θ1) is reduced, the new margin δ∗1 = arg minL(δ,θ1)≥0 ‖δ‖ is enlarged. Intuitively, a reduced value of the loss at the shortest successful perturbation leads to an increase in margin.

heading: 2.2 STABILIZING THE LEARNING WITH CROSS ENTROPY SURROGATE LOSS
text: In practice, we find the gradients of the “logit margin loss” LLMθ to be unstable. The piecewise nature of the LLMθ loss can lead to discontinuity of its gradient, causing large fluctuations on the boundary between the pieces. It also does not fully utilize information provided by all the logits.
In our MMA algorithm, we instead use the “soft logit margin loss” (SLM) LSLMθ (x, y) = log ∑ j 6=y exp(f jθ (x))− f y θ (x),
which serves as a surrogate loss to the “logit margin loss” LLMθ (x, y) by replacing the the max function by the LogSumExp (sometimes also called softmax) function. One immediate property is that the SLM loss is smooth and convex (w.r.t. logits). The next proposition shows that SLM loss is a good approximation to the LM loss. Proposition 2.3. LSLMθ (x, y)− log(K − 1) ≤ LLMθ (x, y) ≤ LSLMθ (x, y), (4) where K denote the number of classes. Remark 2.2. By using the soft logit margin loss, MMA maximizes a lower bound of the margin, the SLM-margin, dSLMθ (x, y):
dSLMθ (x, y) = ‖δ∗‖ = min ‖δ‖ s.t. δ : LSLMθ (x+ δ, y) ≥ 0. To see that, note by Proposition 2.3, LSLMθ (x, y) upper bounds L LM θ (x, y). So we have {δ : LLMθ (x+ δ, y) ≤ 0} ⊆ {δ : LSLMθ (x+ δ, y) ≤ 0}. Therefore, dSLMθ (x, y) ≤ dθ(x, y), i.e. the SLM-margin is a lower bound of the margin.
We next show the gradient of the SLM loss is proportional to the gradient of the cross entropy loss, LCEθ (x, y) = log ∑ j exp(f j θ (x))− f y θ (x), thus minimizing L CE θ (x+ δ
∗, y) w.r.t. θ “is” minimizing LSLMθ (x+ δ
∗, y). Proposition 2.4. For a fixed (x, y) and θ,
∇θLCEθ (x, y) = r(θ, x, y)∇θLSLMθ (x, y), and ∇xLCEθ (x, y) = r(θ, x, y)∇xLSLMθ (x, y) (5)
where the scalar r(θ, x, y) =
∑ i 6=y exp(f
i θ(x))∑
i exp(f i θ(x))
. (6)
Therefore, to simplify the learning algorithm, we perform gradient descent on model parameters using LCEθ (x + δ
∗, y). As such, we use LCEθ on both clean and adversarial examples, which in practice stabilizes training:
min θ LMMAθ (S), where LMMAθ (S) = ∑ i∈S+θ ∩Hθ LCEθ (xi + δ ∗, yi) + ∑ j∈S−θ LCEθ (xj , yj), (7)
where δ∗ = arg minLSLMθ (x+δ,y)≥0 ‖δ‖ is found with the SLM loss, and Hθ = {i : dθ(xi, yi) < dmax} is the set of examples that have margins smaller than the hinge threshold.
2.3 FINDING THE OPTIMAL PERTURBATION δ∗
To implement MMA, we still need to find the δ∗, which is intractable in general settings. We propose an adaptation of the projected gradient descent (PGD) (Madry et al., 2017) attack to give an approximate solution of δ∗, the Adaptive Norm Projective Gradient Descent Attack (AN-PGD). In AN-PGD, we apply PGD on an initial perturbation magnitude init to find a norm-constrained perturbation δ1, then we search along the direction of δ1 to find a scaled perturbation that gives L = 0, we then use this scaled perturbation to approximate ∗. Note that AN-PGD here only serves as an algorithm to give an approximate solution of δ∗, and it can be decoupled from the remaining parts of MMA training. Other attacks that can serve a similar purpose can also fit into our MMA training framework, e.g. the Decoupled Direction and Norm (DDN) attack (Rony et al., 2018). Algorithm 1 describes the Adaptive Norm PGD Attack (AN-PGD) algorithm.
Algorithm 1 Adaptive Norm PGD Attack for approximately solving δ∗. Inputs: (x, y) is the data example. init is the initial norm constraint used in the first PGD attack. Outputs: δ∗, approximate shortest successful perturbation. Parameters: max is the maximum perturbation length. PGD(x, y, ) represents PGD perturbation δ with magnitude .
Remark 2.3. Finding the δ∗ in Propositions 2.1 and 2.2 requires solving a non-convex optimization problem, where the optimality cannot be guaranteed in practice. Previous adversarial training methods, e.g. Madry et al. (2017), suffer the same problem. Nevertheless, as we show later in Figure 4, our proposed MMA training algorithm does achieve the desired behavior of maximizing the margin of each individual example in practice.

heading: 2.4 ADDITIONAL CLEAN LOSS DURING TRAINING
text: In practice, we observe that when the model is only trained with the objective function in Eq. (7), the input space loss landscape is very flat, which makes PGD less efficient in finding δ∗ for training, as shown in Figure 3. Here we choose 50 examples from both the training and test sets respectively, then perform the PGD attack with = 8/255 and keep those failed perturbations. For each example, we linearly interpolate 9 more points between the original example and the perturbed example, and plot their logit margin losses. In each sub-figure, the horizontal axis is the relative position of the interpolated example: e.g. 0.0 represents the original example, 1.0 represents the perturbed example with = 8/255, 0.5 represents the average of them. The vertical axis is the logit margin loss. Recall that when LLMθ (x+ δ, y) < 0, the perturbation δ fails.
OMMA-32 in Figure 3a represents model trained with only LMMAθ in Eq. (7) with dmax = 8. PGD-8 Figure 3b represents model trained with PGD training (Madry et al., 2017) with = 8. As one can see, OMMA-32 has “flatter” loss curves compared to PGD-8. This could potentially weaken the adversary during training, which leads to poor approximation of δ∗ and hampers training.
To alleviate this issue, we add an additional clean loss term to the MMA objective in Eq. (7) to lower the loss on clean examples, such that the input space loss landscape is steeper. Specifically, we use the following combined loss
LCBθ (S) = 1
3 ∑ j∈S LCEθ (xj , yj) + 2 3 LMMAθ (S). (8)
The model trained with this combined loss and dmax = 32 is the MMA-32 shown in Figure 3c. Adding the clean loss is indeed effective. Most of the loss curves are more tilted, and the losses of perturbed examples are lower. We use LCBθ for MMA training in the rest of the paper due to its higher performance. A more detailed comparison between LCBθ and L MMA θ is delayed to Appendix E.
2.5 THE MMA TRAINING ALGORITHM
Algorithm 2 Max-Margin Adversarial Training. Inputs: The training set {(xi, yi)}. Outputs: the trained model fθ(·). Parameters: contains perturbation lengths of training data. min is the minimum perturbation length. max is the maximum perturbation length. A(x, y, init) represents the approximate shortest successful perturbation returned by an algorithm A (e.g. AN-PGD) on the data example (x, y) and at the initial norm init. 1: Randomly initialize the parameter θ of model f , and initialize every element of as min 2: repeat 3: Read minibatch B = {(x1, y1), . . . , (xm, ym)} 4: Make predictions on B and into two: wrongly predicted B0 and correctly predicted B1 5: Initialize an empty batch Badv1 6: for (xi, yi) in B1 do 7: Retrieve perturbation length i from 8: δ∗i = A(xi, yi, i) 9: Update the i in as ‖δ∗i ‖. If ‖δ∗i ‖ < dmax then put (xi + δ∗i , yi) into Badv1 10: end for 11: Calculate gradients of ∑ j∈B0 L CE θ (xj , yj)+ 1 3 ∑ j∈B1 L CE θ (xj , yj)+ 2 3 ∑ j∈Badv1 LCEθ (xj , yj), the combined loss, on B0, B1, and Badv1 , w.r.t. θ, according to Eqs. (7) and (8) 12: Perform one step gradient step update on θ 13: until meet training stopping criterion
Algorithm 2 summarizes our practical MMA training algorithm. During training for each minibatch, we 1) separate it into 2 batches based on if the current prediction matches the label; 2) find δ∗ for each example in the “correct batch”; 3) calculate the gradient of θ based on Eqs. (7) and (8).

heading: 3 UNDERSTANDING ADVERSARIAL TRAINING W.R.T. MARGIN
text: Through our development of MMA training in the last section, we have shown that margin maximization is closely related to adversarial training with the optimal perturbation length ‖δ∗‖. In this section, we further investigate the behavior of adversarial training in the perspective of margin maximization. Adversarial training (Huang et al., 2015; Madry et al., 2017) minimizes the “worst-case” loss under a fixed perturbation magnitude , as follows.
min θ Ex,y∼D max ‖δ‖≤ Lθ(x+ δ, y). (9)
Looking again at Figure 2, we can see that an adversarial training update step does not necessarily increase the margin. In particular, as we perform an update to reduce the value of loss at the fixed perturbation , the parameter is updated from θ0 to θ1. After this update, we can imagine two different scenarios for the updated loss functions Lθ1(·) (the solid curve) in Figure 2 (c) and (d). In both (c) and (d), Lθ1( ) is decreased by the same amount. However, the margin is increased in (c) with δ∗1 > δ ∗ 0 , but decreased in (d) with δ ∗ 1 < δ ∗ 0 . Formalizing the intuitive analysis, we present two theorems connecting adversarial training and margin maximization. For brevity, fixing (x, y), let L(δ, θ) = LLMθ (x+ δ, y), dθ = dθ(x, y), and ∗ θ(ρ) = minδ:L(δ,θ)≥ρ ‖δ‖. Theorem 3.1. Assuming an update from adversarial training changes θ0 to θ1, such that ρ∗ = max‖δ‖≤ L(δ, θ0) > max‖δ‖≤ L(δ, θ1), then
1) if = dθ0 , then ρ ∗ = 0, ∗θ1(ρ ∗) = dθ1 ≥ dθ0 = ∗θ0(ρ ∗); 2) if < dθ0 , then ρ ∗ ≤ 0, ∗θ0(ρ ∗) ≤ dθ0 , ∗θ1(ρ ∗) ≤ dθ1 , and ∗θ1(ρ ∗) ≥ ∗θ0(ρ ∗); 3) if > dθ0 , then ρ ∗ ≥ 0, ∗θ0(ρ ∗) ≥ dθ0 , ∗θ1(ρ ∗) ≥ dθ1 , and ∗θ1(ρ ∗) ≥ ∗θ0(ρ ∗).
Remark 3.1. In other words, adversarial training, with the logit margin loss and a fixed 1) exactly maximizes the margin, if is equal to the margin; 2) maximizes a lower bound of the margin, if is less than the margin; 3) maximizes an upper bound of the margin, if is greater than the margin.
Next we look at adversarial training with the cross entropy loss through the connection between cross entropy and the soft logit margin loss from Proposition 2.4. We first look at adversarial training on the SLM loss. Fixing (x, y), let dSLMθ = d SLM θ (x, y), and ∗ SLM,θ(ρ) = minLSLMθ (x+δ,y)≥ρ ‖δ‖. Corollary 3.1. Assuming an update from adversarial training changes θ0 to θ1, such that max‖δ‖≤ L SLM θ0 (x+ δ, y) > max‖δ‖≤ L SLM θ1 (x+ δ, y), if ≤ dSLMθ0 , then ρ ∗ = max‖δ‖≤ L SLM θ0
(x+ δ, y) ≤ 0, ∗SLM,θ0(ρ ∗) ≤ dθ0 , ∗SLM,θ1(ρ ∗) ≤ dθ1 , and ∗SLM,θ1(ρ ∗) ≥ ∗SLM,θ0(ρ ∗).
Remark 3.2. In other words, if is less than or equal to the SLM-margin, adversarial training, with the SLM loss and a fixed perturbation length , maximizes a lower bound of the SLM-margin, thus a lower bound of the margin.
Recall Proposition 2.4 shows that LCEθ and L SLM θ have the same gradient direction w.r.t. both the model parameter and the input. In adversarial training (Madry et al., 2017), the PGD attack only uses the gradient direction w.r.t. the input, but not the gradient magnitude. Therefore, in the inner maximization loop, using the SLM and CE loss will result in the same approximate δ∗. Furthermore, ∇θLCEθ (x + δ∗, y) and ∇θLSLMθ (x + δ∗, y) have the same direction. If the step size is chosen appropriately, then a gradient update that reduces LCEθ (x+ δ ∗, y) will also reduce LSLMθ (x+ δ ∗, y). Combined with Remark 3.2, these suggest:
Adversarial training with cross entropy loss (Madry et al., 2017) approximately maximizes a lower bound of the margin, if is smaller than or equal to the SLM-margin.
On the other hand, when is larger then the margin, such a relation no longer exists. When is too large, adversarial training is maximizing an upper bound of the margin, which might not necessarily increase the margin. This suggests that for adversarial training with a large , starting with a smaller then gradually increasing it could help, since the lower bound of the margin is maximized at the start of training. Results in Sections 4.1 and 4.2 corroborate exactly with this theoretical prediction.

heading: 4 EXPERIMENTS
text: We empirically examine several hypotheses and compare MMA training with different adversarial training algorithms on the MNIST and CIFAR10 datasets under `∞/`2-norm constrained perturbations. Due to space limitations, we mainly present results on CIFAR10-`∞ for representative models in Table 1. Full results are in Table 2 to 15 in Appendix F. Implementation details are also left to the appendix, including neural network architecture, training and attack hyperparameters.
Our results confirm our theory and show that MMA training is stable to its hyperparameter dmax, and balances better among various attack lengths compared to adversarial training with fixed perturbation magnitude. This suggests that MMA training is a better choice for defense when the perturbation length is unknown, which is often the case in practice.
Measuring Adversarial Robustness: We use the robust accuracy under multiple projected gradient descent (PGD) attacks (Madry et al., 2017) as the robustness measure. Specifically, given an example, each model is attacked by both repeated randomly initialized whitebox PGD attacks and numerous transfer attacks, generated from whitebox PGD attacking other models. If any one of these attacks succeed, then the model is considered “not robust under attack” on this example. For each dataset-norm setting and for each example, under a particular magnitude , we first perform N randomly initialized whitebox PGD attacks on each individual model, then use N · (m − 1) PGD attacks from all the other models to perform transfer attacks, where m is the total number of models considered under each setting (e.g. CIFAR10-`∞). In our experiments, we use N = 10 for models trained on CIFAR10, thus the total number of the “combined” (whitebox and transfer) set of attacks is 320 for CIFAR10-`∞ (m = 32). 3 We use ClnAcc for clean accuracy, AvgAcc for the average over both clean accuracy and robust accuracies at different ’s, AvgRobAcc for the average over only robust accuracies under attack.
Correspondence between dmax and : In MMA training, we maximize each example’s margin until the margin reaches dmax. In standard adversarial training, each example is trained to be robust at . Therefore in MMA training, we usually set dmax to be larger than in standard adversarial training. It is difficult to know the “correct” value of dmax, therefore we test different dmax values, and compare a group of MMA trained models to a group of PGD trained models.

heading: 4.1 EFFECTIVENESS OF MARGIN MAXIMIZATION DURING TRAINING
text: As discussed in Section 3, MMA training enlarges margins of all training points,while PGD training, by minimizing the adversarial loss with a fixed , might fail to enlarge margins for points with initial margins smaller than . This is because when dθ(x, y) < , PGD training is maximizing an upper bound of dθ(x, y), which may not necessarily increase the margin. To verify this, we track how the
3N = 50 for models trained on MNIST. Total number of attacks is 900 for MNIST-`∞ (m = 18), 1200 for MNIST-`2 (m = 24) and 260 for CIFAR10-`2 (m = 26). We explain relevant details in Appendix C.
margin distribution changes during training processes in two models under the CIFAR10-`2 4 case, MMA-3.0 vs PGD-2.5. We use MMA-dmax to denote the MMA trained model with the combined loss in Eq. (8) and hinge threshold dmax, and PGD- to represent the PGD trained (Madry et al., 2017) model with fixed perturbation magnitude .
Specifically, we randomly select 500 training points, and measure their margins after each training epoch. We use the norm of the 1000-step DDN attack (Rony et al., 2018) to approximate the margin. The results are shown in Figure 4, where each subplot is a histogram (rotated by 90◦) of margin values. For the convenience of comparing across epochs, we use the vertical axis to indicate margin value, and the horizontal axis for counts in the histogram. The number below each subplot is the corresponding training epoch. Margins mostly concentrate near 0 for both models at the beginning. As training progresses, both enlarge margins on average. However, in PGD training, a portion of the margins stay close to 0 throughout the training process, at the same time, also pushing some margins to be even higher than 2.5, likely because PGD training continues to maximize lower bounds of this subset of the total margins, as we discussed in Section 3, the value that the PGD-2.5 model is trained for. MMA training, on the other hand, does not “give up” on those data points with small margins. At the end of training, 37.8% of the data points for PGD-2.5 have margins smaller than 0.05, while only 20.4% for MMA. As such, PGD training enlarges the margins of “easy data” which are already robust enough, but “gives up” on “hard data” with small margins. Instead, MMA training pushes the margin of every data point, by finding the proper . In general, when the attack magnitude is unknown, MMA training is more capable in achieving a better balance between small and large margins, and thus a better balance among adversarial attacks with various ’s as a whole.

heading: 4.2 GRADUALLY INCREASING HELPS PGD TRAINING WHEN IS LARGE
text: Our previous analysis in Section 3 suggests that when the fixed perturbation magnitude is small, PGD training increases the lower bound of the margin. On the other hand, when is larger than the margin, PGD training does not necessarily increase the margin. This is indeed confirmed by our experiments. PGD training fails at larger , in particular = 24/255 for the CIFAR10-`∞ as shown in Table 1. We can see that PGD-24’s accuracies at all test ’s are around 10%.
4Here we choose CIFAR10-`2 because the DDN-`2 attack is both fast and effective for estimating margins.
Aiming to improve PGD training, we propose a variant of PGD training, named PGD with Linear Scaling (PGDLS), in which we grow the perturbation magnitude from 0 to the fixed magnitude linearly in 50 epochs. According to our theory, gradually increasing the perturbation magnitude could avoid picking a that is larger than the margin, thus managing to maximizing the lower bound of the margin rather than its upper bound, which is more sensible. It can also be seen as a “global magnitude scheduling” shared by all data points, which is to be contrasted to MMA training that gives magnitude scheduling for each individual example. We use PGDLS- to represent these models and show their performances also in Table 1. We can see that PGDLS-24 is trained successfully, whereas PGD-24 fails. At = 8 or 16, PGDLS also performs similar or better than PGD training, confirming the benefit of training with small perturbation at the beginning.

heading: 4.3 COMPARING MMA TRAINING WITH PGD TRAINING
text: From the first three columns in Table 1, we can see that MMA training is very stable with respect to its hyperparameter, the hinge threshold dmax. When dmax is set to smaller values (e.g. 12 and 20), MMA models attain good robustness across different attacking magnitudes, with the best clean accuracies in the comparison set. When dmax is large, MMA training can still learn a reasonable model that is both accurate and robust. For MMA-32, although dmax is set to a “impossible-tobe-robust” level at 32/255, it still achieves 84.36% clean accuracy and 47.18% robust accuracy at 8/255, thus automatically “ignoring” the demand to be robust at larger ’s, including 20, 24, 28 and 32, recognizing its infeasibility due to the intrinsic difficulty of the problem. In contrast, PGD trained models are more sensitive to their specified fixed perturbation magnitude. In terms of the overall performance, we notice that MMA training with a large dmax, e.g. 20 or 32, achieves high AvgAcc values, e.g. 28.86% or 29.39%. However, for PGD training to achieve a similar performance, needs to be carefully picked (PGD-16 and PGDLS-16), and their clean accuracies suffer a significant drop.
We also compare MMA models with ensembles of PGD trained models. PGD-ens/PGDLS-ens represents the ensemble of PGD/PGDLS trained models with different ’s. The ensemble produces a prediction by performing a majority vote on label predictions, and using the softmax scores as the tie breaker. MMA training achieves similar performance compared to the ensembled PGD models. PGD-ens maintains a good clean accuracy, but it is still marginally outperformed by MMA-32 w.r.t. robustness at various ’s. Further note that 1) the ensembling requires significantly higher computation costs both at training and test times; 2) Unlike attacking individual models, attacking ensembles is still relatively unexplored in the literature, thus our whitebox PGD attacks on the ensembles may not be sufficiently effective; 5 and 3) as shown in Appendix F, for MNIST-`∞/`2, MMA trained models significantly outperform the PGD ensemble models.
Comparison with TRADES: TRADES (Zhang et al., 2019b) improves PGD training by decoupling the minimax training objective into an accuracy term and an robustness regularization term. We compare MMA-32 with TRADES 6 in Table 1 as their clean accuracies are similar. We see that TRADES outperforms MMA on the attacks of lengths that are less than = 12/255, but it sacrifices the robustness under larger attacks. We note that MMA training and TRADES’ idea of optimizing a calibration loss are progresses in orthogonal directions and could potentially be combined.
Testing on gradient free attacks: As a sanity check for gradient obfuscation (Athalye et al., 2018), we also performed the gradient-free SPSA attack (Uesato et al., 2018), to all our `∞-MMA trained models on the first 100 test examples. We find that, in all cases, SPSA does not compute adversarial examples successfully when gradient-based PGD did not.

heading: 5 CONCLUSIONS
text: In this paper, we proposed to directly maximize the margins to improve adversarial robustness. We developed the MMA training algorithm that optimizes the margins via adversarial training with perturbation magnitude adapted both throughout training and individually for the distinct datapoints in the training dataset. Furthermore, we rigorously analyzed the relation between adversarial training and margin maximization. Our experiments on CIFAR10 and MNIST empirically confirmed our theory and demonstrate that MMA training outperforms adversarial training in terms of sensitivity to hyperparameter setting and robustness to variable attack lengths, suggesting MMA is a better choice for defense when the adversary is unknown, which is often the case in practice.
5Attacks on ensembles are explained in Appendix D. 6Downloaded models from https://github.com/yaodongyu/TRADES

heading: ACKNOWLEDGEMENT
text: We thank Marcus Brubaker, Bo Xin, Zhanxing Zhu, Joey Bose and Hamidreza Saghir for proofreading earlier drafts and useful feedbacks, also Jin Sung Kang for helping with computation resources.

heading: A PROOFS
text: A.1 PROOF OF PROPOSITION 2.1
Proof. Recall (δ) = ‖δ‖. Here we compute the gradient for dθ(x, y) in its general form. Consider the following optimization problem:
dθ(x, y) = min δ∈∆(θ) (δ),
where ∆(θ) = {δ : Lθ(x+δ, y) = 0}, and L(δ, θ) are bothC2 functions 7. Denotes its Lagrangian by L(δ, λ), where L(δ, λ) = (δ) + λLθ(x+ δ, y) For a fixed θ, the optimizer δ∗ and λ∗ must satisfy the first-order conditions (FOC)
∂ (δ)
∂δ + λ
∂Lθ(x+ δ, y)
∂δ
∣∣∣∣ δ=δ∗,λ=λ∗ = 0, (10)
Lθ(x+ δ, y)|δ=δ∗ = 0. Put the FOC equations in vector form,
G((δ, λ), θ) =
( ∂ (δ) ∂δ + λ ∂Lθ(x+δ,y) ∂δ
Lθ(x+ δ, y)
) ∣∣∣∣ δ=δ∗,λ=λ∗ = 0.
Note thatG is C1 continuously differentiable since and L(δ, θ) are C2 functions. Furthermore, the Jacobian matrix of G w.r.t (δ, λ) is
∇(δ,λ)G((δ∗, λ∗), θ)
=
( ∂2 (δ∗) ∂δ2 + λ ∗ ∂2L(δ∗,L(δ,θ)) ∂δ2 ∂L(δ∗,θ) ∂δ
∂L(δ∗,θ) ∂δ > 0 ) which by assumption is full rank. Therefore, by the implicit function theorem, δ∗ and λ∗ can be expressed as a function of θ, denoted by δ∗(θ) and λ∗(θ).
To further compute ∇θdθ(x, y), note that dθ(x, y) = (δ∗(θ)). Thus,
∇θdθ(x, y) = ∂ (δ∗)
∂δ
∂δ∗(θ)
∂θ = −λ∗ ∂L(δ
∗, θ)
∂δ
∂δ∗(θ)
∂θ , (11)
where the second equality is by Eq. (10). The implicit function theorem also provides a way of computing ∂δ
∗(θ) ∂θ which is complicated involving taking inverse of the matrix∇(δ,λ)G((δ ∗, λ∗), θ).
Here we present a relatively simple way to compute this gradient. Note that by the definition of δ∗(θ), L(δ∗(θ), θ) ≡ 0. and δ∗(θ) is a differentiable implicit function of θ restricted to this level set. Differentiate with w.r.t. θ on both sides:
∂L(δ∗, θ) ∂θ + ∂L(δ∗, θ) ∂δ ∂δ∗(θ) ∂θ = 0. (12)
Combining Eq. (11) and Eq. (12),
∇θdθ(x, y) = λ∗(θ) ∂L(δ∗, θ)
∂θ . (13)
Lastly, note that ∥∥∥∥∥∂ (δ)∂δ + λ∂Lθ(x+ δ, y)∂δ ∣∣∣∣ δ=δ∗,λ=λ∗ ∥∥∥∥∥ 2 = 0.
7Note that a simple application of Danskin’s theorem would not be valid as the constraint set ∆(θ) depends on the parameter θ.
Therefore, one way to calculate λ∗(θ) is by
λ∗(θ) = ∂ (δ) ∂δ
> ∂Lθ(x+δ,y) ∂δ
∂Lθ(x+δ,y) ∂δ > ∂Lθ(x+δ,y) ∂δ ∣∣∣∣∣ δ=δ∗
A.2 PROOF OF PROPOSITION 2.2
We provide more detailed and formal statements of Proposition 2.2.
For brevity, consider a K-layers fully-connected ReLU network, f(θ;x) = fθ(x) as a function of θ.
f(θ;x) = V >DKWKDK−1WK−1 · · ·D1W>Kx (14) where the Dk are diagonal matrices dependent on ReLU’s activation pattern over the layers, and Wk’s and V are the weights (i.e. θ). Note that f(θ;x) is a piecewise polynomial functions of θ with finitely many pieces. We further define the directional derivative of a function g, along the direction of ~v, to be:
g′(θ;~v) := lim t↓0 g(θ + t~v)− g(θ) t .
Note that for every direction ~v, there exists α > 0 such that f(θ;x) is a polynomial restricted to a line segment [θ, θ + α~v]. Thus the above limit exists and the directional derivative is well defined.
We first show the existence of ~v and t for l(θ0 + t~v) given any . Let lθ0,~v, (t) := sup‖δ‖≤ L(δ, θ0 + t~v). Proposition A.1. For > 0, t ∈ [0, 1], and θ0 ∈ Θ, there exists a direction ~v ∈ Θ, such that the derivative of lθ0,~v, (t) exists and is negative. Moreover, it is given by
l′θ0,~v, (t) = L ′(δ∗, θ0;~v).
Proof. [Proof sketch] Since θ0 is not a local minimum, there exists a direction d, such that L′(δ∗, θ0;~v) = ∂L(δ∗,θ0+t~v) ∂t is negative.
The Danskin theorem provides a way to compute the directional gradient along this direction ~v. We basically apply a version of Danskin theorem for directional absolutely continuous maps and semicontinuous maps (Yu, 2012). 1. the constraint set {δ : ‖δ‖ ≤ } is compact; 2. L(θ0 + t~v;x + δ, y) is piecewise Lipschitz and hence absolutely continuous (an induction argument on the integral representation over the finite pieces). 3. L(θ0 + t~v;x + δ, y) is continuous on both δ and along the direction ~v and hence upper semi continuous. Hence we can apply Theorem 1 in Yu (2012).
Therefore, for any > 0, if θ0 is not a local minimum, then there exits a direction d, such that for θ1 = θ0 + t~v for a proper t,
sup ‖δ‖≤ L(δ, θ0 + t~v) < sup ‖δ‖≤ L(δ, θ0) . (15)
Our next proposition provides an alternative way to increase the margin of fθ. Proposition A.2. Assume fθ0 has a margin 0, and θ1 such that lθ0,~v, 0(t) ≤ lθ1,~v, 0(0) , then fθ1 has a larger margin than 0.
Proof. Since fθ0 has a margin 0, thus max ‖δ‖≤ 0 L(θ0;x+ δ, y) = 0
Further by lθ0,~v, 0(t) ≤ lθ0,~v, 0(0) , sup ‖δ‖≤ L(δ, θ0 + t~v) ≤ sup ‖δ‖≤ L(δ, θ0).
To see the equality (constraint not binding), we use the following argument. The envolope function’s continuity is passed from the continuity of L(θ0;x+ δ, y). The inverse image of a closed set under continuous function is closed. If δ∗ lies in the interior of max‖δ‖≤ 0 L~v, (θ0;x + δ, y) ≥ 0, we would have a contradiction. Therefore the constraint is not binding, due to the continuity of the envolope function. By Eq. (15), max‖δ‖≤ 0 L(θ1;x + δ, y) < 0. So for the parameter θ1, fθ1 has a margin 1 > 0.
Therefore, the update θ0 → θ1 = θ0 + t~v increases the margin of fθ.
A.3 PROOF OF PROPOSITION 2.3
Proof.
LLMθ (x, y) = (max j 6=y f jθ (x))− f y θ (x) (16)
= log(exp(max j 6=y
f jθ (x)))− f y θ (x) (17)
≤ log(exp( ∑ j 6=y f jθ (x)))− f y θ (x) (18)
= LSLMθ (x, y) (19)
≤ log((K − 1) exp(max j 6=y f jθ (x)))− f y θ (x) (20)
= log(K − 1) + (max j 6=y f jθ (x))− f y θ (x) (21)
= log(K − 1) + LLMθ (x, y) (22)
Therefore, LSLMθ (x, y)− log(K − 1) ≤ LLMθ (x, y) ≤ LSLMθ (x, y).
A.4 A LEMMA FOR LATER PROOFS
The following lemma helps relate the objective of adversarial training with that of our MMA training. Here, we denote Lθ(x+ δ, y) as L(δ, θ) for brevity. Lemma A.1. Given (x, y) and θ , assume that L(δ, θ) is continuous in δ, then for ≥ 0, and ρ ≥ L(0, θ) ∈ Range(L(δ, θ)), it holds that
min L(δ,θ)≥ρ ‖δ‖ = =⇒ max ‖δ‖≤ L(δ, θ) = ρ ; (23)
max ‖δ‖≤ L(δ, θ) = ρ =⇒ min L(δ,θ)≥ρ ‖δ‖ ≤ . (24)
Proof. Eq. (23). We prove this by contradiction. Suppose max‖δ‖≤ L(δ, θ) > ρ. When = 0, this violates our asssumption ρ ≥ L(0, θ) in the theorem. So assume > 0. Since L(δ, θ) is a continuous function defined on a compact set, the maximum is attained by δ̄ such that ‖δ̄‖ ≤ and L(δ̄, θ) > ρ. Note that L(δ, θ)) is continuous and ρ ≥ L(0, θ), then there exists δ̃ ∈ 〈0, δ̄〉 i.e. the line segment connecting 0 and δ̄, such that ‖δ̃‖ < and L(δ̃, θ) = ρ. This follows from the intermediate value theorem by restricting L(δ, θ) onto 〈0, δ̄〉. This contradicts minL(δ,θ)≥ρ ‖δ‖ = . If max‖δ‖≤ L(δ, θ) < ρ, then {δ : ‖δ‖ ≤ } ⊂ {δ : L(δ, θ) < ρ}. Every point p ∈ {δ : ‖δ‖ ≤ } is in the open set {δ : L(δ, θ) < ρ}, there exists an open ball with some radius rp centered at p such that Brp ⊂ {δ : L(δ, θ) < ρ}. This forms an open cover for {δ : ‖δ‖ ≤ }. Since {δ : ‖δ‖ ≤ } is compact, there is an open finite subcover U such that: {δ : ‖δ‖ ≤ } ⊂ U ⊂ {δ : L(δ, θ) < ρ}. Since U is finite, there exists h > 0 such that {δ : ‖δ‖ ≤ + h} ⊂ {δ : L(δ, θ) < ρ}. Thus {δ : L(δ, θ) ≥ ρ} ⊂ {δ : ‖δ‖ > + h}, contradicting minL(δ,θ)≥ρ ‖δ‖ = again. Eq. (24). Assume that minL(δ,θ)≥ρ ‖δ‖ > , then {δ : L(δ, θ) ≥ ρ} ⊂ {δ : ‖δ‖ > }. Taking complementary set of both sides, {δ : ‖δ‖ ≤ } ⊂ {δ : L(δ, θ) < ρ}. Therefore, by the compactness of {δ : ‖δ‖ ≤ }, max‖δ‖≤ L(δ, θ) < ρ, contradiction.
A.5 PROOF OF THEOREM 3.1
Proof. Recall that L(δ, θ) = LLMθ (x + δ, y), dθ = dθ(x, y), ∗ θ(ρ) = minδ:L(δ,θ)≥ρ ‖δ‖, and ρ∗ = max‖δ‖≤ L(δ, θ0) > max‖δ‖≤ L(δ, θ1).
We first prove that ∀ , ∗θ1(ρ ∗) ≥ ∗θ0(ρ ∗) by contradiction. We assume ∗θ1(ρ ∗) < ∗θ0(ρ ∗). Let δ∗θ (ρ) = arg minδ:L(δ,θ)≥ρ ‖δ‖, which is ‖δ∗θ1(ρ ∗)‖ < ‖δ∗θ0(ρ ∗)‖. By Eq. (24), we have ‖δ∗θ0(ρ
∗)‖ ≤ . Therefore, ‖δ∗θ1(ρ
∗)‖ < . Then there exist a δ# ∈ {δ : ‖δ‖ ≤ } such that L(δ#, θ1) ≥ ρ∗. This contradicts max‖δ‖≤ L(δ, θ1) < ρ∗. Therefore ∗θ1(ρ ∗) ≥ ∗θ0(ρ ∗). For 1), = dθ0 . By definition of margin in Eq. (1), we have ρ ∗ = max‖δ‖≤dθ0 L(δ, θ0) = 0. Also by definition of ∗θ(ρ), ∗ θ0 (0) = dθ0 and ∗ θ1 (0) = dθ1 . For 2), < dθ0 . We have ρ ∗ = max‖δ‖≤ L(δ, θ0) ≤ max‖δ‖≤dθ0 L(δ, θ0) = 0. Therefore
∗θ0(ρ ∗) ≤ ∗θ0(0) = dθ0 and ∗ θ1 (ρ∗) ≤ ∗θ1(0) = dθ1 .
For 3), > dθ0 . We have ρ ∗ = max‖δ‖≤ L(δ, θ0) ≥ max‖δ‖≤dθ0 L(δ, θ0) = 0. Therefore
∗θ0(ρ ∗) ≥ ∗θ0(0) = dθ0 and ∗ θ1 (ρ∗) ≥ ∗θ1(0) = dθ1 .

heading: B MORE RELATED WORKS
text: We next discuss a few related works in details.
First-order Large Margin: Previous works (Matyasko & Chau, 2017; Elsayed et al., 2018; Yan et al., 2019) have attempted to use first-order approximation to estimate the input space margin. For first-order methods, the margin will be accurately estimated when the classification function is linear. MMA’s margin estimation is exact when the shortest successful perturbation δ∗ can be solved, which is not only satisfied by linear models, but also by a broader range of models, e.g. models that are convex w.r.t. input x. This relaxed condition could potentially enable more accurate margin estimation which improves MMA training’s performance.
(Cross-)Lipschitz Regularization: Sokolic et al. (2017); Tsuzuku et al. (2018) enlarges their margin by controlling the global Lipschitz constant, which in return places a strong constraint on the model and harms its learning capabilities. Instead, our method, alike adversarial training, uses adversarial attacks to estimate the margin to the decision boundary. With a strong method, our estimate is much more precise in the neighborhood around the data point, while being much more flexible due to not relying on a global Lipschitz constraint.
Hard-Margin SVM (Vapnik, 2013) in the separable case: Assuming that all the training examples are correctly classified and using our notations on general classifiers, the hard-margin SVM objective can be written as:
max θ { min i dθ(zi) } s.t. Lθ(zi) < 0,∀i . (25)
On the other hand, under the same “separable and correct” assumptions, MMA formulation in Eq. (3) can be written as
max θ {∑ i dθ(zi) } s.t. Lθ(zi) < 0,∀i , (26)
which is maximizing the average margin rather than the minimum margin in SVM. Note that the theorem on gradient calculation of the margin in Section 2.1 also applies to the SVM formulation of differentiable functions. Because of this, we can also use SGD to solve the following “SVM-style” formulation:
max θ mini∈S+θ dθ(zi)− ∑ j∈S−θ Jθ(zj)  . (27) As our focus is using MMA to improve adversarial robustness which involves maximizing the average margin, we delay the maximization of minimum margin to future work.
Maximizing Robust Radius for Randomized Smoothing: Randomized smoothing (Cohen et al., 2019) is an effective technique for certifying the `2 robust radius of a “smoothed classifier” with high probability bound. Here the certified robust radius is a lower bound of the input space margin of the “smoothed classifier”. Zhai et al. (2020) introduce a method to directly maximizing this certified robust radius.
Bayesian Adversarial Learning: Ye & Zhu (2018) introduce a full Bayesian treatment of adversarial training. In practice, the model is trained to be robust under adversarial perturbations with
different magnitudes. Although both their and our methods adversarially train the model with different perturbation magnitudes, the motivations are completely different.
Dynamic Adversarial Training: Wang et al. (2019) improve adversarial training’s convergence by dynamically adjusting the strength (the number of iterations) of PGD attacks, based on its proposed First-Order Stationary Condition. In a sense, MMA training is also dynamically adjusting the attack strength. However, our aim is margin maximization and the strength here represents the magnitude of the perturbation.
B.1 DETAILED COMPARISON WITH ADVERSARIAL TRAINING WITH DDN
For `2 robustness, we also compare to models adversarially trained on the “Decoupled Direction and Norm” (DDN) attack (Rony et al., 2018), which is concurrent to our work. The DDN attack aims to achieve successful perturbation with minimal `2 norm, thus, DDN could be used as a drop-in replacement for the AN-PGD attack for MMA training. We performed evaluations on the downloaded 8 DDN trained models.
The DDN MNIST model is a larger ConvNet with similar structure to our LeNet5, and the CIFAR10 model is wideresnet-28-10, which is similar but larger than the wideresnet-28-4 that we use.
DDN training, “training on adversarial examples generated by the DDN attack”, differs from MMA in the following ways. When the DDN attack does not find a successful adversarial example, it returns the clean image, and the model will use it for training. In MMA, when a successful adversarial example cannot be found, it is treated as a perturbation with very large magnitude, which will be ignored by the hinge loss when we calculate the gradient for this example. Also, in DDN training, there exists a maximum norm of the perturbation. This maximum norm constraint does not exist for MMA training. When a perturbation is larger than the hinge threshold, it will be ignored by the hinge loss. There also are differences in training hyperparameters, which we refer the reader to Rony et al. (2018) for details.
Despite these differences, in our experiments MMA training achieves similar performances under the `2 cases. While DDN attack and training only focus on `2 cases, we also show that the MMA training framework provides significant improvements over PGD training in the `∞ case.

heading: C DETAILED SETTINGS FOR TRAINING
text: With respect to the weights on LCE and LMMA in Eq. (8), we tested 3 pairs of weights, (1/3, 2/3), (1/2, 1/2) and (2/3, 1/3), in our initial CIFAR10 `∞ experiments. We observed that (1/3, 2/3), namely (1/3 for LCE and 2/3 for LMMA) gives better performance. We then fixed it and use the same values for all the other experiments in the paper, including the MNIST experiments and `2 experiments.
We train LeNet5 models for the MNIST experiments and use wide residual networks (Zagoruyko & Komodakis, 2016) with depth 28 and widen factor 4 for all the CIFAR10 experiments. For all the experiments, we monitor the average margin from AN-PGD on the validation set and choose the model with largest average margin from the sequence of checkpoints during training. The validation set contains first 5000 images of training set. It is only used to monitor training progress and not used in training. Here all the models are trained and tested under the same type of norm constraints, namely if trained on `∞, then tested on `∞; if trained on `2, then tested on `2.
The LeNet5 is composed of 32-channel conv filter + ReLU + size 2 max pooling + 64-channel conv filter + ReLU + size 2 max pooling + fc layer with 1024 units + ReLU + fc layer with 10 output classes. We do not preprocess MNIST images before feeding into the model.
For training LeNet5 on all MNIST experiments, for both PGD and MMA training, we use the Adam optimizer with an initial learning rate of 0.0001 and train for 100000 steps with batch size 50. In our initial experiments, we tested different initial learning rate at 0.0001, 0.001, 0.01, and 0.1 and do not find noticeable differences.
8github.com/jeromerony/fast_adversarial
We use the WideResNet-28-4 as described in Zagoruyko & Komodakis (2016) for our experiments, where 28 is the depth and 4 is the widen factor. We use “per image standardization” 9 to preprocess CIFAR10 images, following Madry et al. (2017).
For training WideResNet on CIFAR10 variants, we use stochastic gradient descent with momentum 0.9 and weight decay 0.0002. We train 50000 steps in total with batch size 128. The learning rate is set to 0.3 at step 0, 0.09 at step 20000, 0.03 at step 30000, and 0.009 at step 40000. This setting is the same for PGD and MMA training. In our initial experiments, we tested different learning rate at 0.03, 0.1, 0.3, and 0.6, and kept using 0.3 for all our later experiments. We also tested a longer training schedule, following Madry et al. (2017), where we train 80000 steps with different learning rate schedules. We did not observe improvement with this longer training, therefore kept using the 50000 steps training.
For models trained on MNIST, we use 40-step PGD attack with the soft logit margin (SLM) loss defined in Section 3, for CIFAR10 we use 10 step-PGD, also with the SLM loss. For both MNIST and CIFAR10, the step size of PGD attack at training time is 2.5 number of steps · In AN-PGD, we always perform 10 step bisection search after PGD, with the SLM loss. For AN-PGD, the maximum perturbation length is always 1.05 times the hinge threshold: max = 1.05dmax. The initial perturbation length at the first epoch, init, have different values under different settings. init = 0.5 for MNIST `2, init = 0.1 for MNIST `∞, init = 0.5 for CIFAR10 `2, init = 0.05 for CIFAR10 `2. In epochs after the first, init will be set to the margin of the same example from last epoch.
Trained models: Various PGD/PGDLS models are trained with different perturbation magnitude , denoted by PGD- or PGDLS- . PGD-ens/PGDLS-ens represents the ensemble of PGD/PGDLS trained models with different ’s. The ensemble makes prediction by majority voting on label predictions, and uses softmax scores as the tie breaker. We perform MMA training with different hinge thresholds dmax, also with/without the additional clean loss (see next section for details). We use OMMA to represent training with only LMMAθ in Eq. (7), and MMA to represent training with the combined loss in Eq. (8). When train For each dmax value, we train two models with different random seeds, which serves two purposes: 1) confirming the performance of MMA trained models are not significantly affected by random initialization; 2) to provide transfer attacks from an “identical” model. As such, MMA trained models are named as OMMA/MMA-dmax-seed. Models shown in the main body correspond to those with seed “sd0”.
For MNIST-`∞, we train PGD/PGDLS models with = 0.1, 0.2, 0.3, 0.4, 0.45. We also train OMMA/MMA models with dmax = 0.45, each with two random seeds. We also consider a standard model trained on clean images, PGD-ens, PGDLS-ens, and the PGD trained model from Madry et al. (2017). Therefore, we have in total m = 2× 5 + 2× 2 + 4 = 18 models under MNIST-`∞. For MNIST-`2, we train PGD/PGDLS models with = 1.0, 2.0, 3.0, 4.0. We also train OMMA/MMA models with dmax = 2.0, 4.0, 6.0, each with two random seeds. We also consider a standard model trained on clean images, PGD-ens, PGDLS-ens, and the DDN trained model from Rony et al. (2018). Therefore, we have in total m = 2 × 4 + 2 × 3 × 2 + 4 = 24 models under MNIST-`2.
For CIFAR10-`∞, we train PGD/PGDLS models with = 4, 8, 12, 16, 20, 24, 28, 32. We also train OMMA/MMA models with dmax = 12, 20, 32, each with two random seeds. We also consider a standard model trained on clean images, PGD-ens, PGDLS-ens, and the PGD trained model from Madry et al. (2017). Therefore, we have in total m = 2 × 8 + 2 × 3 × 2 + 4 = 32 models under CIFAR10-`∞.
For CIFAR10-`2, we train PGD/PGDLS models with = 0.5, 1.0, 1.5, 2.0, 2.5. We also train OMMA/MMA models with dmax = 1.0, 2.0, 3.0, each with two random seeds. We also consider a standard model trained on clean images, PGD-ens, PGDLS-ens, and the DDN trained model from Rony et al. (2018). Therefore, we have in total m = 2 × 5 + 2 × 3 × 2 + 4 = 26 models under MNIST-`2.
With regard to ensemble models, for MNIST-`2 PGD/PGDLS-ens, CIFAR10-`2 PGD/PGDLS-ens, MNIST-`∞PGDLS-ens, and CIFAR10-`∞ PGDLS-ens, they all use the PGD (or PGDLS) models
9Description can be found at https://www.tensorflow.org/api_docs/python/tf/image/ per_image_standardization. We implemented our own version in PyTorch.
trained at all testing (attacking) ’s. For CIFAR10-`∞ PGD-ens, PGD-24,28,32 are excluded for the same reason.

heading: D DETAILED SETTINGS OF ATTACKS
text: For both `∞ and `2 PGD attacks, we use the implementation from the AdverTorch toolbox (Ding et al., 2019b). Regarding the loss function of PGD, we use both the cross entropy (CE) loss and the Carlini & Wagner (CW) loss. 10
As previously stated, each model will have N whitebox PGD attacks on them, N/2 of them are CE-PGD attacks, and the other N/2 are CW-PGD attacks. Recall that N = 50 for MNIST and N = 10 for CIFAR10. At test time, all the PGD attack run 100 iterations. We manually tune the step size parameter on a few MMA and PGD models and then fix them thereafter. The step size for MNIST-`∞ when = 0.3 is 0.0075, the step size for CIFAR10-`∞ when = 8/255 is 2/255, the step size for MNIST-`2 when = 1.0 is 0.25, the step size for CIFAR10-`2 when = 1.0 is 0.25. For other values, the step size is linearly scaled accordingly.
The ensemble model we considered uses the majority vote for prediction, and uses softmax score as the tie breaker. So it is not obvious how to perform CW-PGD and CE-PGD directly on them. Here we take 2 strategies. The first one is a naive strategy, where we minimize the sum of losses of all the models used in the ensemble. Here, similar to attacking single models, we CW and CE loss here and perform the same number attacks.
The second strategy is still a PGD attack with a customized loss towards attacking ensemble models. For the group of classifiers in the ensemble, at each PGD step, if less than half of the classifiers give wrong classification, we sum up the CW losses from correct classifiers as the loss for the PGD attack. If more than half of the classifiers give wrong classification, then we find the wrong prediction that appeared most frequently among classifiers, and denote it as label0, with its corresponding logit, logit0. For each classifier, we then find the largest logit that is not logit0, denoted as logit1. The loss we maximize, in the PGD attack, is the sum of “logit1 - logit0” from each classifier. Using this strategy, we perform additional (compared to attacking single models) whitebox PGD attacks on ensemble models. For MNIST, we perform 50 repeated attacks, for CIFAR10 we perform 10. These are also 100-step PGD attacks.
We expect more carefully designed attacks could work better on ensembles, but we delay it to future work.
For the SPSA attack (Uesato et al., 2018), we run the attack for 100 iterations with perturbation size 0.01 (for gradient estimation), Adam learning rate 0.01, stopping threshold -5.0 and 2048 samples for each gradient estimate. For CIFAR10-`∞, we use = 8/255. For MNIST-`∞, we use = 0.3.

heading: E EFFECTS OF ADDING CLEAN LOSS IN ADDITION TO THE MMA LOSS
text: We further examine the effectiveness of adding a clean loss term to the MMA loss. We represent MMA trained models with the MMA loss in Eq. (7) as MMA-dmax. In Section 2.4, we introduced MMAC-dmax models to resolve MMA-dmax model’s problem of having flat input space loss landscape and showed its effectiveness qualitatively. Here we demonstrate the quantitative benefit of adding the clean loss.
We observe that models trained with the MMA loss in Eq. (7) have certain degrees of TransferGaps. The term TransferGaps represents the difference between robust accuracy under “combined (whitebox+transfer) attacks” and under “only whitebox PGD attacks”. In other words, it is the additional attack success rate that transfer attacks bring. For example, OMMA-32 achieves 53.70% under whitebox PGD attacks, but achieves a lower robust accuracy at 46.31% under combined (whitebox+transfer) attacks, therefore it has a TransferGap of 7.39% (See Appendix F for full results.). After adding the clean loss, MMA-32 reduces its TransferGap at = 8/255 to 3.02%. This corresponds to our observation in Section 2.4 that adding clean loss makes the loss landscape more tilted, such that whitebox PGD attacks can succeed more easily.
10The CW loss is almost equivalent to the logit margin (LM) loss. We use CW loss for the ease of comparing with literature. Here CW (x) = min{maxj 6=y fj(x)− fy(x), 0}. When the classification is correct, CW and LM loss have the same gradient.
Recall that MMA trained models are robust to gradient free attacks, as described in Section 4.3. Therefore, robustness of MMA trained models and the TransferGaps are likely not due to gradient masking.
We also note that TransferGaps for both MNIST-`∞ and `2 cases are almost zero for the MMA trained models, indicating that TransferGaps, observed on CIFAR10 cases, are not solely due to the MMA algorithm, data distributions (MNIST vs CIFAR10) also play an important role.
Another interesting observation is that, for MMA trained models trained on CIFAR10, adding additional clean loss results in a decrease in clean accuracy and an increase in the average robust accuracy, e.g. OMMA-32 has ClnAcc 86.11%, and AvgRobAcc 28.36%, whereas MMA-32 has ClnAcc 84.36%, and AvgRobAcc 29.39%. The fact that “adding additional clean loss results in a model with lower accuracy and more robustness” seems counter-intuitive. However, it actually confirms our motivation and reasoning of the additional clean loss: it makes the input space loss landscape steeper, which leads to stronger adversaries at training time, which in turn poses more emphasis on “robustness training”, instead of clean accuracy training.

heading: F FULL RESULTS AND TABLES
text: We present all the empirical results in Table 4 to 15. Specifically, we show model performances under combined (whitebox+transfer) attacks in Tables 4 to 7. This is our proxy for true robustness measure. We show model performances under only whitebox PGD attacks in Tables 8 to 11. We show TransferGaps in Tables 12 to 15.
In these tables, PGD-Madry et al. models are the “secret” models downloaded from https:// github.com/MadryLab/mnist_challenge and https://github.com/MadryLab/ cifar10_challenge/. DDN-Rony et al. models are downloaded from https://github. com/jeromerony/fast_adversarial/. TRADES models are downloaded from https: //github.com/yaodongyu/TRADES.
For MNIST PGD-Madry et al. models, our whitebox attacks brings the robust accuracy at = 0.3 down to 89.79%, which is at the same level with the reported 89.62% on the website, also with 50 repeated random initialized PGD attacks. For CIFAR10 PGD-Madry et al. models, our whitebox attacks brings the robust accuracy at = 8/255 down to 44.70%, which is stronger than the reported 45.21% on the website, with 10 repeated random initialized 20-step PGD attacks. As our PGD attacks are 100-step, this is not surprising.
We also compared TRADES with MMA trained models under `∞ attacks. On MNIST, overall TRADES outperforms MMA except that TRADES fails completely at large perturbation length of 0.4. This may be because TRADES is trained with attacking length = 0.3, and therefore cannot defend larger attacks. On CIFAR10, we compare MMA-32 with TRADES as their clean accuracies are similar. Similar to the results on MNIST, we see that TRADES outperforms MMA on the attacks of lengths that are less than = 12/255, but it sacrifices the robustness under larger attacks. We also note that MMA training and TRADES’ idea of optimizing a calibration loss are progresses in orthogonal directions and could potentially be combined.
As we mentioned previously, DDN training can be seen as a specific instantiation of the general MMA training idea, and the DDN-Rony et al. models indeed performs very similar to MMA trained models when dmax is set relatively low. Therefore, we do not discuss the performance of DDN-Rony et al. separately.
In Section 4, we have mainly discussed different phenomena under the case of CIFAR10-`∞. For CIFAR10-`2, we see very similar patterns in Tables 7, 11 and 15. These include
• MMA training is fairly stable to dmax, and achieves good robustness-accuracy trade-offs. On the other hand, to achieve good AvgRobAcc, PGD/PGDLS trained models need to have large sacrifices on clean accuracies. • Adding additional clean loss increases the robustness of the model, reduce TransferGap, at a cost of slightly reducing clean accuracy.
As a simpler datasets, different adversarial training algorithms, including MMA training, have very different behaviors on MNIST as compared to CIFAR10.
We first look at MNIST-`∞. Similar to CIFAR10 cases, PGD training is incompetent on large ’s, e.g. PGD-0.4 has significant drop on clean accuracy (to 96.64%) and PGD-0.45 fails to train. PGDLS training, on the other hand, is able to handle large ’s training very well on MNIST-`∞, and MMA training does not bring extra benefit on top of PGDLS. We suspect that this is due to the “easiness” of this specific task on MNIST, where finding proper for each individual example is not necessary, and a global scheduling of is enough. We note that this phenomenon confirms our understanding of adversarial training from the margin maximization perspective in Section 3.
Under the case of MNIST-`2, we notice that MMA training almost does not need to sacrifice clean accuracy in order to get higher robustness. All the models with dmax ≥ 4.0 behaves similarly w.r.t. both clean and robust accuracies. Achieving 40% robust accuracy at = 3.0 seems to be the robustness limit of MMA trained models. On the other hand, PGD/PGDLS models are able to get higher robustness at = 3.0 with robust accuracy of 44.5%, although with some sacrifices to clean accuracy. This is similar to what we have observed in the case of CIFAR10.
We notice that on both MNIST-`∞ and MNIST-`2, unlike CIFAR10 cases, PGD(LS)-ens model performs poorly in terms of robustness. This is likely due to that PGD trained models on MNIST usually have a very sharp robustness drop when the used for attacking is larger than the used for training.
Another significant differences between MNIST cases and CIFAR10 cases is that TransferGaps are very small for OMMA/MMA trained models on MNIST cases. This again is likely due to that MNIST is an “easier” dataset. It also indicates that the TransferGap is not purely due to the MMA training algorithm, it is also largely affected by the property of datasets. Although previous literature (Ding et al., 2019a; Zhang et al., 2019c) also discusses related topics on the difference between MNIST and CIFAR10 w.r.t. adversarial robustness, they do not directly explain the observed phenomena here. We delay a thorough understanding of this topic to future work.
F.1 ADDITIONAL EVALUATION WITH THE CW-`2 ATTACK
We run the CW-`2 attack (Carlini & Wagner, 2017) on the first 1000 test examples for models trained with `2 attacks. This gives the minimum `2 norm a perturbation needs to change the prediction. For each model, we show the clean accuracy, also mean, median, 25th percentile and 75th percentile of these minimum distances in Tables 2 and 3 below.
Looking at CW-`2 results, we have very similar observations as compared to the observations we made based on robust accuracies (under PGD attacks) at different ’s and the average robust accuracy.
On MNIST, for MMA trained models as dmax increases from 2.0 to 6.0, the mean minimum distance goes from 2.15 to 2.76, with the clean accuracy only drops to 97.7% from 99.3%. On the contrary, when we perform PGD/PGDLS with a larger , e.g. = 4.0, the clean accuracy drops significantly to 91.8%, with the mean minimum distance increased to 2.53. Therefore MMA training achieves better performance on both clean accuracy and robustness under the MNIST-`2 case.
On CIFAR10, we observed that MMA training is fairly stable to dmax, and achieves good robustnessaccuracy trade-offs. With carefully chosen value, PGD-1.0/PGDLS-1.0 models can also achieve similar robustness-accuracy tradeoffs as compared to MMA training. However, when we perform PGD training with a larger , the clean accuracy drops significantly.

Review summaries:
This paper proposes an adaptive margin-based adversarial training (eg. MMA) approach to train robust DNNs by maximizing the shortest margin of inputs to the decision boundary. Theoretical analyses have been provided to understand the connection between robust optimization and margin maximization. The main difference between the proposed approach to standard adversarial training is the adaptive selection of the perturbation bound \epsilon. This makes adversarial training with large perturbation possible, which was previously unachievable by standard adversarial training (Madry et al.) Empirical results match the theoretical analysis.

This paper proposes a method, Max-Margin Adversarial (MMA) training, for robust learning against adversarial attacks. In the MMA, the margin in the input space is directly maximized. In order to alleviate an instability of the learning, a softmax variant of the max-margin is introduced. Moreover, the margin-maximization and the minimization of the worst-case loss are studied. Some numerical experiments show that the proposed MMA training is efficient against several adversarial attacks.