|
|
|
@@ -12,8 +12,8 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
- **auto_prefix** (`Cell`) – 递归地生成作用域。默认值:True。
|
|
|
|
- **flags** (`dict`) - Cell的配置信息,目前用于绑定Cell和数据集。用户也通过该参数自定义Cell属性。默认值:None。
|
|
|
|
- **auto_prefix** (Cell) – 递归地生成作用域。默认值:True。
|
|
|
|
- **flags** (dict) - Cell的配置信息,目前用于绑定Cell和数据集。用户也通过该参数自定义Cell属性。默认值:None。
|
|
|
|
|
|
|
|
**支持平台**:
|
|
|
|
|
|
|
|
@@ -39,7 +39,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**flags** (`dict`) - Cell的配置信息,目前用于绑定Cell和数据集。用户也通过该参数自定义Cell属性。默认值:None。
|
|
|
|
**flags** (dict) - Cell的配置信息,目前用于绑定Cell和数据集。用户也通过该参数自定义Cell属性。默认值:None。
|
|
|
|
|
|
|
|
.. py:method:: add_flags_recursive(**flags)
|
|
|
|
|
|
|
|
@@ -47,7 +47,20 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**flags** (`dict`) - Cell的配置信息,目前用于绑定Cell和数据集。用户也通过该参数自定义Cell属性。默认值:None。
|
|
|
|
**flags** (dict) - Cell的配置信息,目前用于绑定Cell和数据集。用户也通过该参数自定义Cell属性。默认值:None。
|
|
|
|
|
|
|
|
.. py:method:: auto_parallel_compile_and_run()
|
|
|
|
|
|
|
|
是否在‘AUTO_PARALLEL’或‘SEMI_AUTO_PARALLEL’模式下执行编译流程。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
bool, `_auto_parallel_compile_and_run` 的值。
|
|
|
|
|
|
|
|
.. py:method:: bprop_debug
|
|
|
|
:property:
|
|
|
|
|
|
|
|
获取自定义反向传播调试功能是否已启用。
|
|
|
|
|
|
|
|
.. py:method:: cast_inputs(inputs, dst_type)
|
|
|
|
|
|
|
|
@@ -55,8 +68,8 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
- **inputs** (`tuple[Tensor]`) - 输入。
|
|
|
|
- **dst_type** (`mindspore.dtype`) - 指定的数据类型。
|
|
|
|
- **inputs** (tuple[Tensor]) - 输入。
|
|
|
|
- **dst_type** (mindspore.dtype) - 指定的数据类型。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -70,7 +83,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**param** (`Parameter`) – Parameter类型,需要被转换类型的输入参数。
|
|
|
|
**param** (Parameter) – Parameter类型,需要被转换类型的输入参数。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -90,8 +103,8 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
- **cell** (`str`) – 需要进行迭代的Cell。默认值:None。
|
|
|
|
- **name_prefix** (`str`) – 作用域。默认值:''。
|
|
|
|
- **cell** (str) – 需要进行迭代的Cell。默认值:None。
|
|
|
|
- **name_prefix** (str) – 作用域。默认值:''。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -115,7 +128,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**inputs** (`tuple`) – Cell的输入。
|
|
|
|
**inputs** (tuple) – Cell的输入。
|
|
|
|
|
|
|
|
.. py:method:: compile_and_run(*inputs)
|
|
|
|
|
|
|
|
@@ -123,7 +136,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**inputs** (`tuple`) – Cell的输入。
|
|
|
|
**inputs** (tuple) – Cell的输入。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -165,7 +178,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**expand** (`bool`) – 如果为True,则递归地获取当前Cell和所有子Cell的parameter。否则,只生成当前Cell的子Cell的parameter。默认值:True。
|
|
|
|
**expand** (bool) – 如果为True,则递归地获取当前Cell和所有子Cell的parameter。否则,只生成当前Cell的子Cell的parameter。默认值:True。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -186,14 +199,31 @@ |
|
|
|
|
|
|
|
String类型,网络的作用域。
|
|
|
|
|
|
|
|
.. py:method:: infer_param_pipeline_stage()
|
|
|
|
|
|
|
|
推导Cell中当前 `pipeline_stage` 的参数。
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
- 如果某参数不属于任何已被设置 `pipeline_stage` 的Cell,此参数应使用 `add_pipeline_stage` 方法来添加它的 `pipeline_stage` 信息。
|
|
|
|
- 如果某参数P被stageA和stageB两个不同stage的算子使用,那么参数P在使用 `infer_param_pipeline_stage` 之前,应使用 `P.add_pipeline_stage(stageA)` 和 `P.add_pipeline_stage(stageB)` 添加它的stage信息。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
属于当前 `pipeline_stage` 的参数。
|
|
|
|
|
|
|
|
**异常:**
|
|
|
|
|
|
|
|
**RuntimeError** – 如果参数不属于任何stage。
|
|
|
|
|
|
|
|
|
|
|
|
.. py:method:: insert_child_to_cell(child_name, child_cell)
|
|
|
|
|
|
|
|
将一个给定名称的子Cell添加到当前Cell。
|
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
- **child_name** (`str`) – 子Cell名称。
|
|
|
|
- **child_cell** (`Cell`) – 要插入的子Cell。
|
|
|
|
- **child_name** (str) – 子Cell名称。
|
|
|
|
- **child_cell** (Cell) – 要插入的子Cell。
|
|
|
|
|
|
|
|
**异常:**
|
|
|
|
|
|
|
|
@@ -208,15 +238,26 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
- **param_name** (`str`) – 参数名称。
|
|
|
|
- **param** (`Parameter`) – 要插入到Cell的参数。
|
|
|
|
- **check_name** (`bool`) – 是否对 `param_name` 中的"."进行检查。默认值:True。
|
|
|
|
- **param_name** (str) – 参数名称。
|
|
|
|
- **param** (Parameter) – 要插入到Cell的参数。
|
|
|
|
- **check_name** (bool) – 是否对 `param_name` 中的"."进行检查。默认值:True。
|
|
|
|
|
|
|
|
**异常:**
|
|
|
|
|
|
|
|
- **KeyError** – 如果参数名称为空或包含"."。
|
|
|
|
- **TypeError** – 如果参数的类型不是Parameter。
|
|
|
|
|
|
|
|
.. py:method:: load_parameter_slice(params)
|
|
|
|
|
|
|
|
根据并行策略获取Tensor分片并替换原始参数。
|
|
|
|
|
|
|
|
请参考 `mindspore.common._Executor.compile` 源代码中的用法。
|
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**params** (dict) – 用于初始化数据图的参数字典。
|
|
|
|
|
|
|
|
|
|
|
|
.. py:method:: name_cells()
|
|
|
|
|
|
|
|
递归地获取一个Cell中所有子Cell的迭代器。
|
|
|
|
@@ -227,6 +268,16 @@ |
|
|
|
|
|
|
|
Dict[String, Cell],Cell中的所有子Cell及其名称。
|
|
|
|
|
|
|
|
.. py:method:: param_prefix
|
|
|
|
:property:
|
|
|
|
|
|
|
|
当前Cell的子Cell的参数名前缀。
|
|
|
|
|
|
|
|
.. py:method:: parameter_layout_dict
|
|
|
|
:property:
|
|
|
|
|
|
|
|
`parameter_layout_dict` 表示一个参数的张量layout,这种张量layout是由分片策略和分布式算子信息推断出来的。
|
|
|
|
|
|
|
|
.. py:method:: parameters_and_names(name_prefix='', expand=True)
|
|
|
|
|
|
|
|
返回Cell中parameter的迭代器。
|
|
|
|
@@ -250,10 +301,17 @@ |
|
|
|
... if m[0]:
|
|
|
|
... names.append(m[0])
|
|
|
|
|
|
|
|
.. py:method:: param_prefix
|
|
|
|
:property:
|
|
|
|
.. py:method:: parameters_broadcast_dict(recurse=True)
|
|
|
|
|
|
|
|
当前Cell的子Cell的参数名前缀。
|
|
|
|
获取这个Cell的参数广播字典。
|
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**recurse** (bool): 是否包含子Cell的参数。 默认: True。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
OrderedDict, 返回参数广播字典。
|
|
|
|
|
|
|
|
.. py:method:: parameters_dict(recurse=True)
|
|
|
|
|
|
|
|
@@ -261,18 +319,50 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**recurse** (`bool`) – 是否递归得包含所有子Cell的parameter。默认值:True。
|
|
|
|
**recurse** (bool) – 是否递归得包含所有子Cell的parameter。默认值:True。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
OrderedDict类型,返回参数字典。
|
|
|
|
|
|
|
|
.. py:method:: recompute(**kwargs)
|
|
|
|
|
|
|
|
设置Cell重计算。Cell中的所有算子将被设置为重计算。如果一个算子的计算结果被输出到一些反向节点来进行梯度计算,且被设置成重计算,那么我们会在反向传播中重新计算它,而不去存储在前向传播中的中间激活层的计算结果。
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
- 如果计算涉及到诸如随机化或全局变量之类的操作,那么目前还不能保证等价。
|
|
|
|
- 如果该Cell中算子的重计算API也被调用,则该算子的重计算模式以算子的重计算API的设置为准。
|
|
|
|
- 该接口仅配置一次,即当父Cell配置了,子Cell不需再配置。
|
|
|
|
- 当应用了重计算且内存充足时,可以配置'mp_comm_recompute=False'来提升性能。
|
|
|
|
- 当应用了重计算但内存不足时,可以配置'parallel_optimizer_comm_recompute=True'来节省内存。有相同融合group的Cell应该配置相同的parallel_optimizer_comm_recompute。
|
|
|
|
|
|
|
|
**参数**:
|
|
|
|
|
|
|
|
- **mp_comm_recompute** (bool) – 表示在自动并行或半自动并行模式下,指定Cell内部由模型并行引入的通信操作是否重计算。默认值:True。
|
|
|
|
- **parallel_optimizer_comm_recompute** (bool) – 表示在自动并行或半自动并行模式下,指定Cell内部由优化器并行引入的AllGather通信是否重计算。默认值:False。
|
|
|
|
|
|
|
|
.. py:method:: register_backward_hook(fn)
|
|
|
|
|
|
|
|
设置网络反向hook函数。此函数仅在PyNative Mode下支持。
|
|
|
|
|
|
|
|
.. note:: fn必须有如下代码定义。 `cell_name` 是已注册网络的名称。 `grad_input` 是传递给网络的梯度。 `grad_output` 是计算或者传递给下一个网络或者算子的梯度,这个梯度可以被修改或者返回。fn的返回值为Tensor或者None。
|
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**fn** (function) – 以梯度作为输入的hook函数。
|
|
|
|
|
|
|
|
.. py:method:: remove_redundant_parameters()
|
|
|
|
|
|
|
|
删除冗余参数。
|
|
|
|
|
|
|
|
这个接口通常不需要显式调用。
|
|
|
|
|
|
|
|
.. py:method:: set_auto_parallel()
|
|
|
|
|
|
|
|
将Cell设置为自动并行模式。
|
|
|
|
|
|
|
|
.. note:: 如果一个Cell需要使用自动并行或半自动并行模式来进行训练、评估或预测,则该Cell需要调用此接口。
|
|
|
|
|
|
|
|
.. py:method:: set_comm_fusion(fusion_type, recurse=True)
|
|
|
|
|
|
|
|
为Cell中的参数设置融合类型。请参考 :class:`mindspore.Parameter.comm_fusion` 的描述。
|
|
|
|
@@ -281,8 +371,8 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
- **fusion_type** (`int`) – Parameter的 `comm_fusion` 属性的设置值。
|
|
|
|
- **recurse** (`bool`) – 是否递归地设置子Cell的可训练参数。默认值:True。
|
|
|
|
- **fusion_type** (int) – Parameter的 `comm_fusion` 属性的设置值。
|
|
|
|
- **recurse** (bool) – 是否递归地设置子Cell的可训练参数。默认值:True。
|
|
|
|
|
|
|
|
.. py:method:: set_grad(requires_grad=True)
|
|
|
|
|
|
|
|
@@ -290,12 +380,41 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**requires_grad** (`bool`) – 指定网络是否需要梯度,如果为True,PyNative模式下Cell将构建反向网络。默认值:True。
|
|
|
|
**requires_grad** (bool) – 指定网络是否需要梯度,如果为True,PyNative模式下Cell将构建反向网络。默认值:True。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
Cell类型,Cell本身。
|
|
|
|
|
|
|
|
.. py:method:: set_parallel_input_with_inputs(*inputs)
|
|
|
|
|
|
|
|
通过并行策略对输入张量进行切分。
|
|
|
|
|
|
|
|
**参数**:
|
|
|
|
|
|
|
|
**inputs** (tuple) – construct方法的输入。
|
|
|
|
|
|
|
|
.. py:method:: set_param_fl(push_to_server=False, pull_from_server=False, requires_aggr=True)
|
|
|
|
|
|
|
|
设置参数与服务器交互的方式。
|
|
|
|
|
|
|
|
**参数**:
|
|
|
|
|
|
|
|
- **push_to_server** (bool) – 是否将参数推送到服务器。默认值:False。
|
|
|
|
- **pull_from_server** (bool) – 是否从服务器提取参数。默认值:False。
|
|
|
|
- **requires_aggr** (bool) – 是否在服务器中聚合参数。默认值:True。
|
|
|
|
|
|
|
|
.. py:method:: set_param_ps(recurse=True, init_in_server=False)
|
|
|
|
|
|
|
|
设置可训练参数是否由参数服务器更新,以及是否在服务器上初始化可训练参数。
|
|
|
|
|
|
|
|
.. note:: 只在运行的任务处于参数服务器模式时有效。
|
|
|
|
|
|
|
|
**参数**:
|
|
|
|
|
|
|
|
- **recurse** (bool) – 是否设置子网络的可训练参数。默认值:True。
|
|
|
|
- **init_in_server** (bool) – 是否在服务器上初始化由参数服务器更新的可训练参数。默认值:False。
|
|
|
|
|
|
|
|
.. py:method:: set_train(mode=True)
|
|
|
|
|
|
|
|
将Cell设置为训练模式。
|
|
|
|
@@ -304,7 +423,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**mode** (`bool`) – 指定模型是否为训练模式。默认值:True。
|
|
|
|
**mode** (bool) – 指定模型是否为训练模式。默认值:True。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -320,7 +439,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**dst_type** (`mindspore.dtype`) – Cell转换为 `dst_type` 类型运行。 `dst_type` 可以是 `mindspore.dtype.float16` 或者 `mindspore.dtype.float32` 。
|
|
|
|
**dst_type** (mindspore.dtype) – Cell转换为 `dst_type` 类型运行。 `dst_type` 可以是 `mindspore.dtype.float16` 或者 `mindspore.dtype.float32` 。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -338,7 +457,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**recurse** (`bool`) – 是否递归地包含当前Cell的所有子Cell的可训练参数。默认值:True。
|
|
|
|
**recurse** (bool) – 是否递归地包含当前Cell的所有子Cell的可训练参数。默认值:True。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -352,7 +471,7 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
**recurse** (`bool`) – 是否递归地包含当前Cell的所有子Cell的不可训练参数。默认值:True。
|
|
|
|
**recurse** (bool) – 是否递归地包含当前Cell的所有子Cell的不可训练参数。默认值:True。
|
|
|
|
|
|
|
|
**返回:**
|
|
|
|
|
|
|
|
@@ -380,5 +499,5 @@ |
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
|
|
|
- **prefix** (`str`) – 前缀字符串。默认值:''。
|
|
|
|
- **recurse** (`bool`) – 是否递归地包含所有子Cell的参数。默认值:True。
|
|
|
|
- **prefix** (str) – 前缀字符串。默认值:''。
|
|
|
|
- **recurse** (bool) – 是否递归地包含所有子Cell的参数。默认值:True。
|