!36119 Fix issue I5C8D0, boost readme

Merge pull request !36119 from archer2049/code_docs_master
This commit is contained in:
i-robot 2022-06-20 08:55:39 +00:00 committed by Gitee
commit d1900ed95e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 90 additions and 24 deletions

View File

@ -148,19 +148,19 @@ Boost能够自动加速网络如减少BN/梯度冻结/累积梯度等。
- **ValueError** Boost的模式不在["auto", "manual", "enable_all", "disable_all"]这个列表中。
.. py:method:: network_auto_process_eval(network)
使用Boost算法推理。
**参数:**
**network** (Cell) - 推理网络。
.. py:method:: network_auto_process_train(network, optimizer)
使用Boost算法训练。
**参数:**
- **network** (Cell) - 训练网络。
- **optimizer** (Union[Cell]) - 用于更新权重的优化器。
@ -253,36 +253,36 @@ Boost能够自动加速网络如减少BN/梯度冻结/累积梯度等。
- **TypeError** 如果 `sens` 不是一个数字。
.. py:method:: adasum_process(loss, grads)
使用Adasum算法训练。
**参数:**
- **loss** (Tensor) 网络训练的loss值。
- **grads** (Tuple(Tensor)) 网络训练过程中的梯度。
**返回:**
Tensor网络训练过程中得到的loss值。
.. py:method:: check_adasum_enable()
Adasum算法仅在多卡或者多机场景生效并且要求卡数符合2的n次方该函数用来判断adasum算法能否生效。
**返回:**
enable_adasum (bool)Adasum算法是否生效。
.. py:method:: check_dim_reduce_enable()
获取当前是否使用降维二阶训练算法训练。
**返回:**
enable_dim_reduce (bool),降维二阶训练算法是否生效。
.. py:method:: gradient_accumulation_process(loss, grads, sens, *inputs)
使用梯度累积算法训练。
**参数:**
@ -291,21 +291,21 @@ Boost能够自动加速网络如减少BN/梯度冻结/累积梯度等。
- **grads** (Tuple(Tensor)) 网络训练过程中的梯度。
- **sens** (Tensor) 作为反向传播输入要填充的缩放数。
- **inputs** (Tuple(Tensor)) 网络训练的输入。
**返回:**
Tensor网络训练过程中得到的loss值。
.. py:method:: gradient_freeze_process(*inputs)
使用梯度冻结算法训练。
**参数:**
- **inputs** (Tuple(Tensor)) 网络训练的输入。
**返回:**
Tensor网络训练过程中得到的loss值。
.. py:class:: mindspore.boost.BoostTrainOneStepWithLossScaleCell(network, optimizer, scale_sense)
@ -505,5 +505,62 @@ Boost能够自动加速网络如减少BN/梯度冻结/累积梯度等。
- **loss** (Tensor) - 网络loss标量Tensor。
.. py:class:: mindspore.boost.GroupLossScaleManager(init_loss_scale, loss_scale_groups)
增强型混合精度算法支持不同损失尺度的多层应用和损失尺度的动态更新。
**参数:**
- **init_loss_scale** (Number) - 初始化loss scale。
- **loss_scale_groups** (List) - 从参数列表里分离出来的loss scale组。
**输入:**
- **x** (Tensor) - 最后一个operator的输出。
- **layer1** (int) - 当前网络层的值。
- **layer2** (int) - 最后一个网络层的值。
**输出:**
- **x** (Tensor) - _DynamicLossScale operator的输出。
.. py:method:: get_loss_scale()
获取loss scale的值。
**返回:**
bool`loss_scale` 的值。
.. py:method:: get_update_cell()
返回 :class:`mindspore.boost.GroupLossScaleManager` 实例。
**返回:**
:class:`mindspore.boost.GroupLossScaleManager` 实例。
.. py:method:: get_loss_scale_status(loss_scale_number, init_loss_scale)
生成动态loss scale元组并设置溢出状态列表。
**参数:**
- **loss_scale_number** (int) - loss scale的数量。
- **init_loss_scale** (float) - 已初始化的loss scale。
.. py:method:: update_loss_scale_status(layer, update_ratio)
更新动态loss scale。
**参数:**
- **layer** (int) - 当前层。
- **update_ratio** (float) - 更新loss scale的当前比例。
**输出:**
float新loss scale值。
.. automodule:: mindspore.boost
:members:

View File

@ -34,7 +34,9 @@
- "O1": 启用boost模式, 性能将提升约20%, 准确率保持不变。
- "O2": 启用boost模式, 性能将提升约30%, 准确率下降小于3%。
如果你想设置boost模式, 可以将 `boost_config_dict` 设置为 `boost.py`
如果想自行配置boost模式, 可以将 `boost_config_dict` 设置为 `boost.py`
为使功能生效需要同时设置optimizer、eval_network或metric参数。
注意:当前默认开启的优化仅适用部分网络,并非所有网络都能获得相同收益。建议在图模式+Ascend平台下开启该模式同时为了获取更好的加速效果请参考文档配置boost_config_dict。
.. py:method:: build(train_dataset=None, valid_dataset=None, sink_size=-1, epoch=1, jit_config=None)

View File

@ -146,7 +146,13 @@ class Model:
the accuracy is reduced by less than 3%.
If you want to config boost mode by yourself, you can set boost_config_dict as `boost.py`.
In order for this function to work, you need to set the optimizer, eval_network or metric parameters
at the same time.
Notice: The current optimization enabled by default only applies to some networks, and not all networks
can obtain the same benefits. It is recommended to enable this function on
the Graph mode + Ascend platform, and for better acceleration, refer to the documentation to configure
boost_config_dict.
Examples:
>>> import mindspore as ms
>>> from mindspore import nn
@ -233,6 +239,7 @@ class Model:
self._loss_scale_manager_set = True
def _check_amp_level_arg(self, optimizer, amp_level):
"""Check amp level arg"""
if optimizer is None and amp_level != "O0":
raise ValueError(
"Auto mixed precision will not work because 'optimizer' is None.Please set amp_level='O0' "