The Marginal Value of Adaptive Gradient Methods in Machine Learning

Ashia C. Wilson, Rebecca Roelofs, Mitchell Stern, Nathan Srebro, Benjamin Recht

Introduction

An increasing share of deep learning researchers are training their models with adaptive gradient methods due to their rapid training time . Adam in particular has become the default algorithm used across many deep learning frameworks. However, the generalization and out-of-sample behavior of such adaptive gradient methods remains poorly understood. Given that many passes over the data are needed to minimize the training objective, typical regret guarantees do not necessarily ensure that the found solutions will generalize .

Notably, when the number of parameters exceeds the number of data points, it is possible that the choice of algorithm can dramatically influence which model is learned . Given two different minimizers of some optimization problem, what can we say about their relative ability to generalize? In this paper, we show that adaptive and non-adaptive optimization methods indeed find very different solutions with very different generalization properties. We provide a simple generative model for binary classification where the population is linearly separable (i.e., there exists a solution with large margin), but AdaGrad , RMSProp , and Adam converge to a solution that incorrectly classifies new data with probability arbitrarily close to half. On this same example, SGD finds a solution with zero error on new data. Our construction suggests that adaptive methods tend to give undue influence to spurious features that have no effect on out-of-sample generalization.

We additionally present numerical experiments demonstrating that adaptive methods generalize worse than their non-adaptive counterparts. Our experiments reveal three primary findings. First, with the same amount of hyperparameter tuning, SGD and SGD with momentum outperform adaptive methods on the development/test set across all evaluated models and tasks. This is true even when the adaptive methods achieve the same training loss or lower than non-adaptive methods. Second, adaptive methods often display faster initial progress on the training set, but their performance quickly plateaus on the development/test set. Third, the same amount of tuning was required for all methods, including adaptive methods. This challenges the conventional wisdom that adaptive methods require less tuning. Moreover, as a useful guide to future practice, we propose a simple scheme for tuning learning rates and decays that performs well on all deep learning tasks we studied.

Background

The canonical optimization algorithms used to minimize risk are either stochastic gradient methods or stochastic momentum methods. Stochastic gradient methods can generally be written

Stochastic momentum methods are a second family of techniques that have been used to accelerate training. These methods can generally be written as

The sequence of iterates (2.2) includes Polyak’s heavy-ball method (HB) with γk=0\gamma_{k}=0, and Nesterov’s Accelerated Gradient method (NAG) with γk=βk\gamma_{k}=\beta_{k}.

Notable exceptions to the general formulations (2.1) and (2.2) are adaptive gradient and adaptive momentum methods, which choose a local distance measure constructed using the entire sequence of iterates (w1,⋯ ,wk)(w_{1},\cdots,w_{k}). These methods (including AdaGrad , RMSProp , and Adam ) can generally be written as

In this context, generalization refers to the performance of a solution ww on a broader population. Performance is often defined in terms of a different loss function than the function ff used in training. For example, in classification tasks, we typically define generalization in terms of classification error rather than cross-entropy.

Understanding how optimization relates to generalization is a very active area of current machine learning research. Most of the seminal work in this area has focused on understanding how early stopping can act as implicit regularization . In a similar vein, Ma and Belkin have shown that gradient methods may not be able to find complex solutions at all in any reasonable amount of time. Hardt et al. show that SGD is uniformly stable, and therefore solutions with low training error found quickly will generalize well. Similarly, using a stability argument, Raginsky et al. have shown that Langevin dynamics can find solutions than generalize better than ordinary SGD in non-convex settings. Neyshabur, Srebro, and Tomioka discuss how algorithmic choices can act as implicit regularizer. In a similar vein, Neyshabur, Salakhutdinov, and Srebro show that a different algorithm, one which performs descent using a metric that is invariant to re-scaling of the parameters, can lead to solutions which sometimes generalize better than SGD. Our work supports the work of by drawing connections between the metric used to perform local optimization and the ability of the training algorithm to find solutions that generalize. However, we focus primarily on the different generalization properties of adaptive and non-adaptive methods.

A similar line of inquiry has been pursued by Keskar et al. . Hochreiter and Schmidhuber showed that “sharp” minimizers generalize poorly, whereas “flat” minimizers generalize well. Keskar et al. empirically show that Adam converges to sharper minimizers when the batch size is increased. However, they observe that even with small batches, Adam does not find solutions whose performance matches state-of-the-art. In the current work, we aim to show that the choice of Adam as an optimizer itself strongly influences the set of minimizers that any batch size will ever see, and help explain why they were unable to find solutions that generalized particularly well.

The potential perils of adaptivity

The goal of this section is to illustrate the following observation: when a problem has multiple global minima, different algorithms can find entirely different solutions when initialized from the same point. In addition, we construct an example where adaptive gradient methods find a solution which has worse out-of-sample error than SGD.

To simplify the presentation, let us restrict our attention to the binary least-squares classification problem, where we can easily compute closed the closed form solution found by different methods. In least-squares classification, we aim to solve

Here XX is an n×dn\times d matrix of features and yy is an nn-dimensional vector of labels in {−1,1}\{-1,1\}. We aim to find the best linear classifier ww. Note that when d>nd>n, if there is a minimizer with loss 00 then there is an infinite number of global minimizers. The question remains: what solution does an algorithm find and how well does it perform on unseen data?

2 Adaptive methods

Suppose there exists a scalar cc such that X sign⁡(XTy)=cyX\,\operatorname{sign}(X^{T}y)=cy. Then, when initialized at w0=0w_{0}=0, AdaGrad, Adam, and RMSProp all converge to the unique solution w∝sign⁡(XTy)w\propto\operatorname{sign}(X^{T}y).

In other words, whenever there exists a solution of Xw=yXw=y that is proportional to sign⁡(XTy)\operatorname{sign}(X^{T}y), this is precisely the solution to which all of the adaptive gradient methods converge.

Proof We prove this lemma by showing that the entire trajectory of the algorithm consists of iterates whose components have constant magnitude. In particular, we will show that

for some scalar λk\lambda_{k}. The initial point w0=0w_{0}=0 satisfies the assertion with λ0=0\lambda_{0}=0.

Now, assume the assertion holds for all k≤tk\leq t. Observe that

where the last equation defines μk\mu_{k}. Hence, letting gk=∇RS(wk+γk(wk−wk−1))g_{k}=\nabla R_{S}(w_{k}+\gamma_{k}(w_{k}-w_{k-1})), we also have

where ∣u∣|u| denotes the component-wise absolute value of a vector and the last equation defines νk\nu_{k}.

proving the claim. In the event that XTyX^{T}y has a component equal to 00, we define 0/0=00/0=0 so that the update is well-defined.

This solution is far simpler than the one obtained by gradient methods, and it would be surprising if such a simple solution would perform particularly well. We now turn to showing that such solutions can indeed generalize arbitrarily poorly.

3 Adaptivity can overfit

Lemma 3.1 allows us to construct a particularly pernicious generative model where AdaGrad fails to find a solution that generalizes. This example uses infinite dimensions to simplify bookkeeping, but one could take the dimensionality to be 6n6n. Note that in deep learning, we often have a number of parameters equal to 25n25n or more , so this is not a particularly high dimensional example by contemporary standards. For i=1,…,ni=1,\ldots,n, sample the label yiy_{i} to be 11 with probability pp and −1-1 with probability 1−p1-p for some p>1/2p>1/2. Let xix_{i} be an infinite dimensional vector with entries

In other words, the first feature of xix_{i} is the class label. The next 22 features are always equal to 11. After this, there is a set of features unique to xix_{i} that are equal to 11. If the class label is 11, then there is 11 such unique feature. If the class label is −1-1, then there are 55 such features. Note that the only discriminative feature useful for classifying data outside the training set is the first one! Indeed, one can perform perfect classification using only the first feature. The other features are all useless. Features 22 and 33 are constant, and each of the remaining features only appear for one example in the data set. However, as we will see, algorithms without such a priori knowledge may not be able to learn these distinctions.

Take nn samples and consider the AdaGrad solution for minimizing 12∣∣Xw−y∣∣2\frac{1}{2}||Xw-y||^{2}. First we show that the conditions of Lemma 3.1 hold. Let b=∑i=1nyib=\sum_{i=1}^{n}y_{i} and assume for the sake of simplicity that b>0b>0. This will happen with arbitrarily high probability for large enough nn. Define u=XTyu=X^{T}y and observe that

Therefore, the AdaGrad solution will label all unseen data as a positive example!

Using (3.2), we see that whenever n+>n−/3n_{+}>n_{-}/3, the SGD solution makes no errors.

A formal construction of this example using a data-generating distribution can be found in Appendix C. Though this generative model was chosen to illustrate extreme behavior, it shares salient features with many common machine learning instances. There are a few frequent features, where some predictor based on them is a good predictor, though these might not be easy to identify from first inspection. Additionally, there are many other features which are sparse. On finite training data it looks like such features are good for prediction, since each such feature is discriminatory for a particular training example, but this is over-fitting and an artifact of having fewer training examples than features. Moreover, we will see shortly that adaptive methods typically generalize worse than their non-adaptive counterparts on real datasets.

Deep Learning Experiments

Having established that adaptive and non-adaptive methods can find different solutions in the convex setting, we now turn to an empirical study of deep neural networks to see whether we observe a similar discrepancy in generalization. We compare two non-adaptive methods – SGD and the heavy ball method (HB) – to three popular adaptive methods – AdaGrad, RMSProp and Adam. We study performance on four deep learning problems: (C1) the CIFAR-10 image classification task, (L1) character-level language modeling on the novel War and Peace, and (L2) discriminative parsing and (L3) generative parsing on Penn Treebank. In the interest of reproducibility, we use a network architecture for each problem that is either easily found online (C1, L1, L2, and L3) or produces state-of-the-art results (L2 and L3). Table 3 summarizes the setup for each application. We take care to make minimal changes to the architectures and their data pre-processing pipelines in order to best isolate the effect of each optimization algorithm.

We conduct each experiment 5 times from randomly initialized starting points, using the initialization scheme specified in each code repository. We allocate a pre-specified budget on the number of epochs used for training each model. When a development set was available, we chose the settings that achieved the best peak performance on the development set by the end of the fixed epoch budget. CIFAR-10 did not have an explicit development set, so we chose the settings that achieved the lowest training loss at the end of the fixed epoch budget.

Our experiments show the following primary findings: (i) Adaptive methods find solutions that generalize worse than those found by non-adaptive methods. (ii) Even when the adaptive methods achieve the same training loss or lower than non-adaptive methods, the development or test performance is worse. (iii) Adaptive methods often display faster initial progress on the training set, but their performance quickly plateaus on the development set. (iv) Though conventional wisdom suggests that Adam does not require tuning, we find that tuning the initial learning rate and decay scheme for Adam yields significant improvements over its default settings in all cases.

Optimization hyperparameters have a large influence on the quality of solutions found by optimization algorithms for deep neural networks. The algorithms under consideration have many hyperparameters: the initial step size α0\alpha_{0}, the step decay scheme, the momentum value β0\beta_{0}, the momentum schedule βk\beta_{k}, the smoothing term ϵ\epsilon, the initialization scheme for the gradient accumulator, and the parameter controlling how to combine gradient outer products, to name a few. A grid search on a large space of hyperparameters is infeasible even with substantial industrial resources, and we found that the parameters that impacted performance the most were the initial step size and the step decay scheme. We left the remaining parameters with their default settings. We describe the differences between the default settings of Torch, DyNet, and Tensorflow in Appendix B for completeness.

To tune the step sizes, we evaluated a logarithmically-spaced grid of five step sizes. If the best performance was ever at one of the extremes of the grid, we would try new grid points so that the best performance was contained in the middle of the parameters. For example, if we initially tried step sizes 22, 11, 0.50.5, 0.250.25, and 0.1250.125 and found that 22 was the best performing, we would have tried the step size 44 to see if performance was improved. If performance improved, we would have tried 88 and so on. We list the initial step sizes we tried in Appendix D.

For step size decay, we explored two separate schemes, a development-based decay scheme (dev-decay) and a fixed frequency decay scheme (fixed-decay). For dev-decay, we keep track of the best validation performance so far, and at each epoch decay the learning rate by a constant factor δ\delta if the model does not attain a new best value. For fixed-decay, we decay the learning rate by a constant factor δ\delta every kk epochs. We recommend the dev-decay scheme when a development set is available; not only does it have fewer hyperparameters than the fixed frequency scheme, but our experiments also show that it produces results comparable to, or better than, the fixed-decay scheme.

2 Convolutional Neural Network

We used the VGG+BN+Dropout network for CIFAR-10 from the Torch blog , which in prior work achieves a baseline test error of 7.55%7.55\%. Figure 1 shows the learning curve for each algorithm on both the training and test dataset.

We observe that the solutions found by SGD and HB do indeed generalize better than those found by adaptive methods. The best overall test error found by a non-adaptive algorithm, SGD, was 7.65±0.14%7.65\pm 0.14\%, whereas the best adaptive method, RMSProp, achieved a test error of 9.60±0.19%9.60\pm 0.19\%.

Early on in training, the adaptive methods appear to be performing better than the non-adaptive methods, but starting at epoch 50, even though the training error of the adaptive methods is still lower, SGD and HB begin to outperform adaptive methods on the test error. By epoch 100, the performance of SGD and HB surpass all adaptive methods on both train and test. Among all adaptive methods, AdaGrad’s rate of improvement flatlines the earliest. We also found that by increasing the step size, we could drive the performance of the adaptive methods down in the first 50 or so epochs, but the aggressive step size made the flatlining behavior worse, and no step decay scheme could fix the behavior.

3 Character-Level Language Modeling

Using the torch-rnn library, we train a character-level language model on the text of the novel War and Peace, running for a fixed budget of 200 epochs. Our results are shown in Figures 2 and 2.

Under the fixed-decay scheme, the best configuration for all algorithms except AdaGrad was to decay relatively late with regards to the total number of epochs, either 60 or 80% through the total number of epochs and by a large amount, dividing the step size by 10. The dev-decay scheme paralleled (within the same standard deviation) the results of the exhaustive search over the decay frequency and amount; we report the curves from the fixed policy.

Overall, SGD achieved the lowest test loss at 1.212±0.0011.212\pm 0.001. AdaGrad has fast initial progress, but flatlines. The adaptive methods appear more sensitive to the initialization scheme than non-adaptive methods, displaying a higher variance on both train and test. Surprisingly, RMSProp closely trails SGD on test loss, confirming that it is not impossible for adaptive methods to find solutions that generalize well. We note that there are step configurations for RMSProp that drive the training loss below that of SGD, but these configurations cause erratic behavior on test, driving the test error of RMSProp above Adam.

4 Constituency Parsing

A constituency parser is used to predict the hierarchical structure of a sentence, breaking it down into nested clause-level, phrase-level, and word-level units. We carry out experiments using two state-of-the-art parsers: the stand-alone discriminative parser of Cross and Huang , and the generative reranking parser of Choe and Charniak . In both cases, we use the dev-decay scheme with δ=0.9\delta=0.9 for learning rate decay.

Cross and Huang develop a transition-based framework that reduces constituency parsing to a sequence prediction problem, giving a one-to-one correspondence between parse trees and sequences of structural and labeling actions. Using their code with the default settings, we trained for 50 epochs on the Penn Treebank , comparing labeled F1 scores on the training and development data over time. RMSProp was not implemented in the used version of DyNet, and we omit it from our experiments. Results are shown in Figures 2 and 2.

We find that SGD obtained the best overall performance on the development set, followed closely by HB and Adam, with AdaGrad trailing far behind. The default configuration of Adam without learning rate decay actually achieved the best overall training performance by the end of the run, but was notably worse than tuned Adam on the development set.

Interestingly, Adam achieved its best development F1 of 91.11 quite early, after just 6 epochs, whereas SGD took 18 epochs to reach this value and didn’t reach its best F1 of 91.24 until epoch 31. On the other hand, Adam continued to improve on the training set well after its best development performance was obtained, while the peaks for SGD were more closely aligned.

Generative Model.

Choe and Charniak show that constituency parsing can be cast as a language modeling problem, with trees being represented by their depth-first traversals. This formulation requires a separate base system to produce candidate parse trees, which are then rescored by the generative model. Using an adapted version of their code base, While the code of Choe and Charniak treats the entire corpus as a single long example, relying on the network to reset itself upon encountering an end-of-sentence token, we use the more conventional approach of resetting the network for each example. This reduces training efficiency slightly when batches contain examples of different lengths, but removes a potential confounding factor from our experiments. we retrained their model for 100 epochs on the Penn Treebank. However, to reduce computational costs, we made two minor changes: (a) we used a smaller LSTM hidden dimension of 500 instead of 1500, finding that performance decreased only slightly; and (b) we accordingly lowered the dropout ratio from 0.7 to 0.5. Since they demonstrated a high correlation between perplexity (the exponential of the average loss) and labeled F1 on the development set, we explored the relation between training and development perplexity to avoid any conflation with the performance of a base parser.

Our results are shown in Figures 2 and 2. On development set performance, SGD and HB obtained the best perplexities, with SGD slightly ahead. Despite having one of the best performance curves on the training dataset, Adam achieves the worst development perplexities.

Conclusion

Despite the fact that our experimental evidence demonstrates that adaptive methods are not advantageous for machine learning, the Adam algorithm remains incredibly popular. We are not sure exactly as to why, but hope that our step-size tuning suggestions make it easier for practitioners to use standard stochastic gradient methods in their research. In our conversations with other researchers, we have surmised that adaptive gradient methods are particularly popular for training GANs and Q-learning with function approximation . Both of these applications stand out because they are not solving optimization problems. It is possible that the dynamics of Adam are accidentally well matched to these sorts of optimization-free iterative search procedures. It is also possible that carefully tuned stochastic gradient methods may work as well or better in both of these applications. It is an exciting direction of future work to determine which of these possibilities is true and to understand better as to why.

Acknowledgements

The authors would like to thank Pieter Abbeel, Moritz Hardt, Tomer Koren, Sergey Levine, Henry Milner, Yoram Singer, and Shivaram Venkataraman for many helpful comments and suggestions. RR is generously supported by DOE award AC02-05CH11231. MS and AW are supported by NSF Graduate Research Fellowships. NS is partially supported by NSF-IIS-13-02662 and NSF-IIS-15-46500, an Inter ICRI-RI award and a Google Faculty Award. BR is generously supported by NSF award CCF-1359814, ONR awards N00014-14-1-0024 and N00014-17-1-2191, the DARPA Fundamental Limits of Learning (Fun LoL) Program, a Sloan Research Fellowship, and a Google Faculty Award.

References

Appendix A Full details of the minimum norm solution from Section 3.3

Positing that αi=α+\alpha_{i}=\alpha_{+} if yi=1y_{i}=1 and αi=α−\alpha_{i}=\alpha_{-} if yi=−1y_{i}=-1 leaves us with the equations

Solving this system of equations yields (3.2).

Appendix B Differences between Torch, DyNet, and Tensorflow

Table 3 lists the default values of the parameters for the various deep learning packages used in our experiments. In Torch, the Heavy Ball algorithm is callable simply by changing default momentum away from 0 with nesterov=False. In Tensorflow and DyNet, SGD with momentum is implemented separately from ordinary SGD. For our Heavy Ball experiments we use a constant momentum of β=0.9\beta=0.9.

Appendix C Data-generating distribution

We sketch here how the example from Section 3.3 can be modified to use a data-generating distribution. To start, let D\mathcal{D} be a uniform distribution over NN examples constructed as before, and let D={(x1,y1),…,(xn,yn)}D=\{(x_{1},y_{1}),\dots,(x_{n},y_{n})\} be a training set consisting of nn i.i.d. draws from D\mathcal{D}. We will ultimately want to take NN to be large enough so that the probability of a repeated training example is small.

Let E\mathcal{E} be the event that there is a repeated training example. We have by a simple union bound that

If the training set has no repeats, the result from Section 3.3 tells us that SGD will learn a perfect classifier, while AdaGrad will find a solution that correctly classifies the training examples but predicts y^=1\hat{y}=1 for all unseen data points. Hence, conditioned on ¬E\neg\mathcal{E}, the error for SGD is

Otherwise, if there is a repeat, we have trivial bounds of 0 and 1 for the conditional error in each case:

Putting these together, we find that the unconditional error for SGD is bounded above by

while the unconditional error for AdaGrad is bounded below by

Let ϵ>0\epsilon>0 be a tolerance. For the error of SGD to be at most ϵ\epsilon, it suffices to take N≥n22ϵN\geq\frac{n^{2}}{2\epsilon}, in which case we have

For the error of AdaGrad to be at least (1−p)(1−ϵ)\left(1-p\right)\left(1-\epsilon\right), it suffices to take N≥n2ϵN\geq\frac{n^{2}}{\epsilon} assuming n≥2n\geq 2, in which case we have

Both of these conditions will be satisfied by taking N≥max⁡{n22ϵ,n2ϵ}=n2ϵN\geq\max\left\{\frac{n^{2}}{2\epsilon},\frac{n^{2}}{\epsilon}\right\}=\frac{n^{2}}{\epsilon}.

Since the choice of ϵ\epsilon was arbitrary, taking ϵ→0\epsilon\to 0 drives the SGD error to 0 and the AdaGrad error to 1−p1-p, matching the original result in the non-i.i.d. setting.

Appendix D Step sizes used for parameter tuning

SGD: {2, 1, 0.5 (best), 0.25, 0.05, 0.01}

AdaGrad: {0.1, 0.05, 0.01 (best, def.), 0.0075, 0.005}

RMSProp: {0.005, 0.001, 0.0005, 0.0003 (best), 0.0001}

Adam: {0.005, 0.001 (default), 0.0005, 0.0003 (best), 0.0001, 0.00005}

The default Torch step sizes for SGD (0.001) , HB (0.001), and RMSProp (0.01) were outside the range we tested.

War & Peace

AdaGrad: {0.4, 0.2, 0.1, 0.05 (best), 0.025}

RMSProp: {0.02, 0.01, 0.005, 0.0025, 0.00125, 0.000625, 0.0005 (best), 0.0001}

Adam: {0.005, 0.0025, 0.00125, 0.000625 (best), 0.0003125, 0.00015625}

Under the fixed-decay scheme, we selected learning rate decay frequencies from the set {10,20,40,80,120,160,∞}\{10,20,40,80,120,160,\infty\} and learning rate decay amounts from the set {0.1,0.5,0.8,0.9}\{0.1,0.5,0.8,0.9\}.

Discriminative Parsing

SGD: {1.0, 0.5, 0.2, 0.1 (best), 0.05, 0.02, 0.01}

HB: {1.0, 0.5, 0.2, 0.1, 0.05 (best), 0.02, 0.01, 0.005, 0.002}

AdaGrad: {1.0, 0.5, 0.2, 0.1, 0.05, 0.02 (best), 0.01, 0.005, 0.002, 0.001, 0.0005, 0.0002, 0.0001}

RMSProp: Not implemented in DyNet at the time of writing.

Adam: {0.01, 0.005, 0.002 (best), 0.001 (default), 0.0005, 0.0002, 0.0001}

Generative Parsing

SGD: {1.0, 0.5 (best), 0.25, 0.1, 0.05, 0.025, 0.01}

HB: {0.25, 0.1, 0.05, 0.02, 0.01 (best), 0.005, 0.002, 0.001}

AdaGrad: {5.0, 2.5, 1.0, 0.5, 0.25 (best), 0.1, 0.05, 0.02, 0.01}

RMSProp: {0.05, 0.02, 0.01, 0.005, 0.002 (best), 0.001, 0.0005, 0.0002, 0.0001}

Adam: {0.005, 0.002, 0.001 (default), 0.0005 (best), 0.0002, 0.0001}