Search

Search papers and lessons

Learning to learn by gradient descent by gradient descent

Marcin Andrychowicz, Misha Denil, Sergio Gomez et al. · 2016

Andrychowicz and colleagues replace a hand-designed optimizer with an LSTM that learns its own update rule from example problems, and the learned rule often transfers to new ones.

On this page

  • Colour = topic mix
  • Neural network basics
  • Calculus
  • Discrete math
  • Probability
  • Learning basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Designing an optimizer, the rule that turns gradients into parameter updates, has so far been a job for people. This paper treats that rule as a function with its own parameters and learns those parameters. The learned rule is a small recurrent network (an LSTM) that sees each parameter's gradient and outputs its step. Trained by gradient descent on a family of problems, it beats standard hand-designed optimizers on those problems and often on new problems with similar structure.

Builds on: Long Short-Term Memory, Backpropagation Through Time, Meta-Learning · Leads to: learned optimizers and the study of optimizers as trainable components

Why it mattered

Most deep learning training still runs on a short list of hand-designed rules: plain gradient descent, momentum, RMSprop and Adam Optimizer. The paper showed that a rule learned from data could match or beat these on the tasks it was trained for, and that it transferred to unseen tasks. The authors trained optimizers on random quadratics and small MNIST networks, and then trained further optimizers for a convolutional network on CIFAR-10 and for neural style transfer.

The problem

Let f(θ)f(\theta) be an objective over parameters θ\theta, such as the loss of a network. The usual method is gradient descent, θt+1=θt−αt∇f(θt)\theta_{t+1} = \theta_t - \alpha_t \nabla f(\theta_t), with a step size αt\alpha_t (see Learning Rate). Plain gradient descent uses only the gradient and ignores curvature. Classical methods rescale the step using curvature from the Hessian Matrix, and practical deep learning rules add memory of past gradients, like Momentum, or scale each parameter's step separately.

Each of those rules encodes an assumption about the problems it will meet. A rule that works well on one family can perform poorly on another. The no free lunch theorem for optimization says that, averaged over all problems, no method beats random search, so any gain has to come from the structure of the problems we care about. Hand design uses that structure through human insight. The paper's question is whether the structure can be learned from example problems instead.

How it works

The method has one job: produce the update gtg_t that moves the optimizee parameters. A small recurrent network called the optimizer does it, and its own weights ϕ\phi are the only things trained.

  1. Pick a problem. Draw a random function ff from the family you care about, for example a 10-dimensional quadratic.
  2. Start the optimizee. Initialize θ0\theta_0 with random values drawn from a Gaussian distribution.
  3. Compute the gradient. Calculate ∇t=∇f(θt)\nabla_t = \nabla f(\theta_t). The optimizer sees each coordinate's gradient on its own.
  4. Run the optimizer. An LSTM receives the gradient and its previous hidden state hth_t, and outputs gtg_t and a new state ht+1h_{t+1}. Its memory lets it act like momentum, combining the history of gradients (see Long Short-Term Memory).
  5. Update the parameters. Set θt+1=θt+gt\theta_{t+1} = \theta_t + g_t.
  6. Score the trajectory. Add the loss f(θt+1)f(\theta_{t+1}) to a running total. Repeat steps 3 to 6 for a fixed horizon TT.
  7. Train the optimizer. Backpropagate the total loss through the unrolled steps and adjust ϕ\phi with Adam, then repeat with a new function.

A trace with a fixed stand-in rule shows the bookkeeping. Take f(θ)=θ2f(\theta) = \theta^2 and θ0=2\theta_0 = 2. The gradient is ∇=2⋅2=4\nabla = 2 \cdot 2 = 4. A rule that outputs g=−0.1⋅4=−0.4g = -0.1 \cdot 4 = -0.4 gives θ1=2−0.4=1.6\theta_1 = 2 - 0.4 = 1.6, and the loss falls from 44 to 1.62=2.561.6^2 = 2.56. The learned optimizer plays the role of this rule, but its output depends on the whole history of gradients, and its weights are what training changes.

flowchart LR
    A["Optimizee gradient for one coordinate"] --> B["Shared LSTM with its own hidden state"]
    B --> C["Update g_t"]
    C --> D["theta_t+1 = theta_t + g_t"]
    D --> E["Loss f(theta_t+1) added to total"]
    E --> A

Two design choices make this practical. First, the optimizer is coordinatewise: one small LSTM with shared weights runs on every parameter, with a separate hidden state per parameter. This keeps the network small enough to handle tens of thousands of parameters, and it makes the rule the same no matter how parameters are ordered. Second, inputs and outputs are rescaled, because gradients can differ in size across layers and neural networks handle small or large values poorly.

The math

The optimizer is a function mm with parameters ϕ\phi. For a function ff and a horizon TT, the objective for the optimizer is

L(ϕ)=Ef[∑t=1Twt f(θt)],\mathcal{L}(\phi) = \mathbb{E}_f\left[\sum_{t=1}^{T} w_t \, f(\theta_t)\right],

where wt≥0w_t \geq 0 are weights per step. The trajectory is generated by

θt+1=θt+gt,[gtht+1]=m(∇t,ht,ϕ).\theta_{t+1} = \theta_t + g_t, \qquad \begin{bmatrix} g_t \\ h_{t+1} \end{bmatrix} = m(\nabla_t, h_t, \phi).

Here ∇t=∇θf(θt)\nabla_t = \nabla_\theta f(\theta_t) is the gradient at step tt and hth_t is the hidden state. The paper first writes the simpler objective Ef[f(θ∗(f,ϕ))]\mathbb{E}_f[f(\theta^*(f, \phi))], which only scores the final point. Setting wtw_t to one only at t=Tt = T recovers it, but then the gradient is zero for all earlier steps, so training the optimizer on short prefixes of trajectories learns very little. Giving every step a positive weight keeps the signal alive along the trajectory.

Step 3 in symbols: the gradient of the optimizer

Training needs ∂L/∂ϕ\partial \mathcal{L} / \partial \phi. Backpropagation through the unrolled steps produces it, which is backpropagation through time (see Backpropagation Through Time). The full computation would also flow through ∂∇t/∂ϕ\partial \nabla_t / \partial \phi, which requires second derivatives of ff. The paper drops those edges and assumes ∂∇t/∂ϕ=0\partial \nabla_t / \partial \phi = 0. That assumption avoids computing Hessian Matrix entries of ff at a cost in accuracy of the gradient estimate.

Step 4 in symbols: sharing across coordinates

With nn optimizee parameters, the coordinatewise optimizer applies one LSTM mm with weights ϕ\phi to each coordinate ii separately:

[gt,i, ht+1,i]=m(∇t,i,ht,i,ϕ),i=1,…,n.\left[g_{t,i}, \, h_{t+1,i}\right] = m(\nabla_{t,i}, h_{t,i}, \phi), \qquad i = 1, \dots, n.

The weights ϕ\phi are shared, while each coordinate keeps its own state ht,ih_{t,i}. Because the same function is applied to every coordinate, permuting the parameters permutes the updates in the same way.

Step 5 in symbols: the preprocessing

Gradient coordinates can be very small or very large. The experiments pass each gradient through an input preprocessing described in Appendix A, which maps it to a more evenly scaled input. The LSTM's outputs are then multiplied by a constant factor (0.1 in the MNIST experiment), which keeps the update in a usable range.

Results

The optimizers are trained with Adam and early stopping on a validation set, then tested on freshly sampled problems. Baselines are SGD, RMSprop, Adam and Nesterov's accelerated gradient, each with its learning rate tuned per problem.

  • Quadratic functions. On random 10-dimensional quadratics f(θ)=∥Wθ−y∥22f(\theta) = \|W\theta - y\|_2^2, the learned optimizers reach lower loss than all four baselines. The paper shows learning curves with the learned rule clearly below the hand-designed rules.
  • Small MNIST network. The base network is an MLP with one hidden layer of 20 sigmoid units and minibatches of 128. The learned optimizer beats NAG, Adam and RMSprop by a significant margin over 100 steps, and still beats them when run for 200 steps.
  • Generalization. The optimizer trained on the 20-unit network works on a 40-unit network and on a two-hidden-layer network. It fails when the activation changes from sigmoid to ReLU, so the learned dynamics do not transfer across every change.
  • CIFAR-10. The model is three convolutional layers with max pooling, a 32-unit fully connected layer, ReLU and batch normalization. The learned optimizer uses two LSTMs, one for convolutional parameters and one for fully connected parameters. It learns much faster than the baselines, and the gains are largest on the CIFAR-2 subset. An optimizer trained only on held-out labels transfers well to them.
  • Neural art. Trained on one style and 1,800 ImageNet content images at 64 by 64, it beats standard optimizers on that setup, and it keeps performing well at 128 by 128 with a new style. The conclusion reports transfer from a training task with 12,288 parameters to one with 49,152 parameters.

Limits: each learned optimizer is trained for a family of problems and can fail outside it, as the ReLU result shows. Training uses truncated horizons and drops second-order terms, so the training objective is only an approximation. The experiments are on small networks and image tasks of the time, and the paper does not claim that the learned rules beat the best hand-designed optimizers across all of deep learning.

Reading guide

  • Section 1 and 1.1. Hand-designed optimizers, and the idea of transfer as generalization over problems. Needs Learning Rate and Meta-Learning.
  • Section 1.2. Related work on learning to learn, mostly older. Read it after Section 2 if the history feels abstract.
  • Section 2. The optimizer as an RNN, the expected loss, and the unrolled objective. Needs Backpropagation Through Time, Long Short-Term Memory and Hessian Matrix.
  • Section 2.1. The coordinatewise LSTM, which shares weights across parameters. Needs Momentum for the comparison the paper draws to the rules it learns.
  • Section 3. The experiments in order: quadratics, MNIST, CIFAR-10, neural art. Read Figure 4 first, then the generalization figures.
  • Appendix A. The gradient preprocessing the experiments use. Read it before Section 3 if the input scaling is unclear.

Check yourself

QuestionWhy does the paper set the step weights wtw_t to a positive value at every step rather than only at the final step?Show answer

With weight only at the last step, the gradient of the objective with respect to the optimizer parameters is zero for all earlier steps, so training learns from the end of each trajectory alone. Positive weights at every step give a training signal throughout the trajectory.

QuestionIn the tiny trace, f(θ)=θ2f(\theta) = \theta^2 with θ0=2\theta_0 = 2 and a fixed rule g=−0.1⋅∇g = -0.1 \cdot \nabla. What is θ1\theta_1 and the loss after one step?Show answer

The gradient is ∇=2⋅2=4\nabla = 2 \cdot 2 = 4, so g=−0.4g = -0.4 and θ1=2−0.4=1.6\theta_1 = 2 - 0.4 = 1.6. The loss is 1.62=2.561.6^2 = 2.56.

QuestionWhy does the coordinatewise design make the learned optimizer invariant to the order of the parameters?Show answer

The same LSTM with the same weights is applied to each coordinate independently, and each coordinate only sees its own gradient and its own hidden state. Reordering the parameters therefore reorders the outputs in the same way and changes nothing else.

QuestionThe paper drops the gradient terms through the optimizee gradients, assuming ∂∇t/∂ϕ=0\partial \nabla_t / \partial \phi = 0. What does this avoid, and what is the cost?Show answer

It avoids computing second derivatives of the objective, which would be expensive for large networks. The cost is that the gradient of the training objective is an approximation, so training follows a slightly different direction than the exact gradient.

QuestionA researcher trains a learned optimizer on sigmoid networks and then deploys it on a ReLU network of the same width. What would you expect, given the paper's results?Show answer

The paper found that changing the activation to ReLU changes the learning dynamics enough that the learned optimizer no longer generalizes. Expect it to lose its advantage, so the researcher should test it against baselines on the new architecture before relying on it.

Sources

Read the full paper

Marcin Andrychowicz, Misha Denil, Sergio Gomez et al., 2016. arXiv:1606.04474