已合并
feat: [graph partition] aclgraph support graph partition #35325
luochao60创建于 5月11日
feat: [graph partition] aclgraph support graph partition #35325
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 luochao60 的贡献)ascend-robot
5月11日 评论:
5月11日 评论:
openLiBingCI
5月11日 评论:
5月11日 评论:
本PR中共发现代码检查告警抑制1处,请Committer检视合理性
本评论自动扫描PR中使用的开源代码检查工具(ruff、clang-tidy、CodeQL等)的屏蔽注释。
这些屏蔽注释会阻止开源代码检查工具对特定代码区域的检测,可能导致潜在问题被忽略。
| 文件路径 | 行号 | 屏蔽类型 | 代码片段 | 工具名称 |
|---|---|---|---|---|
| torch_npu/utils/_graph_tree.py | 399 | 行级屏蔽 | 395: # forward was cudagraph'd but backward is not, to drive the cudagraph 396: # generation state machine) and _dynamo/backends/cudagraphs.py. NPU397: # registers its manager under torch_npu.npu._graph_tree, so without398: # this forward those upstream paths raise AttributeError or return None. 399: import torch._inductor.cudagraph_trees as _upstream_cgt # noqa: F401 400: from torch_npu.npu._graph_tree import get_manager as _npu_get_manager 401: _upstream_cgt.get_manager = _npu_get_manager |
flake8 |


ascend-robot
5月11日 评论:
5月11日 评论:
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 | ✅ adrian07110, chujinjin (2/2) | ✅ adrian07110, chujinjin (2/1) |
| test | ✅ adrian07110, chujinjin (2/2) | ✅ adrian07110, chujinjin (2/1) |
| torch_npu/_inductor | ✅ adrian07110, chujinjin (2/2) | ✅ adrian07110, chujinjin (2/1) |
| torch_npu/distributed | ✅ adrian07110, chujinjin (2/2) | ✅ adrian07110, chujinjin (2/1) |
| torch_npu/npu | ✅ adrian07110, chujinjin (2/2) | ✅ adrian07110, chujinjin (2/1) |
| torch_npu/utils | ✅ adrian07110, chujinjin (2/2) | ✅ adrian07110, chujinjin (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
luochao60, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月11日 添加了label:ascend-cla/yes
此处折叠了428条消息 查看更多
5月14日 添加了label:ci-pipeline-passed
ascend-robot
5月14日 评论:
5月14日 评论:
流水线 PR-pipeline_pytorch#22239 (重试第2次)已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_DIST_X86_Part_01 | ✅ | >>> | |
| UT_DIST_X86_Part_02 | ✅ | >>> | |
| UT_DIST_X86_Part_03 | ✅ | >>> | |
| UT_DIST_X86_Part_04 | ✅ | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01_pool | ✅ | >>> | |
| UT_inductor_Part_02_pool | ✅ | >>> | |
| UT_inductor_Part_03_pool | ✅ | >>> | |
| UT_inductor_Part_04_pool | ✅ | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


ascend-robot
5月14日 评论:
5月14日 评论:
Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: adrian07110, chujinjin.
Reviewers who wrote a comment of /lgtm are: adrian07110, chujinjin.


5月14日 合入了pull request
ascend-robot
5月15日 评论:
5月15日 评论:
流水线 pytorch_gitcode_PR_multiVersion#9160 [ commitID:3ec33b8d ] 已完成


【合入来源】
【修改方案】
torch_npu/utils/_graph_tree.py— 新增get_managermonkey-patch上游
torch._inductor.output_code.maybe_handle_backward_generation和torch._dynamo.backends.cudagraphs会直接调用torch._inductor.cudagraph_trees.get_manager,依赖它返回真实的 manager 实例来推进 backward 的 cudagraph 状态机。NPU 把自己的NPUGraphTreeManager注册在独立 registry(torch_npu.npu._graph_tree),导致上游那两条路径在 NPU 设备上拿不到 manager,触发AssertionError或AttributeError。在_apply_npugraph_tree_methods()末尾把torch._inductor.cudagraph_trees.get_manager重指到 NPU 的get_manager(签名一致、duck-typing 兼容),打通 backward 状态机闭环。torch_npu/_inductor/codegen/wrapper.py— wrapper 体系重构以支持 graph partition提取
_NPUKernelCodegenMixin混入类,把 NPU 特化逻辑(define_kernel中user_autotune → user_autotune_npu、PrecomputedGrid → PrecomputedGridNpu、FixedGrid → FixedGridNpu替换;get_next_kernel_suffix、make_buffer_free等)从原NPUWrapperCodeGen上移;新增NPUSubgraphWrapperCodegen(_NPUKernelCodegenMixin, SubgraphPythonWrapperCodegen)让 subgraph wrapper 共享 NPU 适配;NPUWrapperCodeGen.create()在is_subgraph=True时返回新的 subgraph wrapper。torch_npu/_inductor/lowering_op_list.py— graph partition 所需算子注册GENERATE_LIST新增prims.device_put、aten.unbind、torch.ops.higher_order.cond。torch_npu/csrc/core/npu/NPUHooksInterface.{h,cpp}— Pinned memory 接口实现override 上游
at::PrivateUse1HooksInterface新增的虚函数:isPinnedPtr()走CachingHostAllocator_isPinned,getPinnedMemoryAllocator()返回getPinnedMemoryAllocator()。同时新增CachingHostAllocator.h包含。test/_inductor/test_inductor_graph_partition.py— graph partition 测试集新增 graph partition 场景的系列用例:dynamic shapes、condition op、custom op 拆分、subgraph wrapper user_autotune 兜底、forward cudagraph + backward fallback 等。
【资料变更】
不涉及
【接口变更】
不涉及。C++ 层
NPUHooksInterface::isPinnedPtr和getPinnedMemoryAllocator是对上游PrivateUse1HooksInterface已有虚函数的 override 实现,非新增对外 API。【功能验证】
在
test/_inductor/test_inductor_graph_partition.py中新增覆盖 graph partition 场景的用例:test_graph_partition_dynamic_shapes:动态 shape 下产生 3 个 npugraphtest_graph_partition_condition_op:cond / higher-order op 切图test_graph_partition_custom_op:cudagraph_unsafe 自定义算子切分边界test_graph_partition_subgraph_wrapper_user_autotune:子图 wrapper 的 user_autotune 替换路径通过
python test/_inductor/test_inductor_graph_partition.py在 NPU 设备上跑通全部用例。【CheckList】