Updates relevant entries according to the adagrad scheme. It has been proposed in Adaptive Subgradient Methods for Online Learning and Stochastic Optimization. This module can adaptively assign different learning rates for each parameter in view of the uneven number of samples for different parameters.

$\begin{split}\begin{array}{ll} \\ accum += grad * grad \\ var -= lr * grad * \frac{1}{\sqrt{accum}} \end{array}\end{split}$

Inputs of var, accum and grad comply with the implicit type conversion rules to make the data types consistent. If they have different data types, the lower priority data type will be converted to the relatively highest priority data type.

Parameters

update_slots (bool) – If True, accum will be updated. Default: True.

Inputs:
• var (Parameter) - Variable to be updated. With float32 or float16 data type. The shape is $$(N, *)$$ where $$*$$ means, any number of additional dimensions.

• accum (Parameter) - Accumulation to be updated. The shape and data type must be the same as var.

• lr (Union[Number, Tensor]) - The learning rate value, must be a scalar. With float32 or float16 data type.

• grad (Tensor) - A tensor for gradient. The shape and data type must be the same as var.

Outputs:

Tuple of 2 Tensors, the updated parameters.

• var (Tensor) - The same shape and data type as var.

• accum (Tensor) - The same shape and data type as accum.

Raises
• TypeError – If dtype of var, accum, lr or grad is neither float16 nor float32.

• TypeError – If lr is neither a Number nor a Tensor.

• RuntimeError – If the data type of var, accum and grad conversion of Parameter is not supported.

Supported Platforms:

Ascend CPU GPU

Examples

>>> class Net(nn.Cell):
...     def __init__(self):
...         super(Net, self).__init__()
...         self.var = Parameter(Tensor(np.array([[0.6, 0.4],
...                                               [0.1, 0.5]]).astype(np.float32)), name="var")
...         self.accum = Parameter(Tensor(np.array([[0.6, 0.5],
...                                                 [0.2, 0.6]]).astype(np.float32)), name="accum")