已合并
[test] Add fx graph internal API verify tests #35606
lihaokun-2026创建于 5月14日
[test] Add fx graph internal API verify tests #35606
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 lihaokun-2026 的贡献)5月14日 创建了 pull request,commit 70a2cf2a
5月14日 关联了issue:【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(25)
ascend-robot
5月14日 评论:
5月14日 评论:
openLiBingCI
5月14日 评论:
5月14日 评论:
本PR中共发现代码检查告警抑制1处,请Committer检视合理性
本评论自动扫描PR中使用的开源代码检查工具(ruff、clang-tidy、CodeQL等)的屏蔽注释。
这些屏蔽注释会阻止开源代码检查工具对特定代码区域的检测,可能导致潜在问题被忽略。
| 文件路径 | 行号 | 屏蔽类型 | 代码片段 | 工具名称 |
|---|---|---|---|---|
| test/fx/test_fx_graph_internal.py | 3 | 行级屏蔽 | 1: import inspect 3: import torch_npu # noqa: F401 5: import torch 6: import torch.fx.graph as fx_graph 7: from torch.testing._internal.common_utils import run_tests, TestCase 10: class TestFxGraphApi(TestCase): 11: def test_format_args(self): |
flake8 |


ascend-robot
5月14日 评论:
5月14日 评论:
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
lihaokun-2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍


此处折叠了93条消息 查看更多
sunyu-xuan
5月21日 评论:
5月21日 评论:
/lgtm


5月21日 添加了label:approvedlgtm
ascend-robot
5月21日 评论:
5月21日 评论:
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月21日 合入了pull request
【合入来源】
【修改背景】
本次任务聚焦
torch.fx.graph相关内部能力的测试补齐与行为验证,主要覆盖 FX 图代码生成过程中涉及的内部辅助接口及状态维护逻辑。结合目标分支实际源码核查后发现,
torch.fx.graph.py中相关能力的暴露形式并不完全一致:torch.fx.graph._format_target、torch.fx.graph._is_from_torch、torch.fx.graph._origin_type_map、torch.fx.graph._register_custom_builtin为torch.fx.graph模块级内部对象,可直接进行 API 级测试;torch.fx.graph._format_args在当前目标分支中并非torch.fx.graph模块级函数,也不是CodeGen类方法,而是定义在CodeGen._gen_python_code()内部的局部 helper 函数,无法通过torch.fx.graph._format_args直接访问。因此,本次 PR 对
torch.fx.graph._format_args不进行测试验证。本次任务范围为
test/目录下测试用例开发与验证,不涉及torch_npu/目录实现逻辑修改。【资料支持情况核查】
核查结论:
torch.fx.graph._format_target为模块级内部函数,可直接验证目标路径格式化行为;torch.fx.graph._is_from_torch为模块级内部函数,可直接验证 torch 对象识别行为;torch.fx.graph._origin_type_map为模块级内部映射表,可直接验证内置容器类型映射行为;torch.fx.graph._register_custom_builtin为模块级内部函数,可直接验证自定义 builtin 注册及内部状态更新行为;torch.fx.graph._format_args当前不是模块级 API,而是CodeGen._gen_python_code()内部局部函数,因此测试中不进行测试验证。同时在torch官方社区中并没有针对这5个api的测试方法,同时由于
torch.fx.graph._format_args当前不是模块级 API,而是CodeGen._gen_python_code()内部局部函数,因此测试中不进行测试验证,因此需要在本pr中新增对4个api的测试方法,测试范围已与当前目标分支实际源码保持一致,避免将局部 helper 错误声明为模块级 API。本次提交对应 Torch-NPU API 补齐任务,涉及以下 4 个 API:
torch.fx.graph._format_targettarget路径格式化为合法的 Python 属性访问表达式。对于非法 Python 标识符,会转换为getattr(...)形式。call_method、call_module、get_attr等节点的代码生成。torch.fx.graph._is_from_torchtorch命名空间,用于区分 torch 原生对象和用户自定义对象。torch.add(...)的调用形式。torch.fx.graph._origin_type_map.gettyping类型的映射关系,例如list -> typing.List、dict -> typing.Dict。torch.fx.graph._register_custom_builtin_custom_builtins与_illegal_names内部状态。【修改方案】
新增测试文件:
test/fx/test_fx_graph_internal.py文件顶部补充用途说明,明确该文件用于承载
torch.fx.graph相关内部 API 及 CodeGen 行为的兼容性验证。当前测试覆盖以下 4个api :
torch.fx.graph._format_target;torch.fx.graph._is_from_torch;torch.fx.graph._origin_type_map.get;torch.fx.graph._register_custom_builtin。本次采用最小化修改方案:
test/下测试文件;torch_npu/目录下实现代码;try / except异常捕获逻辑,测试中如出现异常直接暴露;【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
【CheckList】