AI Logic

Optimizers

AdaDelta

Updated:

How AdaDelta works. Left: the flow of one step, dividing by the moving average of squared gradients and multiplying by the RMS of past updates to determine the update. Right: a graph comparing the MNIST test error of SGD, momentum, and AdaGrad across learning rates with the range of AdaDelta, which stays within 1.83-2.59% when ρ and ε are varied

Background and Overview

AdaDelta is an optimizer that, for each parameter, divides the gradient by the moving average of the squared gradient and then multiplies it by the (square root of the) moving average of past squared updates to determine the update. Zeiler published it as a technical report in 2012.

Zeiler states that he designed the method to fix two weaknesses of AdaGrad.

  • The step size keeps shrinking: AdaGrad divides by the sum of squared gradients, so the denominator grows as training progresses, and eventually the step size becomes nearly 0 and learning stops.
  • A global learning rate must be chosen by hand: Too large a learning rate diverges, and too small a one slows learning. Finding a good value takes effort.

AdaDelta solves the first with a moving average and the second by matching units using past updates. As a result, no learning rate appears in the update rule. The paper also reports that results are not very sensitive to the choice of hyperparameters (the decay rate ρ\rho and the small constant ϵ\epsilon).

Theory (Computation in One Step)

Following Algorithm 1 of the paper, the following computation is performed at each step tt. The computation is element-wise over the parameters, and the two moving averages start from E[g2]0=0E[g^2]_0 = 0 and E[Δx2]0=0E[\Delta x^2]_0 = 0.

  1. Compute the gradient gtg_t on a mini-batch.
  2. Update the moving average of the squared gradient E[g2]tE[g^2]_t.
  3. Compute the update Δxt\Delta x_t by multiplying the gradient by the ratio of the RMS of updates up to the previous step to the RMS of the current gradient.
  4. Update the moving average of the squared update E[Δx2]tE[\Delta x^2]_t (used in the numerator at the next step).
  5. Add the update to the parameters.

In formulas, with decay rate ρ\rho and a small constant ϵ\epsilon:

E[g2]t=ρ E[g2]t−1+(1−ρ) gt2E[g^2]_t = \rho\, E[g^2]_{t-1} + (1-\rho)\, g_t^2 Δxt=−RMS[Δx]t−1RMS[g]t gt,RMS[y]t=E[y2]t+ϵ\Delta x_t = -\frac{\mathrm{RMS}[\Delta x]_{t-1}}{\mathrm{RMS}[g]_t}\, g_t, \qquad \mathrm{RMS}[y]_t = \sqrt{E[y^2]_t + \epsilon} E[Δx2]t=ρ E[Δx2]t−1+(1−ρ) Δxt2,xt+1=xt+ΔxtE[\Delta x^2]_t = \rho\, E[\Delta x^2]_{t-1} + (1-\rho)\, \Delta x_t^2, \qquad x_{t+1} = x_t + \Delta x_t

The denominator RMS[g]t\mathrm{RMS}[g]_t is the same "recent gradient magnitude" as in RMSprop. The paper's intermediate Eq. (10), Δxt=−η gt/RMS[g]t\Delta x_t = -\eta\, g_t / \mathrm{RMS}[g]_t with the learning rate η\eta in the numerator, has the same form as RMSprop. AdaDelta replaces this η\eta with RMS[Δx]t−1\mathrm{RMS}[\Delta x]_{t-1}.

The ϵ\epsilon in the numerator plays two roles. At the first step, E[Δx2]0=0E[\Delta x^2]_0 = 0, so without ϵ\epsilon the numerator would be 0 and the parameters would never move. It also keeps updates of at least about ϵ\sqrt{\epsilon} even when updates become small, preventing learning from stalling.

Why No Learning Rate Is Needed (Matching Units)

The paper chooses the numerator based on the idea that the units of the update Δx\Delta x should match the units of the parameter xx. If a parameter has units of length (meters), the update added to it should also be in meters.

  • SGD and momentum have mismatched units: If the loss ff is unitless, the update is proportional to the gradient ∂f/∂x\partial f / \partial x, so its units are "the inverse of the units of xx".
  • AdaGrad and RMSprop also have mismatched units: They divide the gradient by its magnitude, so the update is unitless.
  • Newton's method has matching units: Δx=(∂f/∂x)/(∂2f/∂x2)\Delta x = (\partial f / \partial x) / (\partial^2 f / \partial x^2) has the units of xx.

Rearranging Newton's method (assuming a diagonal Hessian) gives the following relation.

1∂2f/∂x2=Δx∂f/∂x\frac{1}{\partial^2 f / \partial x^2} = \frac{\Delta x}{\partial f / \partial x}

The "gradient magnitude" in the denominator can be represented by RMS[g]t\mathrm{RMS}[g]_t. The numerator needs the magnitude of the update, but the current step's Δxt\Delta x_t is not yet known. So, assuming the curvature changes smoothly, the RMS of updates up to the previous step is used instead. This is the numerator RMS[Δx]t−1\mathrm{RMS}[\Delta x]_{t-1} in the formula. The ratio of numerator to denominator is a "per-parameter step size" with the units of xx, so no separate learning rate is needed.

The paper explains that this formula shares some properties of other methods.

  • Like SGD, it always moves opposite to the gradient: The ratio is always positive, so the direction stays −gt-g_t.
  • The numerator accumulates past information like momentum: It remembers the magnitude of past updates over a window of time.
  • The denominator, like AdaGrad, balances progress across dimensions: But because it is a moving average, progress continues late in training.
  • Because the numerator lags by one step, it is robust to sudden large gradients: The denominator grows first while the numerator has not yet reacted, so the step size for that step becomes small.

Experimental Results

The paper compares AdaDelta with SGD, momentum, and AdaGrad on MNIST handwritten digit classification and large-scale speech recognition. In every experiment, AdaDelta uses ϵ=10−6\epsilon = 10^{-6} and ρ=0.95\rho = 0.95.

Robustness to hyperparameters (MNIST, test error after 6 epochs). The right side of the figure at the top plots the values of Tables 1 and 2 below.

MethodSetting variedTest error (best to worst)
SGD5 learning rates from 11 to 10−410^{-4}2.26% to 58.10%
Momentum5 learning rates from 11 to 10−410^{-4}2.03% to 89.68%
AdaGrad5 learning rates from 11 to 10−410^{-4}1.79% to 43.76%
AdaDelta12 combinations of ρ∈{0.9,0.95,0.99}\rho \in \{0.9, 0.95, 0.99\} × ϵ∈{10−2,10−4,10−6,10−8}\epsilon \in \{10^{-2}, 10^{-4}, 10^{-6}, 10^{-8}\}1.83% to 2.59%

The network has two layers (500 and 300 units) with ReLU. For SGD, momentum, and AdaGrad, a learning rate of the wrong order of magnitude either diverges (too large) or fails to make progress (too small). AdaDelta stays within one point across all 12 combinations.

The header of Table 1 in the paper says "ϵ\epsilon", but the text explains that the learning rate was varied. The table above treats it as the learning rate.

Other results are as follows.

  • MNIST (tanh, 6 epochs): Test error of 2.00%, below the 2.10% of the method by Schaul et al. it was compared with.
  • MNIST (ReLU, 50 epochs): AdaGrad does well for the first 10 epochs but then slows as its denominator keeps growing. AdaDelta starts decreasing about as fast as AdaGrad and keeps lowering the error afterward, approaching momentum, which was the best. In the later stages of training, however, momentum with a tuned learning rate gave better results.
  • Speech recognition (4 layers of 2560 units each, distributed training with 100 or 200 replicas): In the 100-replica experiment, frame accuracy was higher than AdaGrad from the beginning to the end of training. In the 200-replica experiment, with the same settings as MNIST, it reached the same accuracy as the other methods quickly.

The paper also examines the actual step size (the ratio of numerator to denominator) of each layer. Early in training, lower layers, whose gradients tend to be small, get larger step sizes, which works to compensate for vanishing gradients. At the end of training, both gradients and updates become small and ϵ\epsilon takes effect, so the step size approaches 1 while the update itself approaches 0. Behavior similar to gradually decreasing the learning rate emerges naturally.

Practical Considerations

PyTorch's torch.optim.Adadelta has a learning rate lr (default 1.0), and its default decay rate rho is 0.9, different from the paper (0.95). lr is just a coefficient multiplied into the computed Δxt\Delta x_t at the end, and E[Δx2]E[\Delta x^2] accumulates the value before multiplication. To match the paper's computation, keep lr=1.0. To keep AdaDelta's advantage of not tuning the learning rate yourself, it is natural not to include lr in a search.

The meaning and defaults of the PyTorch arguments are as follows.

ArgumentMeaningDefault
lrCoefficient multiplied into the computed update1.0
rhoDecay rate ρ\rho of the two moving averages0.9
epsϵ\epsilon added inside the square roots of both numerator and denominator10−610^{-6}
weight_decayStrength of L2 regularization that adds λx\lambda x to the gradient0
  • The initial step size is set by ϵ\epsilon: At the first step the numerator is ϵ\sqrt{\epsilon}, so if the gradient is large enough, the step is about ϵ/(1−ρ)\sqrt{\epsilon / (1-\rho)}. That is about 0.0045 with the paper's settings and about 0.0032 with PyTorch's defaults. ϵ\epsilon effectively acts as a "learning rate" that sets the step size at the start of training.
  • Oscillation can remain late in training: The paper notes that oscillation near the minimum accumulates in the numerator and could be why it loses to momentum later on. Adding a learning-rate schedule is left as future work in the paper.
  • State is twice the parameter count: It keeps E[g2]E[g^2] and E[Δx2]E[\Delta x^2], so it uses as much memory as Adam.
  • weight_decay acts as L2 regularization: The λx\lambda x added to the gradient is also divided by the RMS, so weights shrink unevenly from one weight to another.

Comparison with Other Optimizers

Methods that adapt the step size per parameter, side by side:

MethodDenominator (gradient magnitude)NumeratorLearning rateGradient average (momentum)Extra memory
AdaGradSum of squared gradientsLearning rate η\etaRequiredNot used1× parameters
RMSpropMoving average of squared gradientsLearning rate η\etaRequiredNot used1× parameters
AdaDeltaMoving average of squared gradientsRMS of past updatesNot required (ϵ\epsilon sets the initial step)Not used2× parameters
AdamMoving average of squared gradients (bias-corrected)Learning rate η\etaRequiredUsed2× parameters

Rough guidelines for choosing:

  • If there is no time to tune the learning rate, use AdaDelta: In the paper's experiments, results barely changed even when ρ\rho and ϵ\epsilon were varied widely.
  • To squeeze out final accuracy, use Adam or SGD with momentum plus a learning-rate schedule: The AdaDelta paper itself reports that momentum came out ahead later in training.
  • For sparse features without long training, AdaGrad is also a candidate: It can move rare features more.

PyTorch example

Show code
python
import torch
import torch.nn as nn


# One AdaDelta step, written exactly as in Algorithm 1 of the paper
def adadelta_step(x, grad, eg2, edx2, rho=0.95, eps=1e-6):
    eg2 = rho * eg2 + (1 - rho) * grad ** 2                    # moving average of squared gradient E[g^2]_t
    dx = -torch.sqrt(edx2 + eps) / torch.sqrt(eg2 + eps) * grad  # multiply by RMS[Δx]_{t-1} / RMS[g]_t
    edx2 = rho * edx2 + (1 - rho) * dx ** 2                    # moving average of squared update E[Δx^2]_t
    return x + dx, eg2, edx2


# Check that it matches PyTorch's Adadelta (lr=1.0 gives the same computation as the paper)
torch.manual_seed(0)
w = torch.randn(5, requires_grad=True)
w_manual = w.detach().clone()
eg2 = torch.zeros_like(w_manual)       # E[g^2]_0 = 0
edx2 = torch.zeros_like(w_manual)      # E[Δx^2]_0 = 0
optimizer = torch.optim.Adadelta([w], lr=1.0, rho=0.95, eps=1e-6)  # paper's settings (PyTorch default is rho=0.9)

for t in range(10):
    loss = ((w - 3.0) ** 2).sum()
    optimizer.zero_grad()
    loss.backward()
    grad = w.grad.detach().clone()
    optimizer.step()
    w_manual, eg2, edx2 = adadelta_step(w_manual, grad, eg2, edx2)

print(torch.allclose(w.detach(), w_manual, atol=1e-6))  # should be True


# Usage in actual training (2-layer network for MNIST; no learning-rate search)
model = nn.Sequential(nn.Flatten(), nn.Linear(784, 500), nn.ReLU(),
                      nn.Linear(500, 300), nn.ReLU(), nn.Linear(300, 10))
optimizer = torch.optim.Adadelta(model.parameters(), lr=1.0, rho=0.95, eps=1e-6)

x = torch.randn(100, 1, 28, 28)        # dummy mini-batch (100 images, as in the paper)
y = torch.randint(0, 10, (100,))
loss = nn.functional.cross_entropy(model(x), y)
optimizer.zero_grad()
loss.backward()
optimizer.step()

FAQ

Q. Does AdaDelta really not need a learning rate?
A.

The paper's update rule has no learning rate. However, the initial step size is about ϵ/(1−ρ)\sqrt{\epsilon / (1-\rho)}, so ϵ\epsilon plays a role similar to a learning rate. In the paper's experiments, varying ϵ\epsilon from 10−210^{-2} to 10−810^{-8} kept the MNIST error within 1.83-2.59%. Keep PyTorch's lr at 1.0.

Q. What is the difference between AdaDelta and RMSprop?
A.

Both use the square root of the moving average of squared gradients as the denominator. RMSprop uses the learning rate η\eta as the numerator, while AdaDelta uses the RMS of past updates, matching the units of the update to those of the parameters. As a result, AdaDelta has no learning rate and keeps state twice the size of the parameters.

Q. Is there still a case for choosing AdaDelta today?
A.

It is a candidate for small experiments where spending time on learning-rate search is undesirable. On the other hand, even in the paper momentum came out ahead later in training, and in deep learning it is more common to combine Adam or AdamW with a learning-rate schedule.

References

  1. M. D. Zeiler, "ADADELTA: An Adaptive Learning Rate Method," arXiv:1212.5701, 2012.
  2. J. Duchi, E. Hazan, and Y. Singer, "Adaptive Subgradient Methods for Online Learning and Stochastic Optimization," Journal of Machine Learning Research, 12, 2011.
  3. PyTorch Documentation, "torch.optim.Adadelta."