Gradient descent revisited via an adaptive online learning rate

01/27/2018 ∙ by Mathieu Ravaut, et al. ∙ UNIVERSITY OF TORONTO 0

Any gradient descent optimization requires to choose a learning rate. With deeper and deeper models, tuning that learning rate can easily become tedious and does not necessarily lead to an ideal convergence. We propose a variation of the gradient descent algorithm in the which the learning rate is not fixed. Instead, we learn the learning rate itself, either by another gradient descent (first-order method), or by Newton's method (second-order). This way, gradient descent for any machine learning algorithm can be optimized.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

In the past decades, gradient descent has been widely adopted to optimize the loss function in machine learning algorithms. Lately, the machine learning community has also used the stochastic gradient descent alternative, which processes input data in batches. Gradient descent can be used in any dimension, and presents the advantage of being easy to understand and inexpensive to compute. Under certain assumptions on the loss function (such as convexity), gradient descent is guaranteed to converge to the minimum of the function,

with a carefully chosen learning rate

. Moreover, stochastic gradient descent has proven to be very efficient even in situations where the loss function is not convex, as is mostly the case with modern deep neural networks. Other methods such as Newton’s method guarantee a much faster convergence, but are typically very expensive. Newton’s method for instance requires to compute the inverse of the Hessian matrix of the loss function with regards to all parameters, which is impossible with today’s hardware and today’s deep networks using millions of parameters.


The quality of a gradient descent heavily depends on the choice of the learning rate . A too high learning rate will see the loss function jumping around the direction of steepest descent, and eventually diverge. While a very low learning rate prevents non-divergence, convergence will be very slow, and the loss function might get stuck in a local minimum. Choosing an ideal learning rate requires an intuition of the problem. Typically, researchers would start by performing a random search or a line-search over a set of different orders of magnitude of learning rates, but this is long and costly. Besides, these methods assume a fixed learning rate over time, as doing one search per iteration would require exponential computation cost. Usually, setting the learning rate to an initial value and gradually decreasing while training is popularly used.

In this paper, we propose to automatically find the learning rate at each epoch. We still need to input an initial value, but at each iteration, our model will find a learning rate that optimizes best the loss function at this point of learning. We explore a first-order method and a second-order one to do so, with a strong emphasis on the latter. Our method could be applied to any machine learning algorithm using gradient descent. We show faster initial convergence on a variety of tasks and models, including:

2 Related work

Techniques for improving optimization of machine learning problems have a long history. The most commonly used technique is Stochastic Gradient Descent (SGD), combined with tricks like momentum (11). While using SGD with complex neural network architectures, the non-convex nature of the problem makes it even harder to optimize.

Recently used alternatives to SGD include Contrastive Divergence

(4), Conjugate Gradients (5), Stochastic Diagonal Levenberg-Marquardt (9), and Hessian-free optimization (10). All these techniques optimize the parameters of the model with the objective of minimizing a loss function. To the best of our knowledge, none of these techniques have been applied to optimize the learning rate at every iteration as we will discuss.

In practice, techniques of the form that decay the learning rate over time are popular. The Adagrad method (1) for instance divides the learning rate at each step by the norm of all previous gradients. Adadelta (14) is an extension of Adagrad that seeks to reduce its aggressive, monotonically decreasing learning rate. Adam (6) is built on top of these methods. It stores an exponentially decaying average of past squared gradients like Adadelta, and also keeps an exponentially decaying average of past gradients, similar to momentum.

LeCun et al. (9) mention that the optimal learning rate is where

is the maximum eigenvalue of the Hessian matrix of the loss function with regards to all parameters. With today’s neural network architectures, computing the Hessian is a computationally very expensive operation. Lecun et al. avoid computing the Hessian via approximating its eigenvalues while Martens et al.

(10)estimate the Hessian via finite differences.

Tom Schaul et al. (12) model the expected loss after a SGD update to deduce the best learning rate update for each dimension. To do so, they assume a diagonal Hessian matrix. In practice, this is evidently not the case, and they rely on observed samples of the gradient to update the learning rate.

Similar to Martens et al. (10) we use finite differences to approximate first order and second order derivatives of the loss function for updating the learning rate at every iteration.

3 Adaptive learning rate

SGD with an adaptive learning rate has the following form:

where , is the empirical loss function, represents the state of the model’s weights at time , and is a continuous function. In the following section we present a first-order and second-order method to update .

3.1 First-order method

The first-order method consists of doing gradient descent on the learning rate.
Let us introduce a function that will be useful in the following:

(1)
(2)

The intuition for the above function is simple: at time using , we suffer a loss of in the next iteration, so represents what the loss would be if we were to perform a gradient descent update with the given learning rate .
The first-order method is written as:

This method introduces a new "meta" learning rate . This method is computationally not expensive as we only require to compute one extra gradient of the loss function L as shown in the equation below.

(3)

We can rewrite the above equation as:

(4)

The intuition behind this gradient is easy: if we continue in a similar direction then we increase the learning rate, if we backtrack then we decrease it. One problem is that the algorithm is not scale invariant anymore, it will behave differently for .

In our experiments, we computed these gradients using finite-difference in places where it was more convenient.

3.2 Second-order method

The previous method presents the problem of choosing another meta-learning rate for optimizing the actual learning rate. To avoid this problem, we can use a second-order Newton-Raphson optimization method.

Now the learning only depends on the loss, and we get rid of the meta-learning rate.
However, the second derivative of requires building the loss Hessian matrix :

(5)

We propose to approximate this Hessian using finite differences similar to (10). By using this approach on then , we get an update formula of the learning rate depending only on several values of the loss function:

(6)
(7)
(8)

Given the finite differences on the first derivative:

(9)

We get the final simple formula for :

(10)

Assuming a constant sign for the numerator, this formula means the following: when slightly increasing the learning rate corresponds to a lower loss than slightly reducing it, then the numerator is negative. In consequence, the learning rate is raised at this update, as pushing in the ascending direction for the learning rate seems to help reducing the loss. However, reality is more complex as the denominator’s sign changes as well.

4 Experiments

4.1 Practical considerations

With the second-order method, the denominator in the learning rate update might underflow. To avoid such a situation, we add to the denominator a small smoothing value to prevent underflow:

(11)
(12)

A typical value of is .

Besides, when updating the loss and the learning rate, one should be very careful about the order of the operations. At the k-th iteration, we have a loss value and a learning rate value . Then the (k+1)-th step of our algorithm is written as follows:

  • Get the five loss values , , , and

Note that each update of the learning rate requires five forward passes in the network to get each of the loss values. Theses forward passes are then "canceled" so that the network can come back to its standard state of the beginning of step k. This cancellation is our algorithm’s trickiest part to implement.

Finally, both first-order and second-order updates of the learning rate don’t guarantee that it does not reach negative values. This would be inconvenient as a gradient ascent does not reduce the loss. Therefore, we force the learning rate to stay positive after each update:

(13)

In practice, the learning rate almost never reaches with the second-order method, but this can happen sometimes with the first-order method.

4.2 Results

We compare our second-order method to a standard SGD method, which uses a fixed learning rate schedule. In the following, this standard method will be called the basic method. That means, the basic method uses as optimizer plain stochastic gradient descent with a fixed learning rate. The first order method was quite unstable and less efficient. When relevant, we also include its results. We compare loss and accuracy on both training and test sets. Our goal in these experiments is not to break state of the art on the given problem, but to show an improvement in our method compared to the basic approach, especially in the first few dozens passes through the training dataset. Thus, we do not use any particular trick (not even momentum on the weights update) to improve training accuracy (like data augmentation or parameter tuning), except when we add dropout to prevent overfitting in some cases.

In the plots for all the results, all legends with suffix _basic refer to simple SGD, and all legends with suffix _adaptive refer to our adaptive SGD algorithm.

4.2.1 Linear regression

We first tried our adaptive learning rate schedule on linear regression applied to the Boston Housing dataset (2). This dataset of 506 points with 13 features is suitable for a simple linear regression model. We split this dataset into 400 points for training, and the remaining 106 for test.

The model consists in fitting a vector of parameters

to the dataset. We are minimizing the square loss .

Given the size of the dataset, we perform gradient descent with a full batch. After line searches, we decided to use for gradient descent, and for first-order and for second-order.

Figure 1: Basic, first-order, and second-order methods training and test losses, Boston Housing

We can also look at the variations of the learning rate over time for both adaptive methods:

Figure 2: Learning rate for both first-order and second-order methods, Boston Housing

From these first results, it seems that both the first-order and second-order methods are more efficient than a plain gradient descent. Indeed they reach lower training and test losses, after a comparable time of training, if not faster. However, in this case the second-order method presents some sudden and extreme amplitude variations, that we cannot really explain. There was an extremely high amplitude peak at 175 iterations, that we set down to 0 in the above graphs. Note that when training and test losses spike at 125 iterations, the second-order method reduces its learning rate value soon after.

4.2.2 Logistic regression

We also tried our method with multi-class logistic regression on the MNIST dataset (13).

The choice of was and we used a meta-learning rate of for first-order

Figure 3: Basic, first-order and second-order losses and accuracies, logistic regression, MNIST
Figure 4: First-order and second-order learning rate variations, logistic regression, MNIST

We see that with the second-order method, the learning rate stabilizes around 0.4.

4.2.3 Image classification with neural networks

CIFAR-10

A common benchmark in machine learning is to classify images on the CIFAR-10 dataset

(7). Deep neural networks are most suited for this task (8). In consequence, we used a LeNet with 5 layers (2 convolutional followed by 3 fully-connected layers) and ResNet-18 (3). We present results with the second-order method with both networks, then the first-order method with ResNet.

Second-order method

We first started by optimizing the LeNet model. We trained it for different learning rate values, and 0.01 appeared to be the best choice. As a plain SGD optimization without momentum tended to overfit, we introduced two dropout layers after the first two fully-connected layers. Thus, we compare the basic method with the second-order adaptive one starting at 0.01, using a batch-size of 32:

Figure 5: Second-order and basic methods with LeNet, CIFAR-10, initial learning rate: 0.01

From here we can notice four things:

  • The adaptive method is noisier than simple SGD.

  • Training is faster with the adaptive method. Looking at the first epochs shows that the training and test losses get optimized much quicklier than in the basic case. This is of special interest when doing early stopping.

  • Given the values that the training loss and accuracy reach, the adaptive method is probably overfitting (but the basic method seems to be on its way to overfit as well).

  • Even with this overfitting, the adaptive method reaches the same maximum test accuracy (59%) than the basic method. This accuracy is reached in less than 10 epochs, versus around 35 epochs for the basic method.

We now look at the performance of ResNet-18 (with two added dropout layers). We train it with the reference learning rate of 0.1 given by (3), and a batch size of 256:

Figure 6: Second-order and basic methods with ResNet, CIFAR-10, initial learning rate: 0.1

Once again, in the adaptive schedule, all training metrics (training and test loss, training and test accuracies) are optimized faster. Typically, in the first epochs, training loss is twice lower in the adaptive version. The second-order method reaches its plateau sooner as well, after around 15 epochs versus 40 in the basic case, and then starts to overfit. Interestingly, this time the best performance achieved by the adaptive method seems to be slightly better (74.4%) than the best one achieved by the basic method (71%). In the following, we will try several techniques to improve our method’s performance.
This current experiment with ResNet-18 on CIFAR-10 with an initial learning rate of 0.1 will be our reference. We now explore the variations of the learning rate for both networks:

Figure 7: Learning rate variations, LeNet and ResNet, CIFAR-10

For LeNet, it seems that the initial learning rate value was a bit too low. The network increases it to boost convergence, but struggles to stabilize to a fixed zone. With ResNet, it seems that a starting learning rate of 0.1 was a bit too high, as we see it decrease its learning rate. Something interesting starts happening here after 30 epochs, as the learning rate starts oscillating. As the loss value stops changing because convergence is reached, it is probable that the denominator in the learning rate updates gets very small.

That leads us to see what happens if we set the initial learning rate at 0.01 for the ResNet model:

Figure 8: Second-order and basic methods with ResNet, CIFAR-10, initial learning rate: 0.01

The adaptive schedule performs consitently better than the basic one with testing accuracy being 10 to 15 points higher all the way around. This time, the initial learning rate seems to be too small, as the network increases its value until stabilizing it around 0.05, a value around the which it oscillated at the end of the previous training schedule. As training slows down, the network slowly decreases the learning rate value.

First-order method

Figure 9: First-order and basic methods with ResNet, CIFAR-10, initial learning rate: 0.1

The first-order method did not bring much of an improvement in comparison to the reference experiment. The tendency to increase overfitting that we noticed with the second-order method is strengthened here, and the learning rate variations are noisier. However, with lower initial learning rates, the first-order method converges sensibly faster than the basic method, but less than the second-order one.

CIFAR-100

In this section, we increment difficulty by solving an image classification problem with 10 times more classes (CIFAR-100 (7) has 100 classes). After a line-search, the ideal learning rate to train ResNet-18 on CIFAR-100 seems to be 0.02.

Figure 10: Second-order and basic methods with ResNet, CIFAR-100, initial learning rate: 0.02

Once again, we see a faster loss reduction, a better generalization but also a stronger tendency to overfit. The initial learning rate of 0.02 seemed to be a judicious choice as the network barely changes its value over time. We lacked the computational resource to explore training on this dataset for a longer and more relevant period of time.

5 Further exploration

5.1 Learning the learning rate

In the previous experiments, we have seen the learning rate converge to a given value over time (or, at least, stabilize around a certain value). This value seems to depend on both the model and the dataset. Now a question rises: given a dataset and a model, is this the ideal learning rate value to perform gradient descent on this task ?

We started an adaptive learning rate training with the learning rate value that the ResNet model converged to in section 4.2.3 with 0.01 as a starting learning rate. That value is approximatively 0.05

Figure 11: Second-order and basic methods with ResNet, CIFAR-10, initial learning rate: 0.05

The trends noticed in the previous training are confirmed. This time, the learning rate variations are of much weaker amplitude, as this parameter is already in a ideal zone. The network slightly raises its learning rate to kick off training at first, then lowly decreases it over time, as training converges.

5.2 Momentum

In the same way that momentum reduces noise in a gradient descent for weights, we thought that adding momentum on the learning rate updates could help for both our methods. For the second-order method, the update on now is:

Here are the results on our reference experiment with :

Figure 12: Second-order with momentum and basic methods with ResNet, initial learning rate: 0.1

Such a momentum does not seem to bring any particular improvement here.

5.3 Getting loss values via a validation set

One idea to reduce overfitting tendency in the two adaptive methods could be to compute the loss on sample validation batches. This way, the update on the learning rate would guarantee to move in a direction that better reduces the generalization error (and not the training error). The formula for this variant is the same, expect for the use of the function, that now becomes:

(14)
(15)

We partitioned the original training set in a training and validation set, and applied this technique on the reference experiment:

Figure 13: Second-order with val. sampling and basic methods with ResNet, initial learning rate: 0.1

These results suggest that the training loss and training accuracy get optimized slower, but a deeper investigation would be needed to conclude on a reduction of overfitting.

5.4 Comparison with other optimizers

In the last few years, a popular variation of gradient descent named Adam (6) has progressively gained consensus among researchers for its efficiency. Thus, we compared our method with Adam and changed its default learning rate of to , our initial value for the adaptive method.

Here is the comparison with our reference experiment, which results were first shown in section 4.2.3:

Figure 14: Second-order and Adam with ResNet, initial learning rate: 0.1

In the first epochs, our method performs better than an Adam optimization, but the overfitting difference is wider.

6 Limitations

6.1 Choice of step

In finite differences, the choice of the paramater

is a main issue. Indeed, in any deep learning problem, we can expect the loss function to present noisy oscillations locally. On one hand, with a too small value of

, we might not capture meaningful variations of the function. On the other hand, a too large would make the learning rate oscillate too much, reaching either too high values or even negative values. Both cases can in turn quickly make the loss function diverge. We have seen empirically that when the learning rate gets negative, training will likely not converge.

All our reported experiments were done using an value of , which seemed to be a good compromise, and showed stable results for a wide variety of tasks. Tuning for a given problem overthrows the interest of not having to tune a learning rate anymore. Ideally, a deeper investigation of finite differences should be able to give values of usable for a large variety of tasks.

6.2 Choice of the initial learning rate

In our algorithm schedule, learning rate variations are automatic, but we have to choose the initial value.

This value seems not to matter so much, as with several ranges of initial values, our algorithm still does better than the basic method. Besides, it always adapts its learning rate to reach the same zone, whatever the initial value (in a reasonable range of learning rate values, e.g. to for CIFAR-10 for instance).

6.3 Cost of loss computations

We have shown faster training in terms of number of epochs. However, at each iteration, we have to perform five forward passes and back-propagations instead of one. Thus, computation time is slowed down compared to the fixed learning rate approach.

6.4 Overfitting

Our version of gradient descent reduces the training loss much faster than in the fixed learning rate approach. The training loss sometimes gets down to very surprisingly low values, while the test loss does not reduce much more than in the basic model. On the contrary, the test loss usually increases and ends at a higher value than the basic method one. Thus, our model seems to be more likely to overfit. We have tried to add dropout to the ResNet model, and that proved successful in reducing the gap between training and testing performance.

However, in terms of accuracy, the second-order method performs systematically as well as the basic method, if not slightly better. Top test accuracy is usually reached early on, which suggests that our adaptive method should be used combined with early stopping.

7 Conclusion

In this paper, we have built a new way to learn the learning rate at each step using finite differences on the loss. We have tested it on a variety of convex and non-convex optimization tasks.

Based on our results, we believe that our method would be able to adapt a good learning rate at every iteration on convex problems. In the case of non-convex problems, we repeatedly observed faster training in the first few epochs. However, our adaptive model seems more inclined to overfit the training data, even though its test accuracy is always comparable to standard SGD performance, if not slightly better. Hence we believe that in neural network architectures, our model can be used initially for pretraining for a few epochs, and then continue with any other standard optimization technique to lead to faster convergence and be computationally more efficient, and perhaps reach a new highest accuracy on the given problem.

Moreover, the learning rate that our algorithm converges to suggests an ideal learning rate for the given training task. One could use our method to tune the learning rate of a standard neural network (using Adam for instance), giving a more precise value than with line-search or random search.

References