已合并
[v2.7.1] test: add validation cases for torch.autograd.profiler_util.Kernel.index #42082
m0_66826439创建于 7月19日
[v2.7.1] test: add validation cases for torch.autograd.profiler_util.Kernel.index #42082
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 m0_66826439 的贡献)7月19日 创建了 pull request,commit f0995a83
7月19日 关联了issue:torch.autograd.profiler_util.Kernel.index 缺少验证用例
atomgit-bot
7月19日 评论:
7月19日 评论:
变更摘要
本 PR 为 torch.autograd.profiler_util.Kernel.index 方法新增验证用例,新增测试文件 test/autograd/test_profiler_util.py。Kernel 是基于 namedtuple 定义的元组类(字段为 name、device、duration),index 是其从 tuple 继承的标准方法。该变更不涉及任何接口修改或 NPU 设备迁移,仅补齐社区缺失的 API 验证覆盖。
主要改动
- 新增
test/autograd/test_profiler_util.py测试文件:创建独立的测试模块,用于验证torch.autograd.profiler_util中的 API,文件按可扩展原则组织,后续其他profiler_utilAPI 可在同一文件中补充。 test_kernel_index_returns_field_position用例:验证Kernel.index按字段值返回正确的元组索引位置(name→0、device→1、duration→2)。test_kernel_index_with_start_stop_bounds用例:验证index方法的start/stop边界参数生效,合法范围内查找成功、越界查找抛出ValueError。test_kernel_index_raises_value_error_when_missing用例:验证查找不存在值时正确抛出ValueError。


ascend-robot
7月19日 评论:
7月19日 评论:
atomgit-bot
7月19日 评论:
7月19日 评论:
代码审查
审查总结
审查文件:
test/autograd/test_profiler_util.py— 发现 1 个 P3 问题(未使用的import torch)
按优先级统计:
- P0: 0
- P1: 0
- P2: 0
- P3: 1
总体风险评估:低风险。 该变更新增了一个针对 torch.autograd.profiler_util.Kernel.index 的测试文件,测试逻辑正确,覆盖了字段位置索引、start/stop 边界参数、以及缺失值抛出 ValueError 三个核心场景。唯一的小瑕疵是第 7 行的 import torch 未被文件直接使用,属于冗余导入,不影响测试执行和正确性。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


此处折叠了52条消息 查看更多
ascend-robot
22 天前 评论:
22 天前 评论:
流水线 PR-pipeline_pytorch#50813 [ commitID:5212e0bc ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_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 : 停止流水线


chenrayray
22 天前 评论:
22 天前 评论:
/lgtm


22 天前 添加了label:lgtm
22 天前 合入了pull request
ascend-robot
22 天前 评论:
22 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13300 [ commitID:5212e0bc ] 已完成


【合入来源】
关联 issue: #2894(社区任务第二期 - Ascend for PyTorch API 一致性开发)
【修改方案】
为
torch.autograd.profiler_util.Kernel.index补齐验证用例(用例补齐场景 1.3)。Kernel定义于torch/autograd/profiler_util.py:Kernel = namedtuple("Kernel", ["name", "device", "duration"])。Kernel.index是 namedtuple 从 tuple 继承的标准方法,返回值在元组中的位置(name=0, device=1, duration=2),找不到抛出ValueError。PyTorch 官方社区
test/目录中无Kernel.index的直接验证用例(test_autograd.py、test/profiler/test_profiler.py仅从profiler_util导入EventList/FunctionEvent/FunctionEventAvg/_format_time,未涉及Kernel.index),故新增test/autograd/test_profiler_util.py,覆盖:name/device/duration字段值返回正确索引(0/1/2)start/stop边界参数生效,越界查找抛出ValueErrorValueError文件按可扩展原则组织,后续
profiler_util其他 API 可在同一文件补充。该 API 为非计算类纯 Python 方法,不涉及张量,无需 NPU 设备迁移;Kernel在 torch_npu 中直接复用 torch 实现(torch_npu/contrib/transfer_to_npu.py:16),无需代码补齐。【资料变更】
不涉及。已检查
docs/zh/native_apis/下各版本目录(pytorch_2-7-1、pytorch_2-9-0、pytorch_2-10-0、pytorch_2-11-0、pytorch_2-12-0)的torch-autograd.md,Kernel及profiler_util下其他工具类(EventList、FunctionEvent、Interval等)均未列入支持度表格;Kernel.index为非计算类纯 Python 方法,与数据类型无关,PyTorch 官方文档同样未单独列出该 tuple 继承方法,无需补充资料。详见 issue #2894。【接口变更】
不涉及。仅新增测试文件,未修改任何对外接口。
【功能验证】
测试环境:
测试方法:
source /usr/local/Ascend/ascend-toolkit/set_env.sh TORCH_DEVICE_BACKEND_AUTOLOAD=1 python3.12 /tmp/test_profiler_util.py -v测试结果(20t NPU 实机环境):
【CheckList】