mindspore.ops.ApplyAdadelta

class mindspore.ops.ApplyAdadelta[source]

Updates relevant entries according to the adadelta scheme.

\[\begin{split}\begin{array}{ll} \\ accum = \rho * accum + (1 - \rho) * grad^2 \\ \text{update} = \sqrt{\text{accum_update} + \epsilon} * \frac{grad}{\sqrt{accum + \epsilon}} \\ \text{accum_update} = \rho * \text{accum_update} + (1 - \rho) * update^2 \\ var -= lr * update \end{array}\end{split}\]

where \(\rho\) represents rho, \(\epsilon\) represents epsilon.

Inputs of var, accum, accum_update 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.

Inputs:
  • var (Parameter) - Weights 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, has the same shape and data type as var.

  • accum_update (Parameter) - Accum_update to be updated, has the same shape and data type as var.

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

  • rho (Union[Number, Tensor]) - Decay rate, must be a scalar. With float32 or float16 data type.

  • epsilon (Union[Number, Tensor]) - A small value added for numerical stability, must be a scalar. With float32 or float16 data type.

  • grad (Tensor) - Gradients, has the same shape and data type as var.

Outputs:

Tuple of 3 Tensor, the updated parameters.

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

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

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

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

  • TypeError – If accum_update, lr, rho or epsilon is neither a Number nor a Tensor.

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

Supported Platforms:

Ascend

Examples

>>> class Net(nn.Cell):
...     def __init__(self):
...         super(Net, self).__init__()
...         self.apply_adadelta = ops.ApplyAdadelta()
...         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")
...         self.accum_update = Parameter(Tensor(np.array([[0.9, 0.1],
...                                                        [0.7, 0.8]]).astype(np.float32)),
...                                                             name="accum_update")
...     def construct(self, lr, rho, epsilon, grad):
...         out = self.apply_adadelta(self.var, self.accum, self.accum_update, lr, rho, epsilon, grad)
...         return out
...
>>> net = Net()
>>> lr = Tensor(0.001, mindspore.float32)
>>> rho = Tensor(0.0, mindspore.float32)
>>> epsilon = Tensor(1e-6, mindspore.float32)
>>> grad = Tensor(np.array([[0.3, 0.7], [0.1, 0.8]]).astype(np.float32))
>>> output = net(lr, rho, epsilon, grad)
>>> print(output)
(Tensor(shape=[2, 2], dtype=Float32, value=
[[ 5.99051356e-01,  3.99683774e-01],
 [ 9.91633832e-02,  4.99105573e-01]]), Tensor(shape=[2, 2], dtype=Float32, value=
[[ 9.00000036e-02,  4.89999980e-01],
 [ 1.00000007e-02,  6.40000045e-01]]), Tensor(shape=[2, 2], dtype=Float32, value=
[[ 8.99990976e-01,  1.00000791e-01],
 [ 6.99930906e-01,  7.99999654e-01]]))