Title: DECOUPLED WEIGHT DECAY REGULARIZATION

Abstract: L 2 regularization and weight decay regularization are equivalent for standard stochastic gradient descent (when rescaled by the learning rate), but as we demonstrate this is not the case for adaptive gradient algorithms, such as Adam. While common implementations of these algorithms employ L 2 regularization (often calling it "weight decay" in what may be misleading due to the inequivalence we expose), we propose a simple modification to recover the original formulation of weight decay regularization by decoupling the weight decay from the optimization steps taken w.r.t. the loss function. We provide empirical evidence that our proposed modification (i) decouples the optimal choice of weight decay factor from the setting of the learning rate for both standard SGD and Adam and (ii) substantially improves Adam's generalization performance, allowing it to compete with SGD with momentum on image classification datasets (on which it was previously typically outperformed by the latter). Our proposed decoupled weight decay has already been adopted by many researchers, and the community has implemented it in TensorFlow and PyTorch; the complete source code for our experiments is available at https://github.com/loshchil/AdamW-and-SGDW Now, let's turn to adaptive gradient algorithms like the popular optimizer Adam Kingma & Ba (2014), which scale gradients by their historic magnitudes. Intuitively, when Adam is run on a loss function f plus L 2 regularization, weights that tend to have large gradients in f do not get regularized as much as they would with decoupled weight decay, since the gradient of the regularizer gets scaled along with the gradient of f . This leads to an inequivalence of L 2 and decoupled weight decay regularization for adaptive gradient algorithms:

1. INTRODUCTION:

Adaptive gradient methods, such as AdaGrad (Duchi et al., 2011) , RMSProp (Tieleman & Hinton, 2012) , Adam (Kingma & Ba, 2014) and most recently AMSGrad (Reddi et al., 2018) have become a default method of choice for training feed-forward and recurrent neural networks (Xu et al., 2015; Radford et al., 2015) . Nevertheless, state-of-the-art results for popular image classification datasets, such as CIFAR-10 and CIFAR-100 Krizhevsky (2009) , are still obtained by applying SGD with momentum (Gastaldi, 2017; Cubuk et al., 2018) . Furthermore, Wilson et al. (2017) suggested that adaptive gradient methods do not generalize as well as SGD with momentum when tested on a diverse set of deep learning tasks, such as image classification, character-level language modeling and constituency parsing. Different hypotheses about the origins of this worse generalization have been investigated, such as the presence of sharp local minima (Keskar et al., 2016; Dinh et al., 2017) and inherent problems of adaptive gradient methods (Wilson et al., 2017) . In this paper, we investigate whether it is better to use L 2 regularization or weight decay regularization to train deep neural networks with SGD and Adam. We show that a major factor of the poor generalization of the most popular adaptive gradient method, Adam, is due to the fact that L 2 regularization is not nearly as effective for it as for SGD. Specifically, our analysis of Adam leads to the following observations:

L 2 regularization and weight decay are not identical. Contrary to a belief which seems popular among some practitioners, the two techniques are not equivalent. For SGD, they can be made equivalent by a reparameterization of the weight decay factor based on the learning rate; this is not the case for Adam. In particular, when combined with adaptive gradients, L 2 regularization leads to weights with large parameter and/or gradient amplitudes being regularized less than they would be when using weight decay.

L 2 regularization is not effective in Adam. One possible explanation why Adam and other adaptive gradient methods might be outperformed by SGD with momentum is that common deep learning libraries only implement L 2 regularization, not the original weight decay. Therefore, on tasks/datasets where the use of L 2 regularization is beneficial for SGD (e.g., on many popular image classification datasets), Adam leads to worse results than SGD with momentum (for which L 2 regularization behaves as expected). Weight decay is equally effective in both SGD and Adam. For SGD, it is equivalent to L 2 regularization, while for Adam it is not. Optimal weight decay depends on the total number of batch passes/weight updates. Our empirical analysis of SGD and Adam suggests that the larger the runtime/number of batch passes to be performed, the smaller the optimal weight decay. This effect tends to be neglected because hyperparameters are often tuned for a fixed number of training epochs. As a result, the values of the weight decay found to perform best for short runs do not generalize to much longer runs.

The main contribution of this paper is to improve regularization in Adam by decoupling the weight decay from the gradient-based update. In a comprehensive analysis, we show that Adam generalizes substantially better with decoupled weight decay than with L 2 regularization, achieving 15% relative improvement in test error (see Figures 2 and 3 ); this holds true for various image recognition datasets (CIFAR-10 and ImageNet32x32), training budgets (ranging from 100 to 1800 epochs), and learning rate schedules (fixed, drop-step, and cosine annealing; see Figure 1 ). We demonstrate that our decoupled weight decay renders the optimal settings of the learning rate and the weight decay factor much more independent, thereby easing hyperparameter optimization (see Figure 2 ).

The main motivation of this paper is to improve Adam to make it competitive w.r.t. SGD with momentum even for those problems where it did not use to be competitive. We hope that as a result, practitioners do not need to switch between Adam and SGD anymore, which in turn should reduce the common issue of selecting dataset/task-specific training algorithms and their hyperparameters.

2. DECOUPLING THE WEIGHT DECAY FROM THE GRADIENT-BASED UPDATE:

In the weight decay described by Hanson & Pratt (1988) , the weights θ decay exponentially as

EQUATION

where λ defines the rate of the weight decay per step and ∇f t (θ t ) is the t-th batch gradient to be multiplied by a learning rate α. For standard SGD, it is equivalent to standard L 2 regularization: Proposition 1 (Weight decay = L 2 reg for standard SGD). Standard SGD with base learning rate α executes the same steps on batch loss functions f t (θ) with weight decay λ (defined in Equation 1) as it executes without weight decay on

f reg t (θ) = f t (θ) + λ 2 θ 2 2 , with λ = λ α .

The proofs of this well-known fact, as well as our other propositions, are given in the Appendix A.

Due to this equivalence, L 2 regularization is very frequently referred to as weight decay, including in popular deep learning libraries. However, as we will demonstrate later in this section, this equivalence does not hold for adaptive gradient methods. One fact that is often overlooked already for the simple case of SGD is that in order for the equivalence to hold, the L 2 regularizer λ has to be set to λ α , i.e., if there is an overall best weight decay value λ, the best value of λ is tightly coupled with the learning rate α. In order to decouple the effects of these two hyperparameters, we advocate to decouple the weight decay step as proposed by Hanson & Pratt (1988) (Equation 1).

Looking first at the case of SGD, we propose to decay the weights simultaneously with the update of θ t based on gradient information in Line 9 of Algorithm 1. This yields our proposed variant of SGD with momentum using decoupled weight decay (SGDW). This simple modification explicitly decouples λ and α (although some problem-dependent implicit coupling may of course remain as for any two hyperparameters). In order to account for a possible scheduling of both α and λ, we introduce a scaling factor η t delivered by a user-defined procedure SetScheduleM ultiplier(t).

Algorithm 1 SGD with L 2 regularization and SGD with decoupled weight decay (SGDW) , both with momentum 1: given initial learning rate α ∈ IR, momentum factor β1 ∈ IR, weight decay/L2 regularization factor λ ∈ IR 2: initialize time step t ← 0, parameter vector θt=0 ∈ IR n , first moment vector mt=0 ← 0, schedule multiplier ηt=0 ∈ IR 3: repeat 4:

t ← t + 1 5:

∇ft(θt-1) ← SelectBatch(θt-1) select batch and return the corresponding gradient 6:

g t ← ∇ft(θt-1) +λθt-1 7:

ηt ← SetScheduleMultiplier(t) can be fixed, decay, be used for warm restarts 8:

mt ← β1mt-1 + ηtαg t 9:

θt ← θt-1 -mt -ηtλθt-1 10: until stopping criterion is met 11: return optimized parameters θt Algorithm 2 Adam with L 2 regularization and Adam with decoupled weight decay (AdamW) 1: given α = 0.001, β1 = 0.9, β2 = 0.999, = 10 -8 , λ ∈ IR 2: initialize time step t ← 0, parameter vector θt=0 ∈ IR n , first moment vector mt=0 ← 0, second moment vector vt=0 ← 0, schedule multiplier ηt=0 ∈ IR 3: repeat 4:

t ← t + 1 5:

∇ft(θt-1) ← SelectBatch(θt-1) select batch and return the corresponding gradient 6:

g t ← ∇ft(θt-1) +λθt-1 7: mt ← β1mt-1 + (1 -β1)g t

here and below all operations are element-wise 8:

vt ← β2vt-1 + (1 -β2)g 2 t 9: mt ← mt/(1 -β t 1 )

β1 is taken to the power of t 10:

vt ← vt/(1 -β t 2 )

β2 is taken to the power of t 11:

ηt ← SetScheduleMultiplier(t) can be fixed, decay, or also be used for warm restarts 12: θt ← θt-1 -ηt α mt/( √ vt + ) +λθt-1 13: until stopping criterion is met 14: return optimized parameters θt

Proposition 2 (Weight decay = L 2 reg for adaptive gradients). Let O denote an optimizer that has iterates θ t+1 ← θ t -αM t ∇f t (θ t ) when run on batch loss function f t (θ) without weight decay, and θ t+1 ← (1 -λ)θ t -αM t ∇f t (θ t ) when run on f t (θ) with weight decay, respectively, with

M t = kI (where k ∈ R). Then, for O there exists no L 2 coefficient λ such that running O on batch loss f reg t (θ) = f t (θ)+ λ 2 θ 2 2 without weight decay is equivalent to running O on f t (θ) with decay λ ∈ R + .

We decouple weight decay and loss-based gradient updates in Adam as shown in line 12 of Algorithm 2; this gives rise to our variant of Adam with decoupled weight decay (AdamW).

Having shown that L 2 regularization and weight decay regularization differ for adaptive gradient algorithms raises the question of how they differ and how to interpret their effects. Their equivalence for standard SGD remains very helpful for intuition: both mechanisms push weights closer to zero, at the same rate. However, for adaptive gradient algorithms they differ: with L 2 regularization, the sums of the gradient of the loss function and the gradient of the regularizer (i.e., the L 2 norm of the weights) are adapted, whereas with weight decay, only the gradients of the loss function are adapted (with the weight decay step separated from the adaptive gradient mechanism). With L 2 regularization both types of gradients are normalized by their typical (summed) magnitudes, and therefore weights x with large typical gradient magnitude s are regularized by a smaller relative amount than other weights. In contrast, weight decay regularizes all weights with the same rate λ, effectively regularizing weights x with large s more than standard L 2 regularization does. We demonstrate this formally for a simple special case of adaptive gradient algorithm with a fixed preconditioner: Proposition 3 (Weight decay = scale-adjusted L 2 reg for adaptive gradient algorithm with fixed preconditioner). Let O denote an algorithm with the same characteristics as in Proposition 2, and using a fixed preconditioner matrix M t = diag(s) -1 (with s i > 0 for all i). Then, O with base learning rate α executes the same steps on batch loss functions f t (θ) with weight decay λ as it executes without weight decay on the scale-adjusted regularized batch loss

EQUATION

where and √ • denote element-wise multiplication and square root, respectively, and λ = λ α .

3. JUSTIFICATION OF DECOUPLED WEIGHT DECAY VIA A VIEW OF ADAPTIVE GRADIENT METHODS AS BAYESIAN FILTERING:

We now discuss a justification of decoupled weight decay in the framework of Bayesian filtering for a unified theory of adaptive gradient algorithms due to Aitchison (2018) . After we posted a preliminary version of our current paper on arXiv, Aitchison noted that his theory "gives us a theoretical framework in which we can understand the superiority of this weight decay over L 2 regularization, because it is weight decay, rather than L 2 regularization that emerges through the straightforward application of Bayesian filtering." (Aitchison, 2018) . While full credit for this theory goes to Aitchison, we summarize it here to shed some light on why weight decay may be favored over L 2 regularization.

Aitchison (2018) views stochastic optimization of n parameters x 1 , . . . , x n as a Bayesian filtering problem with the goal of inferring a distribution over the optimal values of each of the parameters x i given the current values of the other parameters θ -i (t) at time step t. When the other parameters do not change this is an optimization problem, but when they do change it becomes one of "tracking" the optimizer using Bayesian filtering as follows. One is given a probability distribution P (θ t | y 1:t ) of the optimizer at time step t that takes into account the data y 1:t from the first t mini batches, a state transition prior P (θ t+1 | θ t ) reflecting a (small) data-independent change in this distribution from one step to the next, and a likelihood P (y t+1 | θ t+1 ) derived from the mini batch at step t + 1. The posterior distribution P (θ t+1 | y 1:t+1 ) of the optimizer at time step t + 1 can then be computed (as usual in Bayesian filtering) by marginalizing over θ t to obtain the onestep ahead predictions P (θ t+1 | y 1:t ) and then applying Bayes' rule to incorporate the likelihood P (y t+1 | θ t+1 ). Aitchison (2018) assumes a Gaussian state transition distribution P (θ t+1 | θ t ) and an approximate conjugate likelihood P (y t+1 | θ t+1 ), leading to the following closed-form update of the filtering distribution's mean:

EQUATION

where g is the gradient of the log likelihood of the mini batch at time t. This result implies a preconditioner of the gradients that is given by the posterior uncertainty Σ post of the filtering distribution: updates are larger for parameters we are more uncertain about and smaller for parameters we are more certain about. Aitchison (2018) goes on to show that popular adaptive gradient methods, such as Adam and RMSprop, as well as Kronecker-factorized methods are special cases of this framework.

Decoupled weight decay very naturally fits into this unified framework can express weight decay as part of the state-transition distribution: Aitchison (2018) assumes a slow change of the optimizer according to the following Gaussian:

EQUATION

)

where Q is the covariance of Gaussian perturbations of the weights, and A is a regularizer to avoid values growing unboundedly over time. When instantiated as A = λ × I, this regularizer A plays exactly the role of decoupled weight decay as described in Equation 1, since this leads to multiplying the current mean estimate θ t by (1 -λ) at each step. Notably, this regularization is also directly applied to the prior and does not depend on the uncertainty in each of the parameters (which would be required for L 2 regularization). 

4. EXPERIMENTAL VALIDATION:

We now evaluate the performance of decoupled weight decay under various training budgets and learning rate schedules. Our experimental setup follows that of Gastaldi (2017) , who proposed, in addition to L 2 regularization, to apply the new Shake-Shake regularization to a 3-branch residual DNN that allowed to achieve new state-of-the-art results of 2.86% on the CIFAR-10 dataset (Krizhevsky, 2009) . We always used a batch size of 128. The regular data augmentation procedure used for the CIFAR datasets was applied. We used the same model/source code based on fb.resnet.torch1 . The base networks are a 26 2x64d ResNet (i.e. the network has a depth of 26, 2 residual branches and the first residual block has a width of 64) and a 26 2x96d ResNet with 11.6M and 25.6M parameters, respectively. For a detailed description of the network and the Shake-Shake method, we refer the interested reader to Gastaldi (2017) . We also perform experiments on the Im-ageNet32x32 dataset (Chrabaszcz et al., 2017) , a downsampled version of the original ImageNet dataset with 1.2 million 32×32 pixels images.

4.1. EVALUATING DECOUPLED WEIGHT DECAY WITH DIFFERENT LEARNING RATE SCHEDULES:

In our first experiment, we compare Adam with L 2 regularization to Adam with decoupled weight decay (AdamW), using three different learning rate schedules: a fixed learning rate, a drop-step schedule, and a cosine annealing schedule (Loshchilov & Hutter, 2016) . For each learning rate schedule and weight decay variant, we trained a 2x64d ResNet for 100 epochs, using different settings of the initial learning rate α and the weight decay factor λ. Figure 1 shows that decoupled weight decay outperforms L 2 regularization for all learning rate schedules, with larger differences for better learning rate schedules. We also note that decoupled weight decay leads to a more separable hyperparameter search space, especially when a learning rate schedule, such as step-drop and 

4.2. DECOUPLING THE WEIGHT DECAY AND INITIAL LEARNING RATE PARAMETERS:

In order to verify our hypothesis about the coupling of α and λ, in Figure 2 we compare the performance of L 2 regularization vs. decoupled weight decay in SGD (SGD vs. SGDW, top row) and in Adam (Adam vs. AdamW, bottom row). In SGD (Figure 2 , top left), L 2 regularization is not decoupled from the learning rate (the common way as described in Algorithm 1), and the figure clearly shows that the basin of best hyperparameter settings (depicted by color and top-10 hyperparameter settings by black circles) is not aligned with the x-axis or y-axis but lies on the diagonal. This suggests that the two hyperparameters are interdependent and need to be changed simultaneously, while only changing one of them might substantially worsen results. Consider, e.g., the setting at the top left black circle (α = 1/2, λ = 1/8 * 0.001); only changing either α or λ by itself would worsen results, while changing both of them could still yield clear improvements. We note that this coupling of initial learning rate and L 2 regularization factor might have contributed to SGD's reputation of being very sensitive to its hyperparameter settings.

In contrast, the results for SGD with decoupled weight decay (SGDW) in Figure 2 (top right) show that weight decay and initial learning rate are decoupled. The proposed approach renders the two hyperparameters more separable: even if the learning rate is not well tuned yet (e.g., consider the value of 1/1024 in Figure 2 , top right), leaving it fixed and only optimizing the weight decay factor would yield a good value (of 1/4*0.001). This is not the case for SGD with L 2 regularization (see Figure 2 , top left).

The results for Adam with L 2 regularization are given in Figure 2 (bottom left). Adam's best hyperparameter settings performed clearly worse than SGD's best ones (compare Figure 2 , top left). While both methods used L 2 regularization, Adam did not benefit from it at all: its best results obtained for non-zero L 2 regularization factors were comparable to the best ones obtained without the L 2 regularization, i.e., when λ = 0. Similarly to the original SGD, the shape of the hyperparameter landscape suggests that the two hyperparameters are coupled.

In contrast, the results for our new variant of Adam with decoupled weight decay (AdamW) in Figure 2 (bottom right) show that AdamW largely decouples weight decay and learning rate. The results for the best hyperparameter settings were substantially better than the best ones of Adam with L 2 regularization and rivaled those of SGD and SGDW.

In summary, the results in Figure 2 support our hypothesis that the weight decay and learning rate hyperparameters can be decoupled, and that this in turn simplifies the problem of hyperparameter tuning in SGD and improves Adam's performance to be competitive w.r.t. SGD with momentum.

4.3. BETTER GENERALIZATION OF ADAMW:

While the previous experiment suggested that the basin of optimal hyperparameters of AdamW is broader and deeper than the one of Adam, we next investigated the results for much longer runs of 1800 epochs to compare the generalization capabilities of AdamW and Adam.

We fixed the initial learning rate to 0.001 which represents both the default learning rate for Adam and the one which showed reasonably good results in our experiments. Figure 3 shows the results for 12 settings of the L 2 regularization of Adam and 7 settings of the normalized weight decay of AdamW (the normalized weight decay represents a rescaling formally defined in the Appendix B.1, it amounts to a multiplicative factor which depends on the number of bath passes). Interestingly, while the dynamics of the learning curves of Adam and AdamW often coincided for the first half of the training run, AdamW often led to lower training loss and test errors (see Figure 3 top left and top right, respectively). Importantly, the use of weight decay in Adam did not yield as good results as in AdamW (see also Figure 3 , bottom left). Next, we investigated whether AdamW's better results were only due to better convergence or due to better generalization. The results in Figure 3 (bottom right) for the best settings of Adam and AdamW suggest that AdamW did not only yield better training loss but also yielded better generalization performance for similar training loss values. The results on ImageNet32x32 (see SuppFigure 4 in the Appendix) lead to the same conclusion of substantially improved generalization performance. For a better resolution and with training loss curves, see SuppFigure 5 and SuppFigure 6 in the supplementary material.

4.4. ADAMWR WITH WARM RESTARTS FOR BETTER ANYTIME PERFORMANCE:

In order to improve anytime performance of SGDW and AdamW we extended them with warm restarts of (Loshchilov & Hutter, 2016) to obtain SGDWR and AdamWR, respectively (see section B.2 in the Appendix). As Figure 4 shows, AdamWR greatly sped up AdamW on CIFAR-10 and ImageNet32x32, up to a factor of 10 (see the results at the first restart). For the default learning rate of 0.001, AdamW achieved 15% relative improvement in test errors compared to Adam both on CIFAR-10 (also see Figure 3 ) and ImageNet32x32 (also see SuppFigure 5). AdamWR achieved the same improved results but with a much better anytime performance. These improvements closed most of the gap between Adam and SGDWR on CIFAR-10 and yielded comparable performance on ImageNet32x32.

4.5. USE OF ADAMW ON OTHER DATASETS AND ARCHITECTURES:

Several other research groups have already successfully applied AdamW in citable works. For example, Wang et al. (2018) used AdamW to train a novel architecture for face detection on the standard WIDER FACE dataset (Yang et al., 2016) , obtaining almost 10x faster predictions than the previous state of the art algorithms while achieving comparable performance. Völker et al. (2018) employed AdamW with cosine annealing to train convolutional neural networks to classify and characterize error-related brain signals measured from intracranial electroencephalography (EEG) recordings. While their paper does not provide a comparison to Adam, they kindly provided us with a direct comparison of the two on their best-performing problem-specific network architecture Deep4Net and a variant of ResNet. AdamW with the same hyperparameter setting as Adam yielded higher test set accuracy on Deep4Net (73.68% versus 71.37%) and statistically significantly higher test set accuracy on ResNet (72.04% versus 61.34%). Radford et al. (2018) employed AdamW to train Transformer (Vaswani et al., 2017) architectures to obtain new state-of-the-art results on a wide range of benchmarks for natural language understanding. Zhang et al. (2018) compared L 2 regularization vs. weight decay for SGD, Adam and the Kronecker-Factored Approximate Curvature (K-FAC) optimizer (Martens & Grosse, 2015) on the CIFAR datasets with ResNet and VGG architectures, reporting that decoupled weight decay consistently outperformed L 2 regularization in cases where they differ.

5. CONCLUSION AND FUTURE WORK:

Following suggestions that adaptive gradient methods such as Adam might lead to worse generalization than SGD with momentum (Wilson et al., 2017) , we identified and exposed the inequivalence of L 2 regularization and weight decay for Adam. We empirically showed that our version of Adam with decoupled weight decay yields substantially better generalization performance than the common implementation of Adam with L 2 regularization. We also proposed to use warm restarts for Adam to improve its anytime performance.

Our results obtained on image classification datasets must be verified on a wider range of tasks, especially ones where the use of regularization is expected to be important. It would be interesting to integrate our findings on weight decay into other methods which attempt to improve Adam, e.g, normalized direction-preserving Adam (Zhang et al., 2017) . While we focused our experimental analysis on Adam, we believe that similar results also hold for other adaptive gradient methods, such as AdaGrad (Duchi et al., 2011) and AMSGrad (Reddi et al., 2018) .

Proof of Proposition 3:

O without weight decay has the following iterates on

EQUATION

where the division by s is element-wise. O with weight decay has the following iterates on f t (θ):

EQUATION

These iterates are identical since λ = λ α .

B ADDITIONAL PRACTICAL IMPROVEMENTS OF ADAM:

Having discussed decoupled weight decay for improving Adam's generalization, in this section we introduce two additional components to improve Adam's performance in practice.

B.1 NORMALIZED WEIGHT DECAY:

Our preliminary experiments showed that different weight decay factors are optimal for different computational budgets (defined in terms of the number of batch passes). Relatedly, Li et al. (2017) demonstrated that a smaller batch size (for the same total number of epochs) leads to the shrinking effect of weight decay being more pronounced. Here, we propose to reduce this dependence by normalizing the values of weight decay. Specifically, we replace the hyperparameter λ by a new (more robust) normalized weight decay hyperparameter λ norm , and use this to set λ as λ = λ norm b BT , where b is the batch size, B is the total number of training points and T is the total number of epochs.2 Thus, λ norm can be interpreted as the weight decay used if only one batch pass is allowed. We emphasize that our choice of normalization is merely one possibility informed by few experiments; a more lasting conclusion we draw is that using some normalization can substantially improve results.

B.2 ADAM WITH COSINE ANNEALING AND WARM RESTARTS:

We now apply cosine annealing and warm restarts to Adam, following the recent work of Loshchilov & Hutter (2016) . There, the authors proposed Stochastic Gradient Descent with Warm Restarts (SGDR) to improve anytime performance of SGD by quickly cooling down the learning rate according to a cosine schedule and periodically increasing it. SGDR has been successfully adopted to lead to new state-of-the-art results for popular image classification benchmarks (Huang et al., 2017; Gastaldi, 2017; Zoph et al., 2017) , and we therefore tried extending it to Adam. However, while our initial version of Adam with warm restarts had better anytime performance than Adam, it was not competitive with SGD with warm restarts, precisely because L 2 regularization was not working as well as in SGD. Now, having fixed this issue by means of the original weight decay regularization (Section 2) and also having introduced normalized weight decay (Section B.1), the original work on cosine annealing and warm restarts by Loshchilov & Hutter (2016) directly carries over to Adam.

In the interest of keeping the presentation self-contained, we briefly describe how SGDR schedules the change of the effective learning rate in order to accelerate the training of DNNs. Here, we decouple the initial learning rate α and its multiplier η t used to obtain the actual learning rate at iteration t (see, e.g., line 8 in Algorithm 1). In SGDR, we simulate a new warm-started run/restart of SGD once T i epochs are performed, where i is the index of the run. Importantly, the restarts are not performed from scratch but emulated by increasing η t while the old value of θ t is used as an initial solution. The amount by which η t is increased controls to which extent the previously acquired information (e.g., momentum) is used. Within the i-th run, the value of η t decays according to a cosine annealing (Loshchilov & Hutter, 2016) learning rate for each batch as follows:

EQUATION

min and η (i) max are ranges for the multiplier and T cur accounts for how many epochs have been performed since the last restart. T cur is updated at each batch iteration t and is thus not constrained to integer values. Adjusting (e.g., decreasing) η (i) min and η (i) max at every i-th restart (see also Smith (2016)) could potentially improve performance, but we do not consider that option here because it would involve additional hyperparameters. For η (i) max = 1 and η (i) min = 0, one can simplify Eq. ( 14) to η t = 0.5 + 0.5 cos(πT cur /T i ).

(15)

In order to achieve good anytime performance, one can start with an initially small T i (e.g., from 1% to 10% of the expected total budget) and multiply it by a factor of T mult (e.g., T mult = 2) at every restart. The (i + 1)-th restart is triggered when T cur = T i by setting T cur to 0. An example setting of the schedule multiplier is given in C.

Our proposed AdamWR algorithm represents AdamW (see Algorithm 2) with η t following Eq. ( 15) and λ computed at each iteration using normalized weight decay described in the previous section. We note that normalized weight decay allowed us to use a constant parameter setting across short and long runs performed within AdamWR and SGDWR (SGDW with warm restarts).

C AN EXAMPLE SETTING OF THE SCHEDULE MULTIPLIER:

An example schedule of the schedule multiplier η t is given in SuppFigure 1 for T i=0 = 100 and T mult = 2. After the initial 100 epochs the learning rate will reach 0 because η t=100 = 0. Then, since T cur = T i=0 , we restart by resetting T cur = 0, causing the multiplier η t to be reset to 1 due to Eq. ( 15). This multiplier will then decrease again from 1 to 0, but now over the course of 200 epochs because T i=1 = T i=0 T mult = 200. Solutions obtained right before the restarts, when η t = 0 (e.g., at epoch indexes 100, 300, 700 and 1500 as shown in SuppFigure 1) are recommended by the optimizer as the solutions, with more recent solutions prioritized.

D ADDITIONAL RESULTS:

We investigated whether the use of much longer runs (1800 epochs) of "standard Adam" (Adam with L 2 regularization and a fixed learning rate) makes the use of cosine annealing unnecessary.

:

https://github.com/xgastaldi/shake-shake

In the context of our AdamWR variant discussed in Section B.2, T is the total number of epochs in the current restart.

Figures and Tables:

Figure 1: Adam performs better with decoupled weight decay (bottom row, AdamW) than with L 2 regularization (top row, Adam). We show the final test error of a 26 2x64d ResNet on CIFAR-10 after 100 epochs of training with fixed learning rate (left column), step-drop learning rate (with drops at epoch indexes 30, 60 and 80, middle column) and cosine annealing (right column). AdamW leads to a more separable hyperparameter search space, especially when a learning rate schedule, such as step-drop and cosine annealing is applied. Cosine annealing yields clearly superior results.

Figure 2: The Top-1 test error of a 26 2x64d ResNet on CIFAR-10 measured after 100 epochs. The proposed SGDW and AdamW (right column) have a more separable hyperparameter space.

Figure 3: Learning curves (top row) and generalization results (bottom row) obtained by a 26 2x96d ResNet trained with Adam and AdamW on CIFAR-10. See text for details. SuppFigure 4 in the Appendix shows the same qualitative results for ImageNet32x32.

Figure 4: Top-1 test error on CIFAR-10 (left) and Top-5 test error on ImageNet32x32 (right). For a better resolution and with training loss curves, see SuppFigure 5 and SuppFigure 6 in the supplementary material.

Peer review (iclr2019):
 This review has been somewhat challenging to complete. As the authors write, this work has already been impactful and motivated a great deal of further research. The empirical evaluation is convincing and the results have been reproduced and further studied by others. A moderate amount of space in the paper (Section 3, Section 4.5) is used to refer to work motivated by the paper itself. While I do not take issue with this I believe it should be considered for the final decision (in the sense that disentangling the contributions of the authors and related work becomes tricky). With this said, I continue with my review. Paper summary: The authors observe that L2 regularization is not effective when using the Adam optimizer. By replacing L2 regularization with decoupled weight decay the authors are able to close the generalization gap between SGD and Adam and make Adam more robust to hyperparameter settings. The empirical evaluation is comprehensive and convincing. Detailed comments: 1) The authors emphasize the fact that L2 regularization and weight decay are not the same for different optimizers and claim that this goes against the belief of some practitioners. In my experience, most practitioners would not be surprised by this observation itself. The second observation made by the authors, that L2 regularization is not effective in Adam, is the more interesting (and perhaps surprising) observation. 2) I am not convinced of the importance of Proposition 3. In practice, adaptive methods will have a preconditioner which depends locally on the parameters. I understand the motivation from the previous paragraph but felt that the formal result added little. 3) Section 3 introduced the Bayesian filtering perspective of stochastic optimization. The authors share the observation of Aitchison, 2018 that decoupled weight decay can be recovered in this framework. My interpretation is that this observation is important _because_ of the empirical observations in this paper and does not necessarily provide theoretical support for the approach. However, the last paragraph of Section 3 seems to utilize the Bernstein-von Mises theorem to promote the idea that with large datasets the prior distribution is unimportant (and is ignored). I am not sure that I follow this argument. For example, this claim seems to be completely independent of the optimization algorithm used and moreover Propositions 1,2, and 3 are independent of the data distribution. I suspect that this confusion is due to a misunderstanding on my part and would appreciate clarification from the authors. 4) The empirical evaluation in this paper is very strong and these practical techniques have already been adopted by the community in addition to spurring novel research. The empirical observation broadly explores two directions: decoupled weight decay leads to separable hyperparameter search spaces (meaning optimization is less sensitive to hyperparameters), and decoupled weight decay gives improved generalization (and training performance). Both claims are explored throughly with strong evidence given for the improvement due to AdamW. Overall, I find this paper to be presented well and with convincing empirical results. I feel that the theoretical justification for decoupling weight decay are a little weak, and believe that other work is moving towards better explanations then the ones presented in this paper [1,2,3]. Despite this, I believe that this paper should be accepted. Minor comments: - I find the notation in the paper confusing in general. x is used to denote weights, and w to denote hyperparameters (e.g. w* for L2 regularization scale and w for weight decay scale). I don*t see why it wouldn*t be preferable to use the more standard W for weights, x for inputs, and lambda for hparams. - Figure 4: it is difficult to distinguish between Adam and SGDWR (especially left). Clarity: The paper is well written and clear. I find the notation confusing in places, but is consistent throughout. Originality: This paper presents original findings but occasionally relies on work motivated by itself to convince the reader of its importance. I do not think that this subtracts from the value of the work. Significance: The work is clearly significant. Even without knowing that practitioners have adopted the techniques presented in this work, the paper clearly distinguishes itself with strong empirical results.