| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
pytorch profiler show additional headers && fix log Co-authored-by: xieanran<694099604@qq.com> # message auto-generated for no-merge-commit merge: !46096 merge master into master pytorch profiler show additional headers && fix log Created-by: SoraAzzz Commit-by: xieanran Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 主要改动 新增 Mix Block Num 列头并重命名常量:在 torch_npu/profiler/analysis/prof_common_func/_csv_headers.py 中,将 OP_SUMMARY_SHAPE_HEADERS 重命名为 OP_SUMMARY_ADDITIONAL_HEADERS,并在其最前面新增 Mix Block Num 字段,使 kernel 视图可展示该附加列。 同步更新 kernel 视图列头逻辑:在 _kernel_view_parser.py 的 KernelViewParser._get_kernel_headers 中改用新的 OP_SUMMARY_ADDITIONAL_HEADERS 常量,从而让非全量列头场景也能按需筛选并输出新增的附加列。 更新对应单元测试:在 test/profiler/analysis/prof_view/test_kernel_view_parser.py 中,将相关断言与期望列头同步替换为 OP_SUMMARY_ADDITIONAL_HEADERS,覆盖 Mix Block Num 参与列头拼接的用例。 修复日志级别:在 _fwk_api_db_parser.py 的 FwkApiDbParser 中,将找不到 node launch str id 时的 logger.error 调整为 logger.warning,并注明该情况在 aclgraph 场景下安全,避免误报错误日志。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!46096 | 12 天前 | |
| 1 年前 | ||
【pytorch_master】 add dynamic step Co-authored-by: hewenbo<hewenbo16@h-partners.com> # message auto-generated for no-merge-commit merge: !37318 merge master into master 【pytorch_master】 add dynamic step Created-by: hewenbo Commit-by: hewenbo Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2209 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 在_DynamicProfile类中增加set_state方法用于保存成员属性的值,用于重新拉起的新节点读取故障前的step值 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 资料中新增set_state接口 # 【接口变更】 在_DynamicProfile类中增加set_state方法用于保存成员属性的值,用于重新拉起的新节点读取故障前的step值 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 修改前:   修改后:   # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37318 | 3 个月前 | |
AI assist developer for python DT master Co-authored-by: deepSeekya<chenzhihan6@huawei.com> # message auto-generated for no-merge-commit merge: !26305 merge master into master AI assist developer for python DT master Created-by: deepSeekya Commit-by: deepSeekya Merged-by: ascend-robot Description: 【合入说明】 AI辅助研发python dt测试用例生成。 【合入来源】 AI辅助研发需求 dt测试文件覆盖率提升。 See merge request: Ascend/pytorch!26305 | 10 个月前 | |
[fix_torch_profiler_master]修复profiler L0级别kernel_details.csv无shape信息问题 Co-authored-by: yuliangbin<y1416490440@163.com> # message auto-generated for no-merge-commit merge: !31916 merge fix_profiler_l1 into master [fix_torch_profiler_master]修复profiler L0级别kernel_details.csv无shape信息问题 Created-by: yu_liangbin Commit-by: yuliangbin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 关联issue号:https://gitcode.com/Ascend/pytorch/issues/1586 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1.功能:解析得时候会根据是否为aicore_none进行kernel_details.csv的表头过滤,但是在l1、aicore_metrics非aicore_none场景下会导致kernel_details.csv表头缺失shape字段,实际上只有l0场景下kernel_details.csv的表头比较少,l1场景下不应该缺失表头,因此过滤逻辑应当是是否为l0,若是l0场景,则过滤,反之不过滤; 2.UT:UT适配 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 验证结果:离线解析一份l1+aicore_none场景的数据,kernel_details.csv的表头与op_summary.csv的表头一致,未被过滤  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!31916 | 5 个月前 | |
feat(profiler): add fused op flops formulas Co-authored-by: msjz11<liuchengju5@huawei.com> # message auto-generated for no-merge-commit merge: !37663 merge mfu2 into master feat(profiler): add fused op flops formulas Created-by: mjsz11 Commit-by: msjz11 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 在 profiler FLOPs 公式注册中补充融合算子默认 FLOPs 计算规则,新增支持 npu_all_gather_base_mm、npu_transpose_batchmatmul、npu_grouped_matmul、npu_quant_matmul_gelu、npu_grouped_matmul_swiglu_quant_v2、npu_alltoallv_gmm、npu_gmm_alltoallv、npu_block_sparse_attention。 2. 修正 npu_fusion_attention / npu_fused_infer_attention_score 的 Attention FLOPs 口径,按 QK^T + P @ V 统计,使用 q_dim + value_dim,不再误用 key_dim。 3. 统一只统计主 GEMM 或 Attention 矩阵乘 FLOPs,不统计通信、transpose/permute、bias、scale、量化/反量化、GELU/SwiGLU、softmax、dropout 等融合后处理。 4. 补充对应 UT 覆盖融合算子基础 shape、grouped matmul group_list、block sparse attention 有效块统计、BNSD actual lengths,以及 value_dim != key_dim 回归场景。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。未新增或变更客户可见 API,仅补充 profiler 内部 FLOPs 默认计算公式。 # 【功能验证】 1. 执行 python -m py_compile torch_npu/profiler/_flops_formulas.py test/profiler/test_flops_hook.py,通过。 2. 执行 git diff --check,通过。 3. 通过纯 Python 公式断言验证新增融合算子 FLOPs 计算结果,验证通过。 4. 尝试执行 python -m pytest test/profiler/test_flops_hook.py -q,当前本地环境缺少编译扩展 torch_npu._C,收集阶段报 ModuleNotFoundError,未进入 UT 执行。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37663 | 3 个月前 | |
feat(profiler): add fused op flops formulas Co-authored-by: msjz11<liuchengju5@huawei.com> # message auto-generated for no-merge-commit merge: !37663 merge mfu2 into master feat(profiler): add fused op flops formulas Created-by: mjsz11 Commit-by: msjz11 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 在 profiler FLOPs 公式注册中补充融合算子默认 FLOPs 计算规则,新增支持 npu_all_gather_base_mm、npu_transpose_batchmatmul、npu_grouped_matmul、npu_quant_matmul_gelu、npu_grouped_matmul_swiglu_quant_v2、npu_alltoallv_gmm、npu_gmm_alltoallv、npu_block_sparse_attention。 2. 修正 npu_fusion_attention / npu_fused_infer_attention_score 的 Attention FLOPs 口径,按 QK^T + P @ V 统计,使用 q_dim + value_dim,不再误用 key_dim。 3. 统一只统计主 GEMM 或 Attention 矩阵乘 FLOPs,不统计通信、transpose/permute、bias、scale、量化/反量化、GELU/SwiGLU、softmax、dropout 等融合后处理。 4. 补充对应 UT 覆盖融合算子基础 shape、grouped matmul group_list、block sparse attention 有效块统计、BNSD actual lengths,以及 value_dim != key_dim 回归场景。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。未新增或变更客户可见 API,仅补充 profiler 内部 FLOPs 默认计算公式。 # 【功能验证】 1. 执行 python -m py_compile torch_npu/profiler/_flops_formulas.py test/profiler/test_flops_hook.py,通过。 2. 执行 git diff --check,通过。 3. 通过纯 Python 公式断言验证新增融合算子 FLOPs 计算结果,验证通过。 4. 尝试执行 python -m pytest test/profiler/test_flops_hook.py -q,当前本地环境缺少编译扩展 torch_npu._C,收集阶段报 ModuleNotFoundError,未进入 UT 执行。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37663 | 3 个月前 | |
fix: correct init_step_count and erase_step_count cache behavior Co-authored-by: zhufu-2026<3470991357@qq.com> # message auto-generated for no-merge-commit merge: !43360 merge fix_kineto_step_tracker_master into master fix: correct init_step_count and erase_step_count cache behavior Created-by: zhufu-2026 Commit-by: zhufu-2026 Merged-by: ascend-robot Description: # 【合入来源】 ## 任务: [【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(39)#2968](https://gitcode.com/Ascend/pytorch/issues/2968) [【开源实习】Torch-NPU API一致性对齐:补齐测试用例、API功能对齐、补齐文档(41)#2971](https://gitcode.com/Ascend/pytorch/issues/2971) ## 任务分析issue: [【社区任务】: KinetoStepTracker.init_step_count 和 KinetoStepTracker.erase_step_count 的测试覆盖与 NPU 适配检查 #3048](https://gitcode.com/Ascend/pytorch/issues/3048) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 本次提交为 torch.autograd.profiler.KinetoStepTracker 的两个方法补充测试用例: - KinetoStepTracker.init_step_count - KinetoStepTracker.erase_step_count --- ## 【API 功能介绍】 - init_step_count(requester):为指定请求者初始化步数计数,首次调用时注册并将步数置为 0,重复调用无操作。 - erase_step_count(requester):移除指定请求者的步数计数记录,全局步数保持历史最大值。 --- ## 【修改内容】 新增测试文件 test/profiler/test_kineto_step_tracker.py,为原生行为建立回归测试,覆盖以下 7 个核心场景: | 测试用例 | 验证内容 | |----------|----------| | test_init_does_not_alter_global_step | init_step_count 不改变全局步数 | | test_increment_takes_maximum | current_step 返回所有 requester 步数的最大值 | | test_erase_keeps_step_monotonic | 删除 requester 后全局步数不下降 | | test_erase_all_requesters_keeps_history | 删除全部 requester 后全局步数保留历史最大值 | | test_erase_return_value_contract | erase_step_count 返回 bool 表示删除是否成功 | | test_reinit_is_idempotent | 重复 init_step_count 无副作用 | | test_new_requester_after_erase_inherits_zero | 新 requester 继承当前全局步数,保持步数对齐 | --- ## 【资料变更】 不涉及。 --- ## 【接口变更】 不涉及。 --- ## 【功能验证】 ### 测试场景:新增测试用例验证 **补丁本地验证** : bash python -c " import torch import torch_npu print(f'torch={torch.__version__}') print(f'torch_npu={torch_npu.__version__}') print(f'accelerator={torch.npu.get_device_name() if torch.npu.is_available() else \"cpu\"}') " python /workspace/ascend-pytorch/test/profiler/test_kineto_step_tracker.py -v 测试结果: bash torch=torch 2.12.0+cu130 torch_npu=torch-npu 2.12.0rc1 accelerator=Ascend910B3 Global step retains historical maximum even after all requesters are erased. ... ok test_erase_keeps_step_monotonic (__main__.TestKinetoStepTracker.test_erase_keeps_step_monotonic) Erasing any requester never decreases global step (monotonic contract). ... ok test_erase_return_value_contract (__main__.TestKinetoStepTracker.test_erase_return_value_contract) erase_step_count returns bool indicating whether deletion succeeded. ... ok test_increment_takes_maximum (__main__.TestKinetoStepTracker.test_increment_takes_maximum) current_step always equals the maximum step among all requesters. ... ok test_init_does_not_alter_global_step (__main__.TestKinetoStepTracker.test_init_does_not_alter_global_step) init_step_count only registers requester, never changes global step. ... ok test_new_requester_after_erase_inherits_zero (__main__.TestKinetoStepTracker.test_new_requester_after_erase_inherits_zero) New requester starts at step 0 even after global step has advanced. ... ok test_reinit_is_idempotent (__main__.TestKinetoStepTracker.test_reinit_is_idempotent) Calling init_step_count repeatedly on the same requester has no side effect. ... ok ---------------------------------------------------------------------- Ran 7 tests in 0.003s OK # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43360 | 1 个月前 | |
test update ut Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com> # message auto-generated for no-merge-commit merge: !32377 merge 2.12ut into master test update ut Created-by: huangyunlong2022 Commit-by: huangyunlong2022 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 更新ut # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32377 | 5 个月前 | |
fix(profiler): sanitise trace metadata that would corrupt the export Co-authored-by: Dmitry Gladkov<gladkov.dmitry1@huawei.com> # message auto-generated for no-merge-commit merge: !43429 merge fix/profiler-metadata-sanitizer into master fix(profiler): sanitise trace metadata that would corrupt the export Created-by: gladkov_dmitry Commit-by: Dmitry Gladkov Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] Requirement / Feature - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【Modification Scheme】 A metadata value containing a double quote makes the exported chrome trace unparseable, losing the whole recording. Two defects combine. > torch.profiler's add_metadata wraps the value with '"' + value.replace('"', '\"') + '"', escaping quotes but not backslashes, so a value such as C:\temp is already malformed JSON before any writer sees it. > The trace writer then replaces every backslash with a forward slash, turning a correctly escaped \" into /" and ending the JSON string early. add_metadata_json is affected identically, so routing a value through it is not a workaround. Neither can be fixed in torch_npu: the writer belongs to PyTorch's libkineto, which is not vendored here. This patch removes the offending characters before the value is handed over and warns when a value had to be altered, so a quote costs the user an approximation of their string instead of the entire recording. > torch_npu/profiler/_add_metadata_sanitizer_patch.py: replaces characters whose JSON encoding would contain a backslash - quote, backslash and control characters - and walks nested structures for the JSON variant, re-serialising with ensure_ascii=False so no \uXXXX escapes are introduced either. > torch_npu/_init/patches/profiler_patches.py: registered in the "profiler" patch group beside the existing mstx and perf-dump patches. > Values that would have been written correctly pass through byte for byte and raise no warning, so nothing changes for anyone whose metadata already worked. Not NPU-specific: the defect reproduces with activities=[ProfilerActivity.CPU] alone, with no device activity involved. # 【Documentation Change】 > Not involved. The behaviour is described in the module docstring, and the user is warned at runtime whenever a value is altered. # 【Interface Change】 > No API signature change. Customer-visible: a metadata value containing a double quote, backslash or control character is now written in an altered form with a UserWarning, rather than producing an unparseable trace file. Values without those characters are unaffected. # 【Functional Verification】 bash cd /tmp && python /path/to/test/profiler/test_metadata_sanitizer.py > 16 tests across three classes, all passing in 0.02 s. CPU activity only - no NPU and no PrivateUse1 backend required, so this runs anywhere torch_npu can be imported. > test_underlying_defect_is_still_present reproduces the defect through the underlying API that add_metadata funnels into, confirming the writer still corrupts an unsanitised value; test_trace_parses_with_a_quoted_value confirms the patched path produces a valid trace; test_a_clean_value_raises_no_warning confirms unaffected values are untouched. # 【CheckList】 - [x] Comments complete; the user is warned when a value is altered - [x] Return-value / null-pointer checks done - [x] PR title uses type label (fix) - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43429 | 1 个月前 | |
feat(profiler): mspti backend for torch.profiler PrivateUse1 Co-authored-by: Dmitry Gladkov<gladkov.dmitry1@huawei.com> # message auto-generated for no-merge-commit merge: !44554 merge feat/mspti-kineto-backend into master feat(profiler): mspti backend for torch.profiler PrivateUse1 Created-by: gladkov_dmitry Commit-by: Dmitry Gladkov Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [x] Requirement / Feature - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【Modification Scheme】 torch.profiler on Ascend collected CPU activity only. Nothing supplied device data for ProfilerActivity.PrivateUse1, so the NPU half of the timeline was empty and users had to reach for a second, incompatible profiler to see what the device did. This adds a libkineto plugin backed by mspti. NPU kernels now appear in a standard torch.profiler trace next to CPU operations, on one timeline. > PyTorch and libkineto are unchanged. The plugin registers itself through REGISTER_PRIVATEUSE1_PROFILER and is driven by libkineto through IActivityProfilerSession. > This is not torch_npu.profiler. That is a separate implementation over acl_prof with its own enums and configuration class; the two are independent front ends and can be used side by side. Files: > torch_npu/csrc/profiler/mspti_activity_profiler.{h,cpp}: the session - lifecycle, record conversion, device and stream lanes, flow emission. > torch_npu/csrc/framework/interface/MsptiInterface.{h,cpp}: wrappers over libmspti. Every symbol is resolved at runtime through FunctionLoader, so a missing or older libmspti.so gives an empty device lane rather than a link failure. > torch_npu/_init/registry/backend.py, CMakeLists.txt: registration and build. Kernels are linked back to the operations that launched them. A global RecordFunction callback pushes each operation's handle as an mspti external correlation id; mspti ties that handle to the correlation id of the launch call, which the kernel shares. processTrace turns the join into ac2g flows - the arrows a viewer draws from a CPU operation to the kernel it produced. > About three quarters of kernels link. The rest are launched outside any operation scope - allocator work, autograd internals, runtime housekeeping - and have nothing to point back to. The proportion is stable as the workload grows. > The flow tail is a PRIVATEUSE1_RUNTIME marker on the host process, mirroring CUDA where flows start on a cuda_runtime event rather than on a cpu_op. Two presentation decisions worth knowing when reading a trace: > Device operators export without an mspti:: prefix, so they read the way CUDA kernels do in a torch.profiler trace. > The NPU process takes a sort index above any real pid, so its lane renders below the CPU lane. Correlation ids on exported activities come from a private counter rather than from mspti: mspti's ids are not unique per event and collide with torch's low cpu-side ids, which would fail upstream's uniqueness check. stop() drains until records stop arriving rather than until a fixed deadline. mspti delivers asynchronously, roughly 200 ms behind execution, so a time cap truncated the tail of a recording. The loop now exits once several consecutive flushes add nothing, which captures more and returns in about 150 ms. # 【Documentation Change】 > Not involved. Behaviour and limitations are described in the module header. # 【Interface Change】 > No API signature change. Customer-visible: profiling with activities=[ProfilerActivity.CPU, ProfilerActivity.PrivateUse1] now yields NPU device kernels in the trace and in events() / key_averages(), where previously the device side was empty. Existing CPU-only behaviour is unchanged. # 【Functional Verification】 bash cd /tmp && python test/profiler/test_mspti_backend.py > 12 tests in three classes on Ascend 910B4, CANN 9.1.0, torch 2.13.0+cpu. > TestMsptiBackend: kernels reach the trace, carry type and streamId, export without the mspti:: prefix, the NPU lane sorts below the CPU lane, and every cycle of a schedule() run collects - so the backend re-arms between cycles. > TestMsptiAc2g: flows are emitted as start and finish pairs, every start has a finish, one start per operation, none points backwards in time, the ids match operations recorded by torch, the two ends land on different lanes, and the whole trace fits one timeline. > Kernel counts are never asserted in the tests: mspti delivers records asynchronously, so counts vary between runs. The assertions are structural. Trace view. Collected from bare tensor operations rather than a model, so the device lane holds a predictable set of kernels: python a = torch.randn(4096, 4096, device="npu") b = torch.randn(4096, 4096, device="npu") def phases(): with record_function("matmul"): for _ in range(5): torch.matmul(a, b) with record_function("add"): for _ in range(5): torch.add(a, b) with record_function("sum"): for _ in range(5): torch.sum(a) phases() # warm up outside profiling torch.npu.synchronize() with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.PrivateUse1]) as prof: phases() torch.npu.synchronize() prof.export_chrome_trace("trace.json") Fifteen operations issued, <N> device kernels collected. 4096x4096 keeps each kernel millisecond-scale and visible. Opened at ui.perfetto.dev.  > The NPU lane sits below the CPU lane with its kernels named, against the matmul, add and sum phases above, and an ac2g arrow runs from the operation to the kernel it launched. > The flow tail is placed at the kernel's timestamp rather than the host launch time: the host clock reachable from this path has a different base. The link itself is exact; only the arrow's visual origin is approximate. > On CANN versions: only 9.1.0 is installed on the verification machine, so this was not built against an earlier CANN. The mspti dependency is resolved at runtime through FunctionLoader rather than linked, so a CANN without libmspti.so gives an empty device lane rather than a build or load failure. The kineto include added to CMakeLists.txt points at PyTorch's bundled headers, not CANN's, so it carries no CANN version dependency. # 【CheckList】 - [x] Comments complete - [x] Return-value / null-pointer checks done - [x] PR title uses type label (feat) - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44554 | 1 个月前 | |
refactor(profiler): 非侵入式动态 Profiler Optimizer Step Hook 私有 Patch 消除 Co-authored-by: wxb<w.noneck.1024@gmail.com> # message auto-generated for no-merge-commit merge: !44890 merge refactor/remove-pta_profiler_hook into master refactor(profiler): 非侵入式动态 Profiler Optimizer Step Hook 私有 Patch 消除 Created-by: No_neck Commit-by: No_neck;wxb Merged-by: ascend-robot Description: <!-- PR 描述与 2026-08-28 最新代码对齐。 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/4189**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改说明】 ## 背景 torch_npu/profiler/_non_intrusive_profile.py 原实现通过替换 PyTorch 私有方法 torch.optim.Optimizer._patch_step_function 或历史版本的 _hook_for_profile,进一步包装 optimizer.__class__.step,在 Optimizer step 正常返回后调用动态 Profiler 的 dp_step()。 旧实现还使用 OPTIMIZER_ID 只跟踪最后创建或最后 patch 的 Optimizer。该选择规则 没有训练 iteration 语义:如果最后创建的是低频辅助 Optimizer,Profiler 会推进过慢, 使一个采集 step 跨越多次主 Optimizer 更新。 主要问题: 1. 依赖 PT 私有 API,升级兼容风险高; 2. PTA 在 PT wrapper 外再次修改 Optimizer 类方法,影响同类全部实例; 3. step_hooked、OPTIMIZER_ID 和构造顺序形成脆弱的隐式状态; 4. 非等频多 Optimizer 场景会少计,采集边界异常扩大; 5. 旧接入方式没有使用 PT 已提供的公共 Optimizer hook。 ## 修改方案 本 PR 保留 PTA 非侵入式动态 Profiling 能力和原有启动方式,只替换 Optimizer 事件接入 机制: ~~~text PROF_CONFIG_PATH / MSMONITOR_USE_DAEMON / KINETO_USE_DAEMON -> 原有配置检查 -> dp_init(prof_config_path) -> _register_optimizer_step_hook() -> register_optimizer_step_post_hook(callback) optimizer.step() 正常返回 -> PT instance post-hooks -> PT global post-hooks -> PTA _optimizer_step_post_hook(optimizer, args, kwargs) -> local_step[optimizer] += 1 -> local_step > profiler_step 时调用 dp_step() -> profiler_step = local_step ~~~ 聚合语义为: ~~~text profiler_step = max historical successful_step_count observed ~~~ 一次 callback 只增加一个 Optimizer 的局部计数,因此直接比较更新后的局部值与缓存的 历史全局最大值即可,不需要每次执行 max(values()),热路径为 O(1)。弱字典删除已经 释放的 Optimizer 后,缓存的历史全局值不会回退。 ## 代码修改及原因 ### 1. 删除 PT 私有方法依赖 删除: ~~~python _origin_patch_step_function Optimizer._patch_step_function = ... Optimizer._hook_for_profile = ... ~~~ 原因:上述符号是 PT 私有实现,不提供兼容承诺。当前2.13、2.14、2.15目标版本已经 提供公共 global Optimizer post-hook。 ### 2. 删除 PTA 类级 step wrapper 删除: ~~~text step_wrapper patch_step_function step_hooked check_last_optimizer OPTIMIZER_ID ~~~ 原因: - 不再二次替换 optimizer.__class__.step; - 不影响同类 Optimizer 的其他实例; - 不再依赖 Optimizer 创建顺序; - 不再需要维护重复包装标志; - 消除旧非等频场景只跟踪最后一个 Optimizer的问题。 ### 3. 使用 PT 公共 global post-hook 新增: ~~~python from torch.optim.optimizer import Optimizer, register_optimizer_step_post_hook ~~~ 并通过: ~~~python register_optimizer_step_post_hook(cls._optimizer_step_post_hook) ~~~ 注册回调。 选择 global hook 的原因: - 非侵入式 Profiler 不要求用户逐个修改 Optimizer; - 能覆盖注册前和注册后创建的 Optimizer; - PT 负责 Optimizer step 的 hook 分发; - PTA 不再接管 PT 私有构造/反序列化入口。 选择 post-hook 而不是 pre-hook 的原因: - 与旧实现“原始 step 成功后再调用 dp_step()”的顺序一致; - optimizer.step() 抛异常时 PT 不执行 post-hook; - 不会把失败的参数更新计为有效 Profiler step; - PT instance post-hook 仍先于 PTA global post-hook。 ### 4. 在已有类中保存最小聚合状态 新增: ~~~python _optimizer_step_hook_handle = None _optimizer_steps = WeakKeyDictionary() _profiler_step = 0 ~~~ 各字段作用: | 字段 | 作用 | |---|---| | _optimizer_step_hook_handle | 判断是否已注册,防止重复 callback | | _optimizer_steps | 保存每个 Optimizer 的成功 step 次数 | | _profiler_step | 保存已经推进的最大 step | 没有新增独立 tracker 类,避免引入当前生产调用链不需要的 requester API、reset API 和 额外生命周期。 WeakKeyDictionary 不强引用 Optimizer。Optimizer 被释放后,对应记录可自动删除, 避免普通 dict 延长参数和 Optimizer 状态的生命周期。 ### 5. 新增 O(1) post-hook callback ~~~python @classmethod def _optimizer_step_post_hook( cls, optimizer: Optimizer, _args: tuple, _kwargs: dict, ) -> None: step = cls._optimizer_steps.get(optimizer, 0) + 1 cls._optimizer_steps[optimizer] = step if step > cls._profiler_step: dp_step() cls._profiler_step = step ~~~ 逐行说明: - get(optimizer, 0) + 1:为触发 callback 的 Optimizer 增加局部成功 step; - 写回弱字典:保存该 Optimizer 的后续计数起点; - step > _profiler_step:判断是否出现新的最大进度; - dp_step():只在全局进度增加时推进动态 Profiler; - 成功后更新 _profiler_step:不把失败的 dp_step() 标记为已推进。 callback 必须接受 optimizer, args, kwargs,这是 PT 公共 API 契约。不能直接注册 dp_step,因为 dp_step() 不接受该签名,也无法识别和聚合多个 Optimizer。 ### 6. 新增幂等注册 ~~~python @classmethod def _register_optimizer_step_hook(cls) -> None: if cls._optimizer_step_hook_handle is not None: return cls._optimizer_steps.clear() cls._profiler_step = 0 cls._optimizer_step_hook_handle = register_optimizer_step_post_hook( cls._optimizer_step_post_hook ) ~~~ 逐行说明: - handle 非空时返回:重复 init() 不重复注册; - 注册前清空弱字典:新注册生命周期不继承旧对象状态; - 全局 step 置0:与新初始化的动态 Profiler 对齐; - 保存 PT 返回的 handle:作为注册状态,并保留底层 removable 能力。 最新生产代码不增加 unregister 方法。动态 Profiling 一旦启用,hook 在进程内持续 存在;测试直接使用 handle 清理,不为测试增加生产 API。 ### 7. 保留原有启动条件 没有新增环境变量或配置文件字段。继续使用: ~~~text PROF_CONFIG_PATH MSMONITOR_USE_DAEMON KINETO_USE_DAEMON ~~~ 未启用动态 Profiling 时,init() 在 dp_init() 和 hook 注册前返回,因此默认训练 没有新增 callback 或 WeakKeyDictionary 热路径。 启用后先调用: ~~~python dp_init(prof_config_path) ~~~ 再注册 hook,避免 callback 在动态 Profiler 尚未初始化时调用 dp_step()。 本 PR 不增加 TORCH_NPU_PROFILER_STEP_MODE,不增加 optimizer/manual 分支,不修改 配置 schema。 ### 8. 删除 Python 3.8 Dynolog 死分支 最新代码删除 import sys 以及 Dynolog 的 Python <3.8 判断,直接在 daemon 模式设置 DYNO_CONFIG。 当前2.13~2.15目标兼容线支持的 Python 均高于3.8,该判断在受支持环境中不可达。此项 是独立死代码清理,同时避免原提示行的 F541 风险;不改变支持范围内行为。 # 【行为变化】 ## 正常场景 | 场景 | Optimizer event | 修改前典型 dp_step() | 修改后 dp_step() | |---|---:|---:|---:| | 单 Optimizer,18轮 | 18 | 18 | 18 | | 同步双 Optimizer,各18次 | 36 | 取决于最后 ID,通常18 | 18 | | 主18次、低频辅助6次且辅助最后创建 | 24 | 6 | 18 | ## 已知边界 per-optimizer max 是有约束的进度聚合,不是通用 training iteration 检测器: | 场景 | Optimizer event | 修改后 dp_step() | 说明 | |---|---:|---:|---| | 完全交替9+9 | 18 | 9 | 两个局部计数的最大值为9 | | 运行中替换9+9 | 18 | 9 | 新 Optimizer 从0开始追赶 | | 同一 Optimizer 每轮 step 两次 | 2次/轮 | 2次/轮 | 按 Optimizer event 而不是 iteration | 当前 PR 不引入 manual 模式或训练循环 callback。上述行为作为已知限制写入 RFC 和测试 结论,不宣称支持任意训练拓扑。 梯度累计按真实 optimizer.step() 计数:多次 backward 后只调用一次 optimizer.step(),只推进一次;grad 全为 None 但 step 正常返回时,仍按一个 Optimizer event 计数。 # 【接口与资料变更】 ## Python API 不新增或修改用户可见 Python API。 ## 环境变量和配置文件 不新增环境变量,不修改动态 Profiler 配置文件 schema。 保留原有: - PROF_CONFIG_PATH; - MSMONITOR_USE_DAEMON; - 兼容的 KINETO_USE_DAEMON。 ## 兼容性 不再为缺少公共 global post-hook 的历史 PT 版本回退到私有 API。公共 hook 契约已经在 PT/PTA 2.13、2.14、2.15真实 NPU 环境验证。 PT main 仅用于核对公共机制的当前实现;PT main 比 PTA 目标兼容线更新,兼容结论以 三版本真实环境为准。 ## 资料 已同步更新 RFC,明确: - 私有 patch 到公共 hook 的迁移; - 原有环境变量保持不变; - O(1) per-optimizer max 公式; - 多 Optimizer 正常语义与交替/替换边界; - Trace 范围不等于训练吞吐; - 最新精简实现没有独立 tracker 类、step mode 和生产 unregister。 # 【功能验证】 ## 1. 单元与契约测试 当前测试覆盖15项: 1. 重复注册幂等; 2. 异类同步双 Optimizer; 3. 同类同步双 Optimizer; 4. 非等频主辅 Optimizer; 5. 单 Optimizer 连续 step; 6. 注册前创建的 Optimizer; 7. 注册后创建的 Optimizer; 8. 无 grad 正常 step; 9. 梯度累计; 10. step 抛异常时不推进; 11. instance post-hook 先于 global post-hook; 12. disabled 时不初始化、不注册; 13. MSMonitor 入口; 14. KINETO 兼容入口与弃用提示; 15. 配置路径校验、初始化和注册。 测试清理直接移除 handle 并清空类状态,没有新增仅供测试使用的生产方法。 ## 2. Ascend 910B2 三版本验证 | 兼容线 | PyTorch | TorchNPU | 公共 hook 契约 | 真实 active Trace | |---|---|---|---|---| | 2.13 | 2.13.0a0+gitfad7424 | 2.13.0+git45fbeae | 通过 | 通过 | | 2.14 | 2.14.0a0+git69231fe | 2.14.0+gitee7bc39 | 通过 | 通过 | | 2.15 | 2.15.0.dev20260812 | 2.15.0+git56986bb | 通过 | 通过 | 场景结果: | 场景 | Optimizer 更新 | dp_step() | iteration 对齐 | |---|---:|---:|---| | single | 18 | 18 | 是 | | sync dual | 36 | 18 | 是 | | uneven 18+6 | 24 | 18 | 是 | | alternating 9+9 | 18 | 9 | 否,已知边界 | | replacement 9+9 | 18 | 9 | 否,已知边界 | 每个场景均生成非空 trace_view.json。 有效 run-id: - compact_active_2_13_20260827_r2; - compact_active_2_14_20260827_r1; - compact_active_2_15_20260827_r1。 2.13首轮与2.15并发使用 host IPC 和相同 rank=-1,发生动态 Profiler 共享状态冲突; 串行重跑通过。该首轮结果不作为代码失败。 NPU 矩阵候选源码 SHA256: ~~~text b0e0387e2ae80b729e3d12e46ed6e3ac78a1345fc694e3853bfed81ff855b076 ~~~ 该快照与最新目标代码的 Optimizer hook 热路径一致,但仍保留受支持环境不可达的 Python 3.8判断。删除该死分支后需要至少补跑最终源码的 lint 和 UT;若合入门槛要求 最终 SHA 的 NPU 可追溯性,再补一轮 smoke run。 ## 3. 性能验证 默认未启用动态 Profiling 时不注册 hook,因此没有新增 callback 开销。 2.15 master 配对完整训练结果: | 场景 | 旧 OPTIMIZER_ID | 修改后 O(1) max | 差值 | |---|---:|---:|---:| | 单 Optimizer,counter-only | 0.640% | 1.007% | +0.367个百分点 | | 同步双 Optimizer,counter-only | 0.732% | 0.833% | +0.101个百分点 | | 单 Optimizer,真实 inactive dp_step() | 9.238% | 9.291% | +0.053个百分点 | | 同步双 Optimizer,真实 inactive dp_step() | 5.159% | 5.127% | -0.032个百分点 | 结论: - tracker-only 完整训练开销约1%; - 加入真实空闲态 dp_step() 后修改前后差异很小; - 旧实现非等频场景调用更少来自少计,不构成有效性能优势; - Trace 中 Operator、Kernel 或时间窗口变化表示采集范围变化,不直接表示吞吐变化; - 删除 Python 3.8死分支后的最终 SHA 尚未重跑完整性能矩阵。 # 【风险说明】 1. 当前算法不支持从任意 Optimizer 序列恢复真实 training iteration; 2. 完全交替、动态替换和同一 Optimizer 一轮多次 step 是明确边界; 3. 当前状态无锁,不声明支持多线程并发 optimizer.step(); 4. 生产代码不提供 hook 注销/重装生命周期; 5. 外部若自行移除保存的 handle,类字段仍非空,不能自动重新注册; 6. 极短 Optimizer step 会放大 WeakKeyDictionary 的相对开销; 7. PT main 的实现细节不能代替目标兼容线验证。 # 【CheckList】 ## 代码 - [x] 删除 PTA 对 _patch_step_function 的赋值 - [x] 删除 PTA 对 _hook_for_profile 的赋值 - [x] 删除类级 optimizer.__class__.step 包装 - [x] 删除 step_wrapper、step_hooked 和 OPTIMIZER_ID - [x] 使用公共 register_optimizer_step_post_hook() - [x] 使用 WeakKeyDictionary,不强引用 Optimizer - [x] max 聚合热路径为 O(1) - [x] 注册幂等 - [x] disabled 时不注册 hook - [x] 不新增用户环境变量或配置 schema - [x] 不新增独立 tracker 类 - [x] 不新增仅供测试的生产接口 - [x] 删除 Python 3.8 Dynolog 死分支 ## 验证 - [x] 单 Optimizer - [x] 同类和异类同步双 Optimizer - [x] 非等频主辅 Optimizer - [x] 注册前/后创建 Optimizer - [x] 梯度累计和无 grad step - [x] step 异常不推进 - [x] instance/global hook 顺序 - [x] 三个原有启用入口 - [x] PT/PTA 2.13、2.14、2.15真实 NPU active Trace - [x] 交替与替换边界已验证并记录 - [x] O(1) 热路径性能已有配对数据 - [ ] 删除 Python 3.8死分支后的最终源码 lint/UT - [ ] 若合入要求最终 SHA 性能门槛,补跑最终源码配对性能 # 【结论】 本 PR 保留 PTA 非侵入式动态 Profiling 功能,消除 PTA 对 PT 私有 Optimizer 方法和 类级 step() 的 monkey-patch。 修改后只在原有环境变量真正启用动态 Profiling 时注册 PT 公共 global post-hook; 通过已有 _NonIntrusiveProfile 中的最小弱引用状态,以 O(1) per-optimizer max 语义推进 dp_step()。默认训练不增加 callback,同步多 Optimizer和非等频主辅场景 不再依赖最后创建的 Optimizer。 方案不新增用户配置,也不声称解决任意训练循环 iteration 识别。交替、动态替换和同一 Optimizer 多次更新作为明确边界保留。 See merge request: Ascend/pytorch!44890 | 20 天前 | |
Add support of Execution Trace Observer object to torch_npu profiler (based on acl_prof). Co-authored-by: ilya_a<abanin.ilya@huawei.com> # message auto-generated for no-merge-commit merge: !43983 merge add_execution_trace_observer_support into master Add support of Execution Trace Observer object to torch_npu profiler (based on acl_prof). Created-by: ilya_a Commit-by: ilya_a Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 Re-used existing PyTorch Execution Trace Observer object with torch_npu profiler (based on acl_prof). Migrated relevant unit tests from original PyTorch test_execution_trace.py # 【资料变更】 New parameter is added to npu_profiler - execution_trace_observer. Execution Trace Observer implementation with torch_npu profiler must work the same way as with PyTorch community profiler. # 【接口变更】 New parameter is added to npu_profiler - execution_trace_observer. execution_trace_observer (ExecutionTraceObserver) : A PyTorch Execution Trace Observer object. PyTorch Execution Traces <https://arxiv.org/pdf/2305.14516.pdf>__ offer a graph based representation of AI/ML workloads and enable replay benchmarks, simulators, and emulators. When this argument is included the observer start() and stop() will be called for the same time window as npu_profiler. It is the same Execution Trace Observer as the one used by PyTorch community profiler. # 【功能验证】 Build, install, run: export MAX_JOBS=2 TORCH_DEVICE_BACKEND_AUTOLOAD=0 bash ci/build.sh --python=3.11 pip install --no-deps --force-reinstall dist/torch_npu-*.whl ASCEND_LAUNCH_BLOCKING=1 pytest -s test_npu_execution_trace.py # Test results  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43983 | 1 个月前 | |
[sync] PR-37136: [feat]profiler add ProfilerStep range Co-authored-by: hehongzhe<935062458@qq.com> # message auto-generated for no-merge-commit merge: !37513 merge sync-pr37136-tx7-to-master into master [sync] PR-37136: [feat]profiler add ProfilerStep range Created-by: ascend-ds-bot Commit-by: hehongzhe Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/37136 ### 2. Original pull request related issue(s): https://gitcode.com/Ascend/pytorch/issues/2223 ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[0ec3656a](https://gitcode.com/Ascend/pytorch/commit/0ec3656a5b5faec26b77e1c93f9e01881f6f5606)|2026-06-02 12:28:23 +0800 CST|profiler add ProfilerStep range<br>| See merge request: Ascend/pytorch!37513 | 3 个月前 | |
test: add Ascend NPU UT for torch.autograd.profiler.parse_nvprof_trace Co-authored-by: yuhongming-2026<moshui_1@qq.com> # message auto-generated for no-merge-commit merge: !42226 merge part_master into master test: add Ascend NPU UT for torch.autograd.profiler.parse_nvprof_trace Created-by: yuhongming-2026 Commit-by: yuhongming-2026 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2975**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 新增 test/profiler/test_parse_nvprof_trace.py,对原生 API torch.autograd.profiler.parse_nvprof_trace / load_nvprof 在 Ascend NPU 环境下做适配一致性验证。 2. 构造最小 nvprof 兼容 SQLite(含 Marker / Runtime / Concurrent Kernel 表结构),覆盖仅 Marker、Marker+Kernel 关联两类解析路径。 3. 用例依赖 CANN + NPU;无 NPU 时整模块 skip,避免在纯 CPU/CUDA 环境误跑。 4. 补充 API 可用性、EnforceUnique、以及 NPU 算子负载后解析仍可用等场景,保障该接口在 torch_npu 栈上行为正确。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 **测试场景:** - Ascend NPU 环境下验证 parse_nvprof_trace / load_nvprof 可用性与解析结果正确性 - 覆盖:仅 Marker、带 Kernel 关联、NPU 算子执行后再次解析、EnforceUnique **测试方法:** bash cd test/profiler python test_parse_nvprof_trace.py **说明:** 已新增 UT 用例看护;请在本地/CI NPU 环境执行后补充自验证截图。  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42226 | 1 个月前 | |
feat(profiler): add fused op flops formulas Co-authored-by: msjz11<liuchengju5@huawei.com> # message auto-generated for no-merge-commit merge: !37663 merge mfu2 into master feat(profiler): add fused op flops formulas Created-by: mjsz11 Commit-by: msjz11 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 在 profiler FLOPs 公式注册中补充融合算子默认 FLOPs 计算规则,新增支持 npu_all_gather_base_mm、npu_transpose_batchmatmul、npu_grouped_matmul、npu_quant_matmul_gelu、npu_grouped_matmul_swiglu_quant_v2、npu_alltoallv_gmm、npu_gmm_alltoallv、npu_block_sparse_attention。 2. 修正 npu_fusion_attention / npu_fused_infer_attention_score 的 Attention FLOPs 口径,按 QK^T + P @ V 统计,使用 q_dim + value_dim,不再误用 key_dim。 3. 统一只统计主 GEMM 或 Attention 矩阵乘 FLOPs,不统计通信、transpose/permute、bias、scale、量化/反量化、GELU/SwiGLU、softmax、dropout 等融合后处理。 4. 补充对应 UT 覆盖融合算子基础 shape、grouped matmul group_list、block sparse attention 有效块统计、BNSD actual lengths,以及 value_dim != key_dim 回归场景。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。未新增或变更客户可见 API,仅补充 profiler 内部 FLOPs 默认计算公式。 # 【功能验证】 1. 执行 python -m py_compile torch_npu/profiler/_flops_formulas.py test/profiler/test_flops_hook.py,通过。 2. 执行 git diff --check,通过。 3. 通过纯 Python 公式断言验证新增融合算子 FLOPs 计算结果,验证通过。 4. 尝试执行 python -m pytest test/profiler/test_flops_hook.py -q,当前本地环境缺少编译扩展 torch_npu._C,收集阶段报 ModuleNotFoundError,未进入 UT 执行。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37663 | 3 个月前 | |
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 4 个月前 | |
test: add autograd profiler api coverage Co-authored-by: baoxuebin_2026<xuebin@isrc.iscas.ac.cn> # message auto-generated for no-merge-commit merge: !41986 merge codex/autograd-profiler-apis-master into master test: add autograd profiler api coverage Created-by: baoxuebin_2026 Commit-by: baoxuebin_2026 Merged-by: ascend-robot Description: # 【合入来源】 [#2933](https://gitcode.com/Ascend/pytorch/issues/2933) [#2961](https://gitcode.com/Ascend/pytorch/issues/2961) [#2898](https://gitcode.com/Ascend/pytorch/issues/2898) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 公开issue: - torch.autograd.Variable._execution_engine.run_backward:https://gitcode.com/Ascend/pytorch/issues/2933 - torch.autograd.profiler.EnforceUnique:https://gitcode.com/Ascend/pytorch/issues/2961 - torch.autograd.profiler_util.MemRecordsAcc.in_interval:https://gitcode.com/Ascend/pytorch/issues/2898 # 【修改方案】 1. API 功能说明: - torch.autograd.Variable._execution_engine.run_backward:PyTorch autograd execution engine 的反向传播入口,可对指定 graph roots 执行 backward,并返回指定输入的梯度。 - torch.autograd.profiler.EnforceUnique:profiler 内部用于校验 key 唯一性的辅助类,重复 key 会抛出异常。 - torch.autograd.profiler_util.MemRecordsAcc.in_interval:profiler memory records 的区间筛选接口,用于返回指定时间范围内的 memory record。 2. 上游用例检查情况: 检索 PyTorch / Torch-NPU 现有测试后,未找到面向以上 3 个 API 的独立、直接、最小验证用例,因此按任务要求新增 NPU API 验证用例。 3. 新增用例文件: - test/autograd/test_execution_engine.py - test/profiler/test_profiler_utils_api.py 4. 新增用例覆盖场景: - _execution_engine.run_backward 在当前 accelerator 设备上返回指定输入张量的梯度 - EnforceUnique 对重复 key 抛出异常 - MemRecordsAcc.in_interval 按时间区间筛选 memory records 5. 新增文件头部已按要求补充注释,说明该文件验证的 API 功能。 补充说明:当前分支中 MemRecordsAcc.in_interval 用例使用 in_interval(2000, 5000),与该版本 Event.start_ns() 返回的 ns 时间单位保持一致。 # 【资料变更】 不涉及。资料补齐已单独提交文档 PR。 # 【接口变更】 不涉及。未修改跨仓接口,也未修改用户可见接口行为。 # 【功能验证】 测试环境: text torch: 2.13.0 torch_npu: 2.13.0 CANN: 9.1.0 测试方法: source /usr/local/Ascend/ascend-toolkit/set_env.sh TORCH_DEVICE_BACKEND_AUTOLOAD=1 python3.11 test/autograd/test_execution_engine.py -v TORCH_DEVICE_BACKEND_AUTOLOAD=1 python3.11 test/profiler/test_profiler_utils_api.py -v 测试结果: test_run_backward_returns_requested_gradients ... ok Ran 1 test in 34.1s OK test_enforce_unique_raises_on_duplicate_key ... ok test_mem_records_acc_filters_records_in_interval ... ok Ran 2 tests in 21.4s OK See merge request: Ascend/pytorch!41986 | 1 个月前 | |
| 2 年前 | ||
对齐Pytorch Profiler部分接口 Co-authored-by: xfeng<zchlcw663@163.com> # message auto-generated for no-merge-commit merge: !34296 merge main into master 对齐Pytorch Profiler部分接口 Created-by: zyb_230 Commit-by: xfeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1802 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 对齐pytorch profiler的部分接口: 一个是增加一个 skip_first_wait:  一个是custom_trace_id_callback,然后增加两个对应的set和get的接口set_custom_trace_id_callback和get_trace_id   # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” **涉及,需要和资料沟通** # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 涉及,前面已经说明 # 【功能验证】 **场景1** 设置schedule = torch_npu.profiler.schedule(wait=2, warmup=1, active=1, repeat=2, skip_first=0, skip_first_wait=1) 之前:采集第3和第7个step  现在:采集第1和第5个step  **场景2** 测试get_trace_id接口: …… with torch_npu.profiler.profile( activities=[ torch_npu.profiler.ProfilerActivity.NPU, torch_npu.profiler.ProfilerActivity.CPU, ], with_stack=True, schedule = torch_npu.profiler.schedule(wait=2, warmup=1, active=2, repeat=2, skip_first=1, skip_first_wait=1), on_trace_ready=torch_npu.profiler.tensorboard_trace_handler("./result_profiling"), experimental_config=experimental_config) as prof: for i in range(12): add(x0, x1) prof.step() print(f"step {i}: {prof.get_trace_id()}") ……  默认是一个uuid,是直接从pytorch里面拷贝过来的,现在会在profiler_metadata.json里面落盘,db里面也有    **场景3** 异常的skip_first_wait参数不生效,reset为0 正常: 异常:必须设置为整数,否则有警告信息,reset为0   **场景4:** 设置custom_trace_id_callback,这个trace_id,我们是想和每一份ascend_pt数据或者repeat参数绑定的, class RepeatTraceIdGenerator: def __init__(self): self.repeat_count = 0 # 从 0 开始 def __call__(self) -> str: # 每一轮 profile 启动,计数 +1 current_id = str(self.repeat_count) self.repeat_count += 1 return current_id trace_id_gen = RepeatTraceIdGenerator() …… with torch_npu.profiler.profile( activities=[ torch_npu.profiler.ProfilerActivity.NPU, torch_npu.profiler.ProfilerActivity.CPU, ], with_stack=True, schedule = torch_npu.profiler.schedule(wait=2, warmup=1, active=2, repeat=2, skip_first=1, skip_first_wait=1), on_trace_ready=torch_npu.profiler.tensorboard_trace_handler("./result_profiling"), experimental_config=experimental_config, custom_trace_id_callback=trace_id_gen) as prof: for i in range(12): add(x0, x1) prof.step() print(f"step {i}: {prof.get_trace_id()}")  如果call_back类型不对,会有警告信息,然后使用默认的uuid  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34296 | 4 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 12 天前 | ||
| 1 年前 | ||
| 3 个月前 | ||
| 10 个月前 | ||
| 5 个月前 | ||
| 3 个月前 | ||
| 3 个月前 | ||
| 1 个月前 | ||
| 5 个月前 | ||
| 1 个月前 | ||
| 1 个月前 | ||
| 20 天前 | ||
| 1 个月前 | ||
| 3 个月前 | ||
| 1 个月前 | ||
| 3 个月前 | ||
| 1 年前 | ||
| 4 个月前 | ||
| 1 个月前 | ||
| 2 年前 | ||
| 4 个月前 |