Pull Request已成功合入, 合并人@ascend-robot
(感谢 ascend-robot 的贡献)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 | ✅ renyujin, 陈豪 (2/2) | ✅ 陈豪 (1/1) |
| torch_npu/profiler | ✅ 陈豪, renyujin (2/2) | ✅ 陈豪 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
ascend-ds-bot, thanks for your pull request. All authors of the commits have signed the CLA. 👍


ascend docs pipeline is running...


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


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| 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 : 停止流水线


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| 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 : 停止流水线


变更摘要
此 PR 修复了 profiler 在多卡分析场景下,由于配置缓存未正确重置导致的问题。通过在 ProfilerConfig 类中新增 reset_is_load() 方法,并在 ProfilingParser 解析流程中调用该方法,确保每次解析前 _is_load 标记被重置为 False,避免上一次加载的缓存配置影响后续多卡的分析结果。
主要改动
- 新增
ProfilerConfig.reset_is_load()方法:在_profiler_config.py中为ProfilerConfig类添加reset_is_load()方法,用于将_is_load标记重置为False,提供清除配置加载缓存的能力。 - 解析流程中增加缓存重置调用:在
_profiling_parser.py的ProfilingParser解析逻辑中,于调用ProfilerConfig().load_info()之前先执行ProfilerConfig().reset_is_load(),确保每次解析多卡数据时配置加载状态是干净的。 - 新增对应的单元测试:在
test_profiler_config.py中添加test_reset_is_load_will_reset_is_load_to_false测试用例,验证reset_is_load()能将_is_load置为False,同时不影响_rank_id等其他字段。


代码审查
经过对三个变更文件的逐一审查,包括对 Singleton 模式、load_info 缓存逻辑、调用链(analyse_profiling_data → run_parser → 各下游解析器)的完整上下文分析,未发现此 diff 引入任何正确性、安全性、可靠性或破坏性变更问题。
变更要点及验证结论:
-
torch_npu/profiler/analysis/_profiler_config.py:新增reset_is_load()方法,将_is_load置为False。实现简洁正确,ProfilerConfig为@Singleton,方法仅操作实例自身状态,无副作用。 -
torch_npu/profiler/analysis/_profiling_parser.py:在analyse_profiling_data中,于load_info之前调用reset_is_load()。由于ProfilerConfig是单例,两次ProfilerConfig()返回同一实例,确保_is_load被重置后再加载配置。这解决了原 bug(多卡分析时配置缓存导致 rank 不一致),且与no_exception_func装饰器的异常处理逻辑兼容。 -
test/profiler/analysis/test_profiler_config.py:新增test_reset_is_load_will_reset_is_load_to_false测试用例,验证reset_is_load仅重置_is_load而不影响_rank_id等其他状态。测试逻辑正确。
审查总结
- P0/P1/P2 问题:0 个
- P3 问题:0 个
- 整体风险评估:此变更风险低,修复针对性强,无引入新缺陷的迹象。
各文件审查结果:
test/profiler/analysis/test_profiler_config.py— 无问题torch_npu/profiler/analysis/_profiler_config.py— 无问题torch_npu/profiler/analysis/_profiling_parser.py— 无问题
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


/approve




1. Origin pull request:
https://gitcode.com/Ascend/pytorch/merge_requests/39802
2. Original pull request related issue(s):
https://gitcode.com/Ascend/pytorch/issues/2573
3. Original pull request related commit(s):