| @@ -0,0 +1,13 @@ | |||
| mindspore.async_ckpt_thread_status | |||
| ======================================= | |||
| .. py:class:: mindspore.async_ckpt_thread_status() | |||
| 获取异步保存checkpoint文件线程的状态。 | |||
| 在执行异步保存checkpoint时,可以通过该函数获取线程状态以确保写入checkpoint文件已完成。 | |||
| **返回:** | |||
| True,异步保存checkpoint线程正在运行。 | |||
| False,异步保存checkpoint线程未运行。 | |||
| @@ -0,0 +1,30 @@ | |||
| mindspore.build_train_network | |||
| ======================================= | |||
| .. py:class:: mindspore.build_train_network(network, optimizer, loss_fn=None, level='O0', boost_level='O0', **kwargs) | |||
| 构建混合精度训练网络。 | |||
| **参数:** | |||
| - **network** (Cell) – MindSpore的网络结构。 | |||
| - **optimizer** (Optimizer) – 优化器,用于更新参数。 | |||
| - **loss_fn** (Union[None, Cell]) – 损失函数的定义,如果为None,网络结构中应该包含损失函数。默认值:None。 | |||
| - **level** (str) – 支持["O0", "O2", "O3", "auto"]。默认值:"O0"。 | |||
| - **O0** - 不进行精度变化。 | |||
| - **O2** - 使网络在float16精度下运行,如果网络结构中含有`batchnorm`和`loss_fn`,使它们在float32下运行。 | |||
| - **O3** - 使网络在float16精度下运行,并且设置`keep_batchnorm_fp32`为Flase。 | |||
| - **auto** - 根据不同后端设置不同的级别。在GPU上设置为O2,Ascend上设置为O3。自动设置的选项为系统推荐,在特殊场景下可能并不适用。用户可以根据网络实际情况去设置。GPU推荐O2,Ascend推荐O3,`keep_batchnorm_fp32`,`cast_model_type`和`loss_scale_manager`属性由level自动决定,有可能被`kwargs`参数覆盖。 | |||
| - **boost_level** (str) – `mindspore.boost` 中参数 `level` 的选项,设置boost的训练模式级别。支持["O0", "O1", "O2"]. 默认值: "O0". | |||
| - **O0** - 不进行精度变化。 | |||
| - **O2** - 开启boost模式,性能提升20%左右,精度与原始精度相同。 | |||
| - **O3** - 开启boost模式,性能提升30%左右,准确率降低小于3%。 | |||
| 如果设置了 O1 或 O2 模式,boost相关库将自动生效。 | |||
| - **cast_model_type** (mindspore.dtype) – 支持float16,float32。如果设置了该参数,网络将被转化为设置的数据类型,而不会根据设置的level进行转换。 | |||
| - **keep_batchnorm_fp32** (bool) – 当网络被设置为float16时,将保持Batchnorm在float32中运行。设置level不会影响该属性。 | |||
| - **loss_scale_manager** (Union[None, LossScaleManager]) – 如果为None,则不进行loss_scale,否则将根据`LossScaleManager`进行loss_scale。如果设置了,`level`将不会影响这个属性。 | |||
| **异常:** | |||
| - **ValueError** – 仅在GPU和Ascend上支持自动混合精度。如果设备是 CPU,则为 `ValueError`。 | |||
| - **ValueError** - 如果是CPU,则属性 `loss_scale_manager` 只能设置为 `None` 或 `FixedLossScaleManager`。 | |||
| @@ -0,0 +1,41 @@ | |||
| mindspore.load | |||
| ======================================= | |||
| .. py:class:: mindspore.load(file_name, **kwargs) | |||
| 加载MindIR文件。 | |||
| 返回的对象可以由`GraphCell`执行,更多细节参见类:class:`mindspore.nn.GraphCell`。 | |||
| **参数:** | |||
| - **file_name** (str) – MindIR文件名。 | |||
| - **kwargs** (dict) – 配置项字典。 | |||
| - **dec_key** (bytes) - 用于解密的字节类型密钥。 有效长度为 16、24 或 32。 | |||
| - **dec_mode** - 指定解密模式,设置dec_key时生效。可选项:'AES-GCM' | 'AES-CBC'。 默认值:“AES-GCM”。 | |||
| **返回:** | |||
| Object,一个可以由`GraphCell`构成的可执行的编译图。 | |||
| **异常:** | |||
| - **ValueError** – MindIR 文件名不正确。 | |||
| - **RuntimeError** - 解析MindIR文件失败。 | |||
| **样例:** | |||
| >>> import numpy as np | |||
| >>> import mindspore.nn as nn | |||
| >>> from mindspore import Tensor, export, load | |||
| >>> | |||
| >>> net = nn.Conv2d(1, 1, kernel_size=3, weight_init="ones") | |||
| >>> input_tensor = Tensor(np.ones([1, 1, 3, 3]).astype(np.float32)) | |||
| >>> export(net, input_tensor, file_name="net", file_format="MINDIR") | |||
| >>> graph = load("net.mindir") | |||
| >>> net = nn.GraphCell(graph) | |||
| >>> output = net(input_tensor) | |||
| >>> print(output) | |||
| [[[[4. 6. 4.] | |||
| [6. 9. 6.] | |||
| [4. 6. 4.]]]] | |||
| @@ -0,0 +1,47 @@ | |||
| mindspore.parse_print | |||
| ======================================= | |||
| .. py:class:: mindspore.parse_print(print_file_name) | |||
| 解析由 mindspore.ops.Print 生成的保存数据。 | |||
| 将数据打印到屏幕上。也可以通过设置`context`中的参数`print_file_path`来关闭,数据会保存在`print_file_path`指定的文件中。 parse_print 用于解析保存的文件。 更多信息请参考:func:`mindspore.context.set_context` 和:class:`mindspore.ops.Print`。 | |||
| **参数:** | |||
| - **print_file_name** (str) – 保存打印数据的文件名。 | |||
| **返回:** | |||
| List,由Tensor组成的list。 | |||
| **异常:** | |||
| - **ValueError** – 指定的文件名可能为空,请确保输入正确的文件名。 | |||
| **样例:** | |||
| >>> import numpy as np | |||
| >>> import mindspore | |||
| >>> import mindspore.ops as ops | |||
| >>> from mindspore.nn as nn | |||
| >>> from mindspore import Tensor, context | |||
| >>> context.set_context(mode=context.GRAPH_MODE, print_file_path='log.data') | |||
| >>> class PrintInputTensor(nn.Cell): | |||
| ... def __init__(self): | |||
| ... super().__init__() | |||
| ... self.print = ops.Print() | |||
| ... | |||
| ... def construct(self, input_pra): | |||
| ... self.print('print:', input_pra) | |||
| ... return input_pra | |||
| >>> x = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]).astype(np.float32) | |||
| >>> input_pra = Tensor(x) | |||
| >>> net = PrintInputTensor() | |||
| >>> net(input_pra) | |||
| >>> data = mindspore.parse_print('./log.data') | |||
| >>> print(data) | |||
| ['print:', Tensor(shape=[2, 4], dtype=Float32, value= | |||
| [[ 1.00000000e+00, 2.00000000e+00, 3.00000000e+00, 4.00000000e+00], | |||
| [ 5.00000000e+00, 6.00000000e+00, 7.00000000e+00, 8.00000000e+00]])] | |||