Adadelta is yet another variant of AdaGrad. The main difference lies in the fact that it decreases the amount by which the learning rate is adaptive to coordinates. Moreover, traditionally it referred to as not having a learning rate since it uses the amount of change itself as calibration for future change. The algorithm was proposed in [Zeiler, 2012]. It is fairly straightforward, given the discussion of previous algorithms so far.

## 8.9.1. The Algorithm¶

In a nutshell Adadelta uses two state variables, $$\mathbf{s}_t$$ to store a leaky average of the second moment of the gradient and $$\Delta\mathbf{x}_t$$ to store a leaky average of the second moment of the change of parameters in the model itself. Note that we use the original notation and naming of the authors for compatibility with other publications and implementations (there is no other real reason why one should use different Greek variables to indicate a parameter serving the same purpose in momentum, Adagrad, RMSProp, and Adadelta). The parameter du jour is $$\rho$$. We obtain the following leaky updates:

(8.9.1)\begin{split}\begin{aligned} \mathbf{s}_t & = \rho \mathbf{s}_{t-1} + (1 - \rho) \mathbf{g}_t^2, \\ \mathbf{g}_t' & = \sqrt{\frac{\Delta\mathbf{x}_{t-1} + \epsilon}{\mathbf{s}_t + \epsilon}} \odot \mathbf{g}_t, \\ \mathbf{x}_t & = \mathbf{x}_{t-1} - \mathbf{g}_t', \\ \Delta \mathbf{x}_t & = \rho \Delta\mathbf{x}_{t-1} + (1 - \rho) \mathbf{x}_t^2. \end{aligned}\end{split}

The difference to before is that we perform updates with the rescaled gradient $$\mathbf{g}_t'$$ which is computed by taking the ratio between the average squared rate of change and the average second moment of the gradient. The use of $$\mathbf{g}_t'$$ is purely for notational convenience. In practice we can implement this algorithm without the need to use additional temporary space for $$\mathbf{g}_t'$$. As before $$\eta$$ is a parameter ensuring nontrivial numerical results, i.e., avoiding zero step size or infinite variance. Typically we set this to $$\eta = 10^{-5}$$.

## 8.9.2. Implementation¶

Adadelta needs to maintain two state variables for each variable, $$\mathbf{s}_t$$ and $$\Delta\mathbf{x}_t$$. This yields the following implementation.

%mavenRepo snapshots https://oss.sonatype.org/content/repositories/snapshots/

%maven ai.djl:api:0.7.0-SNAPSHOT
%maven ai.djl:basicdataset:0.7.0-SNAPSHOT
%maven org.slf4j:slf4j-api:1.7.26
%maven org.slf4j:slf4j-simple:1.7.26

%maven ai.djl.mxnet:mxnet-engine:0.7.0-SNAPSHOT
%maven ai.djl.mxnet:mxnet-native-auto:1.7.0-a

%load ../utils/plot-utils

import ai.djl.translate.TranslateException;

NDList initAdadeltaStates(int featureDimension) {
NDManager manager = NDManager.newBaseManager();
NDArray sW = manager.zeros(new Shape(featureDimension, 1));
NDArray sB = manager.zeros(new Shape(1));
NDArray deltaW = manager.zeros(new Shape(featureDimension, 1));
NDArray deltaB = manager.zeros(new Shape(1));
return new NDList(sW, deltaW, sB, deltaB);
}

public class Optimization {
float rho = hyperparams.get("rho");
float eps = (float) 1e-5;
for (int i = 0; i < params.size(); i++) {
NDArray param = params.get(i);
NDArray state = states.get(2 * i);
NDArray delta = states.get(2 * i + 1);
// Update parameter, state, and delta
// In-place updates with the '__'i methods (ex. muli)
// state = rho * state + (1 - rho) * param.gradient^2
// rescaledGradient = ((delta + eps)^(1/2) / (state + eps)^(1/2)) * param.gradient
// delta = rho * delta + (1 - rho) * g^2
}
}
}


Choosing $$\rho = 0.9$$ amounts to a half-life time of 10 for each parameter update. This tends to work quite well. We get the following behavior.

AirfoilRandomAccess airfoil = TrainingChapter11.getDataCh11(10, 1500);

int featureDimension = airfoil.getFeatureArraySize();
Map<String, Float> hyperparams = new HashMap<>();
hyperparams.put("rho", rho);
hyperparams, airfoil,
featureDimension, numEpochs);
}


loss: 0.247, 0.105 sec/epoch

REPL.$JShell$122C$TrainingChapter11$LossTime@5d98b869


As usual, for a concise implementation, we simply create an instance of adadelta from the Optimizer class.

Optimizer adadelta = Optimizer.adadelta().optRho(0.9f).build();


[IJava-executor-0] INFO ai.djl.training.listener.LoggingTrainingListener - Training on: 4 GPUs.
[IJava-executor-0] INFO ai.djl.training.listener.LoggingTrainingListener - Load MXNet Engine Version 1.7.0 in 0.089 ms.

Training:    100% |████████████████████████████████████████| Accuracy: 0.67, L2Loss: 0.48

loss: 0.478, 3.246 sec/epoch


## 8.9.3. Summary¶

• Adadelta has no learning rate parameter. Instead, it uses the rate of change in the parameters itself to adapt the learning rate.

• Adadelta requires two state variables to store the second moments of gradient and the change in parameters.

• Adadelta uses leaky averages to keep a running estimate of the appropriate statistics.

## 8.9.4. Exercises¶

1. Adjust the value of $$\rho$$. What happens?

2. Show how to implement the algorithm without the use of $$\mathbf{g}_t'$$. Why might this be a good idea?