O NLINE L EARNING R ATE A DAPTATION WITH H YPERGRADIENT D ESCENT
A BSTRACT
We introduce a general method for improving the convergence rate of gradientbased optimizers that is easy to implement and works well in practice.
We demonstrate the effectiveness of the method in a range of optimization problems by applying it to stochastic gradient descent, stochastic gradient descent with Nesterov momentum and Adam, showing that it signiﬁcantly reduces the need for the manual tuning of the initial learning rate for these commonly used algorithms.
Our method works by dynamically updating the learning rate during optimization using the gradient with respect to the learning rate of the update rule itself.
Computing this “hypergradient” needs little additional computation, requires only one extra copy of the original gradient to be stored in memory, and relies upon nothing more than what is provided by reverse-mode automatic differentiation
I NTRODUCTION
In nearly all gradient descent algorithms the choice of learning rate remains central to efﬁciency;
Bengio (2012) asserts that it is “often the single most important hyper-parameter” and that it always should be tuned.
This is because choosing to follow your gradient signal by something other than the right amount, either too much or too little, can be very costly in terms of how fast the overall descent procedure achieves a particular level of objective value.
Understanding that adapting the learning rate is a good thing to do, particularly on a per parameter basis dynamically, led to the development of a family of widely-used optimizers including AdaGrad (Duchi et al., 2011), RMSProp (Tieleman & Hinton, 2012), and Adam (Kingma & Ba, 2015).
However, a persisting commonality of these methods is that they are parameterized by a “pesky” ﬁxed global learning rate hyperparameter which still needs tuning.
There have been methods proposed that do away with needing to tune such hyperparameters altogether (Schaul et al., 2013) but their adoption has not been widespread, owing perhaps to their complexity, applicability in practice, or performance relative to the aforementioned family of algorithms.
Our initial conceptualization of the learning rate adaptation problem was one of automatic differentiation (Baydin et al., 2018).
We hypothesized that the derivative of a parameter update procedure with respect to its global learning rate ought to be useful for improving optimizer performance.
This conceptualization is not unique, having been explored, for instance, by Maclaurin et al.
While the automatic differentiation perspective was integral to our conceptualization, the resulting algorithm turns out to simplify elegantly and not require additional automatic differentiation machinery.
In fact, it is easily adaptable to nearly any gradient update procedure while only requiring one extra copy of a gradient to be held in memory and very little computational overhead; just a dot product in the dimension of the parameter.
Considering the general applicability of this method and adopting the name “hypergradient” introduced by Maclaurin et al.
(2015) to mean a derivative taken with respect to a hyperparameter, we call our method hypergradient descent .
To our knowledge, our rediscovery appeared ﬁrst in the largely neglected paper of Almeida et al.
(1998), who arrived at the same hypergradient procedure as us.
However, none of the aforementioned modern gradient-based optimization procedures existed at the time of its publication so the only examples considered were gradient and stochastic gradient descent on relatively simple functions.
Having rediscovered this approach, we develop it further and demonstrate that adapting existing gradient descent procedures to use hypergradient descent to dynamically tune global learning rates improves stochastic gradient descent (SGD), stochastic gradient descent with Nesterov momentum (SGDN), and Adam; particularly so on large-scale neural network training problems.
For a given untuned initial learning rate, hypergradient algorithms consistently bring the loss trajectory closer to the optimal one that would be attained with a tuned initial learning rate, and thus signiﬁcantly reduce the need for the expensive and time consuming practice of hyperparameter search (Goodfellow et al., 2016) for learning rates, which is conventionally performed using grid search, random search (Bergstra & Bengio, 2012), Bayesian optimization (Snoek et al., 2012), and model-based approaches (Bergstra et al., 2013; Hutter et al., 2013).
H YPERGRADIENT D ESCENT
We deﬁne the hypergradient descent (HD) method by applying gradient descent on the learning rate of an underlying gradient descent algorithm, independently discovering a technique that has been previously considered in the optimization literature, most notably by Almeida et al.
This differs from the reversible learning approach of Maclaurin et al.
(2015) in that we apply gradientbased updates to a hyperparameter (in particular, the learning rate) at each iteration in an online fashion, instead of propagating derivatives through an entire inner optimization that consists of many iterations.
The method is based solely on the partial derivative of an objective function—following an update step—with respect to the learning rate.
In this paper we consider and report the case where the learning rate α is a scalar.
It is straightforward to generalize the introduced method to the case where α is a vector of per-parameter learning rates.
The most basic form of HD can be derived from regular gradient descent as follows.
Regular gradient descent, given an objective function f and previous parameters θ t − 1 , evaluates the gradient ∇ f
( θ t − 1 ) and moves against it to arrive at updated parameters
[Equation]
where α is the learning rate.
In addition to this update rule, we would like to derive an update rule for the learning rate α itself.
We make the assumption that the optimal value of α does not change much between two consecutive iterations so that we can use the update rule for the previous step to optimize α in the current one.
For this, we will compute ∂f ( θ t − 1 ) /∂α , the partial derivative of the objective f at the previous time step with respect to the learning rate α .
Noting that θ t − 1 = θ t − 2 − α ∇ f ( θ t − 2 ) , i.e., the result of the previous update step, and applying the chain rule, we get
[Equation]
which allows us to compute the needed hypergradient with a simple dot product and the memory cost of only one extra copy of the original gradient.
Using this hypergradient, we construct a higher level update rule for the learning rate as
[Equation]
introducing β as the hypergradient learning rate.
We then modify Eq.
1 to use the sequence α t to become
[Equation]
[Equation]
Equations 3 and 4 thus deﬁne the most basic form of the HD algorithm, updating both θ t and α t at each iteration.
This derivation, as we will see shortly, is applicable to any gradient-based primal
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Figure]
optimization algorithm, and is computation- and memory-efﬁcient in general as it does not require any more information than the last two consecutive gradients that have been already computed in the base algorithm.
2. D ERIVATION OF THE HD RULE IN THE GENERAL CASE
Here we formalize the derivation of the HD rule for an arbitrary gradient descent method.
Assume that we want to approximate a minimizer of a function f : R n → R and we have a gradient descent method with update rule θ t
= u (Θ t − 1 , α ) , where θ t ∈ R n is the point computed by this method at step t , Θ t = { θ i } t i =
and α is the learning rate.
For instance, the regular gradient descent mentioned above corresponds to an update rule of u (Θ t , α )
= θ t − α ∇ f ( θ t ) .
In each step, our goal is to update the value of α towards the optimum value α ∗ t that minimizes the expected value of the objective in the next iteration, that is, we want to minimize E [ f ( θ t )]
=
E [ f ( u (Θ t − 1 , α t ))] , where the expectation is taken with respect to the noise produced by the estimator of the gradient (if we compute the gradient exactly then the noise is just 0 ).
We want to update the previous learning rate α t − 1 so the new computed value, α t , is closer to α ∗ t .
As we did in the example above, we could perform a step gradient descent, where the gradient is
[Equation]
where ˜ ∇ θ f ( θ t ) is the noisy estimator of ∇ θ f
( θ t ) .
The last equality is true if we assume, as it is usual, that the noise at step t is independent of the noise at previous iterations.
However we have not computed θ t yet, we need to compute α t ﬁrst.
If we assume that the optimum value of the learning rate at each step does not change much across iterations, we can avoid this problem by performing one step of the gradient descent to approximate α ∗ t − 1 instead.
The update rule for the learning in such a case is
[Equation]
We call the previous rule, the additive rule of HD.
However, (see Mart´ınez (2017), Section 3.1) it is usually better for this gradient descent to set
[Equation]
(7) so that the rule is [Equation] (cid:13)(cid:13)(cid:13) [Equation]
(cid:13)(cid:13)(cid:13)
[Equation]
(cid:13)(cid:13)(cid:13)
[Equation]
We call this rule the multiplicative rule of HD.
One of the practical advantages of this multiplicative rule is that it is invariant up to rescaling and that the multiplicative adaptation is in general faster than the additive adaptation.
In Figure 2 we can see in black one execution of the multiplicative rule in each case.
Applying these derivation steps to stochastic gradient descent (SGD) (Algorithm 1), we arrive at the hypergradient variant of SGD that we abbreviate as SGD-HD (Algorithm 4).
As all gradient-based algorithms that we consider have a common core where one iterates through a loop of gradient evaluations and parameter updates, for the sake of brevity, we deﬁne the regular algorithms with reference to Algorithm 1, where one substitutes the initialization statement (red) and the update rule (blue) with their counterparts in the variant algorithms. Similarly we deﬁne the hypergradient variants with reference to Algorithm 4.
In this way, from SGD with Nesterov momentum (SGDN)
(Algorithm 2) and Adam (Algorithm 3), we formulate the hypergradient variants of SGDN-HD (Algorithm 5) and Adam-HD (Algorithm 6).
In Section 4, we empirically demonstrate the performance of these hypergradient algorithms for the problems of logistic regression and training of multilayer and convolutional neural networks for image classiﬁcation, also investigating good settings for the hypergradient learning rate β and the initial learning rate α 0 .
Section 5 discusses extensions to this technique and examines the convergence of HD for convex objective functions.
R ELATED W ORK 3. L EARNING R ATE A DAPTATION
Almeida et al.
(1998) previously considered the adaptation of the learning rate using the derivative of the objective function with respect to the learning rate.
Plagianakos et al.
(2001; 1998) proposed methods using gradient-related information of up to two previous steps in adapting the learning rate.
In any case, the approach can be interpreted as either applying gradient updates to the learning rate or simply as a heuristic of increasing the learning rate after a “successful” step and decreasing it otherwise.
Similarly, Shao & Yip (2000) propose a way of controlling the learning rate of a main algorithm by using an averaging algorithm based on the mean of a sequence of adapted learning rates, also investigating rates of convergence.
The stochastic meta-descent (SMD) algorithm
(Schraudolph et al., 2006; Schraudolph, 1999), developed as an extension of the gain adaptation work by Sutton (1992), operates by multiplicatively adapting local learning rates using a meta-learning rate, employing second-order information from fast Hessian-vector products (Pearlmutter, 1994).
Other work that merits mention include RPROP (Riedmiller & Braun, 1993), where local adaptation of weight updates are performed by using only the temporal behavior of the gradient’s sign, and Delta-Bar-Delta (Jacobs, 1988), where the learning rate is varied based on a sign comparison between the current gradient and an exponential average of the previous gradients.
Recently popular optimization methods with adaptive learning rates include AdaGrad (Duchi et al., 2011), RMSProp (Tieleman & Hinton, 2012), vSGD
(Schaul et al., 2013), and Adam (Kingma &
Ba, 2015), where different heuristics are used to estimate aspects of the geometry of the traversed objective.
3. H YPERPARAMETER O PTIMIZATION U SING D ERIVATIVES
Previous authors, most notably Bengio (2000), have noted that the search for good hyperparameter values for gradient descent can be cast as an optimization problem itself, which can potentially be tackled via another level of gradient descent using backpropagation.
More recent work includes
Domke (2012), where an optimization procedure is truncated to a ﬁxed number of iterations to compute the gradient of the loss with respect to hyperparameters, and Maclaurin et al. (2015), applying nested reverse automatic differentiation to larger scale problems in a similar setting.
A common point of these works has been their focus on computing the gradient of a validation loss at the end of a regular training session of many iterations with respect to hyperparameters supplied to the training in the beginning.
This requires a large number of intermediate variables to be maintained in memory for being later used in the reverse pass of automatic differentiation.
Maclaurin et al.
(2015) introduce a reversible learning technique to efﬁciently store the information needed for exactly reversing the learning dynamics during the hyperparameter optimization step.
As described in
Sections 1 and 2, the main difference of our method from this is that we compute the hypergradients and apply hyperparameter updates in an online manner at each iteration, 1 overcoming the costly requirement of keeping intermediate values during training and differentiating through whole training sessions per hyperparameter update.
E XPERIMENTS
We evaluate the behavior of HD in several tasks, comparing the behavior of the variant algorithms
SGD-HD (Algorithm 4), SGDN-HD (Algorithm 5), and Adam-HD (Algorithm 6) to that of their ancestors SGD (Algorithm 1), SGDN (Algorithm 2), and Adam (Algorithm 3) showing, in all cases, a move of the loss trajectory closer to the optimum that would be attained by a tuned initial learning rate.
The algorithms are implemented in Torch (Collobert et al., 2011) and PyTorch (Paszke et al., 2017) using an API compatible with the popular torch.optim package, 2 to which we are planning to contribute via a pull request on GitHub.
Experiments were run using PyTorch, on a machine with Intel Core i7-6850K CPU, 64 GB RAM, and NVIDIA Titan Xp GPU, where the longest training (200 epochs of the VGG Net on CIFAR-10) lasted approximately two hours for each run.
4. O NLINE T UNING OF THE L EARNING R ATE
Figure 2 demonstrates the general behavior of HD algorithms for the training of logistic regression and a multi-layer neural network with two hidden layers of 1,000 units each, for the task of image classiﬁcation with the MNIST database.
The learning rate α is taken from the set of { 10 − 1 , 10 − 2 , 10 − 3 , 10 − 4 , 10 − 5 , 10 − 6 } and β is taken as 10 − 4 in all instances.
3 We observe that for any given untuned initial learning rate, HD algorithms (solid curves) consistently bring the loss [Figure] trajectory closer to the optimal one that would be attained with the tuned initial learning rate of the non-HD algorithm (dashed curves).
In Figure 4 we report the results of a grid search for all the algorithms on the logitistic regression objective; similar results have been observed for the multi-layer neural network and CNN objectives as well.
Figure 4 compels several empirical arguments.
For one, independent of these results [Figure] and even if one acknowledges that using hypergradients for online learning rate adaption improves on the baseline algorithm, one might worry that using hypergradients makes the hyperparameter search problem worse.
One might imagine that their use would require tuning both the initial learning rate α 0 and the hypergradient learning rate β .
In fact, what we have repeatedly observed and can be seen in this ﬁgure is that, given a good value of β , HD is somewhat insensitive to the value of α 0 .
So, in practice tuning β by itself, if hyperparameters are to be tuned at all, is actually sufﬁcient.
Also note that in reasonable ranges for α 0 and β , no matter which values of α 0 and β you choose, you improve upon the original method.
The corollary to this is that if you have tuned to a particular value of α 0 and use our method with an arbitrary small β (no tuning) you will still improve upon the original method started at the same α 0 ; remembering of course that β = 0 recovers the original method in all cases.
In the following subsections, we show examples of online tuning for an initial learning rate of α 0 = 0 .
001 , for tasks of increasing complexity, covering logistic regression, multi-layer neural networks, and convolutional neural networks.
4.1. T UNING E XAMPLE : L OGISTIC R EGRESSION
We ﬁt a logistic regression classiﬁer to the MNIST database, assigning membership probabilities for ten classes to input vectors of length 784.
We use a learning rate of α = 0 .
001 for all algorithms, where for the HD variants this is taken as the initial α 0 .
We take µ = 0 .
9 for SGDN and SGDN-HD.
For Adam, we use β 1 = 0 .
9 , β 2 = 0 .
999 , (cid:15) =
10 − 8 , and apply a 1 / √ t decay to the learning rate (cid:0) α t = α/ √ t (cid:1) as used in Kingma & Ba (2015) only for the logistic regression problem.
We use the [Figure] full 60,000 images in MNIST for training and compute the validation loss using the 10,000 test images.
L2 regularization is used with a coefﬁcient of 10 − 4 .
We use a minibatch size of 128 for all the experiments in the paper.
Figure 3 (left column) shows the negative log-likelihood loss for training and validation along with the evolution of the learning rate α t during training, using β = 0 .
001 for SGD-HD and SGDN-HD, and β = 10 − 7 for Adam-HD.
Our main observation in this experiment, and the following experiments, is that the HD variants consistently outperform their regular versions.
4 While this might not come as a surprise for the case of vanilla SGD, which does not possess capability for adapting the learning rate or the update speed, the improvement is also observed for SGD with Nesterov momentum (SGDN) and Adam.
The improvement upon Adam is particularly striking because this method itself is based on adaptive learning rates.
An important feature to note is the initial smooth increase of the learning rates from α
= 0 .
001 to approximately 0.05 for SGD-HD and SGDN-HD.
For Adam-HD, the increase is up to 0.
(a 17% change), virtually imperceivable in the plot due to scale.
For all HD algorithms, this initial increase is followed by a decay to a range around zero.
We conjecture that this initial increase and the later decay of α t , automatically adapting to the geometry of the problem, is behind the performance increase observed. [Figure]
In the limit of β → 0 , as one recovers the original update rule, the algorithms perform the same in the worst
4. T UNING E XAMPLE : M ULTI -L AYER N EURAL N ETWORK
We next evaluate the effectiveness of HD algorithms on training a multi-layer neural network, again on the MNIST database.
The network consists of two fully connected hidden layers with 1,000 units each and ReLU activations.
We again use a learning rate of α = 0 .
001 for all algorithms.
We use β = 0 .
001 for SGD-HD and SGDN-HD, and β = 10 − 7 for Adam-HD.
L2 regularization is applied with a coefﬁcient of 10 − 4 .
As seen in the results in Figure 3 (middle column), the hypergradient variants again consistently outperform their regular counterparts.
In particular, we see that Adam-HD converges to a level of validation loss not achieved by Adam, and shows an order of magnitude improvement over Adam in the training loss.
Of particular note is, again, the initial rise and fall in the learning rates, where we see the learning rate climb to 0.05 for SGD-HD and SGDN-HD, whereas for Adam-HD the overall behavior of the learning rate is that of decay following a minute initial increase to 0.001083 (invisible in the plot due to scale).
Compared with logistic regression results, the initial rise of the learning rate for SGDN-HD happens noticeably before SGD-HD, possibly caused by the speedup from the momentum updates.
4. T UNING E XAMPLE : C ONVOLUTIONAL N EURAL N ETWORK
To investigate whether the performance we have seen in the previous sections scales to deep architectures and large-scale high-dimensional problems, we apply these to train a VGG Net (Simonyan & Zisserman, 2014) on the CIFAR-10 image recognition dataset (Krizhevsky, 2009).
We base our implementation on the VGG Net architecture for Torch by Sergey Zagoruyko.
The network used has an architecture of (conv-64) × 2 ◦ maxpool ◦ (conv-128) × 2 ◦ maxpool ◦ (conv-256) × 3 ◦ maxpool ◦ (conv-512) × 3 ◦ maxpool ◦ (conv-512) × 3 ◦ maxpool ◦ fc-512 ◦ fc-10, corresponding closely to the “D conﬁguration” in Simonyan & Zisserman (2014).
All convolutions have 3 × 3 ﬁlters and a padding of 1; all max pooling layers are 2 × 2 with a stride of 2.
We use α = 0 .
and β =
We the training in
CIFAR- training and the images for evaluating the validation loss
Looking at Figure 3 (right column), once again we see consistent improvements of the hypergradient variants over their regular counterparts.
SGD-HD and SGDN-HD perform signiﬁcantly better than their regular versions in the validation loss, whereas Adam and Adam-HD reach the same validation loss with relatively the same speed.
Adam-HD performs signiﬁcantly better than Adam in the training loss.
For SGD-HD and SGDN-HD we see an initial rise of α to approximately 0.025, this rise happening, again, with SGDN-HD before SGD-HD.
During this initial rise, the learning rate of
Adam-HD rises only up to 0.001002.
C ONVERGENCE AND E XTENSIONS 5. T RANSITIONING TO THE U NDERLYING A LGORITHM
We observed in our experiments that α follows a consistent trajectory.
As shown in Figure 3, it initially grows large, then shrinks, and thereafter ﬂuctuates around a small value that is comparable to the best ﬁxed α
we could ﬁnd for the underlying algorithm without hypergradients.
This suggests that hypergradient updates improve performance partially due to their effect on the algorithm’s early behaviour, and motivates our ﬁrst proposed extension, which involves smoothly transitioning to a ﬁxed learning rate as the algorithm progresses.
More precisely, in this extension we update α t exactly as previously via Eq. 8, and when we come to the update of θ t , we use as our learning rate a new value γ t instead of α t directly, so that our update rule is θ t = θ t − 1 + u (Θ t − 1 , γ t − 1 ) instead of θ t = θ t − 1 + u (Θ t − 1 , α t − 1 ) as previously.
Our γ t satisﬁes γ t ≈ α t when t is small, and γ t ≈ α ∞ as t → ∞ , where α ∞ is some constant we choose.
Speciﬁcally, γ t = δ ( t ) α t + (1 − δ ( t ))
α ∞ , where δ is some function such that δ (1) =
and δ ( t ) → 0 as t → ∞ (e.g., δ ( t ) = 1 /t 2 ).
Intuitively, this extension will behave roughly like HD at the beginning of the optimization process, and roughly like the original underlying algorithm by the end.
We suggest choosing a value for α ∞ that would produce good performance when used as a ﬁxed learning rate throughout.
Our preliminary experimental evaluation of this extension shows that it gives good convergence performance for a larger range of β than without, and hence can improve the robustness of our approach.
It also allows us to prove theoretical convergence under certain assumptions about f :
Theorem 5.1.
Suppose that f is convex and L -Lipschitz smooth with (cid:107)∇ f ( θ ) (cid:107) <
M for some ﬁxed
M and all θ .
Then θ t → θ ∗ if α ∞ < 1 /L and t δ ( t ) → 0 as t → ∞ , where the θ t are generated according to (non-stochastic) gradient descent.
Proof.
Note that
[Equation]
where the right-hand side is O ( t ) as t → ∞ .
Our assumption about the limiting behaviour of t δ ( t ) then entails δ ( t ) α t → 0 and therefore γ t → α ∞ as t → ∞ .
For large enough t , we thus have 1 / ( L + 1) <
γ t < 1 /L , and the algorithm converges by the fact that standard gradient descent converges for such a (potentially non-constant) learning rate under our assumptions about f (see, e.g.,
Karimi et al.
5. H IGHER - ORDER H YPERGRADIENTS
While our method adapts α t during training, we still make use of a ﬁxed β , and it is natural to wonder whether one can use hypergradients to adapt this value as well.
To do so would involve the addition of an update rule analogous to Eq. 3, using a gradient of our objective function computed now with respect to β .
We would require a ﬁxed learning rate for this β update, but then may consider doing hypergradient updates for this quantity also, and so on arbitrarily.
Since our use of a single hypergradient appears to make a gradient descent algorithm less sensitive to hyperparameter selection, it is possible that the use of higher-order hypergradients in this way would improve robustness even further.
We leave this hypothesis to explore in future work.
C ONCLUSION
Having rediscovered a general method for adapting hyperparameters of gradient-based optimization procedures, we have applied it to the online tuning of the learning rate, and produced hypergradient descent variants of SGD, SGD with Nesterov momentum, and Adam that empirically appear to reduce the time and resources needed to tune the initial learning rate signiﬁcantly.
The method is general, memory and computation efﬁcient, and easy to implement.
The main advantage of the presented method is that, with a small β , it requires signiﬁcantly less tuning to give performance better than—or in the worst case the same as—the baseline.
We believe that the ease with which the method can be applied to existing optimizers give this it the potential to become a standard tool and signiﬁcantly impact the utilization of time and hardware resources in machine learning practice.
Our start towards the establishment of theoretical convergence guarantees in this paper is limited and as such there remains much to be done, both in terms of working towards a convergence result for the non-transitioning variant of hypergradient descent and a more general result for the mixed variant.
Establishing convergence rates would be even more ideal but remains future work.
A CKNOWLEDGMENTS
Baydin and Wood are supported under DARPA PPAML through the U.S. AFRL under Cooperative
Agreement FA8750-14-2-0006, Sub Award number 61160290-111668.
Baydin is supported by the
NVIDIA Corporation with the donation of the Titan Xp GPU used for this research.
Mart ´ ınez Rubio is supported by Intel BDC / LBNL Physics Graduate Studentship.
Wood is supported by The Alan
Turing Institute under the EPSRC grant EP/N510129/1; Intel; and DARPA D3M, under Cooperative
Agreement FA8750-17-2-0093.