-sdy-close-shardings

关闭张量分片并舍弃复制的轴。

-sdy-constant-or-scalar-merger

合并具有匹配分片的相同常量和标量扩展。

对具有相同分片的常量执行轻量级 CSE。

导入流水线会拆分并复制常量和标量扩展,以便在常量子计算的不同用途之间不传播分片。如果常量在传播后具有相同的分片,则此传递会合并它们以节省编译时间。如需了解详情,请参阅 -sdy-constant-or-scalar-splitter。

-sdy-convert-global-to-local

将 SDY 程序从全局形状转换为本地形状。

通过根据分片属性对逻辑维度进行分区,将 SDY 程序从全局形状转换为本地形状。

此传递利用类型转换器将 RankedTensorType 从全局逻辑形状映射到设备本地物理形状。

选项

-per-dim-all-gather                     : Keep per-dimension all-gather without combining them into a single all-gather.
-combine-multi-dimension-reduce-scatter : Combine multi-dimension reduce-scatter into a single reduce-scatter.
-enable-rgv3                            : Use StableHLO ReplicaGroupV3 (mesh-axes based) for collectives.
-replica-count                          : Number of replicas (data parallelism).
-partition-count                        : Number of partitions (model parallelism).

-sdy-drop-sharding-and-mesh

从程序中移除网格运算和分片表示法。

选项

-keep-module-sharding-metadata : Whether to keep module-level sharding metadata (sdy.parameters_shardings and sdy.output_shardings).

-sdy-drop-sharding-rules

从所有已注册的运算中舍弃 OpShardingRuleAttr

-sdy-export-named-computations

从 NamedComputationOp 中列出调用。

创建一个传递,将 NamedComputationOp 转换为 CallOp,并使用名为 NamedComputationOp 的 name 的新私有函数。新的 FuncOp 和 CallOp 具有与原始 NamedComputationOp 的运算数/结果相同的分片。

如果模块中存在与 NamedComputationOp 同名的函数,MLIR 符号表会将其更改为 {name}_#。

-sdy-insert-explicit-reshards

插入显式重新分片,使所有运算都具有兼容的分片。

兼容的分片本质上是指运算可以接受分片的运算数并生成分片的结果,而无需任何重新分片通信(请注意,运算可能仍然需要通信,例如 all-reduce 或 halo-swaps)。

传播后,某些运算可能仍然具有不兼容的分片。

请注意,当一个轴(或子轴)用于跨多个张量对不对应的维度(例如,matmul 中的非收缩维度)进行分片时,或者当一个轴对一个张量中的维度进行分片,但不对另一个张量中的相应维度进行分片时,我们称该运算存在分片冲突。因此,在此传递之后,运算将不再存在冲突。

此传递会显式注入重新分片运算,以便对于每个运算,相应维度在所有运算数和结果中以相同的方式进行分片,并且每个轴(或子轴)只能用于对单个维度类型进行分片。

示例:

输入:

mesh = <"x"=4, "y"=2>
%lhs : tensor<8x32xf32> {sdy.sharding=<@mesh, \[{"x"}, {"y"}\]>}
%rhs : tensor<32x16xf32> {sdy.sharding=<@mesh, \[{"y"}, {"x"}\]>}
stablehlo.dot %lhs, %rhs {sdy.sharding_per_value=<[<@mesh, \[{"x"}, {}\]>]>}
  : (tensor<8x32xf32>, tensor<32x16xf32>) -> tensor<8x16xf32>

输出:

sdy.mesh = <"x"=4, "y"=2>
%lhs : tensor<8x32xf32> {sdy.sharding=<@mesh, \[{"x"}, {"y"}\]>}
%rhs : tensor<32x16xf32> {sdy.sharding=<@mesh, \[{"y"}, {"x"}\]>}
%0 = sdy.reshard %rhs <@mesh, \[{"y"}, {}\]> : tensor<32x16xf32>
stablehlo.dot %lhs, %0 {sdy.sharding_per_value=<[<@mesh, \[{"x"}, {}\]>]>}
  : (tensor<8x32xf32>, tensor<32x16xf32>) -> tensor<8x16xf32>

在上面的示例中,lhs 和 rhs 都在其非收缩维度上以轴“x”进行分片,这是不兼容的。此传递会在点运算之前在 rhs 上插入显式重新分片,以便点运算具有兼容的分片。

选项

-enable-full-version                     : Enable full version.
-mark-partial-result-with-unreduced-axes : Whether to mark partial reduction results with unreduced axes.

-sdy-insert-func-call-reshards

插入重新分片以解决函数和调用分片冲突。

插入重新分片以解决函数和调用分片结果冲突。

-sdy-optimize-collectives

优化集体通信运算。

通过分解拆分维度并融合到组合的 all-to-all 中,消除 all-to-all 链之前的冗余集体排列运算。

-sdy-pad-for-divisibility

使用不可分割的分片将张量填充为可分割的形状。

-sdy-per-instruction-partitioning

有选择地提取目标指令,对其运行分区器流水线以生成设备本地代码,并将其封装在 sdy.manualcomputation.

出于调试和二分法的目的,使用独立的 Shardy 分区器流水线(resolve-permutation-factors、reshard-to-collectives、pad-for-divisibility、convert-global-to-local)有选择地对单个指令进行分区,并将生成的设备本地代码封装在 sdy.manual_computation 中。这样可以保持其余全局程序的完整性,因此 XLA SPMD 仅对未封装的全局指令进行分区。

选项

-filter                   : Filter string for selective partitioning. Can be empty (all sharded ops), comma-separated op name substrings (e.g. 'dot, pad'), or key-values like 'selectLow=0, selectHigh=10, func=subroutine'.
-enable-halo-exchange     : Implement halo exchange logic for windowed operations inside the sub-pipeline.
-replica-count            : Number of replicas (data parallelism).
-partition-count          : Number of partitions (model parallelism).
-rng-bit-generator-unsafe : Whether to allow unsafe partitioning of stablehlo.rng_bit_generator.

-sdy-propagate-to-func-results

将分片从函数终止符传播到函数结果。

将函数终止符值的分片复制到相应的 func.func 结果,同时保留主函数上的现有分片。

-sdy-remove-all-gather-reduce-scatter-for-cmv1

_移除 CMV1 的 sdy.all_gather 和 sdy.reducescatter。

移除模式 all-gather + dot 中的 all-gather。移除模式 dot + reduce-scatter 中的 reduce-scatter。此传递用于与集体 matmul V1 (CMV1) 兼容。这是 b/432019089 的临时解决方案。

-sdy-remove-propagation-debug-info

在导出期间移除传播调试信息(传播边缘和原始分片)。

-sdy-remove-sharding-groups

在传播后移除 ShardingGroupOps。

-sdy-remove-sub-axes-in-input-output-shardings

移除输入/输出分片中的子轴。

Shardy 的某些用户希望函数输入/输出具有不带子轴的分片。此传递会从输入/输出开放维度分片中移除子轴及其尾随轴。此传递通常在 sdy-update-non-divisible-input-output-shardings 之后,以确保移除子轴不会引入任何不可分割的分片。

-sdy-reshard-to-collectives

将 ReshardOp 转换为各种 Shardy 集体运算。

匹配重新分片运算并将其重写为各种 Shardy 集体运算。在此传递之后,模块中将不再有重新分片运算。

如果 keepRedundantReshards 为 true,则保留的唯一重新分片运算是冗余的重新分片运算。默认情况下,它假定已插入显式重新分片 (sdy-insert-explicit-reshards),并且不会保留冗余的重新分片。如果可能尚未插入显式重新分片,则应保留冗余的重新分片。

示例:

输入:

mesh = <"x"=2, "y"=2, "z"=2>
%0 : tensor<16x2xf32> {sdy.sharding<@mesh, \[{"x", "y", "z"}, {}\]>
%1 = sdy.reshard %arg0 <@mesh, \[{"x"}, {}\]> : tensor<16x2xf32>

输出:

mesh = <"x"=2, "y"=2, "z"=2>
%0 : tensor<16x2xf32> {sdy.sharding<@mesh, \[{"x", "y", "z"}, {}\]>
%1 = sdy.all_gather \[{"y", "z"}, {}\] %arg0 out_sharding=<@mesh, \[{"x"}, {}\]> : tensor<16x2xf32>

在上面的示例中,张量 %0 : tensor<16x2xf32> 分片为 \[{"x", "y", "z"}, {}\]。然后,有一个 reshard 运算将其重新分片为 \[{"x"}, {}\]。在第一个轴上,由于在重新分片后移除了后缀 {"y", "z"} ,因此我们推断出我们已 all-gather {"y", "z"}。第二个维度未更改。

选项

-keep-redundant-reshards : Whether it keeps redundant reshards or removes.

-sdy-resolve-permutation-factors

解析映射到 kPermutation 因子的维度上的分片。

具有 kPermutation 因子的分片维度可能需要跨设备通信(例如,窗口的 halo 交换或反向的集体排列)。

如果 enableHaloExchange 为 true,则传递将使用可用的优化通信逻辑来解析排列因子。否则,传递将仅插入 sdy.reshard 运算来复制这些维度。enableHaloExchange 的默认值为 true。

选项

-enable-halo-exchange     : Implement halo exchange logic for windowed operations.
-replica-count            : Number of replicas (data parallelism).
-partition-count          : Number of partitions (model parallelism).
-rng-bit-generator-unsafe : Whether to allow unsafe partitioning of stablehlo.rng_bit_generator.

-sdy-resolve-single-device-sharding

将单设备运算降级为 stablehlo.if,并受目标设备 ID 的保护。

选项

-replica-count   : Number of replicas per partition.
-partition-count : Number of partitions per replica.

-sdy-sharding-constraint-to-reshard

将 ShardingConstraintOp 转换为 ReshardOp。

-sdy-sink-data-flow-edges

将所有 DataFlowEdgeOp 汇入其输入。

将每个 DataFlowEdgeOp 的分片移至其输入(边缘的根目标),并使用其输入替换该运算。

选项

-sink-debug-sharding-origins          : Whether to sink the debug sharding origins info. See `debug-sharding-origins` option in propagation for more info.
-sink-debug-propagation-edge-sharding : Whether to sink the debug propagation edge sharding info. See `debug-propagation-edge-sharding` option in propagation for more info.

-sdy-sink-func-data-flow-edges

将所有 FuncDataFlowEdgeOp 汇入其输入。

将每个 FuncDataFlowEdgeOp 的分片移至其输入,并使用其输入替换该运算。

-sdy-unflatten-call-graph

取消展平调用图。

取消展平图。它会根据附加到函数的 “original_func_name”属性描述的输入/输出分片和原始来源,对具有相同 输入/输出分片和原始来源的函数进行重复数据消除。

选项

-dedup-functions-fully : If true, regardless of the input and output shardings of functions, it keeps one callee function for each caller function. The default is false, meaning it will deduplicate only if the input and output shardings are the same.

-sdy-update-non-divisible-input-output-shardings

使 FuncOp 输入/输出均匀分片,从而无需因不可分割的分片而进行填充。

Shardy 的用户希望函数输入/输出均匀可分割/可分片,以避免需要填充其张量。传播可能会使输入/输出具有不可分割的分片,因此此传递会将它们更新为原始分片的最大维度分片前缀,该前缀是均匀分片的。

-sdy-verify-unreduced-axes

验证未缩减轴使用情况的一致性。

验证对于每个运算,如果其运算数具有未缩减的轴,则该运算要么显式缩减这些轴(例如,通过 sdy.reshard),要么将它们传递给其结果(或者是 func.call 等边界运算)。