已合并
test(fx): add test for lazy_format_graph_code #35081
Lane0218创建于 5月8日
test(fx): add test for lazy_format_graph_code #35081
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Lane0218 的贡献)5月8日 关联了issue:【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(2)
ascend-robot
5月8日 评论:
5月8日 评论:
ascend-robot
5月8日 评论:
5月8日 评论:
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, sunyu-xuan, 李伟 (3/2) | ✅ 李伟 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
liujiacheng_2026, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月8日 添加了label:ascend-cla/yes
此处折叠了44条消息 查看更多
5月21日 添加了label:lgtm
5月21日 添加了label:approved
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: 李伟, huangjingwei, sunyu-xuan.


5月21日 合入了pull request
【合入来源】
本 PR 覆盖以下 API:
torch.fx._utils.lazy_format_graph_code【修改方案】
一、API 功能说明
torch.fx._utils.lazy_format_graph_code是torch.fx中用于延迟格式化GraphModule可读代码的 Python helper。该 API 返回
torch._logging.LazyString,只有在日志系统或调用方真正需要字符串内容时,才调用内部格式化函数。字符串化时会调用GraphModule.print_readable(print_output=False, **kwargs),并将结果包装成包含TRACED GRAPH标识和标题的可读文本。该 API 主要用于 FX pass 的日志输出,例如
split_module、runtime_assert、_tensorify_python_scalars等路径。它不涉及 NPU 算子分派,也不修改 graph 语义。二、用例完备性说明
经检索,PyTorch 社区测试中暂未发现直接覆盖
torch.fx._utils.lazy_format_graph_code的专项测试。因此按任务要求在 Torch-NPUtest目录补充自写用例。新增
TestFXNPU.test_lazy_format_graph_code,验证内容包括:torch.nn.Module并通过symbolic_trace得到GraphModule。lazy_format_graph_code("fx lazy graph", gm, maybe_id=1)。LazyString执行字符串化。TRACED GRAPH。===== fx lazy graph 1 =====。def forward,证明GraphModule.print_readable的结果进入最终格式化文本。该测试是功能类 API 的最小核心验证,不依赖真实 NPU 张量,不绑定具体算子节点文本,也不覆盖颜色输出等非核心格式细节,避免测试过度约束输出实现。
三、NPU 适配说明
本次不修改 Torch-NPU 生产代码,仅新增测试用例。
lazy_format_graph_code是 FX Python 层日志辅助函数,不涉及 NPU kernel、device dispatch 或 tensor 精度计算。NPU 适配目标是验证该 API 在 Torch-NPU 测试环境中可正常导入、调用和生成符合预期的 FX graph 可读输出。为什么不需要修改 API:
torch.fx._utils提供。【资料变更】
不涉及。本 API 的资料补齐由单独文档 PR 提交到
v2.7.1。【接口变更】
不涉及。
【功能验证】
执行命令:
覆盖版本:
masterv2.7.1v2.8.0v2.9.0v2.10.0v2.11.0v2.12.0执行结果:
额外检查:
覆盖上述全部版本,结果均通过。
【CheckList】