mindspore2022/docs/api/api_python/nn/mindspore.nn.SGD.rst

65 lines
2.4 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.SGD
================
.. py:class:: mindspore.nn.SGD(*args, **kwargs)
随机梯度下降的实现。动量可选。
SGD相关介绍参见 `SGD <https://en.wikipedia.org/wiki/Stochastic_gradient_dencent>`_
Nesterov动量公式参见论文 `On the importance of initialization and momentum in deep learning <http://proceedings.mlr.press/v28/sutskever13.html>`_
.. math::
v_{t+1} = u \ast v_{t} + gradient \ast (1-dampening)
如果nesterov为True
.. math::
p_{t+1} = p_{t} - lr \ast (gradient + u \ast v_{t+1})
如果nesterov为False
.. math::
p_{t+1} = p_{t} - lr \ast v_{t+1}
需要注意的是,对于训练的第一步 :math:`v_{t+1} = gradient`。其中p、v和u分别表示 `parameters``accum``momentum`
.. note::
.. include:: mindspore.nn.optim_note_weight_decay.rst
**参数:**
- **params** (Union[list[Parameter], list[dict]]): 当 `params` 为会更新的 `Parameter` 列表时,`params` 中的元素必须为类 `Parameter`。当 `params``dict` 列表时,"params"、"lr"、"weight_decay"、"grad_centralization"和"order_params"为可以解析的键。
.. include:: mindspore.nn.optim_group_param.rst
.. include:: mindspore.nn.optim_group_lr.rst
- **weight_decay** : 目前不支持通过参数分组使用不同的weight_decay。
.. include:: mindspore.nn.optim_group_gc.rst
.. include:: mindspore.nn.optim_group_order.rst
- **learning_rate** (Union[float, int, Tensor, Iterable, LearningRateSchedule]): 默认值0.1。
.. include:: mindspore.nn.optim_arg_dynamic_lr.rst
- **momentum** (float): 浮点动量必须大于等于0.0。默认值0.0。
- **dampening** (float): 浮点动量阻尼值必须大于等于0.0。默认值0.0。
- **weight_decay** (float): 权重衰减L2 penalty必须大于等于0。默认值0.0。
- **nesterov** (bool): 启用Nesterov动量。如果使用Nesterov动量必须为正阻尼必须等于0.0。默认值False。
.. include:: mindspore.nn.optim_arg_loss_scale.rst
**输入:**
- **gradients** (tuple[Tensor]) - `params` 的梯度shape与 `params` 相同。
**输出:**
Tensor[bool]值为True。
**异常:**
**ValueError** 动量、阻尼或重量衰减值小于0.0。