mindstudio-probe 1.3.0__py3-none-any.whl → 8.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. {mindstudio_probe-1.3.0.dist-info → mindstudio_probe-8.1.1.dist-info}/METADATA +4 -2
  2. {mindstudio_probe-1.3.0.dist-info → mindstudio_probe-8.1.1.dist-info}/RECORD +204 -152
  3. msprobe/README.md +32 -1
  4. msprobe/core/__init__.py +17 -0
  5. msprobe/core/common/const.py +120 -21
  6. msprobe/core/common/exceptions.py +2 -2
  7. msprobe/core/common/file_utils.py +279 -50
  8. msprobe/core/common/framework_adapter.py +169 -0
  9. msprobe/core/common/global_lock.py +86 -0
  10. msprobe/core/common/runtime.py +25 -0
  11. msprobe/core/common/utils.py +136 -45
  12. msprobe/core/common_config.py +7 -0
  13. msprobe/core/compare/acc_compare.py +646 -428
  14. msprobe/core/compare/check.py +36 -103
  15. msprobe/core/compare/compare_cli.py +4 -0
  16. msprobe/core/compare/config.py +72 -0
  17. msprobe/core/compare/highlight.py +215 -215
  18. msprobe/core/compare/layer_mapping/layer_mapping.py +2 -0
  19. msprobe/core/compare/merge_result/merge_result.py +4 -4
  20. msprobe/core/compare/multiprocessing_compute.py +223 -110
  21. msprobe/core/compare/npy_compare.py +2 -4
  22. msprobe/core/compare/utils.py +214 -244
  23. msprobe/core/config_check/__init__.py +17 -0
  24. msprobe/{pytorch/dump/kernel_dump/kernel_config.py → core/config_check/checkers/__init__.py} +8 -16
  25. msprobe/core/config_check/checkers/base_checker.py +60 -0
  26. msprobe/core/config_check/checkers/dataset_checker.py +138 -0
  27. msprobe/core/config_check/checkers/env_args_checker.py +96 -0
  28. msprobe/core/config_check/checkers/hyperparameter_checker.py +170 -0
  29. msprobe/core/config_check/checkers/pip_checker.py +90 -0
  30. msprobe/core/config_check/checkers/random_checker.py +367 -0
  31. msprobe/core/config_check/checkers/weights_checker.py +147 -0
  32. msprobe/core/config_check/ckpt_compare/ckpt_comparator.py +74 -0
  33. msprobe/core/config_check/ckpt_compare/megatron_loader.py +302 -0
  34. msprobe/core/config_check/ckpt_compare/metrics.py +83 -0
  35. msprobe/core/config_check/ckpt_compare/name_mapping.yaml +12 -0
  36. msprobe/core/config_check/config_check_cli.py +51 -0
  37. msprobe/core/config_check/config_checker.py +100 -0
  38. msprobe/{mindspore/runtime.py → core/config_check/resource/dependency.yaml} +7 -4
  39. msprobe/core/config_check/resource/env.yaml +57 -0
  40. msprobe/core/config_check/resource/hyperparameter.yaml +21 -0
  41. msprobe/core/config_check/utils/hyperparameter_parser.py +115 -0
  42. msprobe/core/config_check/utils/utils.py +107 -0
  43. msprobe/core/data_dump/api_registry.py +67 -4
  44. msprobe/core/data_dump/data_collector.py +170 -89
  45. msprobe/core/data_dump/data_processor/base.py +72 -51
  46. msprobe/core/data_dump/data_processor/mindspore_processor.py +109 -55
  47. msprobe/core/data_dump/data_processor/pytorch_processor.py +90 -82
  48. msprobe/core/data_dump/json_writer.py +143 -27
  49. msprobe/core/debugger/precision_debugger.py +144 -0
  50. msprobe/core/grad_probe/constant.py +1 -1
  51. msprobe/core/grad_probe/grad_compare.py +1 -1
  52. msprobe/core/grad_probe/utils.py +1 -1
  53. msprobe/core/hook_manager.py +242 -0
  54. msprobe/core/monitor/anomaly_processor.py +384 -0
  55. msprobe/core/service.py +357 -0
  56. msprobe/core/single_save/__init__.py +0 -0
  57. msprobe/core/single_save/single_comparator.py +243 -0
  58. msprobe/core/single_save/single_saver.py +146 -0
  59. msprobe/docs/01.installation.md +6 -5
  60. msprobe/docs/02.config_introduction.md +79 -22
  61. msprobe/docs/03.config_examples.md +1 -0
  62. msprobe/docs/04.kernel_dump_PyTorch.md +1 -1
  63. msprobe/docs/05.data_dump_PyTorch.md +118 -49
  64. msprobe/docs/06.data_dump_MindSpore.md +167 -20
  65. msprobe/docs/07.accuracy_checker_PyTorch.md +2 -2
  66. msprobe/docs/08.accuracy_checker_online_PyTorch.md +69 -9
  67. msprobe/docs/09.accuracy_checker_MindSpore.md +18 -6
  68. msprobe/docs/10.accuracy_compare_PyTorch.md +212 -74
  69. msprobe/docs/11.accuracy_compare_MindSpore.md +87 -37
  70. msprobe/docs/12.overflow_check_PyTorch.md +2 -2
  71. msprobe/docs/13.overflow_check_MindSpore.md +2 -2
  72. msprobe/docs/14.data_parse_PyTorch.md +3 -3
  73. msprobe/docs/17.grad_probe.md +2 -1
  74. msprobe/docs/18.online_dispatch.md +2 -2
  75. msprobe/docs/19.monitor.md +90 -44
  76. msprobe/docs/21.visualization_PyTorch.md +68 -15
  77. msprobe/docs/22.visualization_MindSpore.md +71 -18
  78. msprobe/docs/25.tool_function_introduction.md +23 -22
  79. msprobe/docs/26.data_dump_PyTorch_baseline.md +14 -3
  80. msprobe/docs/27.dump_json_instruction.md +1 -1
  81. msprobe/docs/28.debugger_save_instruction.md +111 -20
  82. msprobe/docs/29.data_dump_MSAdapter.md +2 -2
  83. msprobe/docs/30.overflow_check_MSAdapter.md +2 -2
  84. msprobe/docs/31.config_check.md +95 -0
  85. msprobe/docs/32.ckpt_compare.md +69 -0
  86. msprobe/docs/33.generate_operator_MindSpore.md +181 -0
  87. msprobe/docs/34.RL_collect.md +92 -0
  88. msprobe/docs/35.nan_analyze.md +72 -0
  89. msprobe/docs/data_dump_MindSpore/data_dump_MindSpore_baseline.md +12 -1
  90. msprobe/docs/data_dump_MindSpore/dynamic_graph_quick_start_example.md +3 -1
  91. msprobe/docs/img/compare_result.png +0 -0
  92. msprobe/docs/img/save_compare_result_sample.png +0 -0
  93. msprobe/docs/img/visualization/proxy.png +0 -0
  94. msprobe/mindspore/__init__.py +1 -2
  95. msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +150 -58
  96. msprobe/mindspore/api_accuracy_checker/api_runner.py +7 -3
  97. msprobe/mindspore/api_accuracy_checker/bench_functions/flash_attention_score.py +47 -69
  98. msprobe/mindspore/api_accuracy_checker/cmd_parser.py +4 -0
  99. msprobe/mindspore/api_accuracy_checker/compute_element.py +0 -1
  100. msprobe/mindspore/api_accuracy_checker/data_manager.py +2 -2
  101. msprobe/mindspore/api_accuracy_checker/generate_op_script/op_generator.py +460 -0
  102. msprobe/mindspore/api_accuracy_checker/generate_op_script/operator_replication.template +2081 -0
  103. msprobe/mindspore/api_accuracy_checker/multi_api_accuracy_checker.py +9 -0
  104. msprobe/mindspore/api_accuracy_checker/torch_mindtorch_importer.py +2 -1
  105. msprobe/mindspore/cell_processor.py +204 -33
  106. msprobe/mindspore/code_mapping/graph_parser.py +4 -21
  107. msprobe/mindspore/common/const.py +17 -7
  108. msprobe/mindspore/common/utils.py +128 -11
  109. msprobe/mindspore/compare/common_dir_compare.py +382 -0
  110. msprobe/mindspore/compare/distributed_compare.py +2 -26
  111. msprobe/mindspore/compare/ms_compare.py +17 -405
  112. msprobe/mindspore/compare/ms_graph_compare.py +14 -5
  113. msprobe/mindspore/compare/utils.py +37 -0
  114. msprobe/mindspore/debugger/debugger_config.py +53 -3
  115. msprobe/mindspore/debugger/precision_debugger.py +72 -91
  116. msprobe/mindspore/dump/cell_dump_process.py +877 -0
  117. msprobe/mindspore/dump/cell_dump_with_insert_gradient.py +864 -0
  118. msprobe/mindspore/dump/dump_tool_factory.py +13 -5
  119. msprobe/mindspore/dump/graph_mode_cell_dump.py +139 -0
  120. msprobe/mindspore/dump/graph_tensor_dump.py +123 -0
  121. msprobe/mindspore/dump/hook_cell/api_register.py +40 -6
  122. msprobe/mindspore/dump/hook_cell/hook_cell.py +18 -7
  123. msprobe/mindspore/dump/hook_cell/ms_hook_manager.py +88 -0
  124. msprobe/mindspore/dump/hook_cell/primitive_hooks.py +8 -2
  125. msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +18 -0
  126. msprobe/mindspore/dump/jit_dump.py +21 -18
  127. msprobe/mindspore/dump/kernel_kbyk_dump.py +6 -3
  128. msprobe/mindspore/dym_loader/hook_dynamic_loader.cpp +110 -0
  129. msprobe/mindspore/dym_loader/hook_dynamic_loader.h +15 -15
  130. msprobe/mindspore/free_benchmark/api_pynative_self_check.py +12 -6
  131. msprobe/mindspore/free_benchmark/common/utils.py +1 -1
  132. msprobe/mindspore/grad_probe/global_context.py +7 -2
  133. msprobe/mindspore/grad_probe/grad_stat_csv.py +3 -2
  134. msprobe/mindspore/mindspore_service.py +114 -0
  135. msprobe/mindspore/monitor/common_func.py +52 -0
  136. msprobe/mindspore/monitor/data_writers.py +237 -0
  137. msprobe/mindspore/monitor/features.py +20 -7
  138. msprobe/mindspore/monitor/module_hook.py +281 -209
  139. msprobe/mindspore/monitor/optimizer_collect.py +334 -0
  140. msprobe/mindspore/monitor/utils.py +25 -5
  141. msprobe/mindspore/ms_config.py +16 -15
  142. msprobe/mindspore/task_handler_factory.py +5 -2
  143. msprobe/msprobe.py +19 -0
  144. msprobe/nan_analyze/__init__.py +14 -0
  145. msprobe/nan_analyze/analyzer.py +255 -0
  146. msprobe/nan_analyze/graph.py +189 -0
  147. msprobe/nan_analyze/utils.py +211 -0
  148. msprobe/pytorch/api_accuracy_checker/common/config.py +2 -2
  149. msprobe/pytorch/api_accuracy_checker/compare/compare.py +36 -34
  150. msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +20 -20
  151. msprobe/pytorch/api_accuracy_checker/generate_op_script/op_generator.py +4 -7
  152. msprobe/pytorch/api_accuracy_checker/generate_op_script/operator_replication.template +204 -2
  153. msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +12 -11
  154. msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +1 -0
  155. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +8 -5
  156. msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +2 -3
  157. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +29 -13
  158. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +12 -2
  159. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +45 -31
  160. msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/utils.py +156 -0
  161. msprobe/pytorch/attl_manager.py +65 -0
  162. msprobe/pytorch/bench_functions/npu_fusion_attention.py +27 -0
  163. msprobe/pytorch/common/utils.py +26 -14
  164. msprobe/pytorch/compare/distributed_compare.py +4 -36
  165. msprobe/pytorch/compare/pt_compare.py +13 -84
  166. msprobe/pytorch/compare/utils.py +47 -0
  167. msprobe/pytorch/debugger/debugger_config.py +34 -17
  168. msprobe/pytorch/debugger/precision_debugger.py +66 -118
  169. msprobe/pytorch/dump/module_dump/hook_wrapper.py +93 -0
  170. msprobe/pytorch/dump/module_dump/module_dump.py +11 -58
  171. msprobe/pytorch/dump/module_dump/module_processer.py +143 -113
  172. msprobe/pytorch/grad_probe/grad_stat_csv.py +3 -2
  173. msprobe/pytorch/hook_module/api_register.py +29 -5
  174. msprobe/pytorch/hook_module/hook_module.py +9 -18
  175. msprobe/pytorch/hook_module/jit_script_wrapper.py +33 -0
  176. msprobe/pytorch/hook_module/pt_hook_manager.py +68 -0
  177. msprobe/pytorch/hook_module/support_wrap_ops.yaml +22 -1
  178. msprobe/pytorch/hook_module/utils.py +28 -2
  179. msprobe/pytorch/monitor/csv2tb.py +6 -2
  180. msprobe/pytorch/monitor/data_writers.py +259 -0
  181. msprobe/pytorch/monitor/module_hook.py +227 -158
  182. msprobe/pytorch/monitor/module_metric.py +14 -0
  183. msprobe/pytorch/monitor/optimizer_collect.py +242 -270
  184. msprobe/pytorch/monitor/utils.py +16 -3
  185. msprobe/pytorch/online_dispatch/dispatch.py +4 -2
  186. msprobe/pytorch/online_dispatch/dump_compare.py +5 -2
  187. msprobe/pytorch/parse_tool/lib/utils.py +3 -3
  188. msprobe/pytorch/pt_config.py +8 -7
  189. msprobe/pytorch/pytorch_service.py +73 -0
  190. msprobe/visualization/builder/graph_builder.py +33 -13
  191. msprobe/visualization/builder/msprobe_adapter.py +24 -11
  192. msprobe/visualization/compare/graph_comparator.py +53 -45
  193. msprobe/visualization/compare/mode_adapter.py +31 -1
  194. msprobe/visualization/graph/base_node.py +3 -3
  195. msprobe/visualization/graph/graph.py +2 -2
  196. msprobe/visualization/graph_service.py +250 -103
  197. msprobe/visualization/utils.py +27 -11
  198. msprobe/mindspore/dym_loader/hook_dynamic_loader.cc +0 -106
  199. msprobe/mindspore/monitor/anomaly_detect.py +0 -404
  200. msprobe/mindspore/monitor/module_spec_verifier.py +0 -94
  201. msprobe/mindspore/service.py +0 -549
  202. msprobe/pytorch/monitor/anomaly_analyse.py +0 -201
  203. msprobe/pytorch/monitor/anomaly_detect.py +0 -410
  204. msprobe/pytorch/monitor/module_spec_verifier.py +0 -95
  205. msprobe/pytorch/monitor/unittest/test_monitor.py +0 -160
  206. msprobe/pytorch/service.py +0 -473
  207. {mindstudio_probe-1.3.0.dist-info → mindstudio_probe-8.1.1.dist-info}/LICENSE +0 -0
  208. {mindstudio_probe-1.3.0.dist-info → mindstudio_probe-8.1.1.dist-info}/WHEEL +0 -0
  209. {mindstudio_probe-1.3.0.dist-info → mindstudio_probe-8.1.1.dist-info}/entry_points.txt +0 -0
  210. {mindstudio_probe-1.3.0.dist-info → mindstudio_probe-8.1.1.dist-info}/top_level.txt +0 -0
  211. /msprobe/{mindspore → core}/compare/ms_to_pt_api.yaml +0 -0
  212. /msprobe/{mindspore/dump → core}/kernel_dump/kernel_config.py +0 -0
  213. /msprobe/{pytorch/monitor/unittest → core/monitor}/__init__.py +0 -0
@@ -3,7 +3,7 @@
3
3
  ## 1 简介
4
4
 
5
5
  为了应对大模型场景下,通过离线预检方式 dump API 输入输出数据导致的存储资源紧张问题,提供在线精度预检功能。本功能实现在执行 NPU 训练操作的过程中,通过 TCP/IP 协议在 NPU
6
- Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据在 GPU 设备上运行,将两份输出数据进行比对,得到预检比对结果,从而减少数据 dump 的步骤,降低存储资源的占用。针对偏差较大的算子,两方比对(NPU vs. GPU)的方法缺少裁判进行裁定。 参考离线预检,在线预检场景同时支持两方比对和三方比对方式,按照 api 的精度标准要求,选择比对两方比对和三方比对。
6
+ Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据在 GPU 设备上运行,将两份输出数据进行比对,得到预检比对结果,从而减少数据 dump 的步骤,降低存储资源的占用。针对偏差较大的算子,两方比对(NPU vs. GPU)的方法缺少裁判进行裁定。 参考离线预检,在线预检场景同时支持两方比对和三方比对方式,按照 api 的精度标准要求,选择两方比对或三方比对。
7
7
 
8
8
  ## 2 在线精度预检流程
9
9
 
@@ -37,7 +37,7 @@ Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据
37
37
  | host | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机地址 127.0.0.1 或本机局域网 IP。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
38
38
  | port | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机可用端口。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
39
39
  | rank_list | 指定在线预检的 Rank ID,默认值为 [0],list[int] 类型,应配置为大于等于 0 的整数,且须根据实际卡的 Rank ID 配置,若所配置的值大于实际训练所运行的卡的 Rank ID,则在线预检输出数据为空。GPU 和 NPU 须配置一致。 | 是 |
40
- | tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥文件 server.key 和公钥文件 server.crt,str 类型,未配置该参数时默认取值当前路径。tls_path配置为空字符串时,采用TCP协议明文传输api数据;当配置为路径时,采用TLS1.2协议加密传输数据,加密传输时安全性较高,传输速率较低。 | 否 |
40
+ | tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥 server.key、证书 server.crt、自建CA证书 ca.crt、CRL吊销证书 crl.pem,str 类型,未配置该参数时默认取值当前路径。tls_path配置为空字符串时,采用TCP协议明文传输api数据;当配置为路径时,采用TLS1.2协议加密传输数据,加密传输时安全性较高,传输速率较低。其中 crl.pem 为非必需文件,仅当用户存在吊销记录时使用。 | 否 |
41
41
 
42
42
 
43
43
  #### 3.1.2 NPU 侧在线预检配置说明
@@ -55,7 +55,7 @@ Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据
55
55
  | nfs_path | 在线预检模式共享存储目录路径,str 类型,用于 GPU 设备和 NPU 设备间进行通信。配置该参数后 host 和 port 不生效。 | 否 |
56
56
  | host | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的局域网 IP 地址。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
57
57
  | port | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的端口号。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
58
- | tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥文件 client.key 和公钥文件 client.crt,str 类型,未配置该参数时默认取值当前路径。tls_path配置为空字符串时,采用TCP协议明文传输api数据;当配置为路径时,采用TLS1.2协议加密传输数据,加密传输时安全性较高,传输速率较低。 | 否 |
58
+ | tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥 client.key、证书 client.crt、自建CA证书 ca.crt、CRL吊销证书 crl.pem,str 类型,未配置该参数时默认取值当前路径。tls_path配置为空字符串时,采用TCP协议明文传输api数据;当配置为路径时,采用TLS1.2协议加密传输数据,加密传输时安全性较高,传输速率较低。其中 crl.pem 为非必需文件,仅当用户存在吊销记录时使用。 | 否 |
59
59
  | online_run_ut_recompute | 模型训练是否使用重计算机制,bool类型,默认为False,表示模型没有使用重计算。在线预检暂不支持重计算机制下反向算子的预检,当模型训练使用重计算时,跳过反向算子预检,默认模型关闭重计算。 | 否 |
60
60
 
61
61
  #### 3.1.3 局域网场景配置示例
@@ -63,15 +63,65 @@ Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据
63
63
  若采用 TLS1.2 协议加密传输 api 数据,需配置 SSL 证书,可参考如下生成自签名证书方法。
64
64
 
65
65
  以下秘钥生成方法仅为简单示例,客户应使用与自己需求相符的秘钥生成和存储机制并保证秘钥安全性与机密性,必要时可采用分层秘钥机制。
66
+ 以下示例中加密口令仅供参考,使用时请更换为复杂口令,并保护口令安全。
66
67
  ```shell
67
- # 创建私钥文件server.key
68
- openssl genrsa -out server.key 2048
68
+ # 生成CA证书的根私钥和证书签名请求,其中ca_password为CA私钥加密口令,仅作演示,请更换使用
69
+ openssl req -new -newkey rsa:3072 -passout pass:ca_password -subj "/CN=*ca.com/O=ca.Inc./C=CN/ST=Zhejiang/L=Hangzhou" -keyout ca.key -out ca.csr
70
+ # 自签发根证书
71
+ openssl x509 -req -days 365 -in ca.csr -signkey ca.key -passin pass:ca_password -out ca.crt -extensions v3_ca -extfile <(cat <<-EOF
72
+ [v3_ca]
73
+ basicConstraints = critical,CA:true
74
+ keyUsage = critical, keyCertSign, cRLSign
75
+ EOF
76
+ )
77
+
78
+ # 生成client公私钥,其中client_password为私钥加密口令,仅作演示,请更换使用
79
+ openssl genrsa -aes256 -passout pass:client_password -out client.key 3072
80
+ # 基于client公私钥生成签名请求
81
+ openssl req -new -key client.key -passin pass:client_password -subj "/CN=*example.com/O=Test, Inc./C=CN/ST=Zhejiang/L=Hangzhou" -out client.csr
82
+ # 利用自签发的根证书,签发client证书
83
+ openssl x509 -req -days 180 -CA ca.crt -CAkey ca.key -passin pass:ca_password -in client.csr -out client.crt -CAcreateserial -extfile <(cat <<-EOF
84
+ [v3_server]
85
+ basicConstraints = CA:FALSE
86
+ keyUsage = critical, digitalSignature, keyEncipherment
87
+ extendedKeyUsage = serverAuth
88
+ EOF
89
+ )
90
+
91
+ # 生成server公私钥,其中server_password为私钥加密口令,仅作演示,请更换使用
92
+ openssl genrsa -aes256 -passout pass:server_password -out server.key 3072
93
+ # 基于server公私钥生成签名请求
94
+ openssl req -new -key server.key -passin pass:server_password -subj "/CN=*example.com/O=Test, Inc./C=CN/ST=Zhejiang/L=Hangzhou" -out server.csr
95
+ # 利用自签发的根证书,签发server证书
96
+ openssl x509 -req -days 180 -CA ca.crt -CAkey ca.key -passin pass:ca_password -in server.csr -out server.crt -CAcreateserial -extfile <(cat <<-EOF
97
+ [v3_server]
98
+ basicConstraints = CA:FALSE
99
+ keyUsage = critical, digitalSignature, keyEncipherment
100
+ extendedKeyUsage = serverAuth
101
+ EOF
102
+ )
69
103
 
70
- # 创建签名请求文件server.csr
71
- openssl req -new -key server.key -out server.csr
104
+ ```
105
+
106
+ 当需要吊销已创建的SSL证书时,通过openssl命令生成CRL证书 crl.pem,示例如下:
107
+ ```shell
108
+ # 创建证书信息的文本数据库,空文件即可
109
+ touch index.txt
110
+
111
+ # 创建ca配置文件ca.cnf,内容如下,用于吊销证书使用
112
+ [ca]
113
+ default_ca = CA_default
114
+ [CA_default]
115
+ database = ./index.txt
116
+ default_md = sha256
117
+
118
+ # 吊销证书 client.crt,其中ca_password为CA私钥加密口令,与CA创建时保持一致
119
+ openssl ca -revoke client.crt -config ca.cnf -cert ca.crt -keyfile ca.key -passin pass:ca_password
120
+ # 生成CRL文件
121
+ openssl ca -gencrl -config ca.cnf -cert ca.crt -keyfile ca.key -passin pass:ca_password -out crl.pem -crldays 30
122
+ # 查看生成的CRL文件内容:
123
+ openssl工具的命令: openssl crl -inform PEM -in crl.pem -text
72
124
 
73
- # 自签名, 生成1年期公钥文件server.crt
74
- openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
75
125
  ```
76
126
 
77
127
  注意:配置TLS协议时,传输性能受机器环境和网络质量的影响,可能触发NPU超时中断模型训练,为避免训练和预检中断,丢弃长时间未传输的api数据,同时NPU侧配置HCCL环境变量,配置方式如下:
@@ -233,3 +283,13 @@ bash train.sh
233
283
  - npu_scaled_masked_softmax
234
284
 
235
285
  - npu_swiglu
286
+
287
+ - npu_apply_adam
288
+
289
+ - npu_group_norm_silu
290
+
291
+ - npu_mish
292
+
293
+ - npu_moe_gating_top_k_softmax
294
+
295
+ - npu_sort_v2
@@ -34,9 +34,18 @@ msprobe -f mindspore run_ut -api_info ./dump.json -o ./checker_result
34
34
  | -api_info 或 --api_info_file | 指定 API 信息文件 dump.json。对其中的mint api以及部分Tensor api进行预检,预检支持的Tensor api列表详见 [ 预检支持列表](../mindspore/api_accuracy_checker/checker_support_api.yaml)。 | str | 是 |
35
35
  | -o 或 --out_path | 指定预检结果存盘路径,默认“./”。 | str | 否 |
36
36
  | -csv_path 或 --result_csv_path | 指定本次运行中断时生成的 `accuracy_checking_result_{timestamp}.csv` 文件路径,执行 run_ut 中断时,若想从中断处继续执行,配置此参数即可。需要指定为上次中断的 `accuracy_checking_result_{timestamp}.csv` 文件。详见 [3.3 断点续检](#33-断点续检)。 | str | 否 |
37
+ | -save_error_data | 保存(随机数据模式)精度未达标的 API 输入输出数据。 | 空 | 否 |
37
38
 
38
39
  预检执行结果包括 `accuracy_checking_result_{timestamp}.csv` 和 `accuracy_checking_details_{timestamp}.csv` 两个文件。`accuracy_checking_result_{timestamp}.csv` 属于 API 级,标明每个 API 是否通过测试。建议用户先查看 `accuracy_checking_result_{timestamp}.csv` 文件,对于其中没有通过测试的或者特定感兴趣的 API,根据其 API Name 字段在 `accuracy_checking_details_{timestamp}.csv` 中查询其各个输出的达标情况以及比较指标。详细介绍请参见 [4 预检结果](#4-预检结果)。
39
40
 
41
+ 随机数据模式下,如果需要保存比对不达标的输入和输出数据,可以在 run_ut 执行命令结尾添加 `-save_error_data`,例如:
42
+
43
+ ```bash
44
+ msprobe -f mindspore run_ut -api_info ./dump.json -o ./checker_result -save_error_data
45
+ ```
46
+
47
+ 数据默认会存盘到 '{out_path}/error_data' 路径下。
48
+
40
49
  ### 3.2 使用 multi_run_ut 执行多线程预检
41
50
 
42
51
  multi_run_ut 脚本,可以并行在多个Device执行 run_ut 操作,从而减少预检耗时。示例如下:
@@ -45,16 +54,19 @@ multi_run_ut 脚本,可以并行在多个Device执行 run_ut 操作,从而
45
54
  msprobe -f mindspore multi_run_ut -api_info ./dump.json -d 0 1 2 3
46
55
  ```
47
56
 
48
- | 参数名称 | 说明 |参数类型 | 是否必选 |
49
- | ---------------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------- | ---------------------------------- |
50
- | -api_info 或 --api_info_file | 指定 API 信息文件 dump.json。对其中的mint api以及部分Tensor api进行预检,预检支持的Tensor api列表详见 [ 预检支持列表](../mindspore/api_accuracy_checker/checker_support_api.yaml)。 | str | 是 |
51
- | -o 或 --out_path | 指定预检结果存盘路径,默认“./”。 | str | 否 |
52
- | -csv_path 或 --result_csv_path | 指定本次运行中断时生成的 `accuracy_checking_result_{timestamp}.csv` 文件路径,执行 run_ut 中断时,若想从中断处继续执行,配置此参数即可。需要指定为上次中断的 `accuracy_checking_result_{timestamp}.csv` 文件。详见 [3.3 断点续检](#33-断点续检)。 | str | 否 |
53
- | -d 或 --device | 指定 Device ID,选择 UT 代码运行所在的卡,默认值为 0,支持同时指定 0 ~ Device数量 - 1 ,例如 0 1 2 3 4。 | List[int] | 否 |
57
+ | 参数名称 | 说明 | 参数类型 | 是否必选 |
58
+ | ---------------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------| ---------------------------------- |
59
+ | -api_info 或 --api_info_file | 指定 API 信息文件 dump.json。对其中的mint api以及部分Tensor api进行预检,预检支持的Tensor api列表详见 [ 预检支持列表](../mindspore/api_accuracy_checker/checker_support_api.yaml)。 | str | 是 |
60
+ | -o 或 --out_path | 指定预检结果存盘路径,默认“./”。 | str | 否 |
61
+ | -csv_path 或 --result_csv_path | 指定本次运行中断时生成的 `accuracy_checking_result_{timestamp}.csv` 文件路径,执行 run_ut 中断时,若想从中断处继续执行,配置此参数即可。需要指定为上次中断的 `accuracy_checking_result_{timestamp}.csv` 文件。详见 [3.3 断点续检](#33-断点续检)。 | str | 否 |
62
+ | -d 或 --device | 指定 Device ID,选择 UT 代码运行所在的卡,默认值为 0,支持同时指定 0 ~ Device数量 - 1 ,例如 0 1 2 3 4。 | List[int] | 否 |
63
+ | -save_error_data | 保存(随机数据模式)精度未达标的 API 输入输出数据。 | 空 | 否 |
54
64
 
55
65
  在不同卡数下,使用38B语言大模型的预检耗时基线参考 [multi_run_ut耗时基线](accuracy_checker_MindSpore/accuracy_checker_MindSpore_baseline.md)
56
66
 
57
67
 
68
+ 数据默认会存盘到 './ut_error_data{timestamp}' 路径下
69
+
58
70
  ### 3.3 断点续检
59
71
 
60
72
  断点续检操作通过如下命令执行:
@@ -53,12 +53,12 @@ msprobe -f pytorch compare -i ./compare.json -o ./output -s
53
53
 
54
54
  | 参数名 | 说明 | 是否必选 |
55
55
  |-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- |
56
- | -i 或 --input_path | 指定[比对文件](#214-比对文件),str 类型。 | 是 |
56
+ | -i 或 --input_path | 指定[比对文件](#51-比对文件),str 类型。 | 是 |
57
57
  | -o 或 --output_path | 配置比对结果文件存盘目录,str 类型,默认在当前目录创建output目录。文件名称基于时间戳自动生成,格式为:`compare_result_{timestamp}.xlsx`。<br>提示:output目录下与结果件同名文件将被删除覆盖。 | 否 |
58
- | -s 或 --stack_mode | 比对结果展示调用栈信息(NPU_Stack_Info)的开关,bool 类型。单卡场景开启时,根据[比对文件](#214-比对文件)的参数说明配置stack_path;多卡场景开启时,自动识别npu_dump目录下stack.json文件,如存在生成详细调用栈信息,否则不生成,此参数不生效。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
58
+ | -s 或 --stack_mode | 比对结果展示调用栈信息(NPU_Stack_Info)的开关,bool 类型。单卡场景开启时,根据[比对文件](#51-比对文件)的参数说明配置stack_path;多卡场景开启时,自动识别npu_dump目录下stack.json文件,如存在生成详细调用栈信息,否则不生成,此参数不生效。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
59
59
  | -c 或 --compare_only | 仅比对开关,bool 类型。该参数默认未配置,会启用自动精度分析,工具自动针对比对结果进行分析,识别到第一个精度可能不达标节点(在比对结果文件中的 Accuracy Reached or Not 列显示为 No),并给出问题可能产生的原因(打屏展示并生成 `advisor_{timestamp}.txt` 文件)。通过配置该参数取消自动精度分析,仅输出比对结果表格。 | 否 |
60
60
  | -f 或 --fuzzy_match | 模糊匹配,bool 类型。开启后,对于网络中同一层级且命名仅调用次数不同的 API,可匹配并进行比对。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
61
- | -dm或--data_mapping | 自定义映射关系比对。需要指定自定义映射文件*.yaml。自定义映射文件的格式请参见[自定义映射文件](#215-自定义映射文件)。仅[API和模块无法自动匹配场景](#213-api和模块无法自动匹配场景)需要配置。仅支持逐卡比对,即使用[比对文件](#214-比对文件)的单卡场景示例。 | 否 |
61
+ | -dm或--data_mapping | 自定义映射关系比对。需要指定自定义映射文件*.yaml。自定义映射文件的格式请参见[自定义映射文件](#52-自定义映射文件)。仅[API和模块无法自动匹配场景](#213-api和模块无法自动匹配场景)需要配置。仅支持逐卡比对,即使用[比对文件](#51-比对文件)的单卡场景示例。 | 否 |
62
62
 
63
63
  #### 2.1.2 整网比对场景
64
64
 
@@ -66,19 +66,17 @@ msprobe -f pytorch compare -i ./compare.json -o ./output -s
66
66
 
67
67
  支持单卡和多卡,可同时比对多卡的 dump 数据。多机场景需要每个设备单独执行比对操作。
68
68
 
69
- 1. 配置[config.json](../config.json)文件。
69
+ 1. 参见 [PyTorch 场景下的数据采集](./05.data_dump_PyTorch.md)章节完成 CPU 或 GPU 与 NPU 的精度数据 dump。
70
70
 
71
- 2. 参见 [PyTorch 场景下的数据采集](./05.data_dump_PyTorch.md)章节完成 CPU 或 GPU 与 NPU 的精度数据 dump
71
+ 2. 创建[比对文件](#51-比对文件)。
72
72
 
73
- 3. 创建[比对文件](#214-比对文件)。
74
-
75
- 4. 运行命令:
73
+ 3. 运行命令:
76
74
 
77
75
  ```shell
78
76
  msprobe -f pytorch compare -i ./compare.json -o ./output -s
79
77
  ```
80
78
 
81
- 5. 查看比对结果,请参见 [3 精度比对结果分析](#3-精度比对结果分析)。
79
+ 4. 查看比对结果,请参见 [3 精度比对结果分析](#3-精度比对结果分析)。
82
80
 
83
81
  #### 2.1.3 API和模块无法自动匹配场景
84
82
 
@@ -88,7 +86,7 @@ msprobe -f pytorch compare -i ./compare.json -o ./output -s
88
86
 
89
87
  2. 参见[PyTorch 场景下的数据采集](./05.data_dump_PyTorch.md)章节完成 CPU 或 GPU 与 NPU 的精度数据 dump。
90
88
 
91
- 3. 创建[比对文件](#214-比对文件)(单卡场景示例)。
89
+ 3. 创建[比对文件](#51-比对文件)(单卡场景示例)。
92
90
 
93
91
  4. 运行命令:
94
92
 
@@ -96,75 +94,30 @@ msprobe -f pytorch compare -i ./compare.json -o ./output -s
96
94
  msprobe -f pytorch compare -i ./compare.json -o ./output -s -dm data_mapping.yaml
97
95
  ```
98
96
 
99
- data_mapping.yaml文件配置请参见[自定义映射文件](#215-自定义映射文件)。
97
+ data_mapping.yaml文件配置请参见[自定义映射文件](#52-自定义映射文件)。
100
98
 
101
99
  该场景不支持-f模糊匹配。
102
100
 
103
101
  5. 查看比对结果,请参见 [3 精度比对结果分析](#3-精度比对结果分析)。
104
102
 
105
- #### 2.1.4 比对文件
106
-
107
- 以在当前目录创建 ./compare.json 为例。
108
103
 
109
- - 单卡场景示例:
110
-
111
- ```json
112
- {
113
- "npu_path": "./npu_dump/dump.json",
114
- "bench_path": "./bench_dump/dump.json",
115
- "stack_path": "./npu_dump/stack.json",
116
- "is_print_compare_log": true
117
- }
118
- ```
119
-
120
- - 多卡场景示例:
121
-
122
- ```json
123
- {
124
- "npu_path": "./npu_dump/step0",
125
- "bench_path": "./bench_dump/step0",
126
- "is_print_compare_log": true
127
- }
128
- ```
129
-
130
- **参数说明**:
131
-
132
- | 参数名 | 说明 | 是否必选 |
133
- | -------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|
134
- | npu_path | 配置 NPU 环境下的 dump.json 文件(单卡场景)或真实数据目录(多卡场景),str 类型。 | 是 |
135
- | bench_path | 配置 CPU、GPU 或 NPU 环境下的 dump.json 文件(单卡场景)或真实数据目录(多卡场景),str 类型。 | 是 |
136
- | stack_path | 配置 NPU dump 目录下的 stack.json 文件,str 类型。如果没有配置stack_path,命令行-s参数不生效,程序自动识别是否存在stack.json文件,如存在,则比对结果中呈现NPU_Stack_Info,如不存在,则不呈现。如果配置了stack_path,比对结果中是否呈现NPU_Stack_Info则通过命令行参数-s来控制。 | 否 |
137
- | is_print_compare_log | 配置是否开启单个算子的日志打屏。可取值 true 或 false,默认为 true。关闭后则只输出常规日志,bool 类型。 | 否 |
138
-
139
- #### 2.1.5 自定义映射文件
140
-
141
- 文件名格式:*.yaml,*为文件名,可自定义。
142
-
143
- 文件内容格式:
104
+ #### 2.1.4 单点数据比对场景
144
105
 
145
- ```yaml
146
- # API
147
- {api_type}.{api_name}.{API调用次数}.{前向反向}.{input/output}.{参数序号}: {api_type}.{api_name}.{API调用次数}.{前向反向}.{input/output}.{参数序号}
148
- # 模块
149
- {Module}.{module_name}.{前向反向}.{index}.{input/output}.{参数序号}: {Module}.{module_name}.{前向反向}.{index}.{input/output}.{参数序号}
150
- ```
106
+ 单点数据比对场景是指:CPU 或 GPU 与 NPU环境的网络中单点保存的数据比对。
151
107
 
152
- 冒号左侧和右侧分别为PyTorch框架不同版本或不同芯片环境的API的名称和module模块名称。
108
+ 支持单卡和多卡,可同时比对多卡的单点数据。多机场景需要每个设备单独执行比对操作。
153
109
 
154
- API和模块名称请从《[PyTorch 场景的精度数据采集](05.data_dump_PyTorch.md)》中的dump.json文件获取。
110
+ 1. 参见 [单点保存工具](./28.debugger_save_instruction.md)章节完成 CPU 或 GPU 与 NPU 的单点数据采集。
155
111
 
156
- 文件内容示例:
112
+ 2. 创建[比对文件(单点数据)](#53-比对文件单点数据)。
157
113
 
158
- ```yaml
159
- # API
160
- NPU.npu_fusion_attention.4.forward.input.0: NPU.npu_fusion_attention.4.forward.input.0
161
- # 模块
162
- Module.module.language_model.embedding.word_embedding.VocabParallelEmbedding.forward.0.input.0: Module.module.language_model.embedding.word_embedding.VocabParallelEmbedding.forward.0.input.0
163
- ```
114
+ 3. 运行命令:
164
115
 
165
- API和模块名称在dump.json文件中的“data_name”字段展示,如下图红框处所示:
116
+ ```shell
117
+ msprobe -f pytorch compare -i ./compare.json -o ./output
118
+ ```
166
119
 
167
- ![pt_dump](./img/pt_dump.png)
120
+ 4. 查看比对结果,请参见 [3 精度比对结果分析](#3-精度比对结果分析)
168
121
 
169
122
  ### 2.2 比对函数方式
170
123
 
@@ -219,7 +172,7 @@ compare_distributed(npu_dump_dir, bench_dump_dir, output_path, **kwargs)
219
172
  | -------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- |
220
173
  | npu_dump_dir | 配置 NPU 环境下的 dump 目录。str 类型。dump 数据目录须指定到 step 级。<br/>**配置示例**:'./npu_dump/step0'。 | 是 |
221
174
  | bench_dump_dir | 配置 CPU、GPU 或 NPU 环境下的 dump 目录。str 类型。<br/>**配置示例**:'./gpu_dump/step0'。 | 是 |
222
- | output_path | 配置比对结果文件存盘目录。需要预先创建 output_path 目录。str 类型。<br/>**配置示例**:'./output'。文件名称基于时间戳自动生成,格式为:`compare_result_rank{npu_ID}-rank{cpu/gpu/npu_ID}_{timestamp}.xlsx`。<br>提示:output目录下与结果件同名文件将被删除覆盖。 | 是 |
175
+ | output_path | 配置比对结果文件存盘目录。需要预先创建 output_path 目录。str 类型。<br/>**配置示例**:'./output'。文件名称基于时间戳自动生成,格式为:`compare_result_rank{npu_ID}_{timestamp}.xlsx`。<br>提示:output目录下与结果件同名文件将被删除覆盖。 | 是 |
223
176
  | **kwargs | 支持 compare 的所有可选参数。 其中,stack_mode不生效,自动识别是否存在stack.json,如存在,呈现NPU_Stack_Info,否则不呈现。 | 否 |
224
177
 
225
178
  **函数示例**:
@@ -315,7 +268,7 @@ MD5 模式:
315
268
 
316
269
  1. "Need double check api accuracy.":四个统计值中至少 1 个相对误差 > 0.5(统计数据模式);
317
270
  2. "Fuzzy matching data, the comparison arruracy may be affected.":NPU 或 Bench 的真实数据名没有匹配上(真实数据模式);
318
- 3. "Dump file: {} not found.":NPU 真实数据不存在或者读取出错(真实数据模式);
271
+ 3. "Dump file: {} not found or read failed.":NPU 或 Bench 的真实数据不存在或者读取出错(真实数据模式);
319
272
  4. "No bench data matched.":Bench 的 API 没有匹配上、Bench 真实数据不存在或读取出错(真实数据模式);
320
273
  5. "This is empty data, can not compare.":读取到的数据为空(真实数据模式);
321
274
  6. "Shape of NPU and bench Tensor do not match. Skipped.":NPU 和 Bench 的数据结构不一致(真实数据模式);
@@ -336,7 +289,7 @@ MD5 模式:
336
289
 
337
290
  4. MaxRelativeErr:当最大相对误差越接近 0 表示其计算的误差越小。
338
291
 
339
- 当 dump 数据中存在 0 或 Nan 时,比对结果中最大相对误差则出现 inf 或 Nan 的情况,属于正常现象。
292
+ 当 dump 数据中存在 0 或 nan 时,比对结果中最大相对误差则出现 inf 或 nan 的情况,属于正常现象。
340
293
 
341
294
  5. One Thousandth Err Ratio(相对误差小于千分之一的元素比例)、Five Thousandths Err Ratio(相对误差小于千分之五的元素比例)精度指标:是指 NPU 的 Tensor 中的元素逐个与对应的标杆数据对比,相对误差小于千分之一、千分之五的比例占总元素个数的比例。该数据仅作为精度下降趋势的参考,并不参与计算精度是否通过的判定。
342
295
 
@@ -380,10 +333,10 @@ compare_index:
380
333
  - MeanRelativeErr
381
334
  ```
382
335
 
383
- | 参数名 | 说明 |
384
- | ------------- | ------------------------------------------------------------ |
385
- | api | 表示需要汇总的API或module名称。如果没有配置,工具会提示报错。<br>api名称配置格式为:`{api_type}.{api_name}.{API调用次数}.{前向反向}`<br>须按顺序配置以上四个字段,可按如下组合配置:<br/> {api_type}<br/> {api_type}.{api_name}<br/> {api_type}.{api_name}.{API调用次数}<br/> {api_type}.{api_name}.{API调用次数}.{前向反向}<br/>这里的api指代API或module。 |
386
- | compare_index | 表示需要汇总的比对指标。compare_index需为dump_mode对应比对指标的子集。如果没有配置,工具将根据比对结果自动提取dump_mode对应的全部比对指标进行汇总。<br>统计数据模式比对指标:Max diff、Min diff、Mean diff、Norm diff、MaxRelativeErr、MinRelativeErr、MeanRelativeErr、NormRelativeErr<br>真实数据模式比对指标:Cosine、MaxAbsErr、MaxRelativeErr、One Thousandth Err Ratio、Five Thousandths Err Ratio |
336
+ | 参数名 | 说明 |
337
+ | ------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
338
+ | api | 表示需要汇总的API或module名称。如果没有配置,工具会提示报错。<br>api名称配置格式为:`{api_type}.{api_name}.{API调用次数}.{前向反向}`<br>须按顺序配置以上四个字段,可按如下组合配置:<br/> {api_type}<br/> {api_type}.{api_name}<br/> {api_type}.{api_name}.{API调用次数}<br/> {api_type}.{api_name}.{API调用次数}.{前向反向}<br/>这里的api指代API或module。 |
339
+ | compare_index | 表示需要汇总的比对指标。compare_index需为dump_mode对应比对指标的子集。如果没有配置,工具将根据比对结果自动提取dump_mode对应的全部比对指标进行汇总。<br>统计数据模式比对指标:Max diff、Min diff、Mean diff、L2norm diff、MaxRelativeErr、MinRelativeErr、MeanRelativeErr、NormRelativeErr<br>真实数据模式比对指标:Cosine、EucDist、MaxAbsErr、MaxRelativeErr、One Thousandth Err Ratio、Five Thousandths Err Ratio |
387
340
 
388
341
  **汇总结果件说明**
389
342
 
@@ -414,4 +367,189 @@ compare_index:
414
367
  6. Distributed.broadcast:输入为要广播的数据,输出为广播后的数据。
415
368
  7. Distributed.isend:点对点通信,输入为要发送的数据,输出为发送的数据。
416
369
  8. Distributed.irecv:点对点通信,输入为原数据,输出为接收的新数据。
417
- 9. Distributed.all_to_all_single:输出数据为所有卡上的数据切分后合并的结果。
370
+ 9. Distributed.all_to_all_single:输出数据为所有卡上的数据切分后合并的结果。
371
+
372
+ ## 5 附录
373
+
374
+ ### 5.1 比对文件
375
+
376
+ 以在当前目录创建 ./compare.json 为例。
377
+
378
+ - 单卡场景示例:
379
+
380
+ ```json
381
+ {
382
+ "npu_path": "./npu_dump/dump.json",
383
+ "bench_path": "./bench_dump/dump.json",
384
+ "stack_path": "./npu_dump/stack.json",
385
+ "is_print_compare_log": true
386
+ }
387
+ ```
388
+
389
+ - 多卡场景示例:
390
+
391
+ ```json
392
+ {
393
+ "npu_path": "./npu_dump/step0", # 需填写到step层级(rank的上一层级)
394
+ "bench_path": "./bench_dump/step0", # 需填写到step层级(rank的上一层级)
395
+ "is_print_compare_log": true
396
+ }
397
+ ```
398
+
399
+ **参数说明**
400
+
401
+ | 参数名 | 说明 | 是否必选 |
402
+ | -------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|
403
+ | npu_path | 配置NPU环境下的dump.json文件(单卡场景)或dump目录(多卡场景)。数据类型:str。 | 是 |
404
+ | bench_path | 配置CPU、GPU或NPU环境下的dump.json文件(单卡场景)或dump目录(多卡场景)。数据类型:str。 | 是 |
405
+ | stack_path | 配置NPU dump目录下的stack.json文件。数据类型:str。如果没有配置stack_path,命令行-s参数不生效,程序自动识别是否存在stack.json文件,如存在,则比对结果中呈现NPU_Stack_Info,如不存在,则不呈现。如果配置了stack_path,比对结果中是否呈现NPU_Stack_Info则通过命令行参数-s来控制。 | 否 |
406
+ | is_print_compare_log | 配置是否开启单个算子的日志打屏。可取值true或false,默认为true。关闭后则只输出常规日志。数据类型:bool。 | 否 |
407
+
408
+ ### 5.2 自定义映射文件
409
+
410
+ 文件名格式:*.yaml,*为文件名,可自定义。
411
+
412
+ 文件内容格式:
413
+
414
+ ```yaml
415
+ # API
416
+ {api_type}.{api_name}.{API调用次数}.{前向反向}.{input/output}.{参数序号}: {api_type}.{api_name}.{API调用次数}.{前向反向}.{input/output}.{参数序号}
417
+ # 模块
418
+ {Module}.{module_name}.{前向反向}.{index}.{input/output}.{参数序号}: {Module}.{module_name}.{前向反向}.{index}.{input/output}.{参数序号}
419
+ ```
420
+
421
+ 冒号左侧和右侧分别为PyTorch框架不同版本或不同芯片环境的API的名称和module模块名称。
422
+
423
+ API和模块名称请从《[PyTorch 场景的精度数据采集](05.data_dump_PyTorch.md)》中的dump.json文件获取。
424
+
425
+ 文件内容示例:
426
+
427
+ ```yaml
428
+ # API
429
+ NPU.npu_fusion_attention.4.forward.input.0: NPU.npu_fusion_attention.4.forward.input.0
430
+ # 模块
431
+ Module.module.language_model.embedding.word_embedding.VocabParallelEmbedding.forward.0.input.0: Module.module.language_model.embedding.word_embedding.VocabParallelEmbedding.forward.0.input.0
432
+ ```
433
+
434
+ 当dump.json文件中存在“data_name”字段时,API和模块名称为data_name字段去掉文件后缀,如下图红框处所示:
435
+
436
+ ![pt_dump](./img/pt_dump.png)
437
+
438
+ 当dump.json文件中不存在“data_name”字段时,名称的拼写规则如下:
439
+
440
+ input_args、input_kwargs和output使用统一的命名规则,当值是list类型时,名称后面添加'.{index}',当值类型是dict类型时,名称后面加'.{key}',当值类型是具体Tensor或null或int或float或bool或空list/dict等时,命名结束。
441
+
442
+ 以下面api的dump文件为例:
443
+ ```yaml
444
+ "Functional.max_pool2d.0.forward": {
445
+ "input_args": [
446
+ {
447
+ "type": "torch.Tensor",
448
+ "dytpe": "torch_float32",
449
+ "shape": [
450
+ 1,
451
+ 64,
452
+ 14,
453
+ 14
454
+ ],
455
+ "Max": xxx,
456
+ "Min": xxx,
457
+ "Mean": xxx,
458
+ "Norm": xxx,
459
+ "requires_grad": true
460
+ },
461
+ {
462
+ "type": "int",
463
+ "value": 3
464
+ },
465
+ {
466
+ "type": "int",
467
+ "value": 2
468
+ },
469
+ {
470
+ "type": "int",
471
+ "value": 1
472
+ },
473
+ {
474
+ "type": "int",
475
+ "value": 1
476
+ }
477
+ ],
478
+ "input_kwargs": {
479
+ "ceil_mode": {
480
+ "type": "bool",
481
+ "value": false
482
+ },
483
+ "return_indices": {
484
+ "type": "bool",
485
+ "value": false
486
+ },
487
+ },
488
+ "output": [
489
+ {
490
+ "type": "torch.Tensor",
491
+ "dtype": "torch.float32",
492
+ "shape": [
493
+ 1,
494
+ 64,
495
+ 7,
496
+ 7
497
+ ],
498
+ "Max": xxx,
499
+ "Min": xxx,
500
+ "Mean": xxx,
501
+ "Norm": xxx,
502
+ "requires_grad": true
503
+ }
504
+ ]
505
+ }
506
+ ```
507
+
508
+ 初始名称为Functional.max_pool2d.0.forward,input_args是list,长度为5,第0项后面是Tensor,命名结束;第1-4项后面均是int,命名结束;按照顺序命名为
509
+ ```
510
+ Functional.max_pool2d.0.forward.input.0
511
+ Functional.max_pool2d.0.forward.input.1
512
+ Functional.max_pool2d.0.forward.input.2
513
+ Functional.max_pool2d.0.forward.input.3
514
+ Functional.max_pool2d.0.forward.input.4
515
+ ```
516
+ input_kwargs是dict,key是ceil_mode、return_indices,值均是bool,命名结束;命名为
517
+ ```
518
+ Functional.max_pool2d.0.forward.input.ceil_mode
519
+ Functional.max_pool2d.0.forward.input.return_indices
520
+ ```
521
+ output是list,长度为1,第0项后面是Tensor,命名结束;按照顺序命名为
522
+ ```
523
+ Functional.max_pool2d.0.forward.output.0
524
+ ```
525
+ 综上,生成的的op_name为
526
+ ```
527
+ Functional.max_pool2d.0.forward.input.0
528
+ Functional.max_pool2d.0.forward.input.1
529
+ Functional.max_pool2d.0.forward.input.2
530
+ Functional.max_pool2d.0.forward.input.3
531
+ Functional.max_pool2d.0.forward.input.4
532
+ Functional.max_pool2d.0.forward.input.ceil_mode
533
+ Functional.max_pool2d.0.forward.input.return_indices
534
+ Functional.max_pool2d.0.forward.output.0
535
+ ```
536
+
537
+ ### 5.3 比对文件(单点数据)
538
+
539
+ - 单卡场景示例:
540
+
541
+ ```json
542
+ {
543
+ "npu_path": "./npu_dump/debug.json",
544
+ "bench_path": "./bench_dump/debug.json"
545
+ }
546
+ ```
547
+
548
+ - 多卡场景示例(step0目录下包含debug.json文件):
549
+
550
+ ```json
551
+ {
552
+ "npu_path": "./npu_dump/step0",
553
+ "bench_path": "./bench_dump/step0"
554
+ }
555
+ ```