!2111 fix error in examples of SparseApplyAdam and SparseApplyLazyAdam

Merge pull request !2111 from wangnan39/modify_annotation_of_sparse_adam
This commit is contained in:
mindspore-ci-bot 2020-06-15 19:45:55 +08:00 committed by Gitee
commit 09b5221c6a
1 changed files with 43 additions and 29 deletions

View File

@ -2773,17 +2773,18 @@ class SparseApplyAdam(PrimitiveWithInfer):
If False, updates the gradients without using NAG. Default: False. If False, updates the gradients without using NAG. Default: False.
Inputs: Inputs:
- **var** (Parameter) - Parameters to be updated. - **var** (Parameter) - Parameters to be updated. With float32 data type.
- **m** (Parameter) - The 1st moment vector in the updating formula. Has the same type as `var`. - **m** (Parameter) - The 1st moment vector in the updating formula. Has the same type as `var`. With
float32 data type.
- **v** (Parameter) - The 2nd moment vector in the updating formula. Mean square gradients, - **v** (Parameter) - The 2nd moment vector in the updating formula. Mean square gradients,
has the same type as `var`. has the same type as `var`. With float32 data type.
- **beta1_power** (float) - :math:`beta_1^t` in the updating formula. - **beta1_power** (Tensor) - :math:`beta_1^t` in the updating formula. With float32 data type.
- **beta2_power** (float) - :math:`beta_2^t` in the updating formula. - **beta2_power** (Tensor) - :math:`beta_2^t` in the updating formula. With float32 data type.
- **lr** (float) - :math:`l` in the updating formula. - **lr** (Tensor) - :math:`l` in the updating formula. With float32 data type.
- **beta1** (float) - The exponential decay rate for the 1st moment estimates. - **beta1** (Tensor) - The exponential decay rate for the 1st moment estimates. With float32 data type.
- **beta2** (float) - The exponential decay rate for the 2nd moment estimates. - **beta2** (Tensor) - The exponential decay rate for the 2nd moment estimates. With float32 data type.
- **epsilon** (float) - Term added to the denominator to improve numerical stability. - **epsilon** (Tensor) - Term added to the denominator to improve numerical stability. With float32 data type.
- **gradient** (Tensor) - Gradient value. - **gradient** (Tensor) - Gradient value. With float32 data type.
- **indices** (Tensor) - Gradient indices. With int32 data type. - **indices** (Tensor) - Gradient indices. With int32 data type.
Outputs: Outputs:
@ -2803,17 +2804,23 @@ class SparseApplyAdam(PrimitiveWithInfer):
>>> def __init__(self): >>> def __init__(self):
>>> super(Net, self).__init__() >>> super(Net, self).__init__()
>>> self.sparse_apply_adam = P.SparseApplyAdam() >>> self.sparse_apply_adam = P.SparseApplyAdam()
>>> self.var = Parameter(Tensor(np.ones([3, 3, 3]).astype(np.float32)), name="var") >>> self.var = Parameter(Tensor(np.ones([3, 1, 2]).astype(np.float32)), name="var")
>>> self.m = Parameter(Tensor(np.ones([3, 3, 3]).astype(np.float32)), name="m") >>> self.m = Parameter(Tensor(np.ones([3, 1, 2]).astype(np.float32)), name="m")
>>> self.v = Parameter(Tensor(np.ones([3, 3, 3]).astype(np.float32)), name="v") >>> self.v = Parameter(Tensor(np.ones([3, 1, 2]).astype(np.float32)), name="v")
>>> def construct(self, beta1_power, beta2_power, lr, beta1, beta2, epsilon, grad, indices): >>> def construct(self, beta1_power, beta2_power, lr, beta1, beta2, epsilon, grad, indices):
>>> out = self.sparse_apply_adam(self.var, self.m, self.v, beta1_power, beta2_power, lr, beta1, beta2, >>> out = self.sparse_apply_adam(self.var, self.m, self.v, beta1_power, beta2_power, lr, beta1, beta2,
>>> epsilon, grad, indices) >>> epsilon, grad, indices)
>>> return out >>> return out
>>> net = Net() >>> net = Net()
>>> gradient = Tensor(np.random.rand(3, 3, 3).astype(np.float32)) >>> beta1_power = Tensor(0.9, mstype.float32)
>>> indices = Tensor([0, 1, 2], mstype.int32) >>> beta2_power = Tensor(0.999, mstype.float32)
>>> result = net(0.9, 0.999, 0.001, 0.9, 0.999, 1e-8, gradient, indices) >>> lr = Tensor(0.001, mstype.float32)
>>> beta1 = Tensor(0.9, mstype.float32)
>>> beta2 = Tensor(0.999, mstype.float32)
>>> epsilon = Tensor(1e-8, mstype.float32)
>>> gradient = Tensor(np.random.rand(2, 1, 2), mstype.float32)
>>> indices = Tensor([0, 1], mstype.int32)
>>> result = net(beta1_power, beta2_power, lr, beta1, beta2, epsilon, gradient, indices)
""" """
__mindspore_signature__ = ( __mindspore_signature__ = (
('var', sig_rw.RW_WRITE, sig_kind.KIND_POSITIONAL_KEYWORD, sig_kind.KIND_EMPTY_DEFAULT_VALUE, sig_dtype.T), ('var', sig_rw.RW_WRITE, sig_kind.KIND_POSITIONAL_KEYWORD, sig_kind.KIND_EMPTY_DEFAULT_VALUE, sig_dtype.T),
@ -2900,17 +2907,18 @@ class SparseApplyLazyAdam(PrimitiveWithInfer):
If False, updates the gradients without using NAG. Default: False. If False, updates the gradients without using NAG. Default: False.
Inputs: Inputs:
- **var** (Parameter) - Weights to be updated. - **var** (Parameter) - Parameters to be updated. With float32 data type.
- **m** (Parameter) - The 1st moment vector in the updating formula. Has the same type as `var`. - **m** (Parameter) - The 1st moment vector in the updating formula. Has the same type as `var`. With
float32 data type.
- **v** (Parameter) - The 2nd moment vector in the updating formula. Mean square gradients, - **v** (Parameter) - The 2nd moment vector in the updating formula. Mean square gradients,
has the same type as `var`. has the same type as `var`. With float32 data type.
- **beta1_power** (float) - :math:`beta_1^t` in the updating formula. - **beta1_power** (Tensor) - :math:`beta_1^t` in the updating formula. With float32 data type.
- **beta2_power** (float) - :math:`beta_2^t` in the updating formula. - **beta2_power** (Tensor) - :math:`beta_2^t` in the updating formula. With float32 data type.
- **lr** (float) - :math:`l` in the updating formula. - **lr** (Tensor) - :math:`l` in the updating formula. With float32 data type.
- **beta1** (float) - The exponential decay rate for the 1st moment estimates. - **beta1** (Tensor) - The exponential decay rate for the 1st moment estimates. With float32 data type.
- **beta2** (float) - The exponential decay rate for the 2nd moment estimates. - **beta2** (Tensor) - The exponential decay rate for the 2nd moment estimates. With float32 data type.
- **epsilon** (float) - Term added to the denominator to improve numerical stability. - **epsilon** (Tensor) - Term added to the denominator to improve numerical stability. With float32 data type.
- **gradient** (Tensor) - Gradient value. - **gradient** (Tensor) - Gradient value. With float32 data type.
- **indices** (Tensor) - Gradient indices. With int32 data type. - **indices** (Tensor) - Gradient indices. With int32 data type.
Outputs: Outputs:
@ -2938,9 +2946,15 @@ class SparseApplyLazyAdam(PrimitiveWithInfer):
>>> beta2, epsilon, grad, indices) >>> beta2, epsilon, grad, indices)
>>> return out >>> return out
>>> net = Net() >>> net = Net()
>>> gradient = Tensor(np.random.rand(3, 3, 3).astype(np.float32)) >>> beta1_power = Tensor(0.9, mstype.float32)
>>> indices = Tensor([0, 1, 2], mstype.int32) >>> beta2_power = Tensor(0.999, mstype.float32)
>>> result = net(0.9, 0.999, 0.001, 0.9, 0.999, 1e-8, gradient, indices) >>> lr = Tensor(0.001, mstype.float32)
>>> beta1 = Tensor(0.9, mstype.float32)
>>> beta2 = Tensor(0.999, mstype.float32)
>>> epsilon = Tensor(1e-8, mstype.float32)
>>> gradient = Tensor(np.random.rand(2, 1, 2), mstype.float32)
>>> indices = Tensor([0, 1], mstype.int32)
>>> result = net(beta1_power, beta2_power, lr, beta1, beta2, epsilon, gradient, indices)
""" """
__mindspore_signature__ = ( __mindspore_signature__ = (
('var', sig_rw.RW_WRITE, sig_kind.KIND_POSITIONAL_KEYWORD, sig_kind.KIND_EMPTY_DEFAULT_VALUE, sig_dtype.T), ('var', sig_rw.RW_WRITE, sig_kind.KIND_POSITIONAL_KEYWORD, sig_kind.KIND_EMPTY_DEFAULT_VALUE, sig_dtype.T),