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 : 停止流水线


变更摘要
此 PR 修复了 profiler 在多卡分析场景下 ProfilerConfig 配置缓存未正确重置的问题。在多卡分析时,ProfilerConfig 的 _is_load 标志在上一次分析后仍为 True,导致后续卡的分析无法重新加载配置信息。修复方案为新增 reset_is_load() 方法,并在每次解析 profiling 数据前调用该方法以清除缓存标志,确保每张卡的配置信息能被正确加载。
主要改动
- 新增
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)。


代码审查
我已经仔细审查了所有三个变更文件的 diff 和上下文代码。以下是每个文件的分析:
-
torch_npu/profiler/analysis/_profiler_config.py—ProfilerConfig是@Singleton装饰的类。新增的reset_is_load()方法将_is_load重置为False,从而允许load_info()在后续调用时重新读取配置(而不是因_is_load守卫而直接返回)。 -
torch_npu/profiler/analysis/_profiling_parser.py— 在analyse_profiling_data中的load_info()调用之前添加了ProfilerConfig().reset_is_load()。由于ProfilerConfig是单例,两个ProfilerConfig()调用返回的是同一个实例。此变更确保每个 profiling 路径的配置都会被重新读取,而不是使用缓存的配置。 -
test/profiler/analysis/test_profiler_config.py— 新增的测试方法test_reset_is_load_will_reset_is_load_to_false验证了reset_is_load()能正确重置_is_load而不影响_rank_id。
我检查了以下潜在问题,但均 未发现 此 diff 引入了真正的问题:
-
正确性:
reset_is_load()+load_info()的组合对于每个 worker 进程中顺序处理多张卡的情况是正确且安全的。load_info会覆盖所有配置字段(_rank_id、_export_type、_activities等)。由于使用concurrent.futures.ProcessPoolExecutor(多进程,非多线程),不同 worker 进程之间不存在共享内存,因此不存在竞态条件。 -
部分加载风险:如果
load_info在中途失败(例如_get_json_data返回{}或某个子方法抛出异常),_is_load保持为False,下次调用时会重新尝试。字段回退到默认值或当前值,这是预先存在的设计行为,并非此 diff 引入。 -
字段残留:
load_syscnt_info和load_timediff_info在 JSON 缺少某些字段时会回退到当前值(例如self._freq)。这可能导致来自上一张卡的某些值被保留——但这是这些加载方法预先存在的回退行为,并非此 diff 引入。此 diff 实际上通过允许load_info重新运行,改善了原本完全不重新加载任何字段的问题。 -
测试隔离性:由于
ProfilerConfig是单例,所有测试共享同一个实例——这是现有测试套件的一个预先存在的模式,并非此 diff 引入。
总结
- P0–P2 问题:0
- P3 问题:0
- 总体结论:此 diff 是一个干净、最小化的修复,解决了 issue #2573(多卡离线分析时的配置缓存错误)。
reset_is_load()方法被正确地添加到ProfilerConfig中,在analyse_profiling_data中被正确调用,并且有一个合适的单元测试。未发现任何正确性、安全性、可靠性或破坏性变更的问题。
已审查文件:
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):