You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.nn.AdamWeightDecay.rst 2.9 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. mindspore.nn.AdamWeightDecay
  2. ===============================
  3. .. py:class:: mindspore.nn.AdamWeightDecay(params, learning_rate=1e-3, beta1=0.9, beta2=0.999, eps=1e-6, weight_decay=0.0)
  4. 权重衰减Adam算法的实现。
  5. .. math::
  6. \begin{array}{ll} \\
  7. m_{t+1} = \beta_1 * m_{t} + (1 - \beta_1) * g \\
  8. v_{t+1} = \beta_2 * v_{t} + (1 - \beta_2) * g * g \\
  9. update = \frac{m_{t+1}}{\sqrt{v_{t+1}} + eps} \\
  10. update =
  11. \begin{cases}
  12. update + weight\_decay * w_{t}
  13. & \text{ if } weight\_decay > 0 \\
  14. update
  15. & \text{ otherwise }
  16. \end{cases} \\
  17. w_{t+1} = w_{t} - lr * update
  18. \end{array}
  19. :math:`m` 表示第1矩向量 `moment1` , :math:`v` 表示第2矩向量 `moment2`, :math:`g` 表示 `gradients` ,:math:`lr` 表示 `learning_rate` ,:math:`\beta_1, \beta_2` 表示 `beta1` 和 `beta2` , :math:`t` 表示当前step,:math:`w` 表示 `params`。
  20. .. note::
  21. .. include:: mindspore.nn.optim_note_loss_scale.rst
  22. .. include:: mindspore.nn.optim_note_weight_decay.rst
  23. **参数:**
  24. - **params** (Union[list[Parameter], list[dict]]) - 必须是 `Parameter` 组成的列表或字典组成的列表。当列表元素是字典时,字典的键可以是"params"、"lr"、"weight_decay"、和"order_params":
  25. .. include:: mindspore.nn.optim_group_param.rst
  26. .. include:: mindspore.nn.optim_group_lr.rst
  27. .. include:: mindspore.nn.optim_group_weight_decay.rst
  28. .. include:: mindspore.nn.optim_group_order.rst
  29. - **learning_rate** (Union[float, Tensor, Iterable, LearningRateSchedule]): 默认值:1e-3。
  30. .. include:: mindspore.nn.optim_arg_dynamic_lr.rst
  31. - **beta1** (float):`moment1` 的指数衰减率。参数范围(0.0,1.0)。默认值:0.9。
  32. - **beta2** (float):`moment2` 的指数衰减率。参数范围(0.0,1.0)。默认值:0.999。
  33. - **eps** (float) - 将添加到分母中,以提高数值稳定性。必须大于0。默认值:1e-6。
  34. - **weight_decay** (float) - 权重衰减(L2 penalty)。必须大于等于0。默认值:0.0。
  35. **输入:**
  36. **gradients** (tuple[Tensor]) - `params` 的梯度,shape与 `params` 相同。
  37. **输出:**
  38. tuple[bool],所有元素都为True。
  39. **异常:**
  40. - **TypeError** - `learning_rate` 不是int、float、Tensor、Iterable或LearningRateSchedule。
  41. - **TypeError** - `parameters` 的元素不是Parameter或字典。
  42. - **TypeError** - `beta1` 、 `beta2` 或 `eps` 不是float。
  43. - **TypeError** - `weight_decay` 不是float或int。
  44. - **ValueError** - `eps` 小于等于0。
  45. - **ValueError** - `beta1` 、 `beta2` 不在(0.0,1.0)范围内。
  46. - **ValueError** - `weight_decay` 小于0。