已合并
test(jit):add test for ScriptFunction,ScriptFunction.get_debug_state,ScriptFunction.save,and ScriptFunction.save_to_buffer #35415
test(jit):add test for ScriptFunction,ScriptFunction.get_debug_state,ScriptFunction.save,and ScriptFunction.save_to_buffer #35415
已合并
fengwu154创建于 5月12日
fengwu154
fengwu154
5月12日

【合入来源】

https://gitcode.com/Ascend/pytorch/issues/1904

【修改方案】

  1. get_debug_state 适配
    • 使用 PyTorch 内置的 enable_profiling_mode_for_profiling_tests() 上下文强制启用 profiling executor。
    • 执行两次函数(一次 profile,一次 optimize),确保优化计划生成。
    • 通过 GRAPH_EXECUTOR 常量判断执行器模式,非 profiling 模式自动跳过测试。
  2. save 适配
    • API 签名仅接受字符串路径,因此使用 tempfile.TemporaryDirectory 创建临时文件,避免对文件系统的污染。
  3. save_to_buffer 适配
    • 验证返回类型为 bytes,并通过 io.BytesIO 模拟文件流加载,与保存前输出一致。

    • 原测试缺口test_jit.py 虽大量使用 ScriptFunction,但缺少对其类型、save_to_buffersave 直接路径的专门测试;get_debug_state 仅在特定测试中偶现调用,未系统验证。

  • 新增覆盖

    • 类型断言:确保 @torch.jit.script 生成的函数为 torch.jit.ScriptFunction 实例。
    • 调试状态:验证在 profiling 模式下两次执行后可获得有效状态对象。
    • 序列化闭环:通过 save_to_bufferloadsave(file)load 验证序列化后语义等价。
  • 边界适配get_debug_state 通过 @unittest.skipIf(GRAPH_EXECUTOR != ProfilingMode.PROFILING, ...) 仅在有 profiling 执行器的环境中运行,避免内部断言错误。

  • 新增测试文件 test/jit/test_jit_ScriptFunction.py

  • 实现 4 个测试用例,覆盖 ScriptFunction 类型、调试状态获取、内存序列化与文件序列化。

  • 使用条件跳过(@unittest.skipIf)适配不同执行器模式(profiling / simple / legacy)。

  • 不依赖外部文件,所有测试可在任意环境运行。

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

root@devserver-fae-mirrors:/home/aicc/wf/api/2.7.1/pytorch/test# python test_jit_ScriptFunction.py
....
----------------------------------------------------------------------
Ran 4 tests in 10.120s

OK

覆盖版本:

v2.7.1
v2.9.0
v2.10.0
v2.11.0
v2.12.0
master

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 fengwu154 的贡献)
fengwu154fengwu154
5月12日 创建了 pull request,commit 66195d95
fengwu154fengwu154
5月12日 关联了issue:需要增加test_jit_ScriptFunction测试用例
ascend-robot
ascend-robot成员
5月12日 评论:

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 /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

fengwu154, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robotascend-robot成员
5月12日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
5月12日 评论:

当前仓库存在以下 保护分支

Protected Branch Version Release
master
v2.7.1
v2.9.0
v2.11.0
v2.10.0
v2.12.0

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
fengwu154
fengwu154
5月12日 评论:

compile

likedislike
ascend-robotascend-robot成员
5月12日 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
5月12日 评论:
流水线 PR-pipeline_pytorch#21400 运行中
阶段 任务名 状态 详情
编译构建 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 🕚 >>>
likedislike
ascend-robotascend-robot成员
5月12日 删除了label:ci-pipeline-running
ascend-robot
ascend-robot成员
5月12日 评论:
流水线 PR-pipeline_pytorch#21400 运行失败
阶段 任务名 状态 详情
编译构建 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 >>>
likedislike
ascend-robotascend-robot成员
5月12日 添加了label:ci-pipeline-failed
fengwu154fengwu154
5月12日 修改了pull request 的描述
fengwu154
fengwu154
5月12日 评论:

compile

likedislike
ascend-robotascend-robot成员
5月12日 删除了label:ci-pipeline-failed
ascend-robotascend-robot成员
5月12日 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
5月12日 评论:
流水线 PR-pipeline_pytorch#21405 运行中
阶段 任务名 状态 详情
编译构建 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 🕚 >>>
likedislike
ascend-robot
ascend-robot成员
5月12日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
5月12日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
5月12日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
5月12日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
5月12日 添加了label:docs-ci-pipeline-success
ascend-robot
ascend-robot成员
5月12日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
5月12日 删除了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
5月12日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
5月12日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
5月12日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
5月12日 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
5月12日 删除了label:ci-pipeline-running
ascend-robot
ascend-robot成员
5月12日 评论:
流水线 PR-pipeline_pytorch#21405 已完成
阶段 任务名 状态 详情
编译构建 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 >>>
likedislike
ascend-robotascend-robot成员
5月12日 添加了label:ci-pipeline-passed
此处折叠了7条事件消息 查看更多
fengwu154fengwu154
5月13日 修改了pull request 的描述
sunyu-xuan成员
5月13日 评论:

/lgtm

likedislike
liwei386成员
5月14日 评论:

/approve

likedislike
ascend-robotascend-robot成员
5月14日 添加了label:approvedlgtm
ascend-robot
ascend-robot成员
5月14日 评论:

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.

likedislike
ascend-robotascend-robot成员
5月14日 合入了pull request