How Does Adaptive Optimization Impact Local Neural Network Geometry?
Kaiqi Jiang, Dhruv Malik, Yuanzhi Li
Introduction
The efficient minimization of a parameterized loss function is a core primitive in statistics, optimization and machine learning. Gradient descent (GD), which iteratively updates a parameter vector with a step along the gradient of the loss function evaluated at that vector, is a simple yet canonical algorithm which has been applied to efficiently solve such minimization problems with enormous success. However, in modern machine learning, and especially deep learning, one frequently encounters problems where the loss functions are high dimensional, non-convex and non-smooth. The optimization landscape of such problems is thus extremely challenging, and in these settings gradient descent often suffers from prohibitively high iteration complexity.
To deal with these difficulties and improve optimization efficiency, practitioners in recent years have developed many variants of GD. One prominent class of these GD variants is the family of adaptive algorithms . At a high level, adaptive methods scale the gradient with an adpatively selected preconditioning matrix, which is constructed via a moving average of past gradients. These methods are reminiscent of second order gradient descent, since they construct approximations to the Hessian of the loss functions, while remaining computationally feasible since they eschew full computation of the Hessian. A vast line of empirical work has demonstrated the superiority of adaptive methods over GD to optimize deep neural networks, especially on Natural Language Processing (NLP) tasks with transformers .
From a theoretical perspective, adaptive methods are well understood in the traditional context of convex optimization. For instance, Duchi et al. show that when the loss function is convex, then the Adagrad algorithm yields regret guarantees that are provably as good as those obtained by using the best (diagonal) preconditioner in hindsight. The key mechanism that underlies this improved performance, is that the loss function has some global geometric property (such as sparsity or a coordinate wise bounded Lipschitz constant), and the algorithm adapts to this global geometry by adaptively selecting learning rates for features that are more informative.
However, in non-convex optimization, and deep learning in particular, it is highly unclear whether this simple characterization is sufficient to explain the superiority of adaptive methods over GD. Indeed, for large scale neural networks, global guarantees on the geometric properties of the loss are typically vacuous. For instance, for a 20-layer feedforward neural network, if we scale up the weights in each layer by a factor of , then the global Lipschitz constant of the network is scaled up by a factor of at least . Hence it only makes sense to study convergence by looking at the local geometry of the loss along the trajectory of the optimization algorithm .
Moreover, the interaction between an optimization algorithm and neural network geometry is highly complex — recent work has shown that geometric characteristics of iterates encountered during optimization is highly dependent on the choice of optimization algorithm and associated hyperparameters . For instance, Cohen et al. demonstrate that while training neural networks with GD, the maximum eigenvalue of the Hessian evaluated at the GD iterates first increases and then plateaus at a level 2/(step size). The viewpoint from convex optimization, where a loss function has some (potentially) non-uniform but fixed underlying geometry that we must adapt to, is thus insufficient for neural networks, since the choice of optimization algorithm can actually interact with and influence the observed geometry significantly.
To provide another example of this interactive phenomenon, we consider the following experiment. On the same network training loss function , we run stochastic gradient descent with momentum (SGD+M) and Adam to obtain two different trajectories. We select an iterate from the Adam trajectory and an iterate from the SGD trajectory, such that . We then run SGD+M twice, once from and once from . If the underlying geometry of the loss function was truly fixed, then we would not expect a significant difference in the performance of running SGD+M from either of the two iterates. However, as shown in Figure 1(a), there is a noticeable difference in performance, and running SGD+M from achieves lower loss than running SGD+M from . This suggests that Adam may bias the optimization trajectory towards a region which is more favorable for rapid training. This motivates the following question.
How does adaptive optimization impact the observed geometry of a neural network loss function, relative to SGD (with momentum)?
This statistic thus measures the uniformity of the diagonal of the Hessian, where a smaller value of implies that the Hessian has a more uniform diagonal. It can also be viewed as a stableConsider the case where one parameter has little impact on the loss, then the second derivative w.r.t. this parameter is almost zero, making infinity. So we consider median which is more stable. variant of the condition number. Instead of eigenvalues, we choose diagonal entries because adaptive methods used in practice are coordinate-wise, which can be viewed as the diagonal scaling approaches.Recall that the main theoretical bound in the original Adagrad paper is in terms of the diagonal scaling. Hence we believe the diagonal of Hessian is more relevant than the spectrum. As a supplementary result, in Appendix E, we demonstrate that the loss Hessian approaches diagonal during training for Adam and SGD+M. There has been prior theoretical work on overparameterized neural networks showing that a smaller condition number of Hessian, Neural Tangent Kernel etc. could yield to faster convergence rate for (S)GD . As for (diagonal) adaptive methods (e.g. Adagrad), they were original designed to adapt to the nonuniform diagonal geometry. Intuitively, a smaller , which implies more uniform diagonal geometry, could lead to faster convergence.
Armed with this statistic, we make the following contributions:
On a wide variety of neural network transformer architectures and language modeling datasets, we conduct experiments to compare how and evolve over time, when Adam and SGD+M are run from the same initialization and with their optimal (initial) learning rates respectively. In each case, we demonstrate that the Adam trajectory attains values that are significantly smaller than the values found by SGD+M. We show a simple example of this phenomenon in Figure 1(b). This suggests that relative to SGD+M, Adam biases the optimization trajectory to a region where the Hessian diagonal is more uniform. We call this phenomenon the uniformity of diagonal geometry for adaptive methods. As an aside, we observe that larger improvements in performance of Adam over SGD+M are correlated with larger gaps between and . This suggests that a region where the Hessian diagonal is more uniform is also a region that is more amenable to rapid optimization.
We complement our empirical results with a theoretical analysis of this phenomenon in the simplified setting of large batch Adam and SGD+M, on a two-layer linear network with -dimensional input and hidden layer, and one dimensional output. We show that for a wide range of , but . Our proof reveals that Adam induces the weight matrices to have low rank whose leading singular vectors have certain type of uniformity (see Section 6 for discussion), a fact that we also observe empirically in large scale neural networks, suggesting that this may be a mechanism by which adaptive methods bias trajectories to have uniformity of diagonal geometry.
Related work
Existing analyses of adaptive methods. The vast majority of prior theoretical work on adaptive methods has focused on the blackbox setting . These works make minimal assumptions about the structure of the loss function, beyond (possibly) some global properties such as convexity or smoothness. These global properties (governed by parameters such as the smoothness parameter) are assumed to hold over the entire domain. Hence this style of analysis is worst case, since the resulting convergence bounds depend on polynomially on these global parameters. However, as we show in Section 3.1, in neural networks these parameters are prohibitively large. This worst case analysis is hence unlikely to explain the success of adaptive methods on neural networks. By contrast, our focus is on analyzing the local trajectory that is induced by running the optimization method.
Existing analyses of (S)GD on neural networks. There is an extensive literature on the analysis of GD/SGD in the non-blackbox setting, e.g. overparameterized neural networks, . However, it is unclear how to translate these analyses of GD/SGD, to an analysis that explains the gap between GD/SGD and adaptive methods.
Influence of algorithms on the loss geometry. In many simple convex settings, e.g. linear or logistic regression and the Neural Tangent Kernel , the loss geometry is usually fixed and not influenced by learning algorithms. However, in neural networks the interaction between algorithms and loss landscapes is more complicated. Lewkowycz et al. find a so-called catapult effect of initial learning rate on the training trajectory of SGD and related loss curvature. Cohen et al. demonstrate that while training neural networks with GD, the maximum eigenvalue of the Hessian evaluated at the GD iterates first increases and then plateaus at a level that is inversely proportional to the step size. However, Cohen et al. leave open the problem of whether similar interactive phenomena occur in algorithms that are not GD, including adaptive methods.
Overview of results and setup
As is mentioned in Section 2, existing work on adaptive algorithms has mainly focused on black-box analysis assuming some global worst-case parameters. However, these global bounds can be extremely bad in complicated deep learning models, as is discussed in Section 1. To see this, we initialized a transformer modelhttps://pytorch.org/tutorials/beginner/transformer_tutorial.html with default initialization in Pytorch but chose a large gainThis refers to the gain parameter in some commonly used initialization functions of Pytorch, e.g. torch.nn.init.xavier_uniform_()., and computed the smoothness parameter (denoted as ) and the condition number (denoted as ) of loss Hessian on one layer. We observed that setting the gain as a large constant (e.g. 800) results in extremely large and ( and ), which makes the convergence rates in prior black-box analysis vacuous.
The failure of global worst-case analysis implies that we need to focus on the local trajectory of algorithms. However, it is unclear that when two optimization algorithms are used, they will have the same geometry in local trajectory. In particular, although in theory, adaptive algorithms can yield to a convergence rate with better dependency on certain local geometry of the function comparing to SGD (with momentum), it could still be the case that the local geometry along the trajectory of adaptive algorithm can be much worse than that of SGD (with momentum).
That motivates us to study the local geometry, especially that obtained by adaptive methods comparing to SGD (with momentum) in the paper. Motivated by the diagonal scaling of Adagrad and Adam for neural network training, we ask the follow main question in our paper:
How does the local diagonal geometry (diagonal of the loss Hessian) along the local trajectory of adaptive algorithms compare to that of SGD (with momentum)?
2 Overview of the experiments
As is discussed in Section 1, we consider defined in eq. (1) as a measurement of the uniformity of the diagonal of the loss Hessian. We conduct experiments on different NLP tasks to examine , as in language models, adaptive methods have shown significantly faster convergence than SGD (with momentum). The details of these experiments will be shown in Section 4. To explore potential different patterns of different layers, we do the computation layer by layer. On a wide variety of transformer architectures and language modeling datasets from the same initialization, we observe that:
When we train the neural network using Adam, the uniformity of diagonal geometry, measured by is smaller than that when we train using SGD+M from the same initialization, except for first several layers.
Table 1 shows a typical example of compared to on a sentence classification task using BERT-small (see Section 4.1 for details). We repeated the experiments for 12 times starting from the same initialization. Table 1 shows the averaged and in some randomly selected layers (except for the first several). We also report the averaged and their standard deviations in the brackets. values in Table 1 for most layers are roughly 1.4 to 2 times in corresponding layers. In practice, it can be considered significant because it might imply 1.4 to 2 times faster convergence. Figure 2 shows the corresponding training losses of one in these 12 experiments.
To understand this phenomenon in a more principled point of view, we also provide a formal proof of the statement in a simplified setting: large batch Adam and SGD+M on a two-layer linear network. Although simple, the choice of two-layer linear network to understand learning dynamics is common in prior works (e.g. ). Section 3.3 below describes the theoretical setup.
3 Setup of the theoretical analysis
Let . We use to denote the norm of a vector, and to denote the Frobenius norm of a matrix. Let be the Euclidean inner product between vectors or matrices. Let be the one-dimensional Gaussian distribution with mean and variance . For a scalar (vector, matrix) which evolves over time, we use to denote its value at time .
where does not depend on . We consider the following model with small Gaussian initialization.
are independently initialized with sufficiently large .
where is the learning rate, are momentum parameters, and is for numerical stability. All operations on vectors are element-wise.
The uniformity of diagonal geometry
As is mentioned in Section 3.2, we computed defined in eq. (1) on different language models. In this section, we present the results of SGD+M and Adam on different architectures and datasets. In Appendix A, we present the results of other adaptive algorithms.
During training we started from the same initial weights and used the same learning rate schedule (constant or decreasing) for SGD+M and Adam. We tuned and chose the best (initial) learning rate of SGD+M. The (initial) learning rate of Adam was set as a value under which Adam converged faster than SGD+M with its best learning rate. The concrete values will be stated in later parts of this section. We used large batch sizes to make the training procedure stable. When computing Hessian, we also used large batch sizes. Due to the extremely large dimension, we did the computation on some uniformly selected coordinates, more precisely, 200 coordinates per layer.
We fine-tuned BERT-small on the IMDB dataset : the task is to classify whether movie reviews are positive or negative.https://huggingface.co/docs/transformers/v4.16.2/en/training The momentum parameter in SGD was set as 0.9. The two momentum parameters of Adam were set as (0.9, 0.999). We trained the model using linearly decreasing learning rates for 10 epochs (2500 iterations). The initial learning rates of SGD+M and Adam were 0.001 and 5e-5, respectively. As mentioned in Section 3.2, Figure 2 and Table 1 show the training losses and the comparison between and .
We trained a Seq2Seq network that uses Transformer to solve a machine translation task on Multi30k (CC BY-NC-SA 4.0): this task is to train a German to English translation model.https://pytorch.org/tutorials/beginner/translation_transformer.html The momentum parameter in SGD was set as 0.9. The two momentum parameters of Adam were set as (0.9, 0.98). We trained the model using constant learning rates (0.03 for SGD+M and 1e-4 for Adam) for 60 epochs (1800 iterations). The experiments were repeated for 8 times starting from the same initialization. Figure 3(a) shows the training losses for one among them. Table 2(a) shows the averaged , and (with standard deviation in the brackets) in some randomly selected layers.
2 Experiments on random datasets
We used the same model and momentum parameters as in the translation task described in Section 4.1 but generated random integers as targets. Similar to the setting on real targets, the model was trained using constant learning rates (0.015 for SGD+M and 5e-5 for Adam) for 60 epochs (1800 iterations), and we repeated the experiments for 8 times starting from the same initialization. Figure 3(b) shows the training losses for one among them. Table 2(b) shows the averaged , and (with standard deviation in the brackets) of the same 10 layers as in Table 2(a).To prevent from getting too large due to tiny median, we added an additional term to the denominator of eq. (1) when computing.
3 How the (adaptive) gradient aligns with diagonal of loss Hessian
In this section we present the uniformity of diagonal geometry of adaptive methods from another perspective. Denote as the -th element of the loss Hessian and as the -th element of the gradient. It is conjectured that when is large, the corresponding is usually large as well. For adaptive methods, we can regard the update per step as the learning rate times the “adaptive gradient”. Let’s use to represent the -th component of the adaptive gradient. Through experiments on language models, we find that for different are quite uniform and do not align with as the true gradient does.
4 Summarization of the empirical results and discussion
Overall, through extensive experiments on language models, we demonstrate that starting from the same initialization, the values found by Adam are smaller than those found by SGD+M, except for the first several layers. This suggests that Adam is biased towards a region with more uniform diagonal Hessian than SGD+M.
We observe that on random dataset, SGD+M plateaus after about 400 steps and thus converges much slower when compared to Adam than on real dataset (see Figure 3(a) and Figure 3(b)). On the other hand, the gaps of and are more significant on random data than on real data (see Table 2(a) and Table 2(b)) as well. In Appendix A.4, we conduct another experiment where we switch from SGD to Adam in the middle and compare it with the model trained by Adam from the beginning. The observation is that both the loss gap and the gap of are gradually closed after switching (see Figure 8 and Table 8). Hence we find a positive correlation between fast convergence and the uniformity of diagonal of loss Hessian, suggesting that a region with more uniform diagonal of Hessian is also a region that is more amenable to fast optimization. In Appendix A we study other adaptive algorithms (Adagrad, RMSprop and AMSGrad) and get similar observation: all these adaptive methods converge faster than SGD or SGD+M and also bias the trajectory to a region with smaller , suggesting that the uniformity of diagonal Hessian might be a universal mechanism (partially) explaining the faster optimization of adaptive algorithms than SGD (with momentum).
Considering the fact that our comparison between and is conditioned on the same iteration when SGD+M has larger training loss than Adam, there is a potential alternative explanation of the Hessian diagonal uniformity. That is, the global minimum has uniform Hessian, and Adam simply converges faster to it than SGD+M, thus giving the appearance that it induces better geometry. To rule out this possibility, in Appendix A.3 we add a comparison of our measurements and , where are picked such that th Adam iterate and th SGD+M iterate have the same training loss. The results (in Table 7) show that for most layers, thus demonstrating that the trajectories of Adam and SGD+M are truly different and that the difference is because Adam biases the local geometry (as opposed to faster convergence).
People in practice usually add weight decay (equivalent to regularization) to encourage better generalization ability. In Appendix A.7 we compare SGD+M and Adam when both using small weight decay values (0.001). The results in Figure 13(a) and Table 9 suggest that in this case, the relationship between and convergence speed still holds: Adam converges faster than SGD+M and in most of the layers except for the first several, values are smaller than . This reveals the robustness of our observation under weak regularization. However, under large weight decay parameters, we observed cases where Adam still converged faster but values were larger rather than smaller. In the case of strong regularization, the adaptivity of Adam requires further exploration and we hope to find new mechanisms in the future.
Although in this paper we focus on language models where Adam shows significant fast convergence, we also add supplementary results in Appendix A.8 on image tasks where SGD+M performs better. On a residual network trained on CIFAR-10, we observed that Adam did not converge faster than SGD+M (see Figure 13(b)) and in the meantime, values were no longer smaller than during training (see Table 10). This reveals the connection between the local diagonal geometry and the convergence speed from another perspective. That is, when the diagonal of Hessian of Adam is not more uniform than SGD+M, its convergence speed is not better, either. In summary, all the observations on language and image tasks together suggest a positive correlation between the uniformity of diagonal Hessian and fast optimization.
Theoretical analysis
In Section 4, we empirically demonstrate the uniformity of diagonal geometry. In this section, we theoretically analyze this property for large batch Adam and SGD+M on a two-layer linear network with 1-dimensional output.
Since the weights and Hessians in different layers may have different magnitudes, we compute the layer by layer. We denote (resp. ) as the found by SGD+M (resp. Adam) w.r.t. at time where .
Under Assumption 1, 2 and 3, consider the weights (resp. ) obtained by SGD+M (resp. Adam) defined in (3).
An immediate corollary of this theorem below gives the difference between iterates of Adam and SGD+M that have the same loss.
The low rank structure of weight matrices and uniformity of leading singular vectors
The proof sketch in Appendix B highlights one crucial intuition of Theorem 1: After (resp. ) steps, of SGD+M (resp. Adam) becomes an approximately rank-1 matrix. Consider the left singular vector which corresponds to the leading singular value . We can show that the distribution of for Adam is more uniform than that of SGD+M. This property, we call the uniformity of the leading singular vector, is related to the uniformity of the diagonal of loss Hessian, see Appendix F for more details.
After reviewing the weight matrices we got in different settings, we observed that (A) and (B) hold for many layers in those models. For example, on the translation task mentioned in Section 4.1, we found 12 layers which have approximately low rank structures and for 10 of them, values (defined in (B)) obtained by Adam are smaller than those found by SGD+M. Figure 5 shows the result on one typical layer. Results of more layers can be found in Appendix A.5.
Although in multi-layer nonlinear neural networks, the connection between diagonal of loss Hessian and the weight matrices is more complicated and may depend on the product of many weight matrices rather than one single matrix, we still believe that this definition of is a reasonable ratio to consider.
Conclusion and future work
We demonstrate that adaptive optimization methods bias the training trajectory towards a region where the diagonal of loss Hessian is more uniform, through extensive experiments on language models and theoretical analysis in a simplified setting of two-layer linear networks. Although our findings may not directly lead to an improved algorithm for practical use, they provide a new way of thinking when designing new algorithms: in contrast with the traditional view which tries to design a method that performs better in the bad loss geometry, our findings suggest that we can design algorithms which implicitly avoid regions with bad geometry. There are a lot of future directions along this line. For example, our theoretical results on the two-layer linear networks may be able to generalize to multi-layer networks. In fact, people conjecture that the key-value-query structure in language models can be approximated by a three-layer linear network. Hence the generalization to multi-layer networks might provide more connection to real deep models and could be an interesting and challenging future direction. Moreover, it is also possible to relax our large-batch assumption (Assumption 3) and prove similar results in the general stochastic setting.
References
Appendix A More experiments of the uniformity of diagonal geometry
In this section, we present the values defined in eq. (1) obtained by SGD and Adagrad on a language modeling taskhttps://pytorch.org/tutorials/beginner/transformer_tutorial.html. The task is to assign a probability for the likelihood of a given word (or a sequence of words) to follow a sequence of words. We trained a transformer model to solve this problem on both Wikitext-2 (CC BY-SA 3.0) and random dataset (generating random integers as targets). This model has roughly 8 layers (not counting normalization and dropout layers)
The setup is the same as in Section 3.2. We used the same learning rate schedule (constant or decreasing) for SGD and Adagrad. We tuned and chose the best (initial) learning rate of SGD. The (initial) learning rate of Adagrad was set as a value under which Adagrad converged faster than SGD with its best (initial) learning rate. We used large batch sizes to make the training procedure more stable. When computing Hessian, we also used large batch sizes. Due to the extremely large dimension, we did the computation on some uniformly selected coordinates, more precisely, 200 coordinates per layer.
We tried different initialization (normal and uniform) by using different gains of the Pytorch initialization schedule.
Figure 6(a) shows the training losses on real dataset (wikitext-2). Table 3 (resp. Table 4) shows the for Adagrad and SGD under uniform (resp. normal) initialization with different gains.
A.1.2 Experiments on random dataset
Figure 6(b) shows the training losses on random dataset and Table 5 shows the in different layers.
A.2 RMSprop and AMSGrad
In this section, we present the results of RMSprop and AMSGrad and compare them with SGD+M. The experiments are conducted on the translation task described in Section 4.1. The learning rates we used were 0.000025 for RMSprop, 0.0005 for AMSGrad and 0.03 for SGD+M. Both RMSprop and SGD+M used momentum parameter 0.9. The two momentum parameters of AMSGrad are . Figure 7 shows the training losses and Table 6 shows the corresponding .
A.3 Comparison conditioned on the same loss
In this section, we compare and conditioned on the same training loss. More precisely, we make comparison of and , where are picked such that th Adam iterate and th SGD+M iterate have the same training loss. The details of the tasks are described in in Section 4.1. Table 7 shows the results of and in some layers.
A.4 Experiments of switching from SGD to Adam
In this section we describe another learning schedule: the “Adam after SGD” schedule, where we switched from SGD to Adam in the middle to see whether the loss and can catch up with the model trained by Adam from the very beginning. Again, we used the same model as in the translation task in Section 4.1. In this section, we did not add momentum term to SGD in order to get a larger gap between SGD and Adam than the case using momentum. We want to see whether this larger gap can be closed after switching to Adam in the middle.
As is shown in Figure 8 and Table 8, both the loss gap and the gap of were closed after a period of training after switching algorithms, which provides evidence of the connection between convergence speed and uniformity of diagonal of loss Hessian.
A.5 The low rank structure
In this section, we present more results for the experiments in Section 6.
We examined the weights of the model trained for the translation task in Section 4.1. Among roughly 30 layers, we observed that for 12 layers, at least the weight matrices obtained by Adam after training have approximately low rank structures.
Figure 9 shows the examples of layers with or without the low rank structure.
We then studied the uniformity of leading singular vectors of these 12 layers, i.e. computed and defined in (B) and the second remark of Section 6. The observation is that for 10 out of these 12 layers, values of Adam are smaller those of SGD, which implies the uniformity of leading left singular vectors of Adam. However, we did not observe significant uniformity for Adam in terms of leading right singular vectors (). The second remark of Section 6 discusses possible reasons.
Figure 10 shows how and changed over time in some layers.
A.6 How the (adaptive) gradient aligns with diagonal of loss Hessian
In this section, we present more empirical results on how the (adaptive) gradient aligns with diagonal of loss Hessian. The detailed setup is described in Section 4.3.
Here we compare SGD and Adagrad on the language modeling task on wikitext-2 described in Section A.1. We observed that the figures of all layers are quite similar so we select one layer as an example, as is shown in Figure 11.
A.6.2 SGD with momentum vs. Adam
Figure 4 presents the comparison between Adam and SGD with momentum on the sentence classification task using BERT-small. Here we add more results of the comparison of these two algorithms on the translation task described in Section 4.1. Again, we select one layer as an example, as is shown in Figure 12.
A.7 Adding regularization and other tricks
In this section, we add weight decay to both Adam and SGD+M on the translation task described in Section 4. The momentum parameter in SGD was set as 0.9. The two momentum parameters of Adam were set as (0.9, 0.98). For both algorithms, we set the weight decay parameter as 0.001. We trained the model using constant learning rates for 60 epochs (1800 iterations). We tuned and chose the best learning rate 0.03 for SGD+M. The learning rate of Adam was set as 0.0001, under which Adam converged faster than SGD+M with its best learning rate 0.03. Figure 13(a) shows the training losses and Table 9 shows the values of , and in some randomly selected layers.
A.8 Results on image tasks
We trained a ResNetWe borrowed the implementation here https://pytorch-tutorial.readthedocs.io/en/latest/tutorial/chapter03_intermediate/3_2_2_cnn_resnet_cifar10/ and replace the “layers” array with . on CIFAR-10 dataset and compared the convergence speed and of SGD+M and Adam. The momentum parameter in SGD was set as 0.9. The two momentum parameters of Adam were set as (0.9, 0.98). The model was trained using constant learning rates for 41 epochs (2050 iterations). We tuned and chose the best learning rates for both algorithms: 0.5 for SGD+M and 0.005 for Adam. Figure 13(b) shows the training losses and Table 10 shows the values of , and .
Appendix B Proof sketch of Theorem 1
Now we give a proof sketch of Theorem 1, which contains three major steps. The detailed proof can be found in Appendix F, C and D.
First we relate the diagonal of Hessian to weight matrices . Under Assumption 1, denote as the -th row of and . Since the input dataset is whitened, we can show that
Next, due to the one-dimensional output, we can prove that converges to an approximately rank-1 matrix. More precisely, we have
Using the rank 1 structure, we can further simplify and by
The final step is the detailed analysis of .
Appendix C Analysis of SGD+M
Note that , . Denote . We have that
Based on the magnitude of and , we can intuitively divide the training procedure into 2 phases.
First phase: the first several iterations when and are “small” so that .
Second phase: later iterations when cannot be ignored.
More formally, the boundary between the first and second phase is defined below.
The end of the first phase (denoted as ) is defined as .
By Assumption 2 and the assumption that , at the beginning, w.h.p., . During the training, each increases and approaches . We hope that by choosing a small learning rate, when overshoots for some coordinate , i.e. , it will be close to convergence. To analyze this overshooting issue more carefully, let’s first define the following “almost overshooting time”.
For , denote . Define .
For , we define the “convergence time” .
We can first show that after the first phase, i.e. when , will become an approximately rank-1 matrix, as described in the following lemma.
Under Assumption 1, 2 and 3, suppose . By picking , we have that when , , and that
The following lemma tells us that this approximate rank-1 structure is preserved when .
Under Assumption 1, 2 and 3, suppose . By picking , we have that w.h.p. for ,
and is defined in Definition 2. Moreover, when , .
The following lemma gives us a more detailed description of .
Now we are ready to prove the SGD+M part of Theorem 1.
Here are i.i.d Gaussian random variables by Lemma 3. To prove the concentration of , we borrow the Proposition 12 in Chapter 2.3 of . By setting in this proposition, we have
That means with high probability, for some . By Lemma 34 in Appendix G, we know that w.h.p.
Hence we have proved that .
C.2 Proof of Lemma 1
In the first phase, is “small”, and we write the update equations in the following way
The following lemma gives us an explicit formula of .
Let be the two roots of the quadratic equation . Pick , then we have that
where , . will be specified in the proof.
We can prove that in the first phase, is “small”. More specifically, denote its -th coordinate as , and the -th coordinate of as . Then the following lemmas tell us that , where w.h.p. .
We first have the following bounds of and for .
Next we prove upper and lower bounds of and for .
Now we are ready to prove Lemma 1. Lemma 4 tells us that
where and .
Under the conditions of Theorem 1 and pick , by Lemma 6 and 7, we know that w.h.p. ,
We first prove that reaches for some coordinate before for . To see this, first note that
where and
For , by eq. (7), we get that w.h.p.,
Here we used by Assumption 1.
Further we notice that for , we have ,
which yields that . Together with eq. (9) gives us that reaches for some before for , i.e. .
Further, we know that at time , for some , which means w.h.p.
This is the length of the first phase. As for and for other coordinates, we have that w.h.p. ,
Finally, we consider the loss. Since , we know that .
C.3 Proof of Lemma 3
C.4 Proof of Lemma 4
Replacing by in eq. (6), we get
Eq. (6)-(11) and substituting eq. (5) yield
where .
For the equation , the roots are and . We have that
where , and .
C.5 Proof of Lemma 5
Write where , and . And write , where , and .
Let’s first try to bound and . For any , we have that
and thus . Then we have for all ,
Then we bound and . We have for ,
Finally we use Lemma 31 to bound and . For , the in Lemma 31 are upper bounded by . In the theorem we consider the training period before so the time in Lemma 31 is set as . In the following sections, we will prove that . Then by Lemma 31, we have with probability at least , for and ,
Combining all the above bounds and substituting gives us for and ,
For , we have , and , which gives us and . Substituting into eq. (5) and eq. (6) yields that for and ,
Hence for , we have ,
Then we know that and also get tighter bounds of for . Now we use these new bounds to analyze and again.
C.6 Proof of Lemma 6
Since , and note that , we have that
C.7 Proof of Lemma 7
For the equation , the roots are and , which gives us
Then we have that w.p. at least , ,
Next, we bound the -th coordinate of , i.e. .
By independence under Assumption 2, we have that
Using the Gaussian tail bound and union bound, w.p. at least , for ever , we have that
Since for , we have that , then for a fixed ,
Then by union bound, we have that w.p. at least , for every ,
where follows from eq. (14) and the fact that . Then we get that w.h.p.
Substituting eq. (15) into eq. (13), we get that w.h.p.,
C.8 Proof of Lemma 2
The proof in Section C.2 tells us that at the end of the first phase (when ),
Denote the -th coordinate of as , respectively. Denote the -th element of as . For , we prove by induction that,
with , , and . Note that the and here are different from those defined in Section C.2, but we abuse the notation and still use and to represent the error terms.
The base case is already given by eq. (16).
Suppose our lemma holds for , then for , using the same techniques as in eq. (5) and eq. (6), we have that
Plugging in the inductive hypothesis yields
It implies that our lemma holds for , which completes the proof.
Now we analyze the error terms and . Eq. (16) tells us that and are all positive. We first prove by induction that for all , .
The above discussion already proves the base case. Suppose at time , we have . Note that when , , then for ,
Therefore by induction, we have proved that for all , .
Now we prove that for all ,
The left hand sides of the inequalities are trivial since we have proved that for all . Now we prove the right hand sides by induction.
The base case is already verified by the definition of . Suppose eq.(18) holds for . Then for , using and , we can get that
Similarly, we have that
Therefore by induction, eq. (18) holds for all in the second phase.
So far we have proved the rank 1 structure stated in Lemma 2. The remaining part of the proof is given by the following lemma, whose proof is deferred to Section C.9.
Under Assumption 1, 2 and 3, suppose . By picking , we have that w.h.p. for ,
and that when , we have .
C.9 Proof of Lemma 8
We first have the following lemma which describes the structure of for .
Under Assumption 1, 2 and 3, for , we can write as , with , and
We prove Lemma 8 by induction. Denote the -th coordinate of and as and , respectively. The following lemmas constitute the inductive part.
Under the conditions of Lemma 10 and pick , we have that at time ,
where is defined in Definition 2.
Under the conditions of Lemma 10 and pick , we have that at time ,
,
,
,
By combining Lemma 10, 11 and 13, we can prove by induction that for all , eq. (19) holds (which follows from Lemma 11), and
So far we have proved eq. (19) in Lemma 8. Now let’s prove when , we have that .
If , by Definition 3, we have . If , by Definition 2, there exists such that . Combining with eq. (22) gives us . Combining these two cases, we get that when , .
C.10 Proof of Lemma 9
We prove this lemma by induction. The base case () of is verified by eq. (16).
Suppose at time , , then by eq. 17, we have that
where . That gives us
Therefore we have proved by induction that for in the second phase, . The above steps also proved eq. (20).
C.11 Proof of Lemma 10
Write where we have , . Write where , .
Let’s first bound and . By definition of , we know that for , . Then we have for all ,
We can further get that for ,
Combining the above inequalities gives us ,
Next let’s bound and . By the assumption of this lemma and the analysis before , we know that for all , the in Lemma 31 are upper bounded by and , respectively. In the theorem we consider the training period before so the time in Lemma 31 is set as . In the following sections, we will prove that . Then by Lemma 31, we have with probability at least , for and ,
Combining the above bounds, we get that ,
C.12 Proof of Lemma 11
Let’s first try to bound the length of . More formally, we prove that under the conditions of Lemma 10 and pick , we have that .
Under the conditions of Lemma 10, we know that
When , we have proved that is increasing over time in Section C.8, which implies that since is the leading term of . Combining with gives us
where uses . By picking and noticing that , we have . Hence when , we have that , i.e. .
That means after at most steps from , either , or we have . In other words, .
Combining and Lemma 10 yields that for ,
C.13 Proof of Lemma 12
The proof in Section C.8 tells us that for , , which gives us and . By Lemma 11, we have that
Since , we have , which yields
C.14 Proof of Lemma 13
Substituting into the time version of eq.(24) yields
Since , we have . Combining with , gives us . Then we can rewrite as ,
(B) Note that we assume , then we have for ,
Then for , we have that for ,
(C) Combining eq. (25) and , we know that
Under the conditions of Lemma 10, and pick , we have that .
Appendix D Analysis of Adam
Note that , . Denote . We have that
Denote the -th coordinate of and as and , respectively. By Assumption 2 and the assumption that , at the beginning, w.h.p., . Based on this, we divide the training procedure into two phases (note that these two phases are different from those of GD).
First phase: when the error is negative and its absolute value is big for all .
Second phase: when is close to zero for some coordinate .
More formally, we define the boundary between the two phases below.
The end of the first phase (denoted as ) is defined as .
In the second phase, we define some time points.
Define .
For , we have by Definition 4. For , some may flip the sign and become positive. For certain coordinate , we define the following “flip time”.
We can first show that after a few steps in the first phase, will become an approximately rank-1 matrix, as described in the following lemma.
Under Assumption 1, 2 and 3, suppose . By picking , and , there exists such that w.h.p. for ,
Now we are ready to prove the Adam part of Theorem 1.
D.2 Proof of Lemma 14
For some time , we introduce two conditions.
Next prove that, under Assumption 1 and 2, by picking , and , there exists such that for , the weights can be approximated in the following way.
Before we dive into the proof, let’s introduce some useful lemmas.
The following lemma reflects our key idea: converting the exponential average in Adam to a finite-step average, and trying to bound the stochastic error terms in eq. (28).
where and
The following lemma analyzes the magnitude of weights during a short period at the beginning.
Under Assumption 1, 2 and 3, suppose . Pick , then there exists some time point , such that w.h.p., for , for every ,
Specifically, when , we have , and . Moreover, Condition 1 and 2 are satisfied for . The and in the conditions are both .
The following lemma gives us lower bounds of and .
The following lemma shows that when , we have and that .
Under Assumption 1, 2 and 3, suppose . Pick , . For in Lemma 17, we have that w.h.p. for and , ,
Equipped with these lemmas, now let’s prove eq. (29).
Let’s first look at the update of . For in the first phase, we write the RHS of eq. (32) as
By Lemma 18, we know that . Then we have that
Therefore by Lemma 33 in Appendix G, we have
Since , we know that . Then our choice of gives us and , which implies that . Hence for , .
So far we have successfully proved eq. (29). By in Lemma 18, we know that , which gives us
Finally to complete the proof, we show that . When , we have . Combining with the above results, we know that , i.e. . In Section D.5, we will prove . Then we have .
D.3 Proof of Lemma 16
For certain and , we write eq. (27) as
and are defined in eq. (28).
Since , then if we pick , we can get that , . Hence we can apply Lemma 32 in Appendix G to get that .
D.4 Proof of Corollary 2
D.5 Proof of Lemma 17
The proof is based on the following two lemmas.
Under Assumption 1 and 2, we have that w.p. at least , for every , , and that w.p. at least for any given , .
Furthermore, if for certain , Condition 1 (resp. Condition 2) is satisfied, we will have
Hence we have shown that at some time point , we have . Now we analyze the period .
Moreover, . Then Condition 2 is satisfied with for . In the analysis of , we have already shown that for all (and thus for ), Condition 1 is satisfied, which completes the proof.
D.6 Proof of Lemma 20
Since for , we have that , then for a fixed ,
Then by union bound, we have that w.p. at least , for every , .
As for the upper bounds, using the Gaussian tail bound and union bound, we have w.p. at least ,
D.7 Proof of Lemma 21
Now we analyze the magnitude order of . The analysis of is similar.
where uses Cauchy-Schwarz inequality for the numerator.
On the other hand, when , we have
Using , we obtain that
Together with the upper bound completes the proof.
D.8 Proof of Lemma 18
The proof is based on the following lemma, which gives a coarse analysis on the magnitude of weights and their increments per step during the first phase.
Under Assumption 1, 2 and 3, suppose . Pick , for in Lemma 17, we have that w.h.p. for all , .
Now we go back to the proof of Lemma 18. For , since , we have,
Combining Lemma 22 and eq. (34) gives us ,
Let’s first analyze . Note that
where while .
As for , since for , for different have the same sign. Combining with gives us
D.9 Proof of Lemma 22
For any , and any in the interval , we prove by induction that
.
.
The base case was already proven by Lemma 17.
In Section D.2 we have shown that . Then for , we can use Lemma 21 to get that , ,
Since when , . We get that for ,
That means . This proves (B) for time .
On the other hand, we get that and . Since which means . Then
Since which means , we obtain that
D.10 Proof of Lemma 19
Then eq. (31) immediately follows from eq. (30).
D.11 Proof of Lemma 15
We divide Lemma 15 into the following three lemmas. Combining them together immediately gives us the whole proof.
The first lemma below gives us the structure of in the second phase and that of under some conditions.
The second lemma below also analyzes the structure of but removes the conditions in Lemma 23.
D.12 Proof of Lemma 23
The proof is based on the following lemma, which gives a coarse analysis on the magnitude of weights and their increments per step during the second phase.
Equipped with Lemma 26, we are ready to prove Lemma 23. We will only prove the results of . The proof for uses the same techniques.
By Lemma 14, we have that at the end of the first phase (),
D.13 Proof of Lemma 26
Now we analyze the magnitude order of . Let’s first analyze .
D.14 Proof of Lemma 24
Since , in eq. (38) we have that
However in eq. (37), we cannot similarly prove that because may not have the same sign for . To deal with eq.(37), we need to consider the two cases where or .
.
.
where uses Cauchy-Schwarz inequality and , uses eq. (38) and (39).
By the first phase analysis, we have that
where .
Combining the above results together yields
Therefore, we have that for any ,
D.15 Proof of Lemma 25
D.16 Proof of Lemma 27
where is because . may not be smaller than , but we will show that after at most steps for some , we will have .
Appendix E Hessian tends to become more and more diagonal during training
In this section, we empirically demonstrate that the trend of loss Hessian in practice is to become more and more diagonal during training. We also give a rigorous theoretical analysis on a two-layer network under Assumption 1 and 2.
Let’s first define the diagonal domination of the -th coordinate at time .
To measure the diagonal domination of the whole Hessian, we need to consider the distribution of for different . Figure 14 shows the mean and median of and on the sentence classification task (See Section 4.1). Here we chose 4 layers (Layer #6, 12, 17 and 22) and computed the Hessians across these 4 layers. Since the number of parameters is very large, we did the computation by random sampling. As we can see, for both and , the trend of their mean or median is to decrease over time, although there might be some oscillation.
E.2 Theoretical Analysis
To simplify the theoretical analysis, we consider the mean of over all coordinate and define
We consider a 2-layer network under Assumption 1 and 2, and have two goals in our proof:
To show that after training is smaller than that before training ().
Note that in our setting (see in Assumption 1), the Hessian is a matrix. For a completely “uniform” matrix with the same size, we have that . Hence our second goal is to show that the after training is on lower order than .
Consider the ratio defined in eq. (40). Under Assumption 1 and 2, we have that before training (), with high probability,
For SGD+M defined in eq. (3). For any , by picking the same hyperparameters as in Theorem 1, for mentioned in Theorem 1, we have with constant probability, for any ,
For Adam defined in eq. (3). For any , by picking the same hyperparameters as in Theorem 1, for mentioned in Theorem 1, we have with high probability, for any ,
E.3 Proof of Theorem 2
Lemma 4.3 of gives us the following forms of Hessian.
For any , we know that
where .
For the 2-layer linear network, write the Hessian as
Intuitively, before training the elements of and are very close to zero, and . Since the elements of are , we know that the magnitudes of elements of are much bigger than those of and .
After training, for both SGD+M and Adam, . Then and the magnitudes of its elements are no longer much larger than those of and . From the formula of , we know that all the diagonal entries are nonzero, and among the off-diagonal entries, there are only nonzero entries, which helps us to bound .
For the -th row where , i.e. the -th row of the submatrix , we have
On the other hand, for the diagonal elements, we have w.h.p.
For the -th row where , i.e. the -th row of the submatrix , we have
On the other hand, for the diagonal elements, we have w.h.p.
Then we have that for ,
Taking the average, we obtain that before training, i.e. when ,
E.3.2 Proof of eq. (42)
Suppose the weight matrices have the following structure:
where .
By the analyses in Section C.1, we know that for , the weights obtained by GD with momentum satisfy
Here is defined in Definition 2. Since doesn’t depend on time in the period , we write as for ease of notation.
Hence by Lemma 28, when , we have for ,
By Lemma 3, we have where are i.i.d Gaussian random variables and w.h.p.,
By the proof in Section C.8, we know that for , are positive. The induction in Section C.9 further gives us that for , w.h.p. , which yields . Combining with eq. (47), we obtain
By the proof in Section C.8, we know that for , are positive and monotonically increasing. On the other hand, the proof in Section C.2 and C.9 tells us that w.h.p. (resp. ) decreases from (resp. ) when to (resp. ) when . Therefore, the trend of and is to decrease over time, and when , we have w.h.p.
Moreover, when , the inequality in eq. (26) becomes equality, i.e. and .
Using and eq. (46), we have
which together with the second inequality in eq. (47) yields
Substituting eq. (48) and (50) into eq. (44) and (45) gives us
where the trend of is to decrease over time and .
where the trend of is to decrease over time and .
where the trend of is to decrease over time and
Denote as the variance of for . By concentration of chi-squared distribution, we know that with probability at least for ,
By Lemma 35 in Appendix G, we know that with constant probability . Then with constant probability, . Hence
E.3.3 Proof of eq. (43)
By the analyses in Section D.1, we know that for , the weights obtained by Adam satisfy
where and
Hence by Lemma 28, when , we have for ,
Combining (A) and (B), we get that the trend of and is to decrease over time, and when , we have w.h.p.
Substituting (A) and eq. (53) into eq. (51) and (52) gives us w.h.p.,
E.4 Proof of Lemma 28
By the assumed weight structure, we get that
For the -th row where , i.e. the -th row of the submatrix , by triangle inequality, we have
For the -th row where , i.e. the -th row of the submatrix , by triangle inequality again, we have
Then we have that for ,
Appendix F Connection between diagonal of loss Hessian and weights
The partial derivative at of the cost function for each is given by:
In our experiments, we were interested in the diagonal elements of the hessian. These are given by:
for each possible . For ease in notation, define for each , the quantities and . Then we have the following lemma.
The diagonal elements of the hessian of the cost function are given by:
where the last step follows since and are not functions of .
Note that and . Now define and so that:
where and are not functions of . Now, Equation in the Matrix Cookbookhttps://www.math.uwaterloo.ca/~hwolkowi/matrixcookbook.pdf shows us that for any matrices and we have:
Similarly, consider the Hessian w.r.t. , we have that is an identity matrix and . Therefore,
Hence we have related the uniformity of diagonal Hessian to that of weight matrices. In the detailed analysis, for both GD and Adam, we can prove that converges to an approximately rank 1 matrix. The following lemma allows us to use this rank 1 structure to compute and .
Let’s first consider . we have
Similarly, for . We have that
Appendix G Auxiliary lemmas
By Assumption 3 and Chebyshev’s inequality, we have for fixed and ,
which gives us with probability at least , for ,
Note that for all and ,
Then we have with probability at least , for all and ,
Consider two sequences , which satisfy
Suppose , then for any , the following truncated version
To make it less than , it suffices to choose .
Since , we know that . We also have . Then it suffices to choose
Define . The term can be bounded by
Here the denominator of uses and when .
Now let’s bound . If , we have and since .
If , note that , we have , which yields . Combining the above bounds give us .
On the other hand, can be bounded by
Then ∎
Suppose are i.i.d Gaussian with mean 0 and variance , then for , we have with probability at least ,
It suffices to assume that and prove that w.p. at least , .
where the last inequality uses for . Let , we get that w.p. at least ,
Suppose are i.i.d Gaussian with mean 0 and variance , then we have with constant probability,
It suffices to assume that and prove that with constant probability, .
which means with constant probability, . ∎