diff --git a/docs/mindspore/source_en/features/parallel/operator_parallel.md b/docs/mindspore/source_en/features/parallel/operator_parallel.md index a69ec3468ae2d086a63c0623074caf6738903e35..8791338e675d0f0b1b4f9bc9e65a1d4634516d0a 100644 --- a/docs/mindspore/source_en/features/parallel/operator_parallel.md +++ b/docs/mindspore/source_en/features/parallel/operator_parallel.md @@ -95,7 +95,7 @@ Therefore, directly slicing the input and output tensor of the operator accordin In order to express sharding as in the above scenario, functional extensions are made to the [shard](https://www.mindspore.cn/docs/en/r2.7.0/api_python/parallel/mindspore.parallel.shard.html) interface. -The parameters in_strategy and out_strategy both additionally receive the new quantity type tuple(Layout) type. [Layout](https://www.mindspore.cn/docs/en/r2.7.0/api_python/parallel/mindspore.parallel.Layout.html) is initialized using the device matrix, while requiring an alias for each axis of the device matrix. For example: "layout = Layout((8, 4, 4), name = ("dp", "sp", "mp"))" means that the device has 128 cards in total, which are arranged in the shape of (8, 4, 4), and aliases "dp", "sp", "mp" are given to each axis. +The parameters in_strategy and out_strategy both additionally receive the new data type tuple(Layout) type. [Layout](https://www.mindspore.cn/docs/en/r2.7.0/api_python/parallel/mindspore.parallel.Layout.html) is initialized using the device matrix, while requiring an alias for each axis of the device matrix. For example: "layout = Layout((8, 4, 4), name = ("dp", "sp", "mp"))" means that the device has 128 cards in total, which are arranged in the shape of (8, 4, 4), and aliases "dp", "sp", "mp" are given to each axis. For the specific meaning of Layout and the configuration derivation method, please refer to the following two technical documents: diff --git a/docs/mindspore/source_zh_cn/features/compile/compilation_guide.md b/docs/mindspore/source_zh_cn/features/compile/compilation_guide.md index 396389c7f8fd1e1bbf93bc6a96f9f61359560963..1ccd621af877b20175ce0006cdbca43e2a3a0d65 100644 --- a/docs/mindspore/source_zh_cn/features/compile/compilation_guide.md +++ b/docs/mindspore/source_zh_cn/features/compile/compilation_guide.md @@ -27,7 +27,7 @@ MindSpore提供三种捕获方式,如下: - strict模式:此模式目标是构成一张图,开发者的Python代码如果无法构图,选择此模式运行程序时会报错,需要开发者进行代码修改,变为可构图的语法,适合追求性能的开发者。 - lax模式:此模式目标是尽可能的让开发者程序可运行,思路是针对无法在strict模式构图的代码进行Python fallback,即返回Python层运行。 -Graph Mode模式约束请参考[语法约束](https://www.mindspore.cn/tutorials/zh-CN/r2.7.0/compile/static_graph.html)。ast如何将Python代码解析并构图,举例如下: +Graph Mode约束请参考[语法约束](https://www.mindspore.cn/tutorials/zh-CN/r2.7.0/compile/static_graph.html)。ast如何将Python代码解析并构图,举例如下: ```python @mindspore.jit @@ -258,7 +258,7 @@ subgraph @f1() { 通常冗余代码可能是用户出于可读性等目的有意编写的,也可能仅仅是编码过程中的无心之举。此外,编译优化过程本身通过其它优化技术(如:代数化简、inline、公共子表达式消除等)产生的中间结果,也可能带来冗余消除的机会。 -MindSpore冗余消除的目的及使用的技术与传统编译器类似。不同的是这些冗余优化是在 MindIR 上完成的。例如: +MindSpore冗余消除的目的及使用的技术与传统编译器类似。不同的是这些冗余优化是在 MindIR 上完成的。例如: 1. **无用代码消除** diff --git a/docs/mindspore/source_zh_cn/features/parallel/operator_parallel.md b/docs/mindspore/source_zh_cn/features/parallel/operator_parallel.md index 42fdcfc5659b10059be5d891e3cb7d9643e73dcb..e599b3a4be07acfe5c496fa0113a8967834ecef5 100644 --- a/docs/mindspore/source_zh_cn/features/parallel/operator_parallel.md +++ b/docs/mindspore/source_zh_cn/features/parallel/operator_parallel.md @@ -22,7 +22,7 @@ MindSpore提供两种粒度的算子级并行能力:[算子级并行](#基本 3. [`mindspore.ops.Primitive.add_prim_attr()`](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/ops/mindspore.ops.Primitive.html#mindspore.ops.Primitive.add_prim_attr):为满足不同场景诉求,部分算子能通过`add_prim_attr`接口对其分布式实现进行配置,这些配置仅对`SEMI_AUTO_PARALLEL`与`AUTO_PARALLEL`模式适用,例如: - - `ops.Gather().add_prim_attr("manual_split", split_tuple)`:该接口配置Gather算子的第一个输入非均匀切分,它仅对axis=0时有效。其中`split_tuple`是一个元素为int类型的元组,元素之和须等于Gather算子第一个输入的第零维的长度,元组个数须等于Gather算子第一个输入的第零维切分份数。 + - `ops.Gather().add_prim_attr("manual_split", split_tuple)`:该接口配置Gather算子的第一个输入非均匀切分,它仅对axis=0时有效。其中`split_tuple`是一个元素为int类型的元组,元素之和应等于Gather算子第一个输入的第零维的长度,元组个数应等于Gather算子第一个输入的第零维切分份数。 - `ops.Gather().add_prim_attr("primitive_target", "CPU")`:该接口配置Gather算子在CPU上执行,用于异构场景。 - `ops.Reshape().add_prim_attr("skip_redistribution")`:对于ops.Reshape的前后不进行张量重排布(张量重排布见[基本原理](#基本原理))。 - `ops.ReduceSum().add_prim_attr("cross_batch")`:该接口仅对Reduce类算子适用。当配置这个参数后,Reduce类算子如果轴被切分,则会对分片完成reduce操作后不进行多卡之间的同步,结果会和单卡不等价。 @@ -105,7 +105,7 @@ parallel_net = AutoParallel(net, parallel_mode='semi_auto') 为了表达出如上述场景下的切分,[shard](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/parallel/mindspore.parallel.shard.html) 接口进行了功能扩展。 -入参in_strategy和out_strategy都额外接收新的数量类型——tuple(Layout)。其中[Layout](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/parallel/mindspore.parallel.Layout.html) 通过设备矩阵进行初始化,并同时要求给设备矩阵的每个轴取一个别名。例如:"layout = Layout((8, 4, 4), name = ("dp", "sp", "mp"))"表示该设备共有128张卡,按照(8, 4, 4)的形状进行排列,并为每个轴分别取了别名"dp"、"sp"、"mp"。 +入参in_strategy和out_strategy都额外接收新的数据类型——tuple(Layout)。其中[Layout](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/parallel/mindspore.parallel.Layout.html) 通过设备矩阵进行初始化,并同时要求给设备矩阵的每个轴取一个别名。例如:"layout = Layout((8, 4, 4), name = ("dp", "sp", "mp"))"表示该设备共有128张卡,按照(8, 4, 4)的形状进行排列,并为每个轴分别取了别名"dp"、"sp"、"mp"。 关于Layout的具体含义与配置推导方法,可参考如下两篇技术文档: diff --git a/docs/mindspore/source_zh_cn/features/parallel/pipeline_parallel.md b/docs/mindspore/source_zh_cn/features/parallel/pipeline_parallel.md index fa1721a24d8010de378b3bd303c0ea01c85d1929..6438f75277a2afb0c3bccfe1dc95ab6e71549e4a 100644 --- a/docs/mindspore/source_zh_cn/features/parallel/pipeline_parallel.md +++ b/docs/mindspore/source_zh_cn/features/parallel/pipeline_parallel.md @@ -14,7 +14,7 @@ 2. [mindspore.parallel.auto_parallel.AutoParallel.pipeline(stages=1, output_broadcast=False, interleave=False, scheduler='1f1b')](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/parallel/mindspore.parallel.auto_parallel.AutoParallel.html#mindspore.parallel.auto_parallel.AutoParallel.pipeline):设置流水线并行配置。`stages`表示流水线并行需要设置的切分总数,`output_broadcast`表示流水线并行推理时,最后一个stage的结果是否广播给其他stage,`interleave`表示是否开启interleave优化策略,`scheduler`表示流水线并行的调度策略,当前支持`gpipe`/`1f1b`/`seqpipe`/`seqvpp`/`seqsmartvpp`/`zero_bubble_v`。 -3. [mindspore.parallel.Pipeline(network, micro_size=1, stage_config={"cell1":0, "cell2":1})](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/parallel/mindspore.parallel.nn.Pipeline.html):流水线并行需要需要在`network`外再添加一层`Pipeline`,并通过`micro_size`指定MicroBatch的个数,以及指出网络中各Cell在哪个`stage`中执行。如果对于`network`使用`nn.WithLossCell`封装,则会改变`Cell`的名称,并增加`_backbone`前缀。为了提升机器的利用率,MindSpore将MiniBatch切分成了更细粒度的MicroBatch,最终的loss则是所有MicroBatch计算的loss值累加。其中,micro_size必须大于等于stages的数量。 +3. [mindspore.parallel.Pipeline(network, micro_size=1, stage_config={"cell1":0, "cell2":1})](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/parallel/mindspore.parallel.nn.Pipeline.html):流水线并行需要在`network`外再添加一层`Pipeline`,并通过`micro_size`指定MicroBatch的个数,以及指出网络中各Cell在哪个`stage`中执行。如果对于`network`使用`nn.WithLossCell`封装,则会改变`Cell`的名称,并增加`_backbone`前缀。为了提升机器的利用率,MindSpore将MiniBatch切分成了更细粒度的MicroBatch,最终的loss则是所有MicroBatch计算的loss值累加。其中,micro_size必须大于等于stages的数量。 4. [mindspore.parallel.PipelineGradReducer(parameters, scale_sense=1.0, opt_shard=None)](https://www.mindspore.cn/docs/zh-CN/r2.7.0/api_python/parallel/mindspore.parallel.nn.PipelineGradReducer.html):流水线并行需要使用`PipelineGradReducer`来完成梯度聚合。这是因为流水线并行中,其输出是由多个`MicroBatch`的结果相加得到,因此其梯度也需要进行累加。 @@ -42,7 +42,7 @@ ### 1F1B流水线并行调度 -MindSpore的流水线并行实现中了对执行序进行调整,来达到更优的内存管理。 +MindSpore的流水线并行实现了对执行序进行调整,来达到更优的内存管理。 如图3所示,在编号为0的MicroBatch的正向计算执行完后,立即执行其反向。这样做使得其中间结果的内存得以更早地(相较于图2)释放,进而确保内存使用峰值比图2的方式更低。 @@ -68,7 +68,7 @@ MindSpore在Megatron-LM的interleaved pipeline调度的基础上做了内存优 ### zero_bubble_v pipeline调度 -zero_bubble_v pipeline调度通过将反向计算过程拆分为梯度计算与参数更新,进一步提升流水线并行的效率,减少Bubble率,如图6所示。在zero_bubble_v pipeline调度中,对于连续的模型层,stage的数值会先增大后减小,前一半层的pipeline_segment为0,后一半层的pipeline_segment为1。例如:对于有8个连续层,stage为4时,stage0有第0和第7层,stage1有第1和第6层,stage2有第2和第5层,stage3有第3和第4层,第0层到和3层的pipeline_segment为0,第4层到第7层的pipeline_segment为1。 +zero_bubble_v pipeline调度通过将反向计算过程拆分为梯度计算与参数更新,进一步提升流水线并行的效率,减少Bubble率,如图6所示。在zero_bubble_v pipeline调度中,对于连续的模型层,stage的数值会先增大后减小,前一半层的pipeline_segment为0,后一半层的pipeline_segment为1。例如:对于有8个连续层,stage为4时,stage0有第0和第7层,stage1有第1和第6层,stage2有第2和第5层,stage3有第3和第4层,第0层到第3层的pipeline_segment为0,第4层到第7层的pipeline_segment为1。 ![zero_bubble_v.png](images/zero_bubble_v.png)