Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.ApplyAdamWithAmsgradV2

class mindspore.ops.ApplyAdamWithAmsgradV2(use_locking=False)[source]

Update var according to the Adam algorithm.

lrt:=learning_rate1β2t/(1β1t)mt:=β1mt1+(1β1)gvt:=β2vt1+(1β2)ggv^t:=max(v^t1,vt)var:=varlrtmt/(v^t+ϵ)

t represents updating step while m represents the 1st moment vector, v represents the 2nd moment vector, v^t represents vhat, lr represents learning rate, g represents grad, β1,β2 represent beta1 and beta2, β1t represents beta1_power, β2t represents beta2_power, var represents the variable to be updated, ϵ represents epsilon.

All of the inputs are consistent with implicit type conversion rules, which ensure that the data types are the same. If they have different data types, the lower precision data type will be converted to the data type with relatively higher precision.

Parameters

use_locking (bool) – If True , updating of the var, m, and v tensors will be protected by a lock; Otherwise the behavior is undefined, but may exhibit less contention. Default: False .

Inputs:
  • var (Parameter) - Variable to be updated. The data type can be float16, float32 or float64.

  • m (Parameter) - The 1st moment vector in the updating formula, the shape should be the same as var.

  • v (Parameter) - The 2nd moment vector in the updating formula, the shape should be the same as var.

  • vhat (Parameter) - v^t in the updating formula, the shape and data type value should be the same as var.

  • beta1_power (Union[float, Tensor]) - beta1t(β1t) in the updating formula, with float16, float32 or float64 data type.

  • beta2_power (Union[float, Tensor]) - beta2t(β2t) in the updating formula, with float16, float32 or float64 data type.

  • lr (Union[float, Tensor]) - Learning rate, with float16, float32 or float64 data type.

  • beta1 (Union[float, Tensor]) - Exponential decay rate of the first moment. The data type can be float16, float32 or float64.

  • beta2 (Union[float, Tensor]) - Exponential decay rate of the second moment. The data type can be float16, float32 or float64.

  • epsilon (Union[float, Tensor]) - A value added to the denominator to ensure numerical stability. The data type can be float16, float32 or float64.

  • grad (Tensor) - The gradient, has the same shape as var.

Outputs:

Tuple of 4 Tensors, the updated parameters.

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

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

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

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

Raises
  • TypeError – If var, m, v, vhat is not a Parameter.

  • TypeError – If dtype of var, m, v, vhat, beta1_power, beta2_power, lr, beta1 , beta2 , epsilon or grad is not float64, float32 or float16.

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

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import ops
>>> import mindspore.nn as nn
>>> from mindspore import Tensor, Parameter
>>> import numpy as np
>>> class ApplyAdamWithAmsgradNet(nn.Cell):
...     def __init__(self, use_locking=False):
...         super(ApplyAdamWithAmsgradNet, self).__init__()
...         self.apply_adam_with_amsgrad = ops.ApplyAdamWithAmsgradV2(use_locking)
...         self.var = Parameter(Tensor(np.array([[0.2, 0.2], [0.2, 0.2]]).astype(np.float32)), name="var")
...         self.m = Parameter(Tensor(np.array([[0.1, 0.2], [0.4, 0.3]]).astype(np.float32)), name="m")
...         self.v = Parameter(Tensor(np.array([[0.2, 0.1], [0.3, 0.4]]).astype(np.float32)), name="v")
...         self.vhat = Parameter(Tensor(np.array([[0.1, 0.2], [0.6, 0.2]]).astype(np.float32)), name="vhat")
...         self.beta1 = 0.8
...         self.beta2 = 0.999
...         self.epsilon = 1e-8
...         self.beta1_power = 0.9
...         self.beta2_power = 0.999
...         self.lr = 0.01
...
...     def construct(self, grad):
...         out = self.apply_adam_with_amsgrad(self.var, self.m, self.v, self.vhat,
...                                            self.beta1_power, self.beta2_power, self.lr,
...                                            self.beta1, self.beta2, self.epsilon, grad)
...         return out
>>> net = ApplyAdamWithAmsgradNet()
>>> grad = Tensor(np.array([[0.4, 0.2], [0.2, 0.3]]).astype(np.float32))
>>> output = net(grad)
>>> print(net.var.asnumpy())
[[0.19886853 0.1985858 ]
[0.19853032 0.19849943]]