Merged
feat(pypto): Add pypto.experimental.auto_mix_partition 0/1 config (9.2.0) #6654
feat(pypto): Add pypto.experimental.auto_mix_partition 0/1 config (9.2.0) #6654
Merged
dbjAdd on Sep 23
Total: 9 files changed+71-140
@@ -262,10 +262,10 @@ pypto.experimental.set_operation_options(combine_axis=False)
262 262 
263### Mix 合图问题(仅 A5)263### Mix 合图问题(仅 A5)
264 264 
265-仅针对 A5(设备 ID `d806`)。如果算子实现中开启了自动 CV Mix 合图(`auto_mix_partition=1`),可以尝试关闭合图,观察精度问题是否消失:265+仅针对 A5(设备 ID `d806`)。如果算子实现中开启了自动 CV Mix 合图(`pypto.experimental.auto_mix_partition(1)`),可以尝试关闭合图,观察精度问题是否消失:
266 266 
267```python267```python
268-pypto.set_pass_options(auto_mix_partition=0)268+pypto.experimental.auto_mix_partition(0)
269```269```
270 270 
271若关闭后重新执行精度通过 → 说明是 Mix 合图引入的精度问题,结束定位流程,反馈结果。271若关闭后重新执行精度通过 → 说明是 Mix 合图引入的精度问题,结束定位流程,反馈结果。
@@ -24,7 +24,6 @@ set_pass_options(*,
24 cube_l1_reuse_setting: Optional[Dict[str, int]] = None,24 cube_l1_reuse_setting: Optional[Dict[str, int]] = None,
25 cube_nbuffer_setting: Optional[Dict[str, int]] = None,25 cube_nbuffer_setting: Optional[Dict[str, int]] = None,
26 sg_set_scope: Optional[Union[int, Tuple[int, bool, bool]]] = None,26 sg_set_scope: Optional[Union[int, Tuple[int, bool, bool]]] = None,
27- auto_mix_partition: Optional[Union[int, str]] = None,
28 sg_set_ooo_scope: Optional[int] = None,27 sg_set_ooo_scope: Optional[int] = None,
29 experimental: Optional[Dict[str, int]] = None,28 experimental: Optional[Dict[str, int]] = None,
30 ooo_sched_mode: Optional[str] = None,29 ooo_sched_mode: Optional[str] = None,
@@ -40,9 +39,7 @@ set_pass_options(*,
40| cube_l1_reuse_setting | 输入 | 含义:合图参数,用于配置重复搬运同一GM(Global Memory)数据的子图合并数量。<br> 说明:该参数适用于含有Cube计算的子图合并,与cube_nbuffer_setting同时配置时,先进行此项合并,再进行cube_nbuffer_setting相关合并。<br><br>类型:dict[str, int]。支持两种key格式:<br> ① **函数粒度key**:字符串`"func{magic}_{order}"`或`"DEFAULT"`,可实现不同root function间的精细化配置。合图信息会直接展示在泳道图的hashOrder-hint字段中(含subGraphCount,代表合并前的子图数量,可根据核心数匹配合并力度)。详情参见下方"函数粒度配置说明"。<br> ② **语义标签key**:按语义标签控制(详见下方语义标签key配置说明)。<br> 取值:<br>{"DEFAULT": 1}:跳过L1Reuse合并 <br> {}(空字典):自动合并<br> {"DEFAULT": N, "func8_0": N2}:手动合并,默认粒度为N<br> 默认值:{} 空字典 <br> 影响Pass范围:L1CopyInReuseMerge |39| cube_l1_reuse_setting | 输入 | 含义:合图参数,用于配置重复搬运同一GM(Global Memory)数据的子图合并数量。<br> 说明:该参数适用于含有Cube计算的子图合并,与cube_nbuffer_setting同时配置时,先进行此项合并,再进行cube_nbuffer_setting相关合并。<br><br>类型:dict[str, int]。支持两种key格式:<br> ① **函数粒度key**:字符串`"func{magic}_{order}"`或`"DEFAULT"`,可实现不同root function间的精细化配置。合图信息会直接展示在泳道图的hashOrder-hint字段中(含subGraphCount,代表合并前的子图数量,可根据核心数匹配合并力度)。详情参见下方"函数粒度配置说明"。<br> ② **语义标签key**:按语义标签控制(详见下方语义标签key配置说明)。<br> 取值:<br>{"DEFAULT": 1}:跳过L1Reuse合并 <br> {}(空字典):自动合并<br> {"DEFAULT": N, "func8_0": N2}:手动合并,默认粒度为N<br> 默认值:{} 空字典 <br> 影响Pass范围:L1CopyInReuseMerge |
41| cube_nbuffer_setting | 输入 | 含义:合图参数,用于配置相同结构AIC子图的合并数量。 <br> 说明:该参数适用于结构相同的AIC子图合并,与cube_l1_reuse_setting同时配置时,先进行cube_l1_reuse_setting相关合并,再进行此项合并。<br><br>类型:dict[str, int]。支持两种key格式:<br> ① **函数粒度key**:字符串`"func{magic}_{order}"`或`"DEFAULT"`,可实现不同root function间的精细化配置。合图信息会直接展示在泳道图的hashOrder-hint字段中(含subGraphCount,代表合并前的子图数量,可根据核心数匹配合并力度)。详情参见下方"函数粒度配置说明"。<br> ② **语义标签key**:按语义标签控制(详见下方语义标签key配置说明)。<br> 取值:<br>{"DEFAULT": 1}:跳过AIC子图合并 <br> {}(空字典):显式开启自动合并<br> {"DEFAULT": N, "func8_0": N2}:手动合并,默认粒度为N<br>默认值:{"DEFAULT": 1},即默认跳过AIC子图合并 <br> 影响Pass范围:L1CopyInReuseMerge |40| cube_nbuffer_setting | 输入 | 含义:合图参数,用于配置相同结构AIC子图的合并数量。 <br> 说明:该参数适用于结构相同的AIC子图合并,与cube_l1_reuse_setting同时配置时,先进行cube_l1_reuse_setting相关合并,再进行此项合并。<br><br>类型:dict[str, int]。支持两种key格式:<br> ① **函数粒度key**:字符串`"func{magic}_{order}"`或`"DEFAULT"`,可实现不同root function间的精细化配置。合图信息会直接展示在泳道图的hashOrder-hint字段中(含subGraphCount,代表合并前的子图数量,可根据核心数匹配合并力度)。详情参见下方"函数粒度配置说明"。<br> ② **语义标签key**:按语义标签控制(详见下方语义标签key配置说明)。<br> 取值:<br>{"DEFAULT": 1}:跳过AIC子图合并 <br> {}(空字典):显式开启自动合并<br> {"DEFAULT": N, "func8_0": N2}:手动合并,默认粒度为N<br>默认值:{"DEFAULT": 1},即默认跳过AIC子图合并 <br> 影响Pass范围:L1CopyInReuseMerge |
42| sg_set_scope | 输入 | 含义:手动控制子图切分参数。<br> 说明:通过为Operation分配scope,使得相同scope_id(非-1)的相邻Operation强制合并归入同一子图,从而覆盖切分算法的自动划分结果。 <br> 类型:`Tuple[int, bool, bool]`或`int` <br> **tuple格式**:`(scope_id, allow_parallel_merge, allow_cross_scope_merge)`,各字段含义如下: <br> - `scope_id`(int):scope标识,取值范围 -1~2147483647。相同scope_id的相邻Operation归入同一子图;-1表示不参与scope合并,由切分算法决定子图划分。 <br> - `allow_parallel_merge`(bool):控制同一scope_id下Operation的合并方式。取值True/False。<br>&emsp;&emsp;False(默认):仅允许存在上下游连接通路的Operation合并,即Operation A的输出作为Operation B的输入时才可合并到同一子图。<br>&emsp;&emsp;True:允许位于并行分支(无数据依赖)的相同scope_id的Operation也合并到同一子图。 <br> - `allow_cross_scope_merge`(bool):控制带有scope的子图是否可与无scope(scope_id=-1)的子图合并,扩大scope子图。取值True/False。<br>&emsp;&emsp;False(默认):带有scope的子图保持独立,不与其他子图合并。<br>&emsp;&emsp;True:允许带有scope的子图与scope_id=-1的子图合并。不同scope_id的子图之间不可合并。 <br> **int格式**:传入单个int时等价于`(scope_id, False, False)`,即仅设置scope_id,不允许并行分支合并和跨scope合并。 <br> 默认值:(-1, False, False) <br> 影响Pass范围:GraphPartition <br> 配置建议:1)视图类Operation与其对应的计算类Operation应配置相同的scope_id。2)Reshape Operation较为特殊,部分场景会单独成子图,手动控制合图行为可能失效。|41| sg_set_scope | 输入 | 含义:手动控制子图切分参数。<br> 说明:通过为Operation分配scope,使得相同scope_id(非-1)的相邻Operation强制合并归入同一子图,从而覆盖切分算法的自动划分结果。 <br> 类型:`Tuple[int, bool, bool]`或`int` <br> **tuple格式**:`(scope_id, allow_parallel_merge, allow_cross_scope_merge)`,各字段含义如下: <br> - `scope_id`(int):scope标识,取值范围 -1~2147483647。相同scope_id的相邻Operation归入同一子图;-1表示不参与scope合并,由切分算法决定子图划分。 <br> - `allow_parallel_merge`(bool):控制同一scope_id下Operation的合并方式。取值True/False。<br>&emsp;&emsp;False(默认):仅允许存在上下游连接通路的Operation合并,即Operation A的输出作为Operation B的输入时才可合并到同一子图。<br>&emsp;&emsp;True:允许位于并行分支(无数据依赖)的相同scope_id的Operation也合并到同一子图。 <br> - `allow_cross_scope_merge`(bool):控制带有scope的子图是否可与无scope(scope_id=-1)的子图合并,扩大scope子图。取值True/False。<br>&emsp;&emsp;False(默认):带有scope的子图保持独立,不与其他子图合并。<br>&emsp;&emsp;True:允许带有scope的子图与scope_id=-1的子图合并。不同scope_id的子图之间不可合并。 <br> **int格式**:传入单个int时等价于`(scope_id, False, False)`,即仅设置scope_id,不允许并行分支合并和跨scope合并。 <br> 默认值:(-1, False, False) <br> 影响Pass范围:GraphPartition <br> 配置建议:1)视图类Operation与其对应的计算类Operation应配置相同的scope_id。2)Reshape Operation较为特殊,部分场景会单独成子图,手动控制合图行为可能失效。|
43-| auto_mix_partition | 输入 | 含义:控制ReduceCopyMerge Pass中的自动混合子图切分行为。<br> 说明:该参数用于控制CV混合场景下子图的自动合并策略,开启时编译器会评估相邻子图,在不形成环且满足合图约束时合并成MIX子图,否则不会进行合并。若计算图中存在CV混合scope(通过`sg_set_scope`手动标记,且scope内同时包含Cube和Vector算子),编译器会将该scope涉及的子图合并为Mix子图,此时不进行自动CV Mix合图(防止自动合并改变手动scope的切分结果)。合图时受算子数量上限约束,超限会拒绝合并并打日志;CV混合scope的合并不受此上限拦截,但超限时会打WARN日志提示编译时间风险。<br> 类型:str(推荐)或int(兼容旧版) <br> 默认值:'default' <br> 取值范围:{'off', 'default', 'high'} <br> - 'off':不进行自动CV Mix合图。<br> - 'default':default档,合并后子图Cube op数≤1700且Vector op数≤400。<br> - 'high':high档,合并后子图Cube op数≤2000且Vector op数≤2240。<br> 兼容说明:旧版整数取值0和1分别映射为'off'和'high'。<br> 影响Pass范围:ReduceCopyMerge |
44| sg_set_ooo_scope | 输入 | 含义:控制MIX子图内的OoO调度。<br> 说明:通过为 Operation分配ooo_scope,使得相同ooo_scope_id(非-1)的相邻 Operation 强制合并归入同一ooo_task,从而让相同ooo_scope_id(非-1)的相邻Operation在OoO调度生成的流水上尽可能相邻。不允许并行分支合并和跨ooo_scope合并, 不允许不同loop循环次数下的Operation的合并。 <br> 类型:`int`,即设置ooo_scope_id <br> 默认值:-1 <br> 取值范围:-1或1~10000 <br> `ooo_scope_id`:ooo_scope标识。相同ooo_scope_id的相邻Operation归入同一ooo_task;-1表示不参与ooo_scope合并,由切分算法决定ooo_task划分。 <br> 影响Pass范围:OoOSchedule <br> 配置要求:该功能仅对MIX子图生效。同时使用该功能和loop unroll时,unroll设置不得大于10000。该参数计划在后续版本废弃。|42| sg_set_ooo_scope | 输入 | 含义:控制MIX子图内的OoO调度。<br> 说明:通过为 Operation分配ooo_scope,使得相同ooo_scope_id(非-1)的相邻 Operation 强制合并归入同一ooo_task,从而让相同ooo_scope_id(非-1)的相邻Operation在OoO调度生成的流水上尽可能相邻。不允许并行分支合并和跨ooo_scope合并, 不允许不同loop循环次数下的Operation的合并。 <br> 类型:`int`,即设置ooo_scope_id <br> 默认值:-1 <br> 取值范围:-1或1~10000 <br> `ooo_scope_id`:ooo_scope标识。相同ooo_scope_id的相邻Operation归入同一ooo_task;-1表示不参与ooo_scope合并,由切分算法决定ooo_task划分。 <br> 影响Pass范围:OoOSchedule <br> 配置要求:该功能仅对MIX子图生效。同时使用该功能和loop unroll时,unroll设置不得大于10000。该参数计划在后续版本废弃。|
45-| sg_set_atomic_scope | 输入 | 含义:设置不可拆分的原子范围(atomic scope),为实验特性,通过`experimental`参数传入,后续版本可能调整或移除。 <br> 说明:通过为Operation分配atomic_scope,使得相同atomic_scope_id(非-1)的相邻Operation归入同一原子范围,在编译流程中保持不可拆分。原子范围的影响包括:<br> - VF融合:手动设置atomic_scope的Operation自身成为VF融合组,不与自动识别的VF cluster进行融合。<br> - OoO调度:相同atomic_scope_id的Operation归入同一atomic_task,在流水上尽可能相邻。不允许并行分支合并和跨atomic_scope合并,不允许不同loop循环次数下的Operation合并。<br> - 片上buffer:同一原子范围内的Operation之间不存在部分区间重叠的内存复用,内存区间要么完全不重叠,要么完全重叠。<br> - 同步指令插入:同一原子范围内的Operation之间不插入对其他pipe的同步指令,所有其他pipe的同步统一放置在整个原子范围的开头和结尾。<br> 配置方式:`pypto.set_pass_options(experimental={"sg_set_atomic_scope": atomic_scope_id})`,`atomic_scope_id`类型为`int` <br> 默认值:-1 <br> 取值范围:-1或1~10000 <br> `atomic_scope_id`:atomic_scope标识。相同atomic_scope_id的相邻Operation归入同一原子范围;-1表示不参与atomic_scope合并,由VF融合算法自动识别切分。 <br> 影响Pass范围:VFFusionClusterIdentify、OoOSchedule、InsertSync、MixSubgraphSplit、LoopaxesProc <br> 配置要求:同时使用该功能和loop unroll时,unroll设置不得大于10000。 <br> 与sg_set_scope的关系:sg_set_atomic_scope与sg_set_scope是互补关系,可配合使用亦可独立使用。sg_set_scope控制子图切分,决定哪些Operation属于同一子图;sg_set_atomic_scope在子图内进一步决定哪些Operation作为一个atomic cluster统一处理。两者配合时形成两层控制:先由sg_set_scope切分子图,再由sg_set_atomic_scope在子图内聚合原子范围;独立使用时各自发挥作用,互不依赖。|
46| ooo_sched_mode | 输入 | 含义:控制MIX子图内的OoO调度。<br> 说明:设置MIX子图内ooo_task的流水调度模式。 <br> 类型:`str` <br> 默认值:"" <br> 取值范围:{"", "GAPMIN", "HLF"} <br> 影响Pass范围:OoOSchedule <br> 配置说明:取值为""(默认)时使用基于拓扑序遍历和局部搜索的调度(GapMin调度 + local-search);取值为"GAPMIN"时仅执行GapMin调度,跳过local-search; 取值为"HLF"时使用Highest Level First调度(按任务到汇点最长路径降序排列后做EFT插入调度)。|43| ooo_sched_mode | 输入 | 含义:控制MIX子图内的OoO调度。<br> 说明:设置MIX子图内ooo_task的流水调度模式。 <br> 类型:`str` <br> 默认值:"" <br> 取值范围:{"", "GAPMIN", "HLF"} <br> 影响Pass范围:OoOSchedule <br> 配置说明:取值为""(默认)时使用基于拓扑序遍历和局部搜索的调度(GapMin调度 + local-search);取值为"GAPMIN"时仅执行GapMin调度,跳过local-search; 取值为"HLF"时使用Highest Level First调度(按任务到汇点最长路径降序排列后做EFT插入调度)。|
47| sg_set_tunevf_mode | 输入 | 含义:控制VF(Vector Fusion)调优Pass的行为模式。<br> 说明:用于控制TuneTileOpSeqForVF和TuneSyncForVF两个Pass的执行行为。<br> 类型:`int` <br> 默认值:0 <br> 取值范围:{0, 1, 2} <br> - 0:均衡模式,在OoO Pass输出的op序列的基础上自动完成op顺序的调整,自动平衡Pipeline流水与VF融合的整体性能收益。<br> - 1:指令流水优先模式,不改变OoO排好的op执行序。<br> - 2:vf融合优先模式,不考虑性能建模的收益评估,尽量调整op顺序以保证更大范围的VF融合。该模式仅影响TuneSyncForVF中的NeedAdjustOpSeq判断,不影响TuneTileOpSeqForVF。<br> 影响Pass范围:TuneTileOpSeqForVF, TuneSyncForVF |44| sg_set_tunevf_mode | 输入 | 含义:控制VF(Vector Fusion)调优Pass的行为模式。<br> 说明:用于控制TuneTileOpSeqForVF和TuneSyncForVF两个Pass的执行行为。<br> 类型:`int` <br> 默认值:0 <br> 取值范围:{0, 1, 2} <br> - 0:均衡模式,在OoO Pass输出的op序列的基础上自动完成op顺序的调整,自动平衡Pipeline流水与VF融合的整体性能收益。<br> - 1:指令流水优先模式,不改变OoO排好的op执行序。<br> - 2:vf融合优先模式,不考虑性能建模的收益评估,尽量调整op顺序以保证更大范围的VF融合。该模式仅影响TuneSyncForVF中的NeedAdjustOpSeq判断,不影响TuneTileOpSeqForVF。<br> 影响Pass范围:TuneTileOpSeqForVF, TuneSyncForVF |
48 45 
@@ -58,16 +55,6 @@ set_pass_options(*,
58- sg_set_scope一致性约束:同一scope_id的所有Operation必须设置相同的`allow_parallel_merge`和`allow_cross_scope_merge`,否则编译报错。55- sg_set_scope一致性约束:同一scope_id的所有Operation必须设置相同的`allow_parallel_merge`和`allow_cross_scope_merge`,否则编译报错。
59- scope_id为 -1时,`allow_parallel_merge`和`allow_cross_scope_merge`必须为False。56- scope_id为 -1时,`allow_parallel_merge`和`allow_cross_scope_merge`必须为False。
60- 不同scope_id的子图之间不可合并,`allow_cross_scope_merge`仅控制带scope的子图与无scope(scope_id=-1)的子图合并。57- 不同scope_id的子图之间不可合并,`allow_cross_scope_merge`仅控制带scope的子图与无scope(scope_id=-1)的子图合并。
61-- auto_mix_partition使用说明:
62- <!-- npu="950" id4 -->
63- - Ascend 950PR&950DT系列产品:支持。
64- <!-- end id4 -->
65- <!-- npu="A3" id5 -->
66- - Atlas A3系列产品:不支持,不进行自动cv mix合图。
67- <!-- end id5 -->
68- <!-- npu="910b" id6 -->
69- - Atlas A2系列产品:不支持,不进行自动cv mix合图。
70- <!-- end id6 -->
71- sg_set_scope使用说明:58- sg_set_scope使用说明:
72 <!-- npu="950" id7 -->59 <!-- npu="950" id7 -->
73 - Ascend 950PR&950DT系列产品:支持纯Vector、纯Cube以及CV混合场景的scope配置。60 - Ascend 950PR&950DT系列产品:支持纯Vector、纯Cube以及CV混合场景的scope配置。
@@ -88,16 +75,6 @@ set_pass_options(*,
88 <!-- npu="910b" id12 -->75 <!-- npu="910b" id12 -->
89 - Atlas A2系列产品:不支持,因为不支持cv mix合图。76 - Atlas A2系列产品:不支持,因为不支持cv mix合图。
90 <!-- end id12 -->77 <!-- end id12 -->
91-- sg_set_atomic_scope使用说明:
92- <!-- npu="950" id13 -->
93- - Ascend 950PR&950DT系列产品:支持。
94- <!-- end id13 -->
95- <!-- npu="A3" id14 -->
96- - Atlas A3系列产品:不支持,因为不支持VF融合。
97- <!-- end id14 -->
98- <!-- npu="910b" id15 -->
99- - Atlas A2系列产品:不支持,因为不支持VF融合。
100- <!-- end id15 -->
101- ooo_sched_mode使用说明:78- ooo_sched_mode使用说明:
102 <!-- npu="950" id16 -->79 <!-- npu="950" id16 -->
103 - Ascend 950PR&950DT系列产品:支持。80 - Ascend 950PR&950DT系列产品:支持。
@@ -329,36 +306,6 @@ pypto.set_pass_options(sg_set_ooo_scope=-1)
329pypto.set_pass_options(sg_set_scope=-1)306pypto.set_pass_options(sg_set_scope=-1)
330```307```
331 308 
332-### sg_set_atomic_scope 配置说明
333- 
334-`sg_set_atomic_scope` 设置不可拆分的原子范围(atomic scope),影响范围包括VF融合、OoO调度、片上buffer复用、同步指令插入、mix子图拆分和loop循环分组。该参数为实验特性,通过`experimental`参数传入,后续版本可能调整或移除。
335- 
336-#### 配置示例
337- 
338-```python
339-# 设置 atomic_scope_id
340-pypto.set_pass_options(experimental={"sg_set_atomic_scope": 10})
341- 
342-# 恢复默认(不参与 atomic_scope 合并,由切分算法自动决定)
343-pypto.set_pass_options(experimental={"sg_set_atomic_scope": -1})
344-```
345- 
346-#### 典型场景:通过 atomic_scope 控制VF融合与执行顺序
347- 
348-如下面示例,通过将 mul 和 exp 包在相同的 atomic_scope,可以使得它们形成一个VF融合组,并且 exp 在 add 之前执行
349- 
350-```python
351-pypto.set_pass_options(experimental={"sg_set_atomic_scope": 1})
352-# Vec 操作(atomic_scope_id=1)
353-c = pypto.mul(matmul_result, scale)
354-pypto.set_pass_options(experimental={"sg_set_atomic_scope": -1})
355-d = pypto.add(c, bias)
356-pypto.set_pass_options(experimental={"sg_set_atomic_scope": 1})
357-# Vec 操作(atomic_scope_id=1)
358-e = pypto.exp(c)
359-pypto.set_pass_options(experimental={"sg_set_atomic_scope": -1})
360-```
361- 
362### sg_set_tunevf_mode 配置说明309### sg_set_tunevf_mode 配置说明
363 310 
364#### 配置示例311#### 配置示例
@@ -6,7 +6,7 @@
6 "mg_copyin_upper_bound": 104857600,6 "mg_copyin_upper_bound": 104857600,
7 "mg_vec_parallel_lb": 48,7 "mg_vec_parallel_lb": 48,
8 "copyout_resolve_coalescing": 0,8 "copyout_resolve_coalescing": 0,
9- "auto_mix_partition": 2,9+ "auto_mix_partition": 0,
10 "sg_set_tunevf_mode": 0,10 "sg_set_tunevf_mode": 0,
11 "sg_set_scope": [-1, 0, 0],11 "sg_set_scope": [-1, 0, 0],
12 "sg_set_ooo_scope": [-1],12 "sg_set_ooo_scope": [-1],
@@ -173,13 +173,13 @@
173 },173 },
174 "auto_mix_partition": {174 "auto_mix_partition": {
175 "type": "integer",175 "type": "integer",
176- "default": 2,176+ "default": 0,
177 "label": {177 "label": {
178- "zh": "控制ReduceCopyMerge Pass中的自动混合子图切分行为。0:不进行自动CV Mix合图;1:high档,合并后子图Cube op数不超过2000且Vector op数不超过2240(旧版本取值,行为兼容);2:default档,合并后子图Cube op数不超过1700且Vector op数不超过400;N(N>100):自定义档,合并后子图总op数(Cube+Vector)不超过N,不再分别限制Cube/Vector op数;3~100:非法自定义值,回退default档并打WARN日志。",178+ "zh": "控制ReduceCopyMerge Pass中的自动混合子图切分行为。0:不进行自动CV Mix合图;1:进行自动CV Mix合图,合并后子图Cube op数不超过2000且Vector op数不超过2240。",
179- "en": "Controls the automatic mixed subgraph partitioning behavior in the ReduceCopyMerge Pass. 0: disable auto CV Mix merging; 1: high level, Cube ops <= 2000 and Vector ops <= 2240 per merged subgraph (legacy value, backward compatible); 2: default level, Cube ops <= 1700 and Vector ops <= 400; N (>100): custom level, total op count (Cube + Vector) per merged subgraph must not exceed N; 3~100: invalid custom value, falls back to default level with a WARN log."179+ "en": "Controls the automatic mixed subgraph partitioning behavior in the ReduceCopyMerge Pass. 0: disable auto CV Mix merging; 1: enable auto CV Mix merging, Cube ops <= 2000 and Vector ops <= 2240 per merged subgraph."
180 },180 },
181 "minimum": 0,181 "minimum": 0,
182- "maximum": 100000182+ "maximum": 1
183 },183 },
184 "sg_set_tunevf_mode": {184 "sg_set_tunevf_mode": {
185 "type": "integer",185 "type": "integer",
@@ -245,37 +245,6 @@ def set_print_options(
245 pypto_impl.SetPrintOptions(edgeitems, precision, threshold, linewidth)245 pypto_impl.SetPrintOptions(edgeitems, precision, threshold, linewidth)
246 246 
247 247 
248-# auto_mix_partition 档位名的整数编码, 与 C++ 侧档位语义保持一致:
249-# 'high'=1 为旧值兼容(旧版本 =1 开启即 high 上限), 'default'=2 为推荐收紧档(内部编码, 对外不暴露)
250-_AUTO_MIX_PARTITION_LEVELS = {'off': 0, 'high': 1, 'default': 2}
251- 
252- 
253-def _encode_auto_mix_partition(value: Union[int, str]) -> int:
254- """Normalize auto_mix_partition: string levels map to int encodings, legacy ints 0/1 pass through."""
255- if isinstance(value, str):
256- level = _AUTO_MIX_PARTITION_LEVELS.get(value)
257- if level is None:
258- raise ValueError(
259- f"Invalid auto_mix_partition: '{value}'. Expected 'off', 'default' or 'high'."
260- )
261- return level
262- if isinstance(value, bool) or not isinstance(value, int):
263- raise ValueError(f"Invalid auto_mix_partition: '{value}'. Expected 'off', 'default' or 'high'.")
264- if value not in (0, 1):
265- raise ValueError(
266- f"Invalid auto_mix_partition: {value}. Expected 'off', 'default' or 'high'."
267- )
268- return value
269- 
270- 
271-_AUTO_MIX_PARTITION_LEVEL_NAMES = {code: name for name, code in _AUTO_MIX_PARTITION_LEVELS.items()}
272- 
273- 
274-def _decode_auto_mix_partition(value: int) -> Union[int, str]:
275- """Decode the stored int config back to the user-facing level name."""
276- return _AUTO_MIX_PARTITION_LEVEL_NAMES.get(value, value)
277- 
278- 
279def set_pass_options(248def set_pass_options(
280 *,249 *,
281 vec_nbuffer_setting: Optional[Dict[Union[int, str], int]] = None,250 vec_nbuffer_setting: Optional[Dict[Union[int, str], int]] = None,
@@ -285,7 +254,6 @@ def set_pass_options(
285 sg_set_ooo_scope: Optional[int] = None,254 sg_set_ooo_scope: Optional[int] = None,
286 experimental: Optional[Dict[str, int]] = None,255 experimental: Optional[Dict[str, int]] = None,
287 ooo_sched_mode: Optional[str] = None,256 ooo_sched_mode: Optional[str] = None,
288- auto_mix_partition: Optional[Union[int, str]] = None,
289 sg_set_tunevf_mode: Optional[int] = None,257 sg_set_tunevf_mode: Optional[int] = None,
atomgit-bot

🟠 High Priority

变更点:python/pypto/config.py 的 set_pass_options 签名删除了关键字参数 auto_mix_partition: Optional[Union[int, str]] = None(新文件第 256/257 行之间),且该函数签名形如 def set_pass_options(*, ...),没有 **kwargs 兜底。

受影响契约:set_pass_options 是 jit / runtime 的统一入口,python/pypto/frontend/parser/entry.py:978 会执行 pypto.set_pass_options(**self._pass_options),其中 _pass_options 就是用户传给 pypto.frontend.jit(pass_options=...) 的字典(entry.py:278 dict(pass_options))。

失败模式:仓库内未同步修改的调用方 python/tests/st/test_dualdst.py:51 仍为 pypto.frontend.jit(..., pass_options={"auto_mix_partition": 1})。该 kernel 被调用时会以关键字参数 auto_mix_partition 调用 set_pass_options,由于参数已被删除且无 **kwargs,直接抛出 TypeError: set_pass_options() got an unexpected keyword argument 'auto_mix_partition',导致该 ST 用例(及其覆盖的 dualdst 编译流程)失败。同理,任何沿用旧写法把 auto_mix_partition 放进 pass_options 的存量用户代码也会从“可用”变为“报错”。

建议:保留 set_pass_options 的 auto_mix_partition 参数作为兼容入口(内部转发到 pass_options['auto_mix_partition'] 或新的 experimental 入口),或同步更新 python/tests/st/test_dualdst.py:51 等仍使用 pass_options={"auto_mix_partition": ...} 的调用方为 pypto.experimental.auto_mix_partition(...)。

likedislike
Incorrect?
dbj
dbj
Sep 23 Comments:
likedislike
290) -> None:258) -> None:
291 """259 """
@@ -331,15 +299,6 @@ def set_pass_options(
331 * allow_parallel_merge: bool, enable parallel branch merging299 * allow_parallel_merge: bool, enable parallel branch merging
332 * allow_cross_scope_merge: bool, allow supernode with scope to merge with others300 * allow_cross_scope_merge: bool, allow supernode with scope to merge with others
333 301 
334- auto_mix_partition : Union[int, str]
335- Control the auto mix partition behavior in ReduceCopyMerge pass.
336- 'off' disables auto CV Mix graph merging; 'high' enables it with high
337- op limits (Cube ops <= 2000 and Vector ops <= 2240 per merged
338- subgraph); 'default' enables it with tighter op limits (Cube ops <=
339- 1700 and Vector ops <= 400, the default when not configured).
340- Ints 0 and 1 are accepted as legacy equivalents of 'off' and 'high'.
341- get_pass_options reads back the configured level name.
342- 
343 sg_set_tunevf_mode : int302 sg_set_tunevf_mode : int
344 Control the VF (Vector Fusion) tuning pass behavior.303 Control the VF (Vector Fusion) tuning pass behavior.
345 - 0: default behavior (no change)304 - 0: default behavior (no change)
@@ -377,8 +336,6 @@ def set_pass_options(
377 pass_options['cube_l1_reuse_setting'] = cube_l1_reuse_setting336 pass_options['cube_l1_reuse_setting'] = cube_l1_reuse_setting
378 if cube_nbuffer_setting is not None:337 if cube_nbuffer_setting is not None:
379 pass_options['cube_nbuffer_setting'] = cube_nbuffer_setting338 pass_options['cube_nbuffer_setting'] = cube_nbuffer_setting
380- if auto_mix_partition is not None:
381- pass_options['auto_mix_partition'] = _encode_auto_mix_partition(auto_mix_partition)
382 if sg_set_tunevf_mode is not None:339 if sg_set_tunevf_mode is not None:
383 if sg_set_tunevf_mode not in (0, 1, 2):340 if sg_set_tunevf_mode not in (0, 1, 2):
384 raise ValueError(f"Invalid sg_set_tunevf_mode: '{sg_set_tunevf_mode}'. Expected 0, 1 or 2.")341 raise ValueError(f"Invalid sg_set_tunevf_mode: '{sg_set_tunevf_mode}'. Expected 0, 1 or 2.")
@@ -446,7 +403,6 @@ def get_pass_options() -> Dict[str, Union[str, int, bool, List[int], Dict[int, i
446 }403 }
447 val = rst.get("sg_set_scope", (-1, False, False))404 val = rst.get("sg_set_scope", (-1, False, False))
448 result['sg_set_scope'] = (int(val[0]), bool(val[1]), bool(val[2]))405 result['sg_set_scope'] = (int(val[0]), bool(val[1]), bool(val[2]))
449- result['auto_mix_partition'] = _decode_auto_mix_partition(rst.get('auto_mix_partition', 2))
450 # sg_set_ooo_scope is stored as the sg_set_atomic_scope config key (converted at set time).406 # sg_set_ooo_scope is stored as the sg_set_atomic_scope config key (converted at set time).
451 scope_val = _decode_scope_id(rst.get('sg_set_atomic_scope', [0]))407 scope_val = _decode_scope_id(rst.get('sg_set_atomic_scope', [0]))
452 result['sg_set_ooo_scope'] = scope_val408 result['sg_set_ooo_scope'] = scope_val
@@ -20,5 +20,6 @@ from .operation import (
20 set_operation_options, # noqa: F40120 set_operation_options, # noqa: F401
21 transposed_batchmatmul, # noqa: F40121 transposed_batchmatmul, # noqa: F401
22)22)
23+from .pass_config import auto_mix_partition # noqa: F401
23from .runtime import get_runtime_options, set_runtime_options # noqa: F40124from .runtime import get_runtime_options, set_runtime_options # noqa: F401
24from .shmem import shmem_load, shmem_store # noqa: F40125from .shmem import shmem_load, shmem_store # noqa: F401
@@ -0,0 +1,35 @@
1+#!/usr/bin/env python3
2+# coding: utf-8
3+# Copyright (c) 2026 Huawei Technologies Co., Ltd.
4+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5+# CANN Open Software License Agreement Version 2.0 (the "License").
6+# Please refer to the License for details. You may not use this file except in compliance with the License.
7+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
9+# See LICENSE in the root of the software repository for the full text of the License.
10+# -----------------------------------------------------------------------------------------------------------
11+"""Experimental auto mix partition option.
12+ 
13+Use auto_mix_partition to configure the auto CV Mix merging switch of the
14+ReduceCopyMerge pass, which is not yet stable enough for pypto.set_pass_options.
15+"""
16+ 
17+from ..config import set_options
18+ 
19+ 
20+def auto_mix_partition(value: int):
21+ """
22+ Set the auto mix partition option.
23+ 
24+ Parameters
25+ ---------
26+ value : int
27+ Experimental. Controls the automatic CV Mix subgraph merging in the
28+ ReduceCopyMerge pass. 0 disables auto CV Mix graph merging; 1 enables
29+ it with Cube ops <= 2000 and Vector ops <= 2240 per merged subgraph.
30+ Defaults to 0. This is an experimental feature that may change or be
31+ removed in future releases.
32+ """
33+ if isinstance(value, bool) or not isinstance(value, int) or value not in (0, 1):
34+ raise ValueError(f"Invalid auto_mix_partition: '{value}'. Expected 0 (disable) or 1 (enable).")
35+ set_options(pass_options={'auto_mix_partition': value})
@@ -48,7 +48,7 @@ FP32 = pypto.DT_FP32
48 48 
49# 所有 dualdst kernel 共用同一份 jit 配置: 提前固化, 避免每个 kernel 重复 3 行装饰器。49# 所有 dualdst kernel 共用同一份 jit 配置: 提前固化, 避免每个 kernel 重复 3 行装饰器。
50_DUALDST_JIT = pypto.frontend.jit(50_DUALDST_JIT = pypto.frontend.jit(
51- debug_options={"runtime_debug_mode": 0, "compile_debug_mode": 0}, pass_options={"auto_mix_partition": 1}51+ debug_options={"runtime_debug_mode": 0, "compile_debug_mode": 0}
52)52)
53 53 
54 54 
@@ -96,6 +96,7 @@ def dual_dst_split_n_kernel(
96 单 cube tile 覆盖 M/K/N: 一次 matmul 产出唯一一份 L0C tensor,96 单 cube tile 覆盖 M/K/N: 一次 matmul 产出唯一一份 L0C tensor,
97 它的两个 L0C_COPY_UB consumer 才是 dual_dst 候选对。97 它的两个 L0C_COPY_UB consumer 才是 dual_dst 候选对。
98 """98 """
99+ pypto.experimental.auto_mix_partition(1)
99 upper, lower = _split_n_prologue_64(a_tensor, b_tensor)100 upper, lower = _split_n_prologue_64(a_tensor, b_tensor)
100 upper = _online_softmax_exp(upper, 64, 64)101 upper = _online_softmax_exp(upper, 64, 64)
101 lower = _online_softmax_exp(lower, 64, 64)102 lower = _online_softmax_exp(lower, 64, 64)
@@ -148,6 +149,7 @@ def dual_dst_split_m_kernel(
148 out1_tensor: pypto.Tensor([pypto.STATIC, pypto.STATIC], FP32),149 out1_tensor: pypto.Tensor([pypto.STATIC, pypto.STATIC], FP32),
149):150):
150 """matmul -> L0C -> M 轴二分 -> 两条独立 add-scalar vector chain (SplitM 方向)。"""151 """matmul -> L0C -> M 轴二分 -> 两条独立 add-scalar vector chain (SplitM 方向)。"""
152+ pypto.experimental.auto_mix_partition(1)
151 pypto.set_cube_tile_shapes([128, 128], [64, 64], [64, 64])153 pypto.set_cube_tile_shapes([128, 128], [64, 64], [64, 64])
152 mm = pypto.matmul(a_tensor, b_tensor, b_trans=True, out_dtype=FP32)154 mm = pypto.matmul(a_tensor, b_tensor, b_trans=True, out_dtype=FP32)
153 half_m = mm.shape[0] // 2155 half_m = mm.shape[0] // 2
@@ -197,6 +199,7 @@ def dual_dst_chained_ops_kernel(
197 199 
198 验证 dualdst 融合后下游多步依赖链仍正确。200 验证 dualdst 融合后下游多步依赖链仍正确。
199 """201 """
202+ pypto.experimental.auto_mix_partition(1)
200 upper, lower = _split_n_prologue_64(a_tensor, b_tensor)203 upper, lower = _split_n_prologue_64(a_tensor, b_tensor)
201 upper = _online_softmax_exp(upper, 64, 64)204 upper = _online_softmax_exp(upper, 64, 64)
202 lower = _online_softmax_exp(lower, 64, 64)205 lower = _online_softmax_exp(lower, 64, 64)
@@ -245,6 +248,7 @@ def dual_dst_asymmetric_scale_kernel(
245 248 
246 验证两个 AIV core 实际执行不同语义但共享同一份 L0C 数据。249 验证两个 AIV core 实际执行不同语义但共享同一份 L0C 数据。
247 """250 """
251+ pypto.experimental.auto_mix_partition(1)
248 upper, lower = _split_n_prologue_64(a_tensor, b_tensor)252 upper, lower = _split_n_prologue_64(a_tensor, b_tensor)
249 upper = _online_softmax_exp(upper, 64, 64)253 upper = _online_softmax_exp(upper, 64, 64)
250 lower = _online_softmax_exp(lower, 64, 64)254 lower = _online_softmax_exp(lower, 64, 64)
@@ -321,6 +325,7 @@ def dual_dst_max_gain_kernel(
321 相邻 (偶,奇) 子块被 dualdst 合并, 累计 N_PAIRS 对融合。325 相邻 (偶,奇) 子块被 dualdst 合并, 累计 N_PAIRS 对融合。
322 所有切片边界都是 python int 常量。326 所有切片边界都是 python int 常量。
323 """327 """
328+ pypto.experimental.auto_mix_partition(1)
324 pypto.set_cube_tile_shapes([GAIN_M, GAIN_M], [GAIN_K, GAIN_K], [2 * GAIN_HALF_N, 2 * GAIN_HALF_N])329 pypto.set_cube_tile_shapes([GAIN_M, GAIN_M], [GAIN_K, GAIN_K], [2 * GAIN_HALF_N, 2 * GAIN_HALF_N])
325 mm = pypto.matmul(a_tensor, b_tensor, b_trans=True, out_dtype=FP32)330 mm = pypto.matmul(a_tensor, b_tensor, b_trans=True, out_dtype=FP32)
326 for j in range(2 * N_PAIRS):331 for j in range(2 * N_PAIRS):
@@ -388,6 +393,7 @@ def dual_dst_long_chain_kernel(
388 393 
389 每条 chain 跟 ADDS_CHAIN_DEPTH 步 ADDS 形成长依赖链。394 每条 chain 跟 ADDS_CHAIN_DEPTH 步 ADDS 形成长依赖链。
390 """395 """
396+ pypto.experimental.auto_mix_partition(1)
391 pypto.set_cube_tile_shapes([MM_M, MM_M], [MM_K, MM_K], [MM_N, MM_N])397 pypto.set_cube_tile_shapes([MM_M, MM_M], [MM_K, MM_K], [MM_N, MM_N])
392 # 上半 / 下半 chain 各自的 ADDS scalar 序列; sum 用于 golden 累加。398 # 上半 / 下半 chain 各自的 ADDS scalar 序列; sum 用于 golden 累加。
393 upper_scalars = [0.5, 1.0, 1.5, 2.0] # len == ADDS_CHAIN_DEPTH399 upper_scalars = [0.5, 1.0, 1.5, 2.0] # len == ADDS_CHAIN_DEPTH
@@ -498,6 +504,7 @@ def dual_dst_link_chain_kernel(
498 每个 ws 各自独立, 避开 "同一 GM tensor 多 slice 读写" 的 pypto IR 环路;504 每个 ws 各自独立, 避开 "同一 GM tensor 多 slice 读写" 的 pypto IR 环路;
499 最后一步直接写 out_a / out_b。505 最后一步直接写 out_a / out_b。
500 """506 """
507+ pypto.experimental.auto_mix_partition(1)
501 pypto.set_cube_tile_shapes([LINK_M, LINK_M], [LINK_K, LINK_K], [LINK_N, LINK_N])508 pypto.set_cube_tile_shapes([LINK_M, LINK_M], [LINK_K, LINK_K], [LINK_N, LINK_N])
502 # 中间步 workspace: 每个独立 LogicalTensor, 写一次/读一次, 不与最终 out_a/out_b 共享。509 # 中间步 workspace: 每个独立 LogicalTensor, 写一次/读一次, 不与最终 out_a/out_b 共享。
503 # 用普通 for 循环 (而非 list comprehension) 收集: pypto parser 不进入 list comp 的510 # 用普通 for 循环 (而非 list comprehension) 收集: pypto parser 不进入 list comp 的
@@ -630,6 +637,7 @@ def dual_dst_mega_kernel(
630 out_a_tensor: [MEGA_TOTAL_MM * MEGA_M, MEGA_HALF_N] AIV0 chain 输出沿 M 拼637 out_a_tensor: [MEGA_TOTAL_MM * MEGA_M, MEGA_HALF_N] AIV0 chain 输出沿 M 拼
631 out_b_tensor: [MEGA_TOTAL_MM * MEGA_M, MEGA_HALF_N] AIV1 chain 输出沿 M 拼638 out_b_tensor: [MEGA_TOTAL_MM * MEGA_M, MEGA_HALF_N] AIV1 chain 输出沿 M 拼
632 """639 """
640+ pypto.experimental.auto_mix_partition(1)
633 pypto.set_cube_tile_shapes([MEGA_M, MEGA_M], [MEGA_K, MEGA_K], [MEGA_N, MEGA_N])641 pypto.set_cube_tile_shapes([MEGA_M, MEGA_M], [MEGA_K, MEGA_K], [MEGA_N, MEGA_N])
634 # 外循环 s = 并行分支 idx, 内循环 i = 单分支内串行 mm idx;642 # 外循环 s = 并行分支 idx, 内循环 i = 单分支内串行 mm idx;
635 # 外内嵌套保证 IR op 顺序上 branch_0 的 10 个 mm 聚在一起 (串行语义), 而643 # 外内嵌套保证 IR op 顺序上 branch_0 的 10 个 mm 聚在一起 (串行语义), 而
@@ -229,55 +229,39 @@ def test_sg_set_atomic_scope():
229 229 
230 230 
231def test_auto_mix_partition():231def test_auto_mix_partition():
232- # level names round-trip: get returns the configured form232+ # 0/1 accepted via the experimental entry
233- pypto.set_pass_options(auto_mix_partition="high")233+ pypto.experimental.auto_mix_partition(1)
234- pass_option = pypto.get_pass_options()234+ pypto.experimental.auto_mix_partition(0)
235- assert pass_option["auto_mix_partition"] == 'high'
236 235 
237- pypto.set_pass_options(auto_mix_partition="default")236+ # int values other than 0/1 are rejected (default/custom op-limit config is not exposed)
238- pass_option = pypto.get_pass_options()
239- assert pass_option["auto_mix_partition"] == 'default'
240- 
241- pypto.set_pass_options(auto_mix_partition="off")
242- pass_option = pypto.get_pass_options()
243- assert pass_option["auto_mix_partition"] == 'off'
244- 
245- # legacy int 1 keeps high-level behavior (backward compatible), reads back 'high'
246- pypto.set_pass_options(auto_mix_partition=1)
247- pass_option = pypto.get_pass_options()
248- assert pass_option["auto_mix_partition"] == 'high'
249- 
250- # legacy int 0 keeps off behavior, reads back 'off'
251- pypto.set_pass_options(auto_mix_partition=0)
252- pass_option = pypto.get_pass_options()
253- assert pass_option["auto_mix_partition"] == 'off'
254- 
255- # int values other than legacy 0/1 are rejected (custom op-limit config is not exposed)
256 for invalid_value in (-5, -1, 2, 3, 50, 100, 101, 200):237 for invalid_value in (-5, -1, 2, 3, 50, 100, 101, 200):
257 try:238 try:
258- pypto.set_pass_options(auto_mix_partition=invalid_value)239+ pypto.experimental.auto_mix_partition(invalid_value)
259 assert False, "Should raise ValueError"240 assert False, "Should raise ValueError"
260 except ValueError as e:241 except ValueError as e:
261 assert "Invalid auto_mix_partition" in str(e)242 assert "Invalid auto_mix_partition" in str(e)
262 243 
263- # invalid string244+ # invalid strings (level names are removed)
264- try:245+ for invalid_str in ("high", "default", "off", "middle"):
265- pypto.set_pass_options(auto_mix_partition="middle")246+ try:
266- assert False, "Should raise ValueError"247+ pypto.experimental.auto_mix_partition(invalid_str)
267- except ValueError as e:248+ assert False, "Should raise ValueError"
268- assert "Invalid auto_mix_partition" in str(e)249+ except ValueError as e:
250+ assert "Invalid auto_mix_partition" in str(e)
269 251 
270 # invalid type252 # invalid type
271 try:253 try:
272- pypto.set_pass_options(auto_mix_partition=1.5)254+ pypto.experimental.auto_mix_partition(1.5)
273 assert False, "Should raise ValueError"255 assert False, "Should raise ValueError"
274 except ValueError as e:256 except ValueError as e:
275 assert "Invalid auto_mix_partition" in str(e)257 assert "Invalid auto_mix_partition" in str(e)
276 258 
277- # after reset the default level applies and reads back 'default'259+ # bool is rejected (bool is a subclass of int)
278- pypto.reset_options()260+ try:
279- pass_option = pypto.get_pass_options()261+ pypto.experimental.auto_mix_partition(True)
280- assert pass_option["auto_mix_partition"] == 'default'262+ assert False, "Should raise ValueError"
263+ except ValueError as e:
264+ assert "Invalid auto_mix_partition" in str(e)
281 265 
282 pypto.reset_options()266 pypto.reset_options()
283 267