已合并
test: add consistency validation cases for torch._C._jit_override_can_fuse_on_cpu (#2756) #42184
luoxiaoyan2024创建于 7月20日
test: add consistency validation cases for torch._C._jit_override_can_fuse_on_cpu (#2756) #42184
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 luoxiaoyan2024 的贡献)7月20日 创建了 pull request,commit 31ad0e43
7月20日 关联了issue:【社区任务】7月社区任务第一期-Ascend for PyTorch API 一致性开发(34)
atomgit-bot
7月20日 评论:
7月20日 评论:
🤖 正在生成合并请求摘要,请稍候…


ascend-robot
7月20日 评论:
7月20日 评论:
atomgit-bot
7月20日 评论:
7月20日 评论:
🤖 AI 代码检视正在进行中,请稍候…


此处折叠了121条消息 查看更多
ascend-robot
11 天前 评论:
11 天前 评论:
流水线 PR-pipeline_pytorch#58552 [ commitID:18cc84c6 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| check_error | ✅ | >>> | |
| lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | 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 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


11 天前 添加了label:approvedlgtm
11 天前 合入了pull request
ascend-robot
11 天前 评论:
11 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13817 [ commitID:18cc84c6 ] 运行失败


【合入来源】
关联 issue:https://gitcode.com/Ascend/pytorch/issues/2756
【修改方案】
一、API 功能说明
torch._C._jit_override_can_fuse_on_cpu是 PyTorch JIT(TorchScript)融合器(fuser)的全局标志位 setter,核心功能如下:_jit_set_nvfuser_enabled等融合相关开关配合使用(如社区用例test_jit_fuser_te.py/test_mkldnn_fusion.py)。二、测试文件 test_jit_override_can_fuse_on_cpu.py 完整验证该 API 的原因
该测试用例针对
torch._C._jit_override_can_fuse_on_cpu这一标志位 setter,从功能完整性、边界条件、底层逻辑、兼容性四个维度全覆盖验证,具体如下:test_override_can_fuse_on_cpu:验证torch._C._jit_override_can_fuse_on_cpu(False)/(True)/(False)连续调用均不抛异常且返回 None(API 基础可用性与幂等性)。TestCase,不改写全局融合标志状态(仅读取式调用后复位),避免影响同进程内其他用例。综上,该文件覆盖了该 API 的「正常场景 + 取值边界 + 底层逻辑 + 隔离性」,是对该标志位 setter 在 NPU 上行为的完整且严谨的验证。
三、NPU 适配
torch._C._jit_override_can_fuse_on_cpu具备硬件无关性、纯 C++ 绑定标志位、无底层算子依赖三大核心特征,决定了其无需针对昇腾 NPU 做修改,具体分析:简言之,该 API 是「硬件无关的纯标志位 setter」,核心逻辑不耦合任何特定硬件(包括 GPU/NPU/CPU),因此适配昇腾 NPU 时无需修改 API 本身,可直接复用。
【资料变更】
已检查文档 https://gitcode.com/Ascend/pytorch/tree/v2.12.0/docs/zh/native_apis,
torch._C.*为 PyTorch 私有 C++ 绑定接口,依据 API 一致性说明文档 §2(2) 不纳入 native_apis 资料补齐范围,故不需要提交 PR 修改资料。【接口变更】
【功能验证】
本地复现命令(在 pytorch 仓库根目录执行):
python test/test_jit_override_can_fuse_on_cpu.py -v预期输出包含:
在 Ascend 910B NPU 环境、torch 2.7.1 / 2.11.0 / 2.12.0 + 对应 torch_npu 上执行该用例,均通过。代表性日志(2.7.1 与 2.12.0)如下:
其余 1 个版本(2.11.0)执行结果一致,均输出
test_override_can_fuse_on_cpu ... OK。【CheckList】