已合并
test(fx): add CustomBuiltin test cases for v2.7.1 #34276
olpk创建于 4月24日
test(fx): add CustomBuiltin test cases for v2.7.1 #34276
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 olpk 的贡献)ascend-robot
4月24日 评论:
4月24日 评论:
4月24日 添加了label:stat/needs-squash
ascend-robot
4月24日 评论:
4月24日 评论:
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 |
|---|---|---|
| test | ✅ sunyu-xuan, 李伟 (2/2) | ✅ 李伟 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
jingkai-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍


4月24日 添加了label:ascend-cla/no
此处折叠了351条消息 查看更多
5月25日 添加了label:ci-pipeline-passed
ascend-robot
5月25日 评论:
5月25日 评论:
流水线 PR-pipeline_pytorch#26606 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 : 停止流水线


ascend-robot
5月25日 评论:
5月25日 评论:
Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: 李伟.
Reviewers who wrote a comment of /lgtm are: 李伟, sunyu-xuan.


5月25日 合入了pull request
ascend-robot
5月25日 评论:
5月25日 评论:
In response to this:
/sync v2.8.0 v2.9.0 v2.10.0 v2.11.0 master
同步操作执行结果:
| Branch | Status | Pull Request |
|---|---|---|
| v2.8.0 | 创建同步 PR | https://gitcode.com/Ascend/pytorch/merge_requests/36616 |
| v2.9.0 | 创建同步 PR | https://gitcode.com/Ascend/pytorch/merge_requests/36617 |
| v2.10.0 | 同步失败:请手动创建 PR 进行同步,我们会继续完善分支之间同步操作,尽量避免同步失败的情况 | |
| v2.11.0 | 创建同步 PR | https://gitcode.com/Ascend/pytorch/merge_requests/36618 |
| master | 创建同步 PR | https://gitcode.com/Ascend/pytorch/merge_requests/36619 |


https://gitcode.com/Ascend/pytorch/issues/1630
上游社区(PyTorch 官方)测试覆盖情况分析
torch.fx.Graph / torch.fx.Graph.init
test/test_fx.py(PyTorch 官方仓库)grep -c "def test.[Gg]raph" /workspace/pytorch/test/test_fx.py
查看具体是哪些测试函数
grep "def test.[Gg]raph" /workspace/pytorch/test/test_fx.py | head -20
统计 GraphModule 相关的测试
grep -c "def test.*GraphModule" /workspace/pytorch/test/test_fx.py
统计 Graph 类被使用的次数(证明被广泛测试)
grep -c "torch.fx.Graph" /workspace/pytorch/test/test_fx.py
上游社区测试覆盖情况汇总
序号 测试函数 测试场景
1 test_graph_module GraphModule 基本构造和功能
2 test_graph_edit_with_proxy 通过 Proxy 编辑图
3 test_graph_unique_names 节点名称唯一性
4 test_graph_unique_names_manual 手动设置节点名称
5 test_pickle_graphmodule 序列化/反序列化
6 test_deepcopy_graphmodule_with_transform 带变换的深拷贝
7 test_deepcopy_graph_with_tracer_cls 带 Tracer 类的深拷贝
8 test_pretty_print_graph 打印图结构
9 test_graph_fns Graph 辅助函数
10 test_empty_graph_codegen 空图代码生成
11 test_inline_graph 图内联
12 test_custom_traceback_raised_when_exception_source_is_graphmodule 异常追溯
13 test_graph_module_replicate_for_dp 数据并行复制
14 test_tracing_graphmodules_as_leaf_submodules 作为叶子子模块追踪
15 test_graph_module_init_buffer_param_copied_dict_init 缓冲区和参数复制(字典)
16 test_graph_module_init_buffer_param_copied_mod_init 缓冲区和参数复制(模块)
17 test_deepcopy_graphmodule 深拷贝
18 test_graph_module GraphModule 综合测试
上游社区测试已全面覆盖

torch.fx.Graph的核心功能__init__通过 30 次torch.fx.Graph()实例创建被隐式覆盖torch-npu 直接继承 PyTorch 实现,无需额外适配
_custom_builtins / _CustomBuiltin / SymbolicContext
_custom_builtins ❌ 无结果 社区无测试
_CustomBuiltin ❌ 无结果 社区无测试
SymbolicContext ⚠️ 只有 StatelessSymbolicContext(变体) 社区无直接测试
API功能
原有 API(无需适配)
本次新增测试的 API
用例完备性说明
PyTorch社区在test_fx.py、test_export.py等文件中已有丰富的Graph/GraphModule测试用例,覆盖图的创建、节点操作、符号追踪等核心功能。这些用例均为框架层逻辑测试,不涉及TEST_CUDA/TEST_PRIVATEUSE1等硬件强相关分支。
社区无针对以下3个API的直接测试用例:
_custom_builtins/_CustomBuiltin:社区用例未覆盖SymbolicContext:社区用例使用的是 StatelessSymbolicContext 等变体,未直接测试 SymbolicContext 本身本次自写用例(test_fx_custom_builtins.py)覆盖5个测试方法:
适配方案
torch.fx为框架层图模式API,与底层设备算子完全解耦。在NPU环境下导入torch_npu后直接可用,无需任何代码修改。新增测试用例同样无需适配,可直接在NPU环境运行。
运行结果
在NPU环境下测试通过:
文档检查
已检查 docs/api/torch_npu_apis.md:
torch.fx.Graph和torch.fx.Graph.__init__已在文档中登记 ✅_custom_builtins、_CustomBuiltin、SymbolicContext为 PyTorch FX 内部/实验性 API,不在 torch-npu 公开文档范围内因此本次 不需要 额外提交文档 PR。
多版本兼容性
torch.fx核心架构自PyTorch 1.8引入后保持稳定,推断在2.7.1 ~ 2.12.0及master分支行为一致,均无需适配。