已合并
feat(_inductor): add ascendc backend support for aclgraph capture/replay #40264
dingdairong创建于 7月7日
feat(_inductor): add ascendc backend support for aclgraph capture/replay #40264
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 dingdairong 的贡献)7月7日 创建了 pull request,commit 81eaf341
atomgit-bot
7月7日 评论:
7月7日 评论:
变更摘要
此 PR 为 torch_npu/_inductor 新增了 ascendc 后端支持,用于 aclgraph 的 capture/replay。核心思路是将原先无条件执行的通用 patch 拆分为"顶层 NPU 设备级 patch"和"triton/mlir 后端共用 patch"两层,使得 ascendc 后端可以跳过不相关的 triton 相关 patch,并通过独立的 loader 函数注册到后端加载器中。
主要改动
- 新增
_load_ascendc_backend加载器及后端注册:通过from . import ascendc导入同级ascendc包触发后端注册(含NPUScheduling、NpuWrapperCodeGen及should_partition的 backend override),并在_BACKEND_LOADERS字典中新增"ascendc"键映射到该加载器。 - 抽取
_apply_common_patches函数:将原先无条件调用的patch_has_triton、patch_is_gpu、patch_device_supports_tma、patch_codegen_with_cpp_wrapper、patch_cache_base_get_system封装为共用函数,供 triton/mlir/dvm 后端显式调用。 - 顶层 patch 与后端 patch 解耦:
npu_patch_meta()和register_device_op_overrides_npu()保留在模块顶层无条件执行,确保所有后端(含ascendc)均获得 NPU 设备级基础 patch,而 triton 系 patch 仅在后端 loader 内部按需执行。 - 现有后端点加载器适配:
_load_mlir_backend、_load_dvm_backend、_load_triton_backend均在函数开头增加_apply_common_patches()调用,保持原有行为不变。


ascend-robot
7月7日 评论:
7月7日 评论:
atomgit-bot
7月7日 评论:
7月7日 评论:
代码审查
审查总结
本次审查覆盖了唯一变更文件 torch_npu/_inductor/__init__.py,发现 2 个问题:
| 优先级 | 数量 | 说明 |
|---|---|---|
| P1 | 1 | _load_ascendc_backend 导入不存在的 ascendc 模块 |
| P2 | 1 | _load_ascendc_backend 未调用 patch_is_gpu(),可能导致 NPU 不被识别为 GPU 类型 |
整体风险评估:中等。主要风险在于 ascendc 模块缺失会导致新后端运行时崩溃(P1),以及 patch_is_gpu() 未调用可能导致 NPU 设备类型识别异常(P2)。如果 ascendc 模块已存在于目标分支或将在同一发布中合入,则 P1 问题自动解除;P2 问题需确认 ascendc 模块内部是否自行处理了 GPU_TYPES 注册。其余变更(将模块级 patch 调用重构为 _apply_common_patches() 并按后端按需调用)逻辑正确,无其他问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 0 |
⛔ 需要修改


7月7日 修改了pull request 的描述
此处折叠了136条消息 查看更多
7月8日 添加了label:lgtm
7月8日 合入了pull request
ascend-robot
7月8日 评论:
7月8日 评论:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


ascend-robot
7月8日 评论:
7月8日 评论:
流水线 pytorch_gitcode_PR_multiVersion#12228 [ commitID:789c9adb ] 已完成


【合入来源】
【修改方案】
支持npu_backend option配置为ascendc
compiled_model = torch.compile(
test_add_sum,
backend="inductor", # 指定后端为 Inductor
options={"npu_backend": "ascendc", "triton.cudagraphs": True},
)
【资料变更】
涉及新增
【接口变更】
不涉及
【功能验证】
新增st
【CheckList】