mindspore.experimental.optim.Adadelta
- class mindspore.experimental.optim.Adadelta(params, lr=1.0, rho=0.9, eps=1e-6, weight_decay=0.0, *, maximize=False)[source]
Implements Adadelta algorithm.
\[ \begin{align}\begin{aligned}\newcommand{\grad}[2]{\nabla_{#1} f_{#2}(#2_{#2 - 1})} \newcommand{\updateVar}[3]{#1_{#2} \leftarrow #1_{#2 - 1} \rho + #3_{#2} (1 - \rho)}\\\begin{split}\begin{align*} &\rule{150mm}{0.4pt} \\ &\textbf{Input}: \gamma \text{ (lr)}, \: \theta_0 \text{ (params)}, \: f(\theta) \text{ (objective)}, \: \rho \text{ (decay)}, \: \lambda \text{ (weight decay)} \\ &\textbf{Initialize}: \begin{cases} v_0 \leftarrow 0 \text{ (square avg)} \\ u_0 \leftarrow 0 \text{ (accumulate variables)} \end{cases} \\ &\rule{110mm}{0.4pt} \\ &\textbf{For } t = 1 \text{ to } \ldots \text{ do}: \\ &\quad g_t \leftarrow \grad{\theta}{t} \\ &\quad \text{If } \lambda \neq 0: \\ &\quad\quad g_t \leftarrow g_t + \lambda \theta_{t - 1} \\ &\quad v_t \leftarrow \updateVar{v}{t}{g^2} \\ &\quad \Delta x_t \leftarrow \frac{\sqrt{u_{t - 1} + \epsilon}}{\sqrt{v_t + \epsilon}} g_t \\ &\quad u_t \leftarrow \updateVar{u}{t}{\Delta x^2} \\ &\quad \theta_t \leftarrow \theta_{t - 1} - \gamma \Delta x_t \\ &\rule{110mm}{0.4pt} \\ &\bf{Return}: \theta_t \\ &\rule{110mm}{0.4pt} \end{align*}\end{split}\end{aligned}\end{align} \]Warning
This is an experimental optimizer API that is subject to change. This module must be used with lr scheduler module in LRScheduler Class .
- Parameters
params (Union[list(Parameter), list(dict)]) – list of parameters to optimize or dicts defining parameter groups.
lr (Union[int, float, Tensor], optional) – learning rate. Default:
1.0
.rho (float, optional) – coefficient used for computing a running average of squared gradients. \(\rho\) in the formula above. Default:
0.9
.eps (float, optional) – term added to the denominator to improve numerical stability. \(\epsilon\) in the formula above. Default:
1e-6
.weight_decay (float, optional) – weight decay (L2 penalty). Default:
0.
.
- Keyword Arguments
maximize (bool, optional) – maximize the params based on the objective, instead of minimizing. Default:
False
.
- Inputs:
gradients (tuple[Tensor]) - The gradients of params.
- Raises
ValueError – If the learning rate is not int, float or Tensor.
ValueError – If the learning rate is less than 0.
ValueError – If the eps is less than or equal to 0.0.
ValueError – If the rho is not in the range of [0, 1].
ValueError – If the weight_decay is less than 0.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> from mindspore import nn >>> from mindspore.experimental import optim >>> # Define the network structure of LeNet5. Refer to >>> # https://gitee.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py >>> net = LeNet5() >>> loss_fn = nn.SoftmaxCrossEntropyWithLogits(sparse=True) >>> optimizer = optim.Adadelta(net.trainable_params(), lr=0.1) >>> def forward_fn(data, label): ... logits = net(data) ... loss = loss_fn(logits, label) ... return loss, logits >>> grad_fn = mindspore.value_and_grad(forward_fn, None, optimizer.parameters, has_aux=True) >>> def train_step(data, label): ... (loss, _), grads = grad_fn(data, label) ... optimizer(grads) ... return loss