diff --git a/mindspore/train/amp.py b/mindspore/train/amp.py index d5df952a9d7..f0e7d21b5ac 100644 --- a/mindspore/train/amp.py +++ b/mindspore/train/amp.py @@ -124,26 +124,26 @@ def build_train_network(network, optimizer, loss_fn=None, level='O0', **kwargs): - O0: Do not change. - O2: Cast network to float16, keep batchnorm and `loss_fn` (if set) run in float32, using dynamic loss scale. - - O3: Cast network to float16, with additional property `keep_batchnorm_fp32=False`. + - O3: Cast network to float16, with additional property `keep_batchnorm_fp32=False` . - auto: Set to level to recommended level in different devices. Set level to O2 on GPU, Set level to O3 Ascend. The recommended level is choose by the export experience, cannot always general. User should specify the level for special network. O2 is recommended on GPU, O3 is recommended on Ascend.Property of `keep_batchnorm_fp32` , `cast_model_type` - and `loss_scale_manager` determined by `level` setting may be overwritten by settings in `kwargs`. + and `loss_scale_manager` determined by `level` setting may be overwritten by settings in `kwargs` . - cast_model_type (:class:`mindspore.dtype`): Supports `mstype.float16` or `mstype.float32`.If set, the network - will be casted to `cast_model_type`(`mstype.float16` or `mstype.float32`), but not to be casted to the type - determined by `level` setting. - keep_batchnorm_fp32 (bool): Keep Batchnorm run in `float32` when the network is set to cast to `float16`. + cast_model_type (:class: `mindspore.dtype` ): Supports `mstype.float16` or `mstype.float32` .If set, the network + will be casted to `cast_model_type` ( `mstype.float16` or `mstype.float32` ), but not to be casted to the + type determined by `level` setting. + keep_batchnorm_fp32 (bool): Keep Batchnorm run in `float32` when the network is set to cast to `float16` . If set, the `level` setting will take no effect on this property. loss_scale_manager (Union[None, LossScaleManager]): If None, not scale the loss, otherwise scale the loss by - `LossScaleManager`. If set, the `level` setting will take no effect on this property. + `LossScaleManager` . If set, the `level` setting will take no effect on this property. Raises: 1.Auto mixed precision only supported on device GPU and Ascend.If device is CPU, a `ValueError` exception will be raised. - 2.If device is CPU, property `loss_scale_manager` only can be set as `None` or `FixedLossScaleManager`(with - property `drop_overflow_update=False`), or a `ValueError` exception will be raised. + 2.If device is CPU, property `loss_scale_manager` only can be set as `None` or `FixedLossScaleManager` (with + property `drop_overflow_update=False` ), or a `ValueError` exception will be raised. """ validator.check_value_type('network', network, nn.Cell) validator.check_value_type('optimizer', optimizer, (nn.Optimizer, acc.FreezeOpt)) diff --git a/mindspore/train/model.py b/mindspore/train/model.py index 36bccabd577..337b4498bd0 100755 --- a/mindspore/train/model.py +++ b/mindspore/train/model.py @@ -69,7 +69,7 @@ class Model: metrics (Union[dict, set]): A Dictionary or a set of metrics to be evaluated by the model during training and testing. eg: {'accuracy', 'recall'}. Default: None. eval_network (Cell): Network for evaluation. If not defined, `network` and `loss_fn` would be wrapped as - `eval_network`. Default: None. + `eval_network` . Default: None. eval_indexes (list): When defining the `eval_network`, if `eval_indexes` is None, all outputs of the `eval_network` would be passed to metrics, otherwise `eval_indexes` must contain three elements, including the positions of loss value, predicted value and label. The loss @@ -77,18 +77,18 @@ class Model: to other metric. Default: None. Args: - amp_level (str): Option for argument `level` in `mindspore.amp.build_train_network`, level for mixed + amp_level (str): Option for argument `level` in `mindspore.amp.build_train_network` , level for mixed precision training. Supports ["O0", "O2", "O3", "auto"]. Default: "O0". - O0: Do not change. - O2: Cast network to float16, keep batchnorm run in float32, using dynamic loss scale. - - O3: Cast network to float16, with additional property `keep_batchnorm_fp32=False`. + - O3: Cast network to float16, with additional property `keep_batchnorm_fp32=False` . - auto: Set to level to recommended level in different devices. Set level to O2 on GPU, Set level to O3 Ascend. The recommended level is choose by the export experience, cannot always general. User should specify the level for special network. O2 is recommended on GPU, O3 is recommended on Ascend.The more detailed explanation of `amp_level` setting - can be found at `mindspore.amp.build_train_network`. + can be found at `mindspore.amp.build_train_network` . Examples: >>> from mindspore import Model, nn >>>