mindstudio-probe 1.0.1__py3-none-any.whl → 1.0.4__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.
- {mindstudio_probe-1.0.1.dist-info → mindstudio_probe-1.0.4.dist-info}/LICENSE +201 -201
- {mindstudio_probe-1.0.1.dist-info → mindstudio_probe-1.0.4.dist-info}/METADATA +36 -30
- mindstudio_probe-1.0.4.dist-info/RECORD +276 -0
- {mindstudio_probe-1.0.1.dist-info → mindstudio_probe-1.0.4.dist-info}/WHEEL +1 -1
- {mindstudio_probe-1.0.1.dist-info → mindstudio_probe-1.0.4.dist-info}/entry_points.txt +1 -0
- msprobe/README.md +101 -182
- msprobe/__init__.py +1 -0
- msprobe/{config/config.json → config.json} +49 -27
- msprobe/core/__init__.py +0 -0
- msprobe/{pytorch → core}/advisor/advisor.py +124 -124
- msprobe/{pytorch → core}/advisor/advisor_const.py +59 -59
- msprobe/{pytorch → core}/advisor/advisor_result.py +58 -58
- msprobe/core/common/const.py +341 -241
- msprobe/core/common/exceptions.py +100 -88
- msprobe/core/common/{file_check.py → file_utils.py} +478 -265
- msprobe/core/common/log.py +76 -55
- msprobe/core/common/utils.py +385 -516
- msprobe/core/common_config.py +85 -58
- msprobe/core/compare/acc_compare.py +300 -0
- msprobe/core/compare/check.py +95 -0
- msprobe/core/compare/compare_cli.py +49 -0
- msprobe/core/compare/highlight.py +223 -0
- msprobe/core/compare/multiprocessing_compute.py +149 -0
- msprobe/{pytorch → core}/compare/npy_compare.py +295 -244
- msprobe/core/compare/utils.py +430 -0
- msprobe/core/data_dump/data_collector.py +154 -140
- msprobe/core/data_dump/data_processor/base.py +314 -245
- msprobe/core/data_dump/data_processor/factory.py +59 -61
- msprobe/core/data_dump/data_processor/mindspore_processor.py +186 -0
- msprobe/core/data_dump/data_processor/pytorch_processor.py +366 -346
- msprobe/core/data_dump/json_writer.py +96 -116
- msprobe/core/data_dump/scope.py +178 -178
- msprobe/core/grad_probe/__init__.py +0 -0
- msprobe/core/grad_probe/constant.py +71 -0
- msprobe/core/grad_probe/grad_compare.py +171 -0
- msprobe/core/grad_probe/utils.py +64 -0
- msprobe/docs/01.installation.md +89 -0
- msprobe/docs/02.config_introduction.md +165 -0
- msprobe/docs/03.config_examples.md +247 -0
- msprobe/docs/04.acl_config_examples.md +76 -0
- msprobe/docs/05.data_dump_PyTorch.md +198 -0
- msprobe/docs/06.data_dump_MindSpore.md +243 -0
- msprobe/docs/07.accuracy_checker_PyTorch.md +274 -0
- msprobe/docs/08.accuracy_checker_online_PyTorch.md +198 -0
- msprobe/docs/09.accuracy_checker_MindSpore.md +68 -0
- msprobe/docs/10.accuracy_compare_PyTorch.md +245 -0
- msprobe/docs/11.accuracy_compare_MindSpore.md +202 -0
- msprobe/docs/12.overflow_check_PyTorch.md +79 -0
- msprobe/docs/13.overflow_check_MindSpore.md +31 -0
- msprobe/{pytorch/doc/parse_tool.md → docs/14.data_parse_PyTorch.md} +283 -286
- msprobe/docs/15.free_benchmarking_PyTorch.md +164 -0
- msprobe/docs/17.grad_probe.md +207 -0
- msprobe/docs/FAQ_PyTorch.md +177 -0
- msprobe/docs/S02.report_free_benchmarking_validation_performance_baseline.md +146 -0
- msprobe/docs/img/free_benchmark_framework.png +0 -0
- msprobe/docs/img/grad_probe_image-1.png +0 -0
- msprobe/docs/img/grad_probe_image-2.png +0 -0
- msprobe/docs/img/grad_probe_image-3.png +0 -0
- msprobe/docs/img/grad_probe_image-4.png +0 -0
- msprobe/docs/img/grad_probe_image.png +0 -0
- msprobe/mindspore/__init__.py +1 -1
- msprobe/mindspore/api_accuracy_checker/__init__.py +0 -0
- msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +255 -0
- msprobe/mindspore/api_accuracy_checker/api_info.py +69 -0
- msprobe/mindspore/api_accuracy_checker/api_runner.py +156 -0
- msprobe/mindspore/api_accuracy_checker/base_compare_algorithm.py +197 -0
- msprobe/mindspore/api_accuracy_checker/cmd_parser.py +6 -0
- msprobe/mindspore/api_accuracy_checker/compute_element.py +239 -0
- msprobe/mindspore/api_accuracy_checker/main.py +9 -0
- msprobe/mindspore/api_accuracy_checker/type_mapping.py +114 -0
- msprobe/mindspore/api_accuracy_checker/utils.py +80 -0
- msprobe/mindspore/cell_processor.py +34 -0
- msprobe/mindspore/common/const.py +106 -0
- msprobe/mindspore/common/log.py +38 -0
- msprobe/mindspore/common/utils.py +81 -0
- msprobe/mindspore/compare/distributed_compare.py +75 -0
- msprobe/mindspore/compare/ms_compare.py +219 -0
- msprobe/mindspore/compare/ms_graph_compare.py +348 -0
- msprobe/mindspore/compare/ms_to_pt_api.yaml +399 -0
- msprobe/mindspore/debugger/debugger_config.py +66 -51
- msprobe/mindspore/debugger/precision_debugger.py +126 -32
- msprobe/mindspore/dump/dump_tool_factory.py +35 -38
- msprobe/mindspore/dump/hook_cell/api_registry.py +118 -0
- msprobe/mindspore/dump/hook_cell/hook_cell.py +55 -0
- msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +922 -0
- msprobe/mindspore/dump/hook_cell/wrap_api.py +113 -0
- msprobe/mindspore/dump/jit_dump.py +72 -0
- msprobe/mindspore/dump/kernel_graph_dump.py +59 -60
- msprobe/mindspore/dump/kernel_kbyk_dump.py +64 -0
- msprobe/mindspore/free_benchmark/__init__.py +0 -0
- msprobe/mindspore/free_benchmark/api_pynative_self_check.py +116 -0
- msprobe/mindspore/free_benchmark/common/__init__.py +0 -0
- msprobe/mindspore/free_benchmark/common/config.py +12 -0
- msprobe/mindspore/free_benchmark/common/handler_params.py +17 -0
- msprobe/mindspore/free_benchmark/common/utils.py +71 -0
- msprobe/mindspore/free_benchmark/data/support_wrap_ops.yaml +842 -0
- msprobe/mindspore/free_benchmark/decorator/__init__.py +0 -0
- msprobe/mindspore/free_benchmark/decorator/dec_forward.py +43 -0
- msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +107 -0
- msprobe/mindspore/free_benchmark/handler/__init__.py +0 -0
- msprobe/mindspore/free_benchmark/handler/base_handler.py +90 -0
- msprobe/mindspore/free_benchmark/handler/check_handler.py +41 -0
- msprobe/mindspore/free_benchmark/handler/fix_handler.py +36 -0
- msprobe/mindspore/free_benchmark/handler/handler_factory.py +21 -0
- msprobe/mindspore/free_benchmark/perturbation/add_noise.py +67 -0
- msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +21 -0
- msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +63 -0
- msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +51 -0
- msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +35 -0
- msprobe/mindspore/free_benchmark/perturbation/no_change.py +12 -0
- msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +29 -0
- msprobe/mindspore/free_benchmark/self_check_tool_factory.py +33 -0
- msprobe/mindspore/grad_probe/__init__.py +0 -0
- msprobe/mindspore/grad_probe/global_context.py +90 -0
- msprobe/mindspore/grad_probe/grad_analyzer.py +231 -0
- msprobe/mindspore/grad_probe/grad_monitor.py +27 -0
- msprobe/mindspore/grad_probe/grad_stat_csv.py +132 -0
- msprobe/mindspore/grad_probe/hook.py +94 -0
- msprobe/mindspore/grad_probe/utils.py +30 -0
- msprobe/mindspore/ms_config.py +128 -78
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +44 -45
- msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +34 -32
- msprobe/mindspore/runtime.py +4 -0
- msprobe/mindspore/service.py +378 -0
- msprobe/mindspore/task_handler_factory.py +24 -21
- msprobe/msprobe.py +105 -67
- msprobe/pytorch/__init__.py +4 -4
- msprobe/pytorch/api_accuracy_checker/common/config.py +53 -50
- msprobe/pytorch/api_accuracy_checker/common/utils.py +214 -224
- msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +213 -216
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +606 -545
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_standard.yaml +132 -132
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_threshold.yaml +390 -390
- msprobe/pytorch/api_accuracy_checker/compare/compare.py +386 -345
- msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +73 -73
- msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +245 -248
- msprobe/pytorch/api_accuracy_checker/config.yaml +10 -4
- msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +335 -328
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +200 -203
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +133 -127
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +592 -493
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +70 -7
- msprobe/pytorch/api_accuracy_checker/run_ut/torch_ut_setting.json +7 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/__init__.py +0 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +197 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +325 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +204 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +219 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/ssl_config.py +10 -0
- msprobe/pytorch/bench_functions/__init__.py +15 -0
- msprobe/pytorch/bench_functions/apply_adam_w.py +28 -0
- msprobe/pytorch/bench_functions/confusion_transpose.py +19 -0
- msprobe/pytorch/bench_functions/fast_gelu.py +55 -0
- msprobe/pytorch/bench_functions/layer_norm_eval.py +6 -0
- msprobe/pytorch/bench_functions/linear.py +12 -0
- msprobe/pytorch/bench_functions/matmul_backward.py +48 -0
- msprobe/pytorch/bench_functions/npu_fusion_attention.py +509 -0
- msprobe/pytorch/bench_functions/rms_norm.py +15 -0
- msprobe/pytorch/bench_functions/rotary_mul.py +52 -0
- msprobe/pytorch/bench_functions/scaled_mask_softmax.py +26 -0
- msprobe/pytorch/bench_functions/swiglu.py +55 -0
- msprobe/pytorch/common/__init__.py +2 -2
- msprobe/pytorch/common/compare_script.template +14 -14
- msprobe/pytorch/common/log.py +20 -31
- msprobe/pytorch/common/parse_json.py +39 -37
- msprobe/pytorch/common/utils.py +305 -224
- msprobe/pytorch/compare/distributed_compare.py +66 -111
- msprobe/pytorch/compare/mapping.yaml +607 -607
- msprobe/pytorch/compare/match.py +34 -36
- msprobe/pytorch/compare/pt_compare.py +50 -0
- msprobe/pytorch/debugger/debugger_config.py +95 -86
- msprobe/pytorch/debugger/precision_debugger.py +125 -95
- msprobe/pytorch/free_benchmark/__init__.py +8 -8
- msprobe/pytorch/free_benchmark/common/constant.py +70 -67
- msprobe/pytorch/free_benchmark/common/counter.py +71 -71
- msprobe/pytorch/free_benchmark/common/enums.py +37 -37
- msprobe/pytorch/free_benchmark/common/params.py +129 -129
- msprobe/pytorch/free_benchmark/common/utils.py +102 -98
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +179 -183
- msprobe/pytorch/free_benchmark/compare/single_benchmark.py +104 -104
- msprobe/pytorch/free_benchmark/main.py +105 -102
- msprobe/pytorch/free_benchmark/perturbed_layers/base_layer.py +13 -13
- msprobe/pytorch/free_benchmark/perturbed_layers/layer_factory.py +41 -41
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +90 -90
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +104 -104
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +63 -63
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +68 -68
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/no_change.py +28 -28
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/npu_base_layser.py +45 -45
- msprobe/pytorch/free_benchmark/perturbed_layers/run_cpu.py +19 -19
- msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +217 -203
- msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +39 -39
- msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +23 -23
- msprobe/pytorch/free_benchmark/result_handlers/handler_factory.py +30 -31
- msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +170 -170
- msprobe/pytorch/function_factory.py +76 -0
- msprobe/pytorch/functional/dump_module.py +39 -39
- msprobe/pytorch/grad_probe/__init__.py +0 -0
- msprobe/pytorch/grad_probe/grad_monitor.py +91 -0
- msprobe/pytorch/grad_probe/grad_stat_csv.py +129 -0
- msprobe/pytorch/hook_module/api_registry.py +161 -161
- msprobe/pytorch/hook_module/hook_module.py +120 -109
- msprobe/pytorch/hook_module/support_wrap_ops.yaml +1879 -1876
- msprobe/pytorch/hook_module/utils.py +30 -29
- msprobe/pytorch/hook_module/wrap_aten.py +110 -100
- msprobe/pytorch/hook_module/wrap_distributed.py +78 -75
- msprobe/pytorch/hook_module/wrap_functional.py +105 -108
- msprobe/pytorch/hook_module/wrap_npu_custom.py +93 -73
- msprobe/pytorch/hook_module/wrap_tensor.py +71 -72
- msprobe/pytorch/hook_module/wrap_torch.py +86 -88
- msprobe/pytorch/hook_module/wrap_vf.py +62 -64
- msprobe/pytorch/module_processer.py +138 -98
- msprobe/pytorch/online_dispatch/__init__.py +20 -20
- msprobe/pytorch/online_dispatch/compare.py +236 -236
- msprobe/pytorch/online_dispatch/dispatch.py +271 -273
- msprobe/pytorch/online_dispatch/dump_compare.py +155 -186
- msprobe/pytorch/online_dispatch/single_compare.py +391 -391
- msprobe/pytorch/online_dispatch/torch_ops_config.yaml +49 -49
- msprobe/pytorch/online_dispatch/utils.py +130 -187
- msprobe/pytorch/parse.py +4 -4
- msprobe/pytorch/parse_tool/cli.py +32 -32
- msprobe/pytorch/parse_tool/lib/compare.py +260 -259
- msprobe/pytorch/parse_tool/lib/config.py +52 -51
- msprobe/pytorch/parse_tool/lib/file_desc.py +31 -31
- msprobe/pytorch/parse_tool/lib/interactive_cli.py +102 -102
- msprobe/pytorch/parse_tool/lib/parse_exception.py +54 -54
- msprobe/pytorch/parse_tool/lib/parse_tool.py +158 -158
- msprobe/pytorch/parse_tool/lib/utils.py +316 -367
- msprobe/pytorch/parse_tool/lib/visualization.py +85 -90
- msprobe/pytorch/pt_config.py +188 -93
- msprobe/pytorch/service.py +246 -167
- mindstudio_probe-1.0.1.dist-info/RECORD +0 -228
- msprobe/config/README.md +0 -397
- msprobe/mindspore/doc/dump.md +0 -65
- msprobe/mindspore/dump/api_kbk_dump.py +0 -55
- msprobe/pytorch/compare/acc_compare.py +0 -1024
- msprobe/pytorch/compare/highlight.py +0 -100
- msprobe/pytorch/doc/FAQ.md +0 -193
- msprobe/pytorch/doc/api_accuracy_checker.md +0 -269
- msprobe/pytorch/doc/atat/321/207/342/226/223/342/225/233/321/205/342/225/221/320/266/321/205/342/225/226/320/265/321/205/320/225/342/225/226/321/206/320/245/342/226/221/321/206/320/235/320/276dump/321/206/320/260/320/227/321/205/320/227/320/226/321/206/320/220/320/267/321/210/320/223/342/225/234/321/205/320/257/342/225/221/321/207/342/225/221/342/224/220/321/206/320/232/320/265/321/205/320/241/320/232.md +0 -182
- msprobe/pytorch/doc/dump.md +0 -207
- msprobe/pytorch/doc/ptdbg_ascend_compare.md +0 -176
- msprobe/pytorch/doc/ptdbg_ascend_overview.md +0 -68
- msprobe/pytorch/doc/ptdbg_ascend_quickstart.md +0 -381
- msprobe/pytorch/doc/run_overflow_check.md +0 -25
- msprobe/pytorch/doc//321/205/320/254/320/270/321/207/342/225/221/342/224/220/321/207/342/226/223/342/225/233/321/205/342/225/221/320/266/321/206/320/277/320/244/321/205/320/277/342/225/243.md +0 -90
- msprobe/test/core_ut/common/test_utils.py +0 -345
- msprobe/test/core_ut/data_dump/test_data_collector.py +0 -47
- msprobe/test/core_ut/data_dump/test_json_writer.py +0 -183
- msprobe/test/core_ut/data_dump/test_scope.py +0 -151
- msprobe/test/core_ut/test_common_config.py +0 -152
- msprobe/test/core_ut/test_file_check.py +0 -218
- msprobe/test/core_ut/test_log.py +0 -109
- msprobe/test/mindspore_ut/test_api_kbk_dump.py +0 -51
- msprobe/test/mindspore_ut/test_debugger_config.py +0 -42
- msprobe/test/mindspore_ut/test_dump_tool_factory.py +0 -51
- msprobe/test/mindspore_ut/test_kernel_graph_dump.py +0 -66
- msprobe/test/mindspore_ut/test_kernel_graph_overflow_check.py +0 -63
- msprobe/test/mindspore_ut/test_ms_config.py +0 -69
- msprobe/test/mindspore_ut/test_overflow_check_tool_factory.py +0 -51
- msprobe/test/mindspore_ut/test_precision_debugger.py +0 -56
- msprobe/test/mindspore_ut/test_task_handler_factory.py +0 -58
- msprobe/test/pytorch_ut/advisor/test_advisor.py +0 -83
- msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py +0 -108
- msprobe/test/pytorch_ut/api_accuracy_checker/common/test_config.py +0 -39
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_algorithm.py +0 -112
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_api_precision_compare.py +0 -77
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare.py +0 -125
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare_column.py +0 -10
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare_utils.py +0 -43
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/dump.json +0 -179
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/forward.json +0 -63
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_data_generate.py +0 -99
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_multi_run_ut.py +0 -115
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_run_ut.py +0 -72
- msprobe/test/pytorch_ut/compare/test_acc_compare.py +0 -17
- msprobe/test/pytorch_ut/free_benchmark/perturbed_layers/test_perturbed_layser.py +0 -105
- msprobe/test/pytorch_ut/free_benchmark/result_handlers/test_result_handler.py +0 -121
- msprobe/test/pytorch_ut/free_benchmark/test_main.py +0 -101
- msprobe/test/pytorch_ut/functional/test_dump_module.py +0 -15
- msprobe/test/pytorch_ut/hook_module/test_api_registry.py +0 -130
- msprobe/test/pytorch_ut/hook_module/test_hook_module.py +0 -42
- msprobe/test/pytorch_ut/hook_module/test_wrap_aten.py +0 -65
- msprobe/test/pytorch_ut/hook_module/test_wrap_distributed.py +0 -35
- msprobe/test/pytorch_ut/hook_module/test_wrap_functional.py +0 -20
- msprobe/test/pytorch_ut/hook_module/test_wrap_tensor.py +0 -35
- msprobe/test/pytorch_ut/hook_module/test_wrap_torch.py +0 -43
- msprobe/test/pytorch_ut/hook_module/test_wrap_vf.py +0 -11
- msprobe/test/pytorch_ut/test_pt_config.py +0 -69
- msprobe/test/pytorch_ut/test_service.py +0 -59
- msprobe/test/resources/advisor.txt +0 -3
- msprobe/test/resources/compare_result_20230703104808.csv +0 -9
- msprobe/test/resources/compare_result_without_accuracy.csv +0 -9
- msprobe/test/resources/config.yaml +0 -3
- msprobe/test/resources/npu_test.pkl +0 -8
- msprobe/test/run_test.sh +0 -30
- msprobe/test/run_ut.py +0 -58
- msprobe/test/test_module_processer.py +0 -64
- {mindstudio_probe-1.0.1.dist-info → mindstudio_probe-1.0.4.dist-info}/top_level.txt +0 -0
- /msprobe/{pytorch/doc → docs}/img/BLOOM-7B_1.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/BLOOM-7B_2.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/BLOOM-7B_3.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/BLOOM-7B_4.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_1.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_2.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_3.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_4.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_5.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_6.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_7.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/GPT-3_8.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/YOLOV5S_1.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/YOLOV5S_2.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/accuracy_checking_details.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/accuracy_checking_result.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/api_precision_compare_details.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/api_precision_compare_result.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/auto_analyze_log.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/compare_result_pkl.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/compare_result_pkl_md5.png.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/cpu_info.png +0 -0
- /msprobe/{config → docs}/img/free_benchmark.png +0 -0
- /msprobe/{pytorch/doc → docs}/img/module_compare.png +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# PyTorch 场景的在线精度预检
|
|
2
|
+
|
|
3
|
+
## 1 简介
|
|
4
|
+
|
|
5
|
+
为了应对大模型场景下,通过离线预检方式 dump API 输入输出数据导致的存储资源紧张问题,提供在线精度预检功能。本功能实现在执行 NPU 训练操作的过程中,通过 TCP/IP 协议在 NPU
|
|
6
|
+
Host 与 GPU Host 设备间建立连接,将 NPU 上对应 API 的输入数据在 GPU 设备上运行,将两份输出数据进行比对,得到预检比对结果,从而减少数据 dump 的步骤,降低存储资源的占用。针对偏差较大的算子,两方比对(NPU vs. GPU)的方法缺少裁判进行裁定。 参考离线预检,在线预检场景同时支持两方比对和三方比对方式,按照 api 的精度标准要求,选择比对两方比对和三方比对。
|
|
7
|
+
|
|
8
|
+
## 2 在线精度预检流程
|
|
9
|
+
|
|
10
|
+
在线精度预检当前支持**局域网场景**和**共享存储场景**,请根据不同的场景选择对应的配置。
|
|
11
|
+
|
|
12
|
+
在线精度预检操作流程如下:
|
|
13
|
+
|
|
14
|
+
1. 准备 GPU 和 NPU 可正常运行的训练环境,PyTorch 版本大于等于2.0,并保证两台 Host 在同一局域网内可正常通信或能通过共享存储进行通信。
|
|
15
|
+
2. GPU 和 NPU Host 设备上同时安装msprobe工具,详见[ msprobe 安装](./01.installation.md)章节,其中在线预检要安装 twisted、pyOpenSSL,这些包为 Python 模块。
|
|
16
|
+
3. 分别配置 GPU 侧、NPU 侧的 config.json 文件。
|
|
17
|
+
4. 在 GPU 侧运行 `msprobe -f pytorch run_ut -config ./config.json`。
|
|
18
|
+
5. 在 NPU 侧配置训练脚本。
|
|
19
|
+
6. 在 NPU 侧执行训练。
|
|
20
|
+
|
|
21
|
+
## 3 在线精度预检操作指导
|
|
22
|
+
|
|
23
|
+
### 3.1 配置 config.json 文件
|
|
24
|
+
|
|
25
|
+
预检工具安装完成后,需要在 GPU 和 NPU 环境下分别配置 config.json。其中需要重点关注文件中的 is_online、is_benchmark_device、host 和 port 参数的配置,保障在线预检时 GPU 和 NPU 两台设备间的通信正常。
|
|
26
|
+
|
|
27
|
+
#### 3.1.1 GPU 侧在线预检配置说明
|
|
28
|
+
|
|
29
|
+
| 参数名称 | 说明 | 是否必选 |
|
|
30
|
+
|-----------------|--------------|------|
|
|
31
|
+
| task | 任务名称,str 类型,配置为 run_ut 表示预检任务。通过其他字段 is_online 判断离线预检、在线预检任务。 | 是 |
|
|
32
|
+
| white_list | 预检的 API 白名单,list[str] 类型。<br/>**配置示例**:white_list=["conv1d", "conv2d"]。默认未配置白名单,即预检全量 API 数据。 | 否 |
|
|
33
|
+
| black_list | 预检的 API 黑名单,list[str] 类型。<br/>**配置示例**:white_list=["conv1d", "conv2d"]。默认未配置黑名单,即预检全量 API 数据。 | 否 |
|
|
34
|
+
| error_data_path | 配置保存精度未达标的 API 输入输出数据路径,str 类型。在线预检模式下该参数不生效。 | 否 |
|
|
35
|
+
| is_online | 在线预检模式开关,bool 类型,可取值 True(开启)、False(关闭),默认关闭。 | 是 |
|
|
36
|
+
| nfs_path | 在线预检模式共享存储目录路径,str 类型,用于 GPU 设备和 NPU 设备间进行通信。配置该参数后 host、port 和 tls_path 不生效。 | 否 |
|
|
37
|
+
| host | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机地址 127.0.0.1 或本机局域网 IP。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
|
|
38
|
+
| port | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机可用端口。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
|
|
39
|
+
| rank_list | 指定在线预检的 Rank ID,默认值为 [0],list[int] 类型,应配置为大于等于 0 的整数,且须根据实际卡的 Rank ID 配置,若所配置的值大于实际训练所运行的卡的 Rank ID,则在线预检输出数据为空。GPU 和 NPU 须配置一致。 | 是 |
|
|
40
|
+
| tls_path | 在线预检模式局域网场景 SSL 证书路径,该路径下包含私钥文件 server.key 和公钥文件 server.crt,str 类型,默认值为空,表示明文传输 api 数据,否则采用 TLS1.2 加密传输,加密传输时安全性较高,传输速率较低。 | 否 |
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
#### 3.1.2 NPU 侧在线预检配置说明
|
|
44
|
+
|
|
45
|
+
| 参数名称 | 说明 | 是否必选 |
|
|
46
|
+
|------------------|-------------|------|
|
|
47
|
+
| task | 任务名称,str 类型,配置为 tensor 表示 dump API 统计信息和完全复刻整网的 API 运行情况的真实数据。通过字段 online_run_ut 判断是否使用在线预检功能。 | 是 |
|
|
48
|
+
| dump_path | dump 路径,str 类型,配置为合法路径即可,兼容 tensor 任务静态检查。 | 是 |
|
|
49
|
+
| level | dump 级别,str 类型,在线预检时配置为 L1,表示 dump API 级精度数据。在线预检可不配置,默认取值 L1。 | 是 |
|
|
50
|
+
| rank | 指定对某张卡上的数据进行 dump,list[int] 类型,默认未配置(表示 dump所有卡的数据),需要与 GPU 侧配置项 rank_list 保持一致。 | 否 |
|
|
51
|
+
| step | 指定 dump 某个 step 的数据,list[int] 类型,默认未配置,表示 dump 所有 step 的数据。dump 特定 step 时,须指定为训练脚本中存在的 step。 | 否 |
|
|
52
|
+
| seed | 随机种子数,int 类型,默认值为 1234。通过固定随机数保证模型的输入或输出一致。 | 否 |
|
|
53
|
+
| is_deterministic | 确定性计算模式,bool 类型,可取值 true(开启)或 false(关闭),默认关闭。 | 否 |
|
|
54
|
+
| scope | dump 范围,list[str] 类型,默认未配置(list 也未配置时表示 dump 所有 api 的数据),配置方式参考 [config.json 配置介绍](./02.config_introduction.md)。 | 否 |
|
|
55
|
+
| list | dump 范围,list[str] 类型,默认未配置(scope 也未配置时表示 dump 所有 api 的数据),配置方式参考 [config.json 配置介绍](./02.config_introduction.md)。 | 否 |
|
|
56
|
+
| online_run_ut | 在线预检模式开关,bool 类型,可取值 True(开启)、False(关闭),默认关闭。 | 是 |
|
|
57
|
+
| nfs_path | 在线预检模式共享存储目录路径,str 类型,用于 GPU 设备和 NPU 设备间进行通信。配置该参数后 host 和 port 不生效。 | 否 |
|
|
58
|
+
| host | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的局域网 IP 地址。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
|
|
59
|
+
| port | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的端口号。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
|
|
60
|
+
|
|
61
|
+
#### 3.1.3 局域网场景配置示例
|
|
62
|
+
|
|
63
|
+
若采用TLS1.2协议加密传输api数据,需配置SSL证书,可参考如下生成自签名证书方法,仅供调试使用,生产环境请申请正式证书。
|
|
64
|
+
```shell
|
|
65
|
+
# 创建私钥文件server.key
|
|
66
|
+
openssl genrsa -out server.key 2048
|
|
67
|
+
|
|
68
|
+
# 创建签名请求文件server.csr
|
|
69
|
+
openssl req -new -key server.key -out server.csr
|
|
70
|
+
|
|
71
|
+
# 自签名, 生成1年期公钥文件server.crt
|
|
72
|
+
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
GPU 侧:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"task": "run_ut",
|
|
80
|
+
"run_ut": {
|
|
81
|
+
"white_list": [],
|
|
82
|
+
"black_list": [],
|
|
83
|
+
"error_data_path": "./",
|
|
84
|
+
"is_online": true,
|
|
85
|
+
"nfs_path": "",
|
|
86
|
+
"host": "127.0.0.1",
|
|
87
|
+
"port": 59208,
|
|
88
|
+
"rank_list": [0]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
NPU 侧:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"task": "tensor",
|
|
98
|
+
"dump_path": "./dump_path",
|
|
99
|
+
"rank": [0],
|
|
100
|
+
"step": [0],
|
|
101
|
+
"level": "L1",
|
|
102
|
+
"seed": 1234,
|
|
103
|
+
"is_deterministic": true,
|
|
104
|
+
"tensor": {
|
|
105
|
+
"scope": [],
|
|
106
|
+
"list": [],
|
|
107
|
+
"online_run_ut": true,
|
|
108
|
+
"nfs_path": "",
|
|
109
|
+
"host": "xx.xx.xx.x",
|
|
110
|
+
"port": 59208
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### 3.1.4 共享存储场景配置示例
|
|
116
|
+
|
|
117
|
+
GPU 侧:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"task": "run_ut",
|
|
122
|
+
"run_ut": {
|
|
123
|
+
"white_list": [],
|
|
124
|
+
"black_list": [],
|
|
125
|
+
"error_data_path": "./",
|
|
126
|
+
"is_online": true,
|
|
127
|
+
"nfs_path": "/nfs/xxx/data",
|
|
128
|
+
"host": "",
|
|
129
|
+
"port": -1,
|
|
130
|
+
"rank_list": [0]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
NPU 侧:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"task": "tensor",
|
|
140
|
+
"dump_path": "./dump_path",
|
|
141
|
+
"rank": [0],
|
|
142
|
+
"step": [0],
|
|
143
|
+
"level": "L1",
|
|
144
|
+
"seed": 1234,
|
|
145
|
+
"is_deterministic": true,
|
|
146
|
+
"tensor": {
|
|
147
|
+
"scope": [],
|
|
148
|
+
"list": [],
|
|
149
|
+
"online_run_ut": true,
|
|
150
|
+
"nfs_path": "/nfs/xxx/data",
|
|
151
|
+
"host": "",
|
|
152
|
+
"port": -1
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 3.2 在 GPU 侧运行 run_ut
|
|
158
|
+
|
|
159
|
+
由于 GPU 侧为通信接收端,需先于 NPU 侧执行 run_ut 操作,命令如下:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
msprobe -f pytorch run_ut -config ./config.json
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
GPU 侧配置好 config.json 文件后执行 run_ut 命令,此时 GPU 处于预检等待状态:
|
|
166
|
+
|
|
167
|
+
- 局域网场景:当 NPU 侧启动训练后将预检的 API 输入和输出数据发送到 GPU 侧时,GPU 启动预检操作。
|
|
168
|
+
- 共享存储场景:当 NPU 侧启动训练后将预检的 API 输入和输出数据发送到共享存储时,GPU 启动预检操作。
|
|
169
|
+
|
|
170
|
+
### 3.2 在 NPU 侧配置训练脚本
|
|
171
|
+
|
|
172
|
+
在 NPU 训练脚本中添加如下代码以获取 run_ut 操作的预检 API 输入和输出数据:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from msprobe.pytorch import PrecisionDebugger
|
|
176
|
+
|
|
177
|
+
debugger = PrecisionDebugger("config.json")
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
debugger.start()
|
|
181
|
+
|
|
182
|
+
...
|
|
183
|
+
|
|
184
|
+
debugger.stop()
|
|
185
|
+
debugger.step()
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### 3.3 在 NPU 侧执行训练脚本
|
|
189
|
+
|
|
190
|
+
配置完 NPU 侧训练脚本后即可执行训练脚本,命令示例如下:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
bash train.sh
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
训练脚本执行完毕后,在GPU侧dump_path目录下生成比对结果文件,
|
|
197
|
+
`accuracy_checking_result_{timestamp}_rank{rank_id}.csv`和`accuracy_checking_details_{timestamp}_rank{rank_id}.csv`记录两方比对结果
|
|
198
|
+
`api_precision_compare_result_{timestamp}_rank{rank_id}.csv`和`api_precision_compare_details_{timestamp}_rank{rank_id}.csv`记录三方比对结果。详细介绍请参见[离线精度预检中的 **4 预检结果**](./07.accuracy_checker_PyTorch.md#4-预检结果)。
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# MindSpore 动态图场景的离线精度预检
|
|
2
|
+
|
|
3
|
+
## 1 简介
|
|
4
|
+
|
|
5
|
+
**MindSpore 动态图精度预检**<sup>a</sup>通过扫描昇腾 NPU 上用户训练 MindSpore 模型中的所有 Mint API,输出精度情况的诊断和分析。工具以模型中所有 Mint API 前反向的 dump 结果为输入,构造相应的 API 单元测试,将 NPU 输出与标杆(CPU 高精度)比对,计算对应的精度指标,从而找出 NPU 中存在精度问题的 Mint API。本工具支持随机生成模式和真实数据模式<sup>b</sup>。
|
|
6
|
+
|
|
7
|
+
a. 支持 Mindspore 版本:2.4;
|
|
8
|
+
b. 在预检 dump 时可以选择由工具构造随机数进行输入获得 dump 数据或选择获取真实输入数据进行预检 dump 操作。随机生成模式执行效率高,可以快速获得结果,但数据精度低,只能大致判断精度问题;真实数据模式执行效率略低于随机生成模式,但是数据精度高,可以准确判断精度问题。
|
|
9
|
+
|
|
10
|
+
## 2 离线预检流程
|
|
11
|
+
|
|
12
|
+
操作流程如下:
|
|
13
|
+
|
|
14
|
+
1. 在 NPU 和 GPU 环境下分别安装 msprobe。详见[ msprobe 安装](./01.installation.md)章节。
|
|
15
|
+
2. 在 NPU 训练脚本内添加 msprobe 工具 dump 接口 PrecisionDebugger,采集待预检数据。详见 [MindSpore 场景下的数据采集](./06.data_dump_MindSpore.md)章节,注意需要配置 level="L1"。
|
|
16
|
+
3. 执行预检操作,查看预检结果文件,分析预检不达标的API。
|
|
17
|
+
|
|
18
|
+
## 3 离线预检操作指导
|
|
19
|
+
|
|
20
|
+
命令如下:
|
|
21
|
+
```bash
|
|
22
|
+
msprobe -f mindspore run_ut -api_info ./dump.json -o ./checker_result
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
| 参数名称 | 说明 |参数类型 | 是否必选 |
|
|
26
|
+
| ---------------------------- | --------------------------------------|---------------------- | ---------------------------------- |
|
|
27
|
+
| -api_info 或 --api_info_file | 指定 API 信息文件 dump.json。 | str | 是 |
|
|
28
|
+
| -o 或 --out_path | 指定预检结果存盘路径,默认“./”。 | str | 否 |
|
|
29
|
+
|
|
30
|
+
预检执行结果包括 `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-预检结果)。
|
|
31
|
+
|
|
32
|
+
## 4 预检结果
|
|
33
|
+
|
|
34
|
+
精度预检生成的 `accuracy_checking_result_{timestamp}.csv` 和 `accuracy_checking_details_{timestamp}.csv` 文件内容详情如下:
|
|
35
|
+
|
|
36
|
+
`accuracy_checking_details_{timestamp}.csv`
|
|
37
|
+
|
|
38
|
+
| 字段 | 含义 |
|
|
39
|
+
| ------------------- | ------------------------------------------------------------ |
|
|
40
|
+
| API Name | API 名称。 |
|
|
41
|
+
| Bench Dtype | 标杆数据的 API 数据类型。 |
|
|
42
|
+
| Tested Dtype | 被检验数据的 API 数据类型。 |
|
|
43
|
+
| Shape | API 的 Shape 信息。 |
|
|
44
|
+
| Cosine | 被检验数据与标杆数据的余弦相似度。 |
|
|
45
|
+
| MaxAbsErr | 被检验数据与标杆数据的最大绝对误差。 |
|
|
46
|
+
| MaxRelativeErr | 被检验数据与标杆数据的最大相对误差。 |
|
|
47
|
+
| Status | API 预检通过状态,pass 表示通过测试,error 表示未通过。 |
|
|
48
|
+
| message | 提示信息。 |
|
|
49
|
+
|
|
50
|
+
注意点:torch无法对dtype为整数类型的tensor进行反向求导,mindspore则支持。反向过程的预检仅比较dtype为浮点型的输出。
|
|
51
|
+
|
|
52
|
+
`accuracy_checking_result_{timestamp}.csv`
|
|
53
|
+
|
|
54
|
+
| 字段 | 含义 |
|
|
55
|
+
| --------------------- | ----------------- |
|
|
56
|
+
| API Name | API 名称。 |
|
|
57
|
+
| Forward Test Success | 前向 API 是否通过测试,pass 为通过,error 为错误。 |
|
|
58
|
+
| Backward Test Success | 反向 API 是否通过测试,pass 为通过,error 为错误,如果是空白的话代表该 API 没有反向输出。 |
|
|
59
|
+
| Message | 提示信息。 |
|
|
60
|
+
|
|
61
|
+
Forward Test Success 和 Backward Test Success 是否通过测试是由 `accuracy_checking_details_{timestamp}.csv` 中的余弦相似度、最大绝对误差判定结果决定的。具体规则详见 [4.1 API 预检指标](#41-api-预检指标)。
|
|
62
|
+
需要注意的是 `accuracy_checking_details_{timestamp}.csv` 中可能存在一个 API 的前向(反向)有多个输出,那么每个输出记录一行,而在 `accuracy_checking_result_{timestamp}.csv` 中的结果需要该 API 的所有结果均为 pass 才能标记为 pass,只要存在一个 error 则标记 error。
|
|
63
|
+
|
|
64
|
+
### 4.1 API 预检指标
|
|
65
|
+
|
|
66
|
+
- API 预检指标是通过对`accuracy_checking_details_{timestamp}.csv`中的余弦相似度、最大绝对误差的数值进行判断,得出该API是否符合精度标准的参考指标。详细规则如下:
|
|
67
|
+
|
|
68
|
+
- 余弦相似度大于0.99,并且最大绝对误差小于0.0001,标记“pass”,否则标记为“error”。
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# PyTorch 场景的精度比对
|
|
2
|
+
|
|
3
|
+
## 1 简介
|
|
4
|
+
|
|
5
|
+
- 本节主要介绍通过命令行和比对函数的方式进行 CPU 或 GPU 与 NPU 的精度数据比对,执行精度比对操作前需要先完成 CPU 或 GPU 与 NPU 的精度数据 dump,参见 [PyTorch 场景下的数据采集](./05.data_dump_PyTorch.md)章节。
|
|
6
|
+
|
|
7
|
+
- msprobe 使用子命令 compare 进行比对,可支持单卡和多卡场景的精度数据比对。
|
|
8
|
+
|
|
9
|
+
- 比对函数均通过单独创建精度比对脚本执行,可支持单卡和多卡场景的精度数据比对。
|
|
10
|
+
|
|
11
|
+
- 工具性能:比对数据量较小时(单份文件小于 10 GB),比对速度 0.1 GB/s;比对数据量较大时,比对速度 0.3 GB/s。 推荐环境配置:独占环境,CPU 核心数 192,固态硬盘(IO 速度参考:固态硬盘 > 500 MB/s,机械硬盘 60 ~ 170 MB/s)。用户环境性能弱于标准约束或非独占使用的比对速度酌情向下浮动。比对速度的计算方式:两份比对文件大小/比对耗时。
|
|
12
|
+
|
|
13
|
+
**使用场景**:
|
|
14
|
+
|
|
15
|
+
- 同一模型,从 CPU 或 GPU 移植到 NPU 中存在精度下降问题,对比 NPU 芯片中的 API 计算数值与 CPU 或 GPU 芯片中的 API 计算数值,进行问题定位。
|
|
16
|
+
- 同一模型,进行迭代(模型、框架版本升级或设备硬件升级)时存在的精度下降问题,对比相同模型在迭代前后版本的 API 计算数值,进行问题定位。
|
|
17
|
+
|
|
18
|
+
**注意事项**:
|
|
19
|
+
|
|
20
|
+
- NPU 自研 API,在 CPU 或 GPU 侧若没有对应的 API,该 API 的 dump 数据不比对。
|
|
21
|
+
- NPU 与 CPU 或 GPU 的计算结果误差可能会随着模型的执行不断累积,最终会出现同一个 API 因为输入的数据差异较大而无法比对的情况。
|
|
22
|
+
- CPU 或 GPU 与 NPU 中两个相同的 API 会因为调用次数不同导致无法比对或比对到错误的 API,不影响整体运行,该 API 忽略。
|
|
23
|
+
|
|
24
|
+
**API匹配条件**:
|
|
25
|
+
|
|
26
|
+
进行精度比对时,需要判断CPU或GPU的API与NPU的API是否相同可比对,须满足以下匹配条件:
|
|
27
|
+
|
|
28
|
+
- 两个API的名称相同,API命名规则:`{api_type}.{api_name}.{api调用次数}.{正反向}.{输入输出}.index`,如:Functional.conv2d.1.backward.input.0。
|
|
29
|
+
- 两个API的输入输出Tensor数量和各个Tensor的Shape相同。
|
|
30
|
+
|
|
31
|
+
通常满足以上两个条件,工具就认为是同一个API,成功进行API的匹配,后续进行相应的计算精度比对。
|
|
32
|
+
|
|
33
|
+
## 2 精度比对操作指导
|
|
34
|
+
|
|
35
|
+
### 2.1 命令行方式
|
|
36
|
+
|
|
37
|
+
将 CPU 或 GPU 与 NPU 的 dump 文件进行比对,支持单卡和多卡,可同时比对多卡的 dump 数据。多机场景需要每个设备单独执行比对操作。
|
|
38
|
+
|
|
39
|
+
请先参见 [PyTorch 场景下的数据采集](./05.data_dump_PyTorch.md)章节完成 CPU 或 GPU 与 NPU 的精度数据 dump。
|
|
40
|
+
|
|
41
|
+
**操作步骤**:
|
|
42
|
+
|
|
43
|
+
1. 创建[比对文件](#211-比对文件)。
|
|
44
|
+
|
|
45
|
+
2. 运行命令:
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
msprobe -f pytorch compare -i ./compare.json -o ./output -s
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**参数说明**:
|
|
52
|
+
|
|
53
|
+
| 参数名 | 说明 | 是否必选 |
|
|
54
|
+
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- |
|
|
55
|
+
| -i 或 --input_path | 指定[比对文件](#211-比对文件)。 | 是 |
|
|
56
|
+
| -o 或 --output_path | 配置比对结果文件存盘目录。文件名称基于时间戳自动生成,格式为:`compare_result_{timestamp}.xlsx`。 | 是 |
|
|
57
|
+
| -s 或 --stack_mode | 配置 stack_mode 的开关。仅当[比对文件](#211-比对文件)配置 stack_path 需要开启。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
|
|
58
|
+
| -c 或 --compare_only | 仅比对开关。未配置默认关闭仅比对,使用自动精度分析,工具自动针对比对结果进行分析,识别到第一个精度不达标节点(在比对结果文件中的 Accuracy Reached or Not 列显示为 No),并给出问题可能产生的原因(打屏展示并生成 `advisor_{timestamp}.txt` 文件)。该参数默认未配置,使用自动精度分析,通过配置该参数开启仅比对,关闭自动精度分析,仅输出比对结果表格。 | 否 |
|
|
59
|
+
| -f 或 --fuzzy_match | 模糊匹配。开启后,对于网络中同一层级且命名仅调用次数不同的 API,可匹配并进行比对。通过直接配置该参数开启,默认未配置,表示关闭。 | 否 |
|
|
60
|
+
|
|
61
|
+
3. 查看比对结果,请参见 [3 精度比对结果分析](#3-精度比对结果分析)。
|
|
62
|
+
|
|
63
|
+
#### 2.1.1 比对文件
|
|
64
|
+
|
|
65
|
+
以在当前目录创建 ./compare.json 为例。
|
|
66
|
+
|
|
67
|
+
- 单卡场景示例:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"npu_path": "./npu_dump/dump.json",
|
|
72
|
+
"bench_path": "./bench_dump/dump.json",
|
|
73
|
+
"stack_path": "./npu_dump/stack.json",
|
|
74
|
+
"is_print_compare_log": true
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
- 多卡场景示例:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"npu_path": "./npu_dump/step0",
|
|
83
|
+
"bench_path": "./bench_dump/step0",
|
|
84
|
+
"is_print_compare_log": true
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**参数说明**:
|
|
89
|
+
|
|
90
|
+
| 参数名 | 说明 | 是否必选 |
|
|
91
|
+
| -------------------- | ------------------------------------------------------------ | ------------------ |
|
|
92
|
+
| npu_path | 配置 NPU 环境下的 dump.json 文件(单卡场景)或真实数据目录(多卡场景)。数据类型:str。 | 是 |
|
|
93
|
+
| bench_path | 配置 CPU、GPU 或 NPU 环境下的 dump.json 文件(单卡场景)或真实数据目录(多卡场景)。数据类型:str。 | 是 |
|
|
94
|
+
| stack_path | 配置 NPU dump 目录下的 stack.json 文件。数据类型:str。 | 单卡必选,多卡不选 |
|
|
95
|
+
| is_print_compare_log | 配置是否开启日志打屏。可取值 True 或 False。数据类型:bool | 否 |
|
|
96
|
+
|
|
97
|
+
### 2.2 比对函数方式
|
|
98
|
+
|
|
99
|
+
#### 2.2.1 compare_distributed 函数
|
|
100
|
+
|
|
101
|
+
此函数将 CPU 或 GPU 与 NPU 的 dump 文件进行比对,支持单卡和多卡,可同时比对多卡的 dump 数据。多机场景需要每个设备单独执行比对操作。可自动检索和匹配对应卡和进程所 dump 的数据文件,再调用 compare 进行比对。单机单卡时与 compare 函数二选一。
|
|
102
|
+
|
|
103
|
+
**函数原型**:
|
|
104
|
+
|
|
105
|
+
```Python
|
|
106
|
+
compare_distributed(npu_dump_dir, bench_dump_dir, output_path, **kwargs)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**参数说明**:
|
|
110
|
+
|
|
111
|
+
| 参数名 | 说明 | 是否必选 |
|
|
112
|
+
| -------------- | ------------------------------------------------------------ | -------- |
|
|
113
|
+
| npu_dump_dir | 配置 NPU 环境下的 dump 目录。str 类型。dump 数据目录须指定到 step 级。<br/>**配置示例**:'./npu_dump/step0'。 | 是 |
|
|
114
|
+
| bench_dump_dir | 配置 CPU、GPU 或 NPU 环境下的 dump 目录。str 类型。<br/>**配置示例**:'./gpu_dump/step0'。 | 是 |
|
|
115
|
+
| output_path | 配置比对结果文件存盘目录。需要预先创建 output_path 目录。str 类型。<br/>**配置示例**:'./output'。文件名称基于时间戳自动生成,格式为:`compare_result_rank{npu_ID}-rank{cpu/gpu/npu_ID}_{timestamp}.xlsx`。 | 是 |
|
|
116
|
+
| **kwargs | 支持 compare 的所有可选参数。 | 否 |
|
|
117
|
+
|
|
118
|
+
**函数示例**:
|
|
119
|
+
|
|
120
|
+
```Python
|
|
121
|
+
from msprobe.pytorch import *
|
|
122
|
+
compare_distributed('./npu_dump/step0', './gpu_dump/step0', './output')
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### 2.2.2 compare 函数
|
|
126
|
+
|
|
127
|
+
此函数将 CPU 或 GPU 与 NPU 的 dump 文件进行比对,仅支持单机单卡。
|
|
128
|
+
|
|
129
|
+
**函数原型**:
|
|
130
|
+
|
|
131
|
+
```Python
|
|
132
|
+
compare(input_param, output_path, stack_mode=False, auto_analyze=True, fuzzy_match=False)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**参数说明**:
|
|
136
|
+
|
|
137
|
+
| 参数名 | 说明 | 是否必选 |
|
|
138
|
+
| ------------ | ------------------------------------------------------------ | -------- |
|
|
139
|
+
| input_param | 配置 dump 数据文件及目录,dict 类型。配置参数包括:<br> "npu_json_path":指定 NPU dump 目录下的 dump.json 文件。<br/>**配置示例**:"npu_json_path": "./npu_dump/dump.json"。<br/> "bench_json_path":指定 CPU、GPU 或 NPU dump 目录下的 dump.json 文件。<br/>**配置示例**:"bench_json_path": "./bench_dump/dump.json"。<br/> "stack_json_path":指定 NPU dump 目录下的 stack.json 文件。<br/>**配置示例**:"stack_json_path": "./npu_dump/stack.json"。<br/> "is_print_compare_log":配置是否开启日志打屏。<br/>**配置示例**:True 或 False。 | 是 |
|
|
140
|
+
| output_path | 配置比对结果文件存盘目录,str 类型。<br/>**配置示例**:'./output'。文件名称基于时间戳自动生成,格式为:`compare_result_{timestamp}.xlsx`。 | 是 |
|
|
141
|
+
| stack_mode | 配置 stack_mode 的开关,bool 类型。仅当配置 stack_json_path 时需要开启。<br/>**配置示例**:stack_mode=True,默认为 False。 | 否 |
|
|
142
|
+
| auto_analyze | 自动精度分析,bool 类型。开启后工具自动针对比对结果进行分析,识别到第一个精度不达标节点(在比对结果文件中的 Accuracy Reached or Not 列显示为 No),并给出问题可能产生的原因(打屏展示并生成 advisor_{timestamp}.txt 文件)。<br/>**配置示例**:auto_analyze=False,默认为 True。 | 否 |
|
|
143
|
+
| fuzzy_match | 模糊匹配,bool 类型。开启后,对于网络中同一层级且命名仅调用次数不同的 API,可匹配并进行比对。<br/>**配置示例**:fuzzy_match=True,默认为 False。 | 否 |
|
|
144
|
+
|
|
145
|
+
**函数示例**:
|
|
146
|
+
|
|
147
|
+
单机单卡场景下创建比对脚本,例如 compare.py,拷贝如下代码,具体参数请根据实际环境修改。
|
|
148
|
+
|
|
149
|
+
```Python
|
|
150
|
+
from msprobe.pytorch import compare
|
|
151
|
+
input_param={
|
|
152
|
+
"npu_json_path": "./npu_dump/dump.json",
|
|
153
|
+
"bench_json_path": "./bench_dump/dump.json",
|
|
154
|
+
"stack_json_path": "./npu_dump/stack.json",
|
|
155
|
+
"is_print_compare_log": True
|
|
156
|
+
}
|
|
157
|
+
compare(input_param, output_path="./output", stack_mode=True)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### 2.2.3 统计量比对
|
|
161
|
+
|
|
162
|
+
在使用 **compare** 或 **compare_distributed** 函数创建的比对脚本且在 [config.json](../config.json) 文件中配置 `"task": "statistics"` 时,可以进行统计量比对,此时比对 dump.json 文件中的统计信息,开启后的比对结果生成 Max diff、Min diff、Mean diff 和 L2norm diff,表示 NPU dump 数据中 API 的输入或输出与标杆数据输入或输出的最大值、最小值、平均值以及 L2 范数的差。可以通过该值判断 API 是否存在精度问题:当某个 API 的输入和输出的 Max diff、Min diff、Mean diff 和 L2norm diff 均为 0 或无限趋于 0,那么可以判断该 API 无精度问题,反之则可能存在精度问题。
|
|
163
|
+
|
|
164
|
+
**比对脚本示例**:
|
|
165
|
+
|
|
166
|
+
以 compare.py 为例:
|
|
167
|
+
|
|
168
|
+
```Python
|
|
169
|
+
from msprobe.pytorch import compare
|
|
170
|
+
input_param={
|
|
171
|
+
"npu_json_path": "./npu_dump/dump.json",
|
|
172
|
+
"bench_json_path": "./bench_dump/dump.json",
|
|
173
|
+
"stack_json_path": "./npu_dump/stack.json",
|
|
174
|
+
"is_print_compare_log": True
|
|
175
|
+
}
|
|
176
|
+
compare(input_param, output_path="./output", stack_mode=True)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**统计量比对结果说明**:
|
|
180
|
+
|
|
181
|
+
数据量比对同样生成 `compare_result_{timestamp}.xlsx` 和 `advisor_{timestamp}.txt` 文件。其中 `advisor_{timestamp}.txt` 主要对 `compare_result_{timestamp}.xlsx` 中可能存在精度问题(Result 为 Waring)的 API 提出定位建议;`compare_result_{timestamp}.xlsx` 主要有如下两种情况:
|
|
182
|
+
|
|
183
|
+
- "summary_mode": "statistics" 时比对 dump.json 文件:
|
|
184
|
+
|
|
185
|
+

|
|
186
|
+
|
|
187
|
+
上图是对 dump.json 文件中 NPU 及标杆 API 的统计信息进行比对,判断可能存在精度问题的 API,文件中记录 NPU 及标杆 API 的基本信息和统计信息,其中需要关注 Result 列,包含结果:Waring(NPU 与标杆统计信息的比对中存在相对误差大于 0.5,则需要重点检查该 API);为空(相对误差小于等于 0.5,可以不需要重点关注,但不代表不存在精度问题);Nan(表示统计信息数据没有匹配上)。
|
|
188
|
+
|
|
189
|
+
- "summary_mode": "md5" 时比对 dump.json 文件:
|
|
190
|
+
|
|
191
|
+

|
|
192
|
+
|
|
193
|
+
上图是对 dump.json 文件中 NPU 及标杆 API 的 MD5 信息进行比对,判断 API 数据的完整性,文件中记录 NPU 及标杆 API 的基本信息和 MD5 信息,其中需要关注 Result 列,包含结果:Pass(表示 NPU 与标杆的 MD5 值一致,即 API 数据完整);Different(表示 NPU 与标杆的 MD5 值不一致,即 API 数据不完全一致,可以通过 NPU_Stack_Info 列 API 调用栈查询该 API 的详细信息);Nan(表示 MD5 信息数据没有匹配上)。
|
|
194
|
+
|
|
195
|
+
## 3 精度比对结果分析
|
|
196
|
+
|
|
197
|
+
PyTorch 精度比对是以 CPU 或 GPU 的计算结果为标杆,通过计算精度评价指标判断 API 在运行时是否存在精度问题。
|
|
198
|
+
|
|
199
|
+
- `advisor_{timestamp}.txt` 文件中给出了可能存在精度问题的 API 的专家建议,可直接打开查看。
|
|
200
|
+
|
|
201
|
+
- `compare_result_{timestamp}.xlsx` 文件列出了所有执行精度比对的 API 详细信息和比对结果,示例如下:
|
|
202
|
+
|
|
203
|
+

|
|
204
|
+
|
|
205
|
+
可以从该结果文件中进行[判断计算精度达标情况](#31-判断计算精度达标情况)、[计算精度评价指标分析](#32-计算精度评价指标分析)以及[异常信息识别](#33-异常信息识别)等分析动作。
|
|
206
|
+
|
|
207
|
+
### 3.1 判断计算精度达标情况
|
|
208
|
+
|
|
209
|
+
精度比对结果 `compare_result_{timestamp}.xlsx` 文件中只需要通过 Accuracy Reached or Not 来判断计算精度是否达标,判断标准如下:
|
|
210
|
+
|
|
211
|
+
1. Cosine < 0.99 且 MaxAbsError > 0.001 时,精度不达标,标记为 No。
|
|
212
|
+
2. Cosine < 0.9,精度不达标,标记为 No。
|
|
213
|
+
3. MaxAbsError > 1,精度不达标,标记为 No。
|
|
214
|
+
4. 其余情况下记为精度达标,标记为 Yes。
|
|
215
|
+
|
|
216
|
+
### 3.2 计算精度评价指标分析
|
|
217
|
+
|
|
218
|
+
1. Cosine:通过计算两个向量的余弦值来判断其相似度,数值越接近于 1 说明计算出的两个张量越相似,实际可接受阈值为大于 0.99。在计算中可能会存在 nan,主要由于可能会出现其中一个向量为 0。
|
|
219
|
+
|
|
220
|
+
2. MaxAbsErr:当最大绝对误差越接近 0 表示其计算的误差越小,实际可接受阈值为小于 0.001。
|
|
221
|
+
|
|
222
|
+
3. MaxRelativeErr:当最大相对误差越接近 0 表示其计算的误差越小。
|
|
223
|
+
|
|
224
|
+
当 dump 数据中存在 0 或 Nan 时,比对结果中最大相对误差则出现 inf 或 Nan 的情况,属于正常现象。
|
|
225
|
+
|
|
226
|
+
4. One Thousandth Err Ratio(双千分之一)、Five Thousandths Err Ratio(双千分之五)精度指标:是指 NPU 的 Tensor 中的元素逐个与对应的标杆数据对比,相对误差大于千分之一、千分之五的比例占总元素个数的比例小于千分之一、千分之五。该数据仅作为精度下降趋势的参考,并不参与计算精度是否通过的判定。
|
|
227
|
+
|
|
228
|
+
### 3.3 异常信息识别
|
|
229
|
+
|
|
230
|
+
精度比对结果 `compare_result_{timestamp}.xlsx` 文件中对于存在异常信息的API会进行高亮处理:
|
|
231
|
+
|
|
232
|
+
- 红色可能出现的情况有:
|
|
233
|
+
- NPU max 或 NPU min 信息中存在 nan/inf;
|
|
234
|
+
- Max diff存在大于1e+10的值;
|
|
235
|
+
- 统计数据中output的Max diff除以max(0.01, Bench max) > 0.5;
|
|
236
|
+
- 真实数据中One Thousandth Err Ratio的input > 0.9同时output < 0.6。
|
|
237
|
+
- 黄色可能出现的情况有:
|
|
238
|
+
- Max diff的input与output都大于1,同时output比input大一个数量级以上;
|
|
239
|
+
- 统计数据Max diff除以max(0.01, Bench max)的output > 0.1同时input < 0.01;
|
|
240
|
+
- 真实数据One Thousandth Err Ratio的input - output > 0.1;
|
|
241
|
+
- 真实数据Cosine的input - output > 0.1。
|
|
242
|
+
|
|
243
|
+
Shape为 [ ] 时,统计量列说明:
|
|
244
|
+
|
|
245
|
+
当 NPU Tensor Shape 列为 [ ] 时,表示标量或 0 维张量,统计量列(NPU max、NPU min、NPU mean、NPU l2norm)展示相同的唯一元素。Bench 同理。
|