mindspore.ops.ApplyGradientDescent
- class mindspore.ops.ApplyGradientDescent(*args, **kwargs)[source]
Updates relevant entries according to the following.
\[var = var - \alpha * \delta\]Inputs of var and delta comply with the implicit type conversion rules to make the data types consistent. If they have different data types, lower priority data type will be converted to relatively highest priority data type. RuntimeError exception will be thrown when the data type conversion of Parameter is required.
- Inputs:
var (Parameter) - Variable tensor to be updated. With float32 or float16 data type.
alpha (Union[Number, Tensor]) - Scaling factor, must be a scalar. With float32 or float16 data type.
delta (Tensor) - A tensor for the change, has the same type as var.
- Outputs:
Tensor, represents the updated var.
- Raises
- Supported Platforms:
Ascend
Examples
>>> import numpy as np >>> import mindspore.nn as nn >>> from mindspore import Tensor, Parameter >>> from mindspore.ops import operations as ops >>> class Net(nn.Cell): ... def __init__(self): ... super(Net, self).__init__() ... self.apply_gradient_descent = ops.ApplyGradientDescent() ... self.var = Parameter(Tensor(np.random.rand(2, 2).astype(np.float32)), name="var") ... self.alpha = 0.001 ... def construct(self, delta): ... out = self.apply_gradient_descent(self.var, self.alpha, delta) ... return out ... >>> net = Net() >>> delta = Tensor(np.random.rand(2, 2).astype(np.float32)) >>> output = net(delta) >>> print(output.shape) (2, 2)