已合并
test(fx): add tests for graph codegen api #34460
nwww创建于 4月26日
test(fx): add tests for graph codegen api #34460
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 nwww 的贡献)ascend-robot
4月26日 评论:
4月26日 评论:
ascend-robot
4月26日 评论:
4月26日 评论:
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 | ✅ 李伟, huangjingwei (2/2) | ✅ 李伟 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
nannan-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍


4月26日 添加了label:ascend-cla/yes
此处折叠了92条消息 查看更多
Jingwei Huang
5月7日 评论:
5月7日 评论:
/lgtm


5月11日 添加了label:approvedlgtm
ascend-robot
5月11日 评论:
5月11日 评论:
Review Guide
This pull-request passes review.
Committers who wrote a comment of /approve are: 李伟.
Reviewers who wrote a comment of /lgtm are: 李伟, huangjingwei.


5月11日 合入了pull request
【合入来源】
关联 issue:https://gitcode.com/Ascend/pytorch/issues/1637
【修改方案】
本 PR 新增 torch.fx 代码生成相关 API 的单元测试,覆盖如下 API:
具体修改内容:
test/fx/test_fx_codegen_api.py测试文件。test_graph_python_code_returns_python_code用例,验证Graph.python_code("self")返回对象类型为PythonCode,并校验返回对象包含src、globals字段。test_graph_set_codegen用例,验证Graph.set_codegen设置自定义CodeGen后,GraphModule可重新编译并正常执行。【资料变更】
不涉及。
本 PR 仅新增测试用例,不修改资料文档。
torch.fx.graph.PythonCode在 native_apis 文档中的支持状态已通过单独 docs PR 补充。【接口变更】
不涉及。
本 PR 不修改客户可见接口,不修改 API 行为,仅新增测试用例验证现有 API 兼容性。
【功能验证】
测试场景:
torch.fx.Graph.python_code可正常生成 PythonCode。torch.fx.graph.PythonCode对象包含src和globals字段。torch.fx.Graph.set_codegen设置自定义 CodeGen 后,GraphModule 可重新编译并正常执行。测试命令:
TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -u test/fx/test_fx_codegen_api.py -v 测试结果: `test_graph_python_code_returns_python_code (__main__.TestFXCodegenAPI.test_graph_python_code_returns_python_code) ... ok` `test_graph_set_codegen (__main__.TestFXCodegenAPI.test_graph_set_codegen) ... ok` `Ran 2 tests in 0.168s` `OK` 说明: 该 API 为 torch.fx Python 层代码生成接口,不涉及 NPU 算子计算。本次测试主要验证 API 功能行为与 PyTorch 原生保持一致。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常