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