Pull Request已成功合入, 合并人@ascend-robot
(感谢 maoyuanpeng1 的贡献)Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/pytorch | ✅ chujinjin, hbhu_bin (2/2) | ✅ chujinjin (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
maoyuanpeng1, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.9.0 | ||
| v2.12.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


Ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


Ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


compile


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


这里为啥要删除


删除 _get_backend_index_for_npu 中通过 structured_delegate 查询 structured group kernel 的兜底逻辑,是为了避免 AOTInductor C shim为 out-only structured 算子生成 functional ABI。
在本次 structured meta 支持中,NPU backend index 改为 use_out_as_primary=True,并且 structured 算子的 backend metadata 标在 structured out variant 上。这个变化后,backend_index.has_kernel(NativeFunctionsGroup) 的语义会从查询 functional variant 变成查询 out variant。
原逻辑中:
backend_indices[dk].has_kernel(func) or (
func.structured_delegate is not None
and func.structured_delegate in structured_func_group_dict
and backend_indices[dk].has_kernel(
structured_func_group_dict[func.structured_delegate]
)
)
第二段会在当前 func 是 functional variant 时,通过 structured_delegate 找到它所属的 structured group,并查询该 group 是否有 NPU kernel。由于当前 has_kernel(group) 会命中 out variant,这会把“只支持 xxx.out”误判为“functional xxx 也支持”。
例如 NPU yaml 中只声明了:
- func: cumprod.out(...)
没有声明:
- func: cumprod(...)
在新语义下,恢复旧逻辑会导致:
has_kernel(cumprod functional) -> False
has_kernel(cumprod structured group) -> has_kernel(cumprod.out) -> True
于是 AOTInductor C shim 会错误生成:
AOTI_TORCH_EXPORT AOTITorchError aoti_torch_npu_cumprod(...);
类似还会多生成 _addmm_activation、gcd 等 functional shim,触发 c_shim_npu.h 的 ABI diff 检查失败。
因此 _get_backend_index_for_npu 只能按当前 NativeFunction 本身判断:
if backend_indices[dk].has_kernel(func):
return backend_indices[dk]
这样 AOTI C shim 只会为当前 schema 自身在 backend index 中存在的 op 生成导出函数,不会把 structured out variant 的支持扩散到 functional variant,避免错误扩大 AOTI C ABI。
这里的目的其实就是为了通过structure进行支持的
但是我们很多算子(在pytorch中是structured算子)只实现了out版本,没有实现functional版本。这与structured算子本来就是背道而驰。
这些模板不能复用的原因是什么


这里新增的有没有可以复用上游社区的,
如果针对structured的代码比较多的话,是不是可以单独抽出一个文件,那样理解起来是不是简单些




【合入来源】
https://gitcode.com/Ascend/pytorch/issues/2110
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】