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,164 @@
|
|
|
1
|
+
# PyTorch 场景的无标杆比对
|
|
2
|
+
|
|
3
|
+
## 1 简介
|
|
4
|
+
* 本工具的目标是在不依赖标杆数据的情况下、检测模型训练中可能存在的精度问题API级别算子,并提供升精度和tocpu接口快速验证;
|
|
5
|
+
* 工具基于**数值病态分析理论**:对算子的输入增加很小的扰动、从而放大输出值异常现象;检测算子原始输出和扰动后输出间误差是否符合精度标准;
|
|
6
|
+
|
|
7
|
+
* 该工具的**特点**有:
|
|
8
|
+
* 不依赖标杆模型、不需要离线对比
|
|
9
|
+
* 提供接口,对可疑算子升精度、tocpu进行快速验证
|
|
10
|
+
* 推荐使用场景(针对**算子精度问题**):
|
|
11
|
+
* **暂无标杆数据**,模型Loss异常,要做精度问题算子排查
|
|
12
|
+
* **验证可疑算子**,要做进一步确认、验证是否对模型Loss有影响
|
|
13
|
+
* 低精度模型效果不如高精度,要做精度问题算子排查
|
|
14
|
+
* 该工具的约束
|
|
15
|
+
* 仅支持Pytorch2.x场景
|
|
16
|
+
* 推荐限定算子范围使用(白名单、或脚本中工具启用范围)、算子范围越大、性能和显存损耗越大;详情见[无标杆工具场景验证和性能基线报告(待补充)](./S02.report_free_benchmarking_validation_performance_baseline.md)
|
|
17
|
+
|
|
18
|
+
## 2 工具实现原理
|
|
19
|
+
1. **扰动算子白名单**:根据算子名识别需要插桩算子范围
|
|
20
|
+
2. **扰动因子**:基于torch.nn.Module的hook机制、在注册的hook函数中对算子输入进行特定类型扰动
|
|
21
|
+
3. **误差分析**:
|
|
22
|
+
* **check**: 在hook函数中二次执行算子得到扰动后的算子输出、计算扰动后输出与原始输出的相对误差,查看是否符合精度标准
|
|
23
|
+
* **fix**: 需要做验证时、可以选择将特定扰动类型(升精度、to cpu)的输出替换原始输出、观察对模型Loss是否有影响
|
|
24
|
+
4. **精度风险算子**:不达标精度标准的,最终会在输出件中展示
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## 3 操作指导
|
|
30
|
+
|
|
31
|
+
```mermaid
|
|
32
|
+
flowchart LR
|
|
33
|
+
A0[安装msprobe工具]
|
|
34
|
+
subgraph config.json配置
|
|
35
|
+
A1[确定插桩范围]
|
|
36
|
+
A2[选择扰动因子]
|
|
37
|
+
A3[选择处理方式]
|
|
38
|
+
A1-->A2
|
|
39
|
+
A2-->A3
|
|
40
|
+
end
|
|
41
|
+
B(在模型脚本中开启工具)
|
|
42
|
+
C(启动模型训练)
|
|
43
|
+
D(查看精度风险算子\n观察模型loss曲线)
|
|
44
|
+
|
|
45
|
+
A0-->
|
|
46
|
+
config.json配置-->B
|
|
47
|
+
B-->C
|
|
48
|
+
C-->D
|
|
49
|
+
D-->config.json配置
|
|
50
|
+
```
|
|
51
|
+
工具的推荐使用思路是:
|
|
52
|
+
|
|
53
|
+
1. 配置config.json开启精度风险算子的排查
|
|
54
|
+
2. 根据精度风险算子输出件、修改config.json开启验证功能、观察模型loss曲线是否改善
|
|
55
|
+
|
|
56
|
+
### 3.1 安装msprobe工具
|
|
57
|
+
参照[msprobe安装](./docs/01.installation.md)
|
|
58
|
+
### 3.2 config.json配置
|
|
59
|
+
修改[config.json](../config.json) 的task类型为"**free_benchmark**"开启无标杆功能。支持的配置项详见[配置文件介绍](./02.config_introduction.md),默认配置如下:
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"task": "free_benchmark",
|
|
63
|
+
"dump_path": "./dump_path",
|
|
64
|
+
"rank": [],
|
|
65
|
+
"step": [],
|
|
66
|
+
"level": "L1",
|
|
67
|
+
"seed": 1234,
|
|
68
|
+
"is_deterministic": false,
|
|
69
|
+
|
|
70
|
+
"free_benchmark": {
|
|
71
|
+
"scope": [],
|
|
72
|
+
"list": [],
|
|
73
|
+
"fuzz_device": "npu",
|
|
74
|
+
"pert_mode": "improve_precision",
|
|
75
|
+
"handler_type": "check",
|
|
76
|
+
"fuzz_level": "L1",
|
|
77
|
+
"fuzz_stage": "forward",
|
|
78
|
+
"if_preheat": false,
|
|
79
|
+
"preheat_step": 15,
|
|
80
|
+
"max_sample": 20
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
用户需根据自己的使用场景、对<a herf="2 工具实现原理">工具实现原理</a>中几个关键步骤进行配置
|
|
85
|
+
#### 3.2.1 扰动算子白名单(确定插桩范围):
|
|
86
|
+
|
|
87
|
+
| 相关参数名 | 是否必选 | 可配置项 | 适用场景 |
|
|
88
|
+
| ---------- | -------- | ----------------- | ------------------------------------------------------------------------------------------- |
|
|
89
|
+
| scope | 可选 | | 需要通过指定算子名来限制算子插桩范围 如:["Torch.matmul.0.forward", "Tensor.pow.4.forward"] |
|
|
90
|
+
| list | 可选 | | 需要通过指定算子类型来限制算子插桩范围 如:\["relu"\] 会匹配所有算子名中包含relu的算子 |
|
|
91
|
+
| fuzz_stage | 可选 | "forward"(默认) | 需要进行算子**前向**计算的精度问题排查或**验证可疑算子** |
|
|
92
|
+
| | | "backward" | 需要进行算子**反向**计算的精度问题排查,不支持仅反向验证,前向验证包括反向 |
|
|
93
|
+
|
|
94
|
+
#### 3.2.2. 选择扰动因子:
|
|
95
|
+
|
|
96
|
+
| 相关参数 | 是否必选 | 可配置项 | 适用场景 |
|
|
97
|
+
| ----------- | -------- | ---------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
98
|
+
| pert_mode | 可选 | "improve_precision" (默认) | (常用)(可做验证) 插桩算子可能在**低精度**下有精度问题,扰动因子会将输入的低精度向量升精度 |
|
|
99
|
+
| | | "bit_noise" | (常用)插桩算子可能在**轻微扰动**下暴露精度问题,扰动因子会将输入向量最后一个比特位翻转 |
|
|
100
|
+
| | | "add_noise" | 插桩算子可能在**轻微扰动**下暴露精度问题,扰动因子会为输入向量增加一个极小值 |
|
|
101
|
+
| | | "change_value" | 插桩算子可能存在**大数吃小数**问题,扰动因子会交换输入向量的首尾值 |
|
|
102
|
+
| | | "no_change" | 插桩算子可能存在**数值稳定性**精度问题,扰动因子会复制原始输入 |
|
|
103
|
+
| | | "to_cpu" | (可做验证) 插桩算子可能在**同cpu**精度表现不一致,扰动因子会将输入转至cpu,需要配合fuzz_device="cpu"使用 |
|
|
104
|
+
| fuzz_device | 可选 | "npu" (默认) | 扰动因子不需要to cpu操作 |
|
|
105
|
+
| | | "cpu" | 扰动因子需要to cpu操作,目前仅"to cpu"扰动因子 |
|
|
106
|
+
|
|
107
|
+
#### 3.2.3. 选择处理方式:
|
|
108
|
+
| 相关参数名 | 是否必选 | 可配置项 | 适用场景 |
|
|
109
|
+
| ------------ | -------- | ----------------- | ----------------------------------------------------------------------------------------- |
|
|
110
|
+
| handler_type | 可选 | "check" (默认) | 要做精度问题算子排查,输出扰动前后不符合精度标准的算子,支持所有扰动因子 |
|
|
111
|
+
| | | "fix" | 要做可疑算子验证,用扰动后输出替换原始输出,支持"improve_precision"、"to_cpu"两种扰动因子 |
|
|
112
|
+
|
|
113
|
+
### 3.3 在模型脚本中开启工具
|
|
114
|
+
|
|
115
|
+
通过PrecisionDebugger统一入口开启工具,示例如下:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from msprobe.pytorch import PrecisionDebugger
|
|
119
|
+
|
|
120
|
+
debugger = PrecisionDebugger(config_path='./config.json')
|
|
121
|
+
...
|
|
122
|
+
debugger.start() # 一般在训练循环开头启动工具
|
|
123
|
+
... # 循环体
|
|
124
|
+
debugger.stop() # 一般在训练循环末尾结束工具
|
|
125
|
+
debugger.step() # 在训练循环的最后需要重置工具,非循环场景不需要
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 3.4 启动模型训练
|
|
129
|
+
训练过程中出现可以通过一下日志检查工具是否正常使用
|
|
130
|
+
| 日志级别 | 日志内容 | 检查说明 |
|
|
131
|
+
| -------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
132
|
+
| INFO | \[msprobe\] Free Benchmark: Perturbation is {扰动因子} of {算子名}. | 扰动因子与配置相符、算子名在插桩范围内 |
|
|
133
|
+
| INFO | \[msprobe\] Free Benchmark: For {算子名},{原因}. Cancel perturbation. | 算子名在插桩范围内,但当前算子由于{原因}不支持添加扰动 |
|
|
134
|
+
| INFO | \[msprobe\] Free benchmark: preheat sample in step {step} api_name {算子名} curr_called_seq: {当前采样数}/{总采样数}" | 仅开启预热、算子名在插桩范围内,在当前step的采样情况 |
|
|
135
|
+
| WARNING | \[msprobe\] Free benchmark: 无标杆工具不支持当前算子的输入类型 {算子名}. | 算子名在插桩范围内,但当前算子没有可操作的输入(不存在Tensor、list类型等) |
|
|
136
|
+
|
|
137
|
+
其余日志均说明当前算子未能正常添加扰动、请检查日志信息判断是否更换扰动因子或不考虑当前算子结果。
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
### 3.5 查看精度风险算子
|
|
141
|
+
|
|
142
|
+
check模式下,无标杆比对在dump_path目录下将扰动前后不符合精度标准的结果输出在文件 free_benchmark.csv,如下示例:
|
|
143
|
+
|
|
144
|
+

|
|
145
|
+
|
|
146
|
+
| 字段 | 说明 |
|
|
147
|
+
| ------------ | ---------------------------------------------------------------------------------------- |
|
|
148
|
+
| rank | Rank ID,int 类型。 |
|
|
149
|
+
| pert_mode | 扰动因子的类型,string 类型。 |
|
|
150
|
+
| stage | 前向或反向,string 类型。 |
|
|
151
|
+
| step | 迭代数,int 类型。 |
|
|
152
|
+
| api_name | API 名称,string 类型。 |
|
|
153
|
+
| max_rel | 输出对比最大相对误差,float 类型。 |
|
|
154
|
+
| dtype | 输入的 dtype,string 类型。 |
|
|
155
|
+
| shape | 输入的 shape,tuple 类型。 |
|
|
156
|
+
| output_index | 如果输出为列表或元组,其中一个元素检测不一致,则会有该元素的 index,否则为空,int 类型。 |
|
|
157
|
+
|
|
158
|
+
无标杆根据参照的精度标准如下:
|
|
159
|
+
| 输出dtype | 相对误差阈值 |
|
|
160
|
+
| -------------- | ------------ |
|
|
161
|
+
| torch.float16 | 0.002 |
|
|
162
|
+
| torch.bfloat16 | 0.004 |
|
|
163
|
+
| torch.float32 | 0.0002 |
|
|
164
|
+
| 其他 | 0.0002 |
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Ascend模型梯度状态监测工具
|
|
2
|
+
|
|
3
|
+
梯度状态监测工具提供了两种能力:
|
|
4
|
+
|
|
5
|
+
- 将模型权重的梯度数据导出。这种功能可以将模型权重的梯度值以统计量的形式采集出来,用以分析问题。
|
|
6
|
+
- 将两份梯度数据进行相似度对比。在有标杆问题中,可以确认训练过程中精度问题出现的step,以及抓取反向过程中的问题。
|
|
7
|
+
|
|
8
|
+
工具支持PyTorch版本:2.0/2.1/2.2;支持MindSpore版本:r2.3。
|
|
9
|
+
|
|
10
|
+
## 工具特性
|
|
11
|
+
|
|
12
|
+
- 使用便捷,无需在训练流程里插入代码
|
|
13
|
+
- 可以精准定位问题出现的step
|
|
14
|
+
|
|
15
|
+
## 使用方式
|
|
16
|
+
|
|
17
|
+
### 梯度数据导出
|
|
18
|
+
|
|
19
|
+
1. 创建配置文件config.json,样例如下:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"task": "grad_probe",
|
|
24
|
+
"dump_path": "./dump_path",
|
|
25
|
+
"rank": [],
|
|
26
|
+
"step": [],
|
|
27
|
+
"grad_probe": {
|
|
28
|
+
"grad_level": "L1",
|
|
29
|
+
"param_list": [],
|
|
30
|
+
"bounds": [-1, 0, 1]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
> step指的是优化器被调用的次数(并非模型跑的step,某些step,例如loss为nan时,不会调用优化器)
|
|
35
|
+
|
|
36
|
+
**参数说明**
|
|
37
|
+
|
|
38
|
+
| 参数 | 说明 | 输入类型 | 是否必选 |
|
|
39
|
+
|--------------------------------|-----------------------------------|-----------------|----------|
|
|
40
|
+
| task | 填为"grad_probe"。 | str | 是 |
|
|
41
|
+
| dump_path | 输出目录。如果不存在就会创建一个新目录。 | str | 是 |
|
|
42
|
+
| rank | rank id列表,在多卡场景下,表示需要导出梯度数据的进程的rank id。列表为空就表示导出所有rank的数据。默认为空。(MindSpore静态图模式下,当前暂不支持指定rank功能) | List[int] | 否 |
|
|
43
|
+
| step | step列表,表示需要导出数据的step列表。列表为空就表示导出所有step的数据。默认为空。(MindSpore静态图模式下,当前暂不支持指定step功能) | List[int] | 否 |
|
|
44
|
+
| grad_level | 输出级别。决定导出数据的详细程度,级别越大导出数据越详细。可取值:L0, L1, L2。默认L1。|str | 否 |
|
|
45
|
+
| param_list | 权重名称列表,表示需要监控的权重。列表为空就表示监控所有权重。默认为空。 | List[str] | 否 |
|
|
46
|
+
| bounds | 区间列表,用来划分区间以统计数值的分布。需要保证由数据小到大排列。可以使用默认值[-1, 0, 1]。 | List[float, int] | 否 |
|
|
47
|
+
|
|
48
|
+
**不同级别的level的导出数据**
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
| 级别 | 特征数据表头 | 是否有方向数据 |
|
|
52
|
+
| ---- | ------------------------------------------------------------ | -------------- |
|
|
53
|
+
| L0 | ("param_name", "MD5", "max", "min", "norm", "shape") | 否 |
|
|
54
|
+
| L1 | ("param_name", "max", "min", "norm", "shape") | 是 |
|
|
55
|
+
| L2 | ("param_name", *intervals, "=0", "max", "min", "norm", "shape") | 是 |
|
|
56
|
+
|
|
57
|
+
intervals就是根据值分布bounds划分出的区间。
|
|
58
|
+
MindSpore静态图模式下,L0级别中暂不支持"MD5"
|
|
59
|
+
|
|
60
|
+
**方向数据解释**
|
|
61
|
+
|
|
62
|
+
因为模型的参数往往非常大,所以存储真实数据是不可接受的,这里折衷一下,只存储梯度数据的正负号(一个布尔值),也就是方向。
|
|
63
|
+
|
|
64
|
+
**bounds和值分布解释**
|
|
65
|
+
|
|
66
|
+
+ 值分布:梯度数据落在各个区间的元素个数占总元素个数的比例。
|
|
67
|
+
+ bounds:一个列表,用来划分出区间以统计值分布。例如传入bounds = [-10, 0, 10],此时有一个 grad_value: Tensor = [9.3 , 5.4, -1.0, -12.3],依据 bounds 划分出 (-inf, -10]、(-10, 0]、(0, 10]、(10, inf) 四个区间,然后统计grad_value里的数据落在每个区间内的个数,得到 1、1、2、0。如下图所示:
|
|
68
|
+

|
|
69
|
+
|
|
70
|
+
2. 插入代码。示例代码如下:
|
|
71
|
+
|
|
72
|
+
- PyTorch框架:模型构造完成后,传入config.json的路径实例化一个GradientMonitor对象,然后调用gm.monitor并将`模型`作为参数传入。
|
|
73
|
+
```python
|
|
74
|
+
from msprobe.pytorch import PrecisionDebugger
|
|
75
|
+
debugger = PrecisionDebugger("config_json_path")
|
|
76
|
+
debugger.monitor(model)
|
|
77
|
+
```
|
|
78
|
+
- MindSpore框架:优化器构造完成后,传入config.json的路径实例化一个GradientMonitor对象,然后调用gm.monitor并将`优化器`作为参数传入。
|
|
79
|
+
```python
|
|
80
|
+
from msprobe.mindspore import PrecisionDebugger
|
|
81
|
+
debugger = PrecisionDebugger("config_json_path")
|
|
82
|
+
debugger.monitor(optimizer)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
3. 结束监控(MindSpore静态图模式下需要)
|
|
86
|
+
|
|
87
|
+
在训练结束之后,调用stop接口
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
debugger.stop()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 输出结果
|
|
94
|
+
**输出目录结构**(以level配置L2为例)
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
{dump_path}
|
|
98
|
+
├── rank{rank_id}
|
|
99
|
+
│ ├── grad_summary_{step}.csv
|
|
100
|
+
│ ├── step{step}
|
|
101
|
+
│ │ ├── {param_name}.npy
|
|
102
|
+
```
|
|
103
|
+
+ {timestamp}:梯度工具导出数据的时候会在output_path下生成一个时间戳目录,然后在这个时间戳目录下输出结果。
|
|
104
|
+
+ rank_{rank_id}:在分布式场景下,会记录卡的rank_id。非分布式场景下,如果是CPU则记录进程号,如果是CPU或GPU则记录卡号
|
|
105
|
+
+ grad_summary_{step}.csv:会分step记录每一步的梯度数据统计值。
|
|
106
|
+
+ step_{step}:这个目录下会存放该step的梯度的方向数据。
|
|
107
|
+
+ {param_name}.pt(npy):模型参数的梯度方向数据,PyTorch保存的是pt文件,MindSpore是npy文件。
|
|
108
|
+
|
|
109
|
+
**grad_summary_{step}.csv**
|
|
110
|
+
|
|
111
|
+
样例如下:
|
|
112
|
+
|
|
113
|
+

|
|
114
|
+
|
|
115
|
+
| 字段 | 含义 |
|
|
116
|
+
| --------------------- | ------------------------------------------------------------|
|
|
117
|
+
| Param_name | 模型参数名称。 |
|
|
118
|
+
| MD5 | 梯度数据的MD5值。 |
|
|
119
|
+
| (-inf, -0.01]...[0.01, inf) | 梯度值落在区间内的元素个数占总元素的比例。 |
|
|
120
|
+
| =0 | 梯度为0的元素个数占总元素的比例。 |
|
|
121
|
+
| Max | 最大值。 |
|
|
122
|
+
| Min | 最小值。 |
|
|
123
|
+
| Norm | L2norm值。 |
|
|
124
|
+
| Shape | 形状。 |
|
|
125
|
+
|
|
126
|
+
### 梯度相似度比对
|
|
127
|
+
|
|
128
|
+
会根据所导出的权重,分step比对梯度相似度,输出每个权重的梯度相似度和总的梯度相似度。单个权重的梯度相似度为两份方向数据的重合度,总的梯度相似度为每个权重的梯度相似度按元素个数加权。
|
|
129
|
+
|
|
130
|
+
#### 前提条件
|
|
131
|
+
|
|
132
|
+
- 相同配置下,以Level为L1或L2分别采集npu和gpu环境下的梯度数据。
|
|
133
|
+
- 将两份梯度数据传到同一环境下。
|
|
134
|
+
|
|
135
|
+
#### 使用方式
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
新建如下Python脚本,传入npu和gpu的dump_path以及输出目录,比对结果输出目录不存在的话会新建:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from msprobe import *
|
|
142
|
+
GradComparator.compare_distributed("配置文件里写的dump_path",
|
|
143
|
+
"配置文件里写的dump_path",
|
|
144
|
+
"比对结果输出目录")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### 比对结果
|
|
149
|
+
|
|
150
|
+
**输出目录结构**
|
|
151
|
+
|
|
152
|
+
如下为多卡比对结果,单卡则没有rank_{rank_id}这一级目录。
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
比对结果输出目录
|
|
156
|
+
├── rank{rank_id}
|
|
157
|
+
│ ├── similarities.csv
|
|
158
|
+
│ └── similarities_picture
|
|
159
|
+
│ ├── {param_name}.png
|
|
160
|
+
│ └── summary_similarities.png
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**问题界定**
|
|
164
|
+
|
|
165
|
+
原则:对于任意权重,第0步的梯度相似度低于0.97,或者某一步的梯度相似度下降超过0.03,认为这一步存在精度问题。例子如下:
|
|
166
|
+
|
|
167
|
+
- 第0步相似度低于0.97
|
|
168
|
+
|
|
169
|
+

|
|
170
|
+
|
|
171
|
+
- 第3步相似度下降超过0.03
|
|
172
|
+
|
|
173
|
+

|
|
174
|
+
|
|
175
|
+
- 正常情况
|
|
176
|
+
|
|
177
|
+

|
|
178
|
+
|
|
179
|
+
这个原则是一个经验性的指标,并不是严格的标注,还需要结合实际情况具体分析。
|
|
180
|
+
|
|
181
|
+
## 公开接口
|
|
182
|
+
|
|
183
|
+
**接口说明**
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
PrecisionDebugger.monitor(module)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
| 参数 | 说明 | 是否必选 |
|
|
190
|
+
| ----- | -------------------- | -------- |
|
|
191
|
+
| module |Pytorch框架下传入模型,必须是torch.nn.Module;MindSpore框架下传入优化器。 | 是 |
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
**接口说明**
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
GradComparator.compare_distributed(dump_path1, dump_path2, output_path)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
| 参数 | 说明 | 数据类型 | 是否必选 |
|
|
201
|
+
| ----- | -------------------- | -------- | ----- |
|
|
202
|
+
| dump_path1 |需要比对的其中一个dump目录,也就是配置文件里写的dump_path。 | str | 是 |
|
|
203
|
+
| dump_path2 |需要比对的其中一个dump目录,也就是配置文件里写的dump_path,与dump_path1可以互换。 | str | 是 |
|
|
204
|
+
| output_path |输出结果目录,不存在会新建。 | str | 是 |
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
# FAQ
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# 1 精度预检工具
|
|
2
|
+
|
|
3
|
+
1. 预检工具在 dump 和 run_ut 的过程中,是否需要同时开启或关闭 jit 编译(jit_compile)?
|
|
4
|
+
|
|
5
|
+
答:是。
|
|
6
|
+
|
|
7
|
+
2. 预检工具对于 type_as 这类涉及数据类型转换操作的 API,是否具有参考性?
|
|
8
|
+
|
|
9
|
+
由于这类 API 在 CPU 侧存在精度先提升后下降的操作,因此这类 API 的有效性的参考价值有限。
|
|
10
|
+
|
|
11
|
+
3. run ut 过程中出现报错:ERROR: Got unsupported ScalarType BFloat16。
|
|
12
|
+
|
|
13
|
+
答:请使用最新版本的工具。
|
|
14
|
+
|
|
15
|
+
4. Dropout 算子,CPU 和 NPU 的随机应该不一样,为什么结果比对是一致的?
|
|
16
|
+
|
|
17
|
+
答:这个结果是正常的,工具对该算子有特殊处理,只判定位置为 0 的位置比例大约和设定 p 值相当。
|
|
18
|
+
|
|
19
|
+
5. 为什么浮点型数据 bench 和 CPU 的 dtype 不一致?
|
|
20
|
+
|
|
21
|
+
答:对于 fp16 的数据,CPU 会上升一个精度 fp32 去计算,这是和算子那边对齐的精度结论,CPU 用更高精度去计算会更接近真实值。
|
|
22
|
+
|
|
23
|
+
6. 添加预检工具后截取操作报错:`IndexError: too many indices for tensor of dimension x` 或 `TypeError: len() of a 0-d tensor`。
|
|
24
|
+
|
|
25
|
+
答:注释工具目录 `mstt/debug/accuracy_tools/msprobe/pytorch/hook_module/support_wrap_ops.yaml` 文件中 Tensor: 下的 `- __getitem__`,工具会跳过采集该 API。如果是需要 dump 关键位置 API 也可以考虑根据报错堆栈信息注释引发报错的类型检查。
|
|
26
|
+
|
|
27
|
+
7. Tensor 魔法函数具体对应什么操作?
|
|
28
|
+
|
|
29
|
+
答:
|
|
30
|
+
|
|
31
|
+
| Tensor魔法函数 | 具体操作 |
|
|
32
|
+
| --------------- | ---------------- |
|
|
33
|
+
| `__add__` | + |
|
|
34
|
+
| `__and__` | & |
|
|
35
|
+
| `__bool__` | 返回 Tensor 布尔值 |
|
|
36
|
+
| `__div__` | / |
|
|
37
|
+
| `__eq__` | == |
|
|
38
|
+
| `__ge__` | >= |
|
|
39
|
+
| `__gt__` | > |
|
|
40
|
+
| `__iadd__` | += |
|
|
41
|
+
| `__iand__` | &= |
|
|
42
|
+
| `__idiv__` | /= |
|
|
43
|
+
| `__ifloordiv__` | //= |
|
|
44
|
+
| `__ilshift__` | <<= |
|
|
45
|
+
| `__imod__` | %= |
|
|
46
|
+
| `__imul__` | *= |
|
|
47
|
+
| `__ior__` | \|= |
|
|
48
|
+
| `__irshift__` | >>= |
|
|
49
|
+
| `__isub__` | -= |
|
|
50
|
+
| `__ixor__` | ^= |
|
|
51
|
+
| `__lshift__` | << |
|
|
52
|
+
| `__matmul__` | 矩阵乘法 |
|
|
53
|
+
| `__mod__` | % |
|
|
54
|
+
| `__mul__` | * |
|
|
55
|
+
| `__nonzero__` | 同`__bool__` |
|
|
56
|
+
| `__or__` | \| |
|
|
57
|
+
| `__radd__` | +(反向) |
|
|
58
|
+
| `__rmul__` | *(反向) |
|
|
59
|
+
| `__rshift__` | >> |
|
|
60
|
+
| `__sub__` | - |
|
|
61
|
+
| `__truediv__` | 同`__div__` |
|
|
62
|
+
| `__xor__` | ^ |
|
|
63
|
+
|
|
64
|
+
# 2 精度比对工具
|
|
65
|
+
|
|
66
|
+
## 2.1 工具使用
|
|
67
|
+
|
|
68
|
+
### 2.1.1 dump 指定融合算子
|
|
69
|
+
|
|
70
|
+
数据采集当前支持融合算子的输入输出,需要在 `mstt/debug/accuracy_tools/msprobe/pytorch/hook_module/support_wrap_ops.yaml` 中添加,比如以下代码段调用的 softmax 融合算子。
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
def npu_forward_fused_softmax(self, input_, mask):
|
|
74
|
+
resl = torch_npu.npu_scaled_masked_softmax(input_, mask, self.scale, False)
|
|
75
|
+
return resl
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
如果需要 dump 其中调用的 npu_scaled_masked_softmax 算子的输入输出信息,需要在 `support_wrap_ops.yaml` 中的 `torch_npu: ` 中自行添加该融合算子:
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
- npu_scaled_masked_softmax
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
(npu_scaled_masked_softmax 融合算子工具已支持 dump,本例仅供参考)。
|
|
85
|
+
|
|
86
|
+
## 2.2 常见问题
|
|
87
|
+
|
|
88
|
+
1. 在同一个目录多次执行 dump 会冲突吗?
|
|
89
|
+
|
|
90
|
+
答:会,同一个目录多次 dump,会覆盖上一次结果,可以使用 dump_path 参数修改 dump 目录。
|
|
91
|
+
|
|
92
|
+
2. 如何 dump 算子级的数据?
|
|
93
|
+
|
|
94
|
+
答:需要配置 level 为 L2 模式。
|
|
95
|
+
|
|
96
|
+
3. 工具比对发现 NPU 和标杆数据的 API 无法完全对齐?
|
|
97
|
+
|
|
98
|
+
答:torch 版本和硬件差异属于正常情况。
|
|
99
|
+
|
|
100
|
+
## 2.3 异常情况
|
|
101
|
+
|
|
102
|
+
1. HCCL 报错: error code: EI0006。
|
|
103
|
+
|
|
104
|
+
**故障现象**:使用 msprobe 工具时,报错:error code: EI0006。
|
|
105
|
+
|
|
106
|
+
**故障原因**:CANN 软件版本较低导致不兼容。
|
|
107
|
+
|
|
108
|
+
**故障处理**:升级新版 CANN 软件版本。
|
|
109
|
+
|
|
110
|
+
2. torch_npu._C._clear_overflow_npu() RuntimeError NPU error,error code is 107002。
|
|
111
|
+
|
|
112
|
+
如果运行溢出检测功能遇到这个报错,采取以下解决方法:
|
|
113
|
+
|
|
114
|
+
如果是单卡运行,添加如下代码,0 是卡号,选择自己空闲的卡号。
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
torch.npu.set_device('npu:0')
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
如果多卡运行,请在代码中修改对应卡号,比如进程使用卡号为 {rank} 时可以添加如下代码:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
torch.npu.set_device(f'npu:{rank}')
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
如果运行精度比对功能遇到这个报错,尝试安装最新版本的 msprobe。
|
|
127
|
+
|
|
128
|
+
3. dump 得到的 `VF_lstm_99_forward_input.1.0.npy`、`VF_lstm_99_forward_input.1.1.npy` 类似的数据是否正常?
|
|
129
|
+
|
|
130
|
+
带 1.0/1.1/1.2 后缀的 npy 是正常现象,例如,当输入数据为 [[tensor1, tensor2, tensor3]] 会生成这样的后缀。
|
|
131
|
+
|
|
132
|
+
4. 进行 compare 报错:The current file contains stack information, please turn on the stack_mode。
|
|
133
|
+
|
|
134
|
+
在比对脚本中,设置 `stack_mode=True`,例如:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from msprobe.pytorch import compare
|
|
138
|
+
dump_result_param={
|
|
139
|
+
"npu_json_path": "./npu_dump/dump.json",
|
|
140
|
+
"bench_json_path": "./gpu_dump/dump.json",
|
|
141
|
+
"stack_json_path": "./npu_dump/stack.json",
|
|
142
|
+
"is_print_compare_log": True
|
|
143
|
+
}
|
|
144
|
+
compare(dump_result_param, output_path="./output", stack_mode=True)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
5. dump 指定反向 API 的 kernel 级别的数据报错:NameError:name 'torch_npu' is not defined。
|
|
148
|
+
|
|
149
|
+
答:如果是 npu 环境,请安装 torch_npu;如果是 gpu 环境,暂不支持 dump 指定 API 的 kernel 级别的数据。
|
|
150
|
+
|
|
151
|
+
6. 配置 dump_path 后,使用工具报错:[ERROR] The file path /home/xxx/dump contains special characters。
|
|
152
|
+
|
|
153
|
+
答:请检查你设置的 dump 绝对路径是否包含特殊字符,确保路径名只包含大小写字母、数字、下划线、斜杠、点和短横线;注意,如果执行脚本的路径为 /home/abc++/,设置的 dump_path="./dump",工具实际校验的路径为绝对路径 /home/abc++/dump,++ 为特殊字符,会引发本条报错。
|
|
154
|
+
|
|
155
|
+
7. 无法 dump matmul 权重的反向梯度数据。
|
|
156
|
+
|
|
157
|
+
答:matmul 期望的输入是二维,当输入不是二维时,会将输入通过 view 操作展成二维,再进行 matmul 运算,因此在反向求导时,backward_hook 能拿到的是 UnsafeViewBackward 这步操作里面数据的梯度信息,取不到 MmBackward 这步操作里面数据的梯度信息,即权重的反向梯度数据。典型的例子有,当 linear 的输入不是二维,且无 bias 时,会调用 output = input.matmul(weight.t()),因此拿不到 linear 层的 weight 的反向梯度数据。
|
|
158
|
+
|
|
159
|
+
8. dump.json 文件中的某些 api 的 dtype 类型为 float16,但是读取此 api 的 npy 文件显示的 dtype 类型为 float32。
|
|
160
|
+
|
|
161
|
+
答:msprobe 工具在 dump 数据时需要将原始数据从 npu to cpu 上再转换为 numpy 类型,npu to cpu 的逻辑和 gpu to cpu 是保持一致的,都存在 dtype 可能从 float16 变为 float32 类型的情况,如果出现 dtype 不一致的问题,最终采集数据的 dtype 以 pkl 文件为准。
|
|
162
|
+
|
|
163
|
+
9. 使用 dataloader 后 raise 异常 Exception("msprobe: exit after iteration {}". format(max(self.config.step)))。
|
|
164
|
+
|
|
165
|
+
答:正常现象,dataloader 通过 raise 结束程序,堆栈信息可忽略。
|
|
166
|
+
|
|
167
|
+
10. 添加 msprobe 工具后截取操作报错:`IndexError: too many indices for tensor of dimension x` 或 `TypeError: len() of a 0-d tensor`。
|
|
168
|
+
|
|
169
|
+
答:注释工具目录 `mstt/debug/accuracy_tools/msprobe/pytorch/hook_module/support_wrap_ops.yaml` 文件中 `Tensor: ` 下的 `- __getitem__`,工具会跳过采集该 API。如果是需要采集关键位置 API 也可以考虑根据报错堆栈信息注释引发报错的类型检查。
|
|
170
|
+
|
|
171
|
+
11. 添加 msprobe 工具后 F.gelu 触发 ValueError 报错:`activation_func must be F.gelu`等。
|
|
172
|
+
|
|
173
|
+
答:注释工具目录 `mstt/debug/accuracy_tools/msprobe/pytorch/hook_module/support_wrap_ops.yaml` 文件中 `functional: ` 下的 `-gelu`,工具会跳过采集该 API。如果需要采集关键位置 api 也可以考虑根据报错堆栈信息注释引发报错的类型检查。
|
|
174
|
+
|
|
175
|
+
12. 添加 msprobe 工具后触发与 AsStrided 算子相关、或者编译相关的报错,如:`Failed to compile Op [AsStrided]`。
|
|
176
|
+
|
|
177
|
+
答:注释工具目录 `mstt/debug/accuracy_tools/msprobe/pytorch/hook_module/support_wrap_ops.yaml` 文件中 `Tensor: `下的 `-t` 和 `- transpose`。
|