mindstudio-probe 1.0.3__py3-none-any.whl → 1.1.0__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.3.dist-info → mindstudio_probe-1.1.0.dist-info}/LICENSE +201 -201
- {mindstudio_probe-1.0.3.dist-info → mindstudio_probe-1.1.0.dist-info}/METADATA +36 -34
- mindstudio_probe-1.1.0.dist-info/RECORD +287 -0
- {mindstudio_probe-1.0.3.dist-info → mindstudio_probe-1.1.0.dist-info}/WHEEL +1 -1
- {mindstudio_probe-1.0.3.dist-info → mindstudio_probe-1.1.0.dist-info}/entry_points.txt +1 -0
- msprobe/README.md +131 -237
- msprobe/__init__.py +16 -1
- msprobe/{config/config.json → config.json} +47 -49
- msprobe/core/advisor/advisor.py +124 -124
- msprobe/core/advisor/advisor_const.py +58 -59
- msprobe/core/advisor/advisor_result.py +58 -58
- msprobe/core/common/const.py +402 -318
- msprobe/core/common/exceptions.py +99 -99
- msprobe/core/common/{file_check.py → file_utils.py} +523 -283
- msprobe/core/common/inplace_op_checker.py +38 -0
- msprobe/core/common/inplace_ops.yaml +251 -0
- msprobe/core/common/log.py +86 -69
- msprobe/core/common/utils.py +371 -616
- msprobe/core/common_config.py +78 -71
- msprobe/core/compare/acc_compare.py +472 -298
- msprobe/core/compare/check.py +180 -95
- msprobe/core/compare/compare_cli.py +69 -49
- msprobe/core/compare/highlight.py +259 -222
- msprobe/core/compare/multiprocessing_compute.py +174 -149
- msprobe/core/compare/npy_compare.py +310 -295
- msprobe/core/compare/utils.py +464 -429
- msprobe/core/data_dump/data_collector.py +153 -144
- msprobe/core/data_dump/data_processor/base.py +337 -293
- msprobe/core/data_dump/data_processor/factory.py +76 -59
- msprobe/core/data_dump/data_processor/mindspore_processor.py +192 -198
- msprobe/core/data_dump/data_processor/pytorch_processor.py +383 -389
- msprobe/core/data_dump/json_writer.py +117 -116
- msprobe/core/data_dump/scope.py +194 -178
- msprobe/core/grad_probe/constant.py +74 -70
- msprobe/core/grad_probe/grad_compare.py +170 -175
- msprobe/core/grad_probe/utils.py +77 -52
- msprobe/docs/01.installation.md +99 -0
- msprobe/docs/02.config_introduction.md +137 -0
- msprobe/docs/03.config_examples.md +237 -0
- msprobe/docs/04.acl_config_examples.md +78 -0
- msprobe/docs/05.data_dump_PyTorch.md +326 -0
- msprobe/docs/06.data_dump_MindSpore.md +285 -0
- msprobe/docs/07.accuracy_checker_PyTorch.md +297 -0
- msprobe/docs/08.accuracy_checker_online_PyTorch.md +238 -0
- msprobe/docs/09.accuracy_checker_MindSpore.md +68 -0
- msprobe/docs/10.accuracy_compare_PyTorch.md +327 -0
- msprobe/docs/11.accuracy_compare_MindSpore.md +333 -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 +170 -0
- msprobe/docs/16.free_benchmarking_MindSpore.md +140 -0
- msprobe/{doc/grad_probe/grad_probe.md → docs/17.grad_probe.md} +205 -207
- 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 → docs/18.online_dispatch.md} +89 -90
- msprobe/docs/FAQ.md +189 -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/ms_dump.png +0 -0
- msprobe/docs/img/ms_layer.png +0 -0
- msprobe/docs/img/pt_dump.png +0 -0
- msprobe/mindspore/__init__.py +2 -1
- msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +278 -245
- msprobe/mindspore/api_accuracy_checker/api_info.py +76 -69
- msprobe/mindspore/api_accuracy_checker/api_runner.py +155 -151
- msprobe/mindspore/api_accuracy_checker/base_compare_algorithm.py +196 -196
- msprobe/mindspore/api_accuracy_checker/cmd_parser.py +6 -0
- msprobe/mindspore/api_accuracy_checker/compute_element.py +238 -223
- msprobe/mindspore/api_accuracy_checker/main.py +8 -15
- msprobe/mindspore/api_accuracy_checker/type_mapping.py +113 -113
- msprobe/mindspore/api_accuracy_checker/utils.py +79 -62
- msprobe/mindspore/cell_processor.py +58 -34
- msprobe/mindspore/common/const.py +108 -87
- msprobe/mindspore/common/log.py +37 -37
- msprobe/mindspore/common/utils.py +97 -57
- msprobe/mindspore/compare/distributed_compare.py +62 -75
- msprobe/mindspore/compare/layer_mapping.py +146 -0
- msprobe/mindspore/compare/modify_mapping.py +107 -0
- msprobe/mindspore/compare/ms_compare.py +357 -117
- msprobe/mindspore/compare/ms_graph_compare.py +364 -317
- msprobe/mindspore/compare/ms_to_pt_api.yaml +399 -399
- msprobe/mindspore/debugger/debugger_config.py +69 -74
- msprobe/mindspore/debugger/precision_debugger.py +150 -107
- msprobe/mindspore/dump/dump_tool_factory.py +50 -35
- msprobe/mindspore/dump/hook_cell/api_registry.py +128 -104
- msprobe/mindspore/dump/hook_cell/hook_cell.py +55 -53
- msprobe/mindspore/dump/hook_cell/primitive_hooks.py +206 -0
- msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +994 -925
- msprobe/mindspore/dump/hook_cell/wrap_api.py +121 -0
- msprobe/mindspore/dump/jit_dump.py +96 -56
- msprobe/mindspore/dump/kernel_graph_dump.py +75 -60
- msprobe/mindspore/dump/kernel_kbyk_dump.py +79 -65
- msprobe/mindspore/free_benchmark/api_pynative_self_check.py +131 -116
- msprobe/mindspore/free_benchmark/common/config.py +27 -12
- msprobe/mindspore/free_benchmark/common/handler_params.py +32 -17
- msprobe/mindspore/free_benchmark/common/utils.py +85 -71
- msprobe/mindspore/free_benchmark/data/support_wrap_ops.yaml +842 -842
- msprobe/mindspore/free_benchmark/decorator/dec_forward.py +57 -42
- msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +122 -107
- msprobe/mindspore/free_benchmark/handler/base_handler.py +105 -90
- msprobe/mindspore/free_benchmark/handler/check_handler.py +56 -41
- msprobe/mindspore/free_benchmark/handler/fix_handler.py +51 -36
- msprobe/mindspore/free_benchmark/handler/handler_factory.py +36 -21
- msprobe/mindspore/free_benchmark/perturbation/add_noise.py +82 -67
- msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +36 -21
- msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +78 -63
- msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +77 -0
- msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +49 -34
- msprobe/mindspore/free_benchmark/perturbation/no_change.py +27 -12
- msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +44 -27
- msprobe/mindspore/free_benchmark/self_check_tool_factory.py +48 -33
- msprobe/mindspore/grad_probe/global_context.py +100 -91
- msprobe/mindspore/grad_probe/grad_analyzer.py +231 -231
- msprobe/mindspore/grad_probe/grad_monitor.py +27 -27
- msprobe/mindspore/grad_probe/grad_stat_csv.py +131 -131
- msprobe/mindspore/grad_probe/hook.py +94 -92
- msprobe/mindspore/grad_probe/utils.py +29 -28
- msprobe/mindspore/ms_config.py +128 -126
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +60 -45
- msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +49 -34
- msprobe/mindspore/runtime.py +4 -4
- msprobe/mindspore/service.py +297 -354
- msprobe/mindspore/task_handler_factory.py +24 -24
- msprobe/msprobe.py +105 -107
- msprobe/pytorch/__init__.py +23 -4
- msprobe/pytorch/api_accuracy_checker/common/config.py +70 -55
- msprobe/pytorch/api_accuracy_checker/common/utils.py +246 -165
- msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +230 -213
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +632 -581
- 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 +416 -381
- msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +90 -73
- msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +265 -244
- msprobe/pytorch/api_accuracy_checker/config.yaml +10 -10
- msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +370 -332
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +221 -199
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +150 -134
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +518 -581
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +213 -74
- msprobe/pytorch/api_accuracy_checker/run_ut/torch_ut_setting.json +7 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +218 -202
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +370 -324
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +227 -204
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/dump_dispatch.py +110 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +244 -218
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/torch_ops_config.yaml +63 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/utils.py +44 -0
- msprobe/pytorch/bench_functions/__init__.py +30 -15
- msprobe/pytorch/bench_functions/apply_adam_w.py +43 -28
- msprobe/pytorch/bench_functions/confusion_transpose.py +34 -19
- msprobe/pytorch/bench_functions/fast_gelu.py +70 -55
- msprobe/pytorch/bench_functions/layer_norm_eval.py +21 -6
- msprobe/pytorch/bench_functions/linear.py +27 -12
- msprobe/pytorch/bench_functions/matmul_backward.py +63 -48
- msprobe/pytorch/bench_functions/npu_fusion_attention.py +538 -421
- msprobe/pytorch/bench_functions/rms_norm.py +30 -15
- msprobe/pytorch/bench_functions/rotary_mul.py +71 -52
- msprobe/pytorch/bench_functions/scaled_mask_softmax.py +41 -26
- msprobe/pytorch/bench_functions/swiglu.py +70 -55
- msprobe/pytorch/common/__init__.py +17 -2
- msprobe/pytorch/common/compare_script.template +14 -14
- msprobe/pytorch/common/log.py +33 -32
- msprobe/pytorch/common/parse_json.py +54 -39
- msprobe/pytorch/common/utils.py +310 -300
- msprobe/pytorch/compare/distributed_compare.py +66 -66
- msprobe/pytorch/compare/mapping.yaml +607 -607
- msprobe/pytorch/compare/match.py +49 -33
- msprobe/pytorch/compare/pt_compare.py +82 -40
- msprobe/pytorch/debugger/debugger_config.py +108 -95
- msprobe/pytorch/debugger/precision_debugger.py +173 -125
- msprobe/pytorch/free_benchmark/__init__.py +23 -8
- msprobe/pytorch/free_benchmark/common/constant.py +70 -70
- msprobe/pytorch/free_benchmark/common/counter.py +71 -71
- msprobe/pytorch/free_benchmark/common/enums.py +65 -37
- msprobe/pytorch/free_benchmark/common/params.py +144 -129
- msprobe/pytorch/free_benchmark/common/utils.py +118 -102
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +200 -179
- msprobe/pytorch/free_benchmark/compare/single_benchmark.py +119 -104
- msprobe/pytorch/free_benchmark/main.py +120 -105
- msprobe/pytorch/free_benchmark/perturbed_layers/base_layer.py +28 -13
- msprobe/pytorch/free_benchmark/perturbed_layers/layer_factory.py +56 -41
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +105 -90
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +119 -104
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +87 -63
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +83 -68
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/no_change.py +43 -28
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/npu_base_layser.py +60 -45
- msprobe/pytorch/free_benchmark/perturbed_layers/run_cpu.py +34 -19
- msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +256 -217
- msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +54 -39
- msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +38 -23
- msprobe/pytorch/free_benchmark/result_handlers/handler_factory.py +45 -30
- msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +185 -170
- msprobe/pytorch/function_factory.py +91 -75
- msprobe/pytorch/functional/module_dump.py +84 -0
- msprobe/pytorch/grad_probe/grad_monitor.py +91 -90
- msprobe/pytorch/grad_probe/grad_stat_csv.py +128 -128
- msprobe/pytorch/hook_module/__init__.py +16 -1
- msprobe/pytorch/hook_module/api_registry.py +166 -161
- msprobe/pytorch/hook_module/hook_module.py +118 -120
- msprobe/pytorch/hook_module/support_wrap_ops.yaml +1879 -1877
- msprobe/pytorch/hook_module/utils.py +28 -29
- msprobe/pytorch/hook_module/wrap_aten.py +111 -110
- msprobe/pytorch/hook_module/wrap_distributed.py +77 -78
- msprobe/pytorch/hook_module/wrap_functional.py +104 -105
- msprobe/pytorch/hook_module/wrap_npu_custom.py +85 -84
- msprobe/pytorch/hook_module/wrap_tensor.py +69 -71
- msprobe/pytorch/hook_module/wrap_torch.py +84 -86
- msprobe/pytorch/hook_module/wrap_vf.py +60 -62
- msprobe/pytorch/module_processer.py +153 -138
- msprobe/pytorch/online_dispatch/__init__.py +20 -20
- msprobe/pytorch/online_dispatch/compare.py +235 -236
- msprobe/pytorch/online_dispatch/dispatch.py +271 -271
- msprobe/pytorch/online_dispatch/dump_compare.py +155 -156
- msprobe/pytorch/online_dispatch/single_compare.py +391 -391
- msprobe/pytorch/online_dispatch/torch_ops_config.yaml +57 -49
- msprobe/pytorch/online_dispatch/utils.py +127 -146
- msprobe/pytorch/parse.py +19 -4
- msprobe/pytorch/parse_tool/cli.py +31 -32
- msprobe/pytorch/parse_tool/lib/compare.py +259 -271
- msprobe/pytorch/parse_tool/lib/config.py +52 -52
- 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 +161 -158
- msprobe/pytorch/parse_tool/lib/utils.py +320 -321
- msprobe/pytorch/parse_tool/lib/visualization.py +85 -91
- msprobe/pytorch/pt_config.py +317 -187
- msprobe/pytorch/service.py +311 -252
- mindstudio_probe-1.0.3.dist-info/RECORD +0 -272
- msprobe/config/README.md +0 -539
- msprobe/mindspore/doc/compare.md +0 -58
- msprobe/mindspore/doc/dump.md +0 -217
- msprobe/mindspore/dump/hook_cell/wrap_functional.py +0 -91
- msprobe/mindspore/dump/hook_cell/wrap_tensor.py +0 -63
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/ssl_config.py +0 -10
- msprobe/pytorch/doc/FAQ.md +0 -193
- msprobe/pytorch/doc/api_accuracy_checker.md +0 -313
- msprobe/pytorch/doc/api_accuracy_checker_online.md +0 -187
- msprobe/pytorch/doc/dump.md +0 -260
- msprobe/pytorch/doc/msprobe/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/ptdbg_ascend_compare.md +0 -240
- 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/206/320/247/320/260/321/206/320/260/320/227/321/206/320/255/320/226/321/205/342/225/226/320/265/321/205/320/225/342/225/226/321/205/320/254/342/225/221/321/206/320/251/320/277/321/211/320/272/320/234/321/210/320/277/320/221/321/205/320/242/320/234/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 -151
- msprobe/pytorch/functional/data_processor.py +0 -0
- msprobe/pytorch/functional/dump_module.py +0 -39
- {mindstudio_probe-1.0.3.dist-info → mindstudio_probe-1.1.0.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/{doc/grad_probe/img/image-1.png → docs/img/grad_probe_image-1.png} +0 -0
- /msprobe/{doc/grad_probe/img/image-2.png → docs/img/grad_probe_image-2.png} +0 -0
- /msprobe/{doc/grad_probe/img/image-3.png → docs/img/grad_probe_image-3.png} +0 -0
- /msprobe/{doc/grad_probe/img/image-4.png → docs/img/grad_probe_image-4.png} +0 -0
- /msprobe/{doc/grad_probe/img/image.png → docs/img/grad_probe_image.png} +0 -0
- /msprobe/{pytorch/doc → docs}/img/module_compare.png +0 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# PyTorch 场景的精度数据采集
|
|
2
|
+
|
|
3
|
+
msprobe 工具主要通过在训练脚本内添加 dump 接口、启动训练的方式采集精度数据。
|
|
4
|
+
|
|
5
|
+
本工具提供固定的 API 支持列表,若需要删除或增加 dump 的 API,可以在 msprobe/pytorch/hook_module/support_wrap_ops.yaml 文件内手动修改,如下示例:
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
functional: # functional为算子类别,找到对应的类别,在该类别下按照下列格式删除或添加API
|
|
9
|
+
- conv1d
|
|
10
|
+
- conv2d
|
|
11
|
+
- conv3d
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 1 接口介绍
|
|
15
|
+
|
|
16
|
+
### 1.1 PrecisionDebugger
|
|
17
|
+
|
|
18
|
+
**功能说明**:通过加载 dump 配置文件的方式来确定 dump 操作的详细配置。
|
|
19
|
+
|
|
20
|
+
**原型**:
|
|
21
|
+
|
|
22
|
+
```Python
|
|
23
|
+
PrecisionDebugger(config_path=None, task=None, dump_path=None, level=None, model=None, step=None)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
1. config_path:指定 dump 配置文件路径;model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"时,必须在该接口或 **start** 接口中配置该参数。其他参数均在 [config.json](../config.json) 文件中可配,详细配置可见 [config.json 介绍](./02.config_introduction.md)。
|
|
27
|
+
2. 此接口的参数均不是必要,且优先级高于 [config.json](../config.json) 文件中的配置,但可配置的参数相比 config.json 较少。
|
|
28
|
+
|
|
29
|
+
### 1.2 start
|
|
30
|
+
|
|
31
|
+
**功能说明**:启动精度数据采集。在模型初始化之后的位置添加。需要与 stop 函数一起添加在 for 循环内。
|
|
32
|
+
|
|
33
|
+
**原型**:
|
|
34
|
+
|
|
35
|
+
```Python
|
|
36
|
+
debugger.start(model=None)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
1. model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"时,必须在该接口或 **PrecisionDebugger** 接口中配置该参数。
|
|
40
|
+
本接口中的 model 比 PrecisionDebugger 中 model 参数优先级更高,会覆盖 PrecisionDebugger 中的 model 参数。
|
|
41
|
+
|
|
42
|
+
### 1.3 stop
|
|
43
|
+
|
|
44
|
+
**功能说明**:停止精度数据采集。在 **start** 函数之后的任意位置添加。若需要 dump 反向数据,则需要添加在反向计算代码(如,loss.backward)之后。使用示例可参见 [2.1 快速上手](#21-快速上手)和 [2.2 采集完整的前反向数据](#22-采集完整的前反向数据)。
|
|
45
|
+
|
|
46
|
+
**原型**:
|
|
47
|
+
|
|
48
|
+
```Python
|
|
49
|
+
debugger.stop()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 1.4 forward_backward_dump_end
|
|
53
|
+
|
|
54
|
+
**功能说明**:停止精度数据采集。用于 dump 指定代码的前反向数据。在 **start** 函数之后,反向计算代码(如,loss.backward)之前的任意位置添加,可以采集 **start** 函数和该函数之间的前反向数据,可以通过调整 **start** 函数与该函数的位置,来指定需要 dump 的代码块。要求 **stop** 函数添加在反向计算代码(如,loss.backward)之后,此时该函数与 **stop** 函数之间的代码不会被 dump。使用示例可参见 [2.3 采集指定代码块的前反向数据](#23-采集指定代码块的前反向数据)
|
|
55
|
+
|
|
56
|
+
**原型**:
|
|
57
|
+
|
|
58
|
+
```Python
|
|
59
|
+
forward_backward_dump_end()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 1.5 step
|
|
63
|
+
|
|
64
|
+
**功能说明**:更新 dump 参数。在最后一个 **stop** 函数后或一个 step 结束的位置添加。需要与 **start** 函数一起添加在 for 循环内。
|
|
65
|
+
|
|
66
|
+
**原型**:
|
|
67
|
+
|
|
68
|
+
```Python
|
|
69
|
+
debugger.step()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 1.6 module_dump
|
|
73
|
+
|
|
74
|
+
**功能说明**:开启模块级精度数据dump。该接口为函数模块化接口,即只会dump输入的模块数据,不会dump子模块和模块内API的数据。
|
|
75
|
+
需要配合start、stop和step等接口使用。使用示例可参考[2.4 采集函数模块化数据](#24-采集函数模块化数据)
|
|
76
|
+
|
|
77
|
+
**原型**:
|
|
78
|
+
|
|
79
|
+
```Python
|
|
80
|
+
module_dump(module, module_name)
|
|
81
|
+
```
|
|
82
|
+
**参数说明**:
|
|
83
|
+
|
|
84
|
+
1. module: 网络中实例化好的nn.Module类对象。数据类型:torch.nn.Module。必选。
|
|
85
|
+
2. module_name:用户自定义该module名称,主要用于dump数据的命名。数据类型:str。必选。
|
|
86
|
+
|
|
87
|
+
### 1.7 module_dump_end
|
|
88
|
+
|
|
89
|
+
**功能说明**:结束模块级精度数据dump。在module_dump和module_dump_end之间的API或者Module,除了传入的module,其他数据均不会被dump。
|
|
90
|
+
在执行完module_dump_end后数据恢复正常的dump模式。
|
|
91
|
+
|
|
92
|
+
**原型**:
|
|
93
|
+
|
|
94
|
+
```Python
|
|
95
|
+
module_dump_end()
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 1.8 seed_all
|
|
99
|
+
|
|
100
|
+
**功能说明**:对于网络中随机性的固定和确定性计算,msprobe工具提供了seed_all接口用于固定网络中的随机性和开启确定性计算。
|
|
101
|
+
|
|
102
|
+
**原型**:
|
|
103
|
+
```python
|
|
104
|
+
seed_all(seed=1234, mode=False)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**参数说明**:
|
|
108
|
+
|
|
109
|
+
1. seed: 随机性种子。参数示例: seed=1000。默认值:1234。非必选
|
|
110
|
+
2. mode:确定性计算模式。可配置True或False。参数示例:mode=True。默认为False。非必选(注意:确定性计算会导致API执行性能降低,建议在发现模型多次执行结果不同的情况下开启)
|
|
111
|
+
|
|
112
|
+
seed_all 函数可固定随机数的范围如下表。
|
|
113
|
+
|
|
114
|
+
| API | 固定随机数 |
|
|
115
|
+
| ---------------------------------------- | --------------------------- |
|
|
116
|
+
| os.environ['PYTHONHASHSEED'] = str(seed) | 禁止 Python 中的 hash 随机化 |
|
|
117
|
+
| os.environ['HCCL_DETERMINISTIC'] = True | 固定通信算子计算的确定性 |
|
|
118
|
+
| random.seed(seed) | 设置 random 随机生成器的种子 |
|
|
119
|
+
| np.random.seed(seed) | 设置 numpy 中随机生成器的种子 |
|
|
120
|
+
| torch.manual_seed(seed) | 设置当前 CPU 的随机种子 |
|
|
121
|
+
| torch.cuda.manual_seed(seed) | 设置当前 GPU 的随机种子 |
|
|
122
|
+
| torch.cuda.manual_seed_all(seed) | 设置所有 GPU 的随机种子 |
|
|
123
|
+
| torch_npu.npu.manual_seed(seed) | 设置当前 NPU 的随机种子 |
|
|
124
|
+
| torch_npu.npu.manual_seed_all(seed) | 设置所有 NPU 的随机种子 |
|
|
125
|
+
| torch.use_deterministic_algorithms(True) | CUDA/CANN 使能确定性计算(注意mode为True时才会调用该方法开启确定性 |
|
|
126
|
+
| torch.backends.cudnn.enable=False | 关闭 cuDNN |
|
|
127
|
+
| torch.backends.cudnn.benchmark=False | cuDNN 确定性地选择算法 |
|
|
128
|
+
| torch.backends.cudnn.deterministic=True | cuDNN 仅使用确定性的卷积算法 |
|
|
129
|
+
|
|
130
|
+
需要保证 CPU 或 GPU 以及 NPU 的模型输入完全一致,dump 数据的比对才有意义,seed_all 并不能保证模型输入完全一致,如下表所示场景需要保证输入的一致性。
|
|
131
|
+
|
|
132
|
+
| 场景 | 固定方法 |
|
|
133
|
+
| --------------- | ------------- |
|
|
134
|
+
| 数据集的 shuffle | 关闭 shuffle。 |
|
|
135
|
+
| dropout | 关闭 dropout。 |
|
|
136
|
+
|
|
137
|
+
关闭 shuffle 示例:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
train_loader = torch.utils.data.DataLoader(
|
|
141
|
+
train_dataset,
|
|
142
|
+
batch_size = batch_size,
|
|
143
|
+
shuffle = False,
|
|
144
|
+
num_workers = num_workers
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
关闭 dropout:
|
|
149
|
+
|
|
150
|
+
在使用 `from msprobe.pytorch import PrecisionDebugger` 后,工具会自动将 `torch.nn.functional.dropout`、`torch.nn.functional.dropout2d`、`torch.nn.functional.dropout3d`、`torch.nn.Dropout`、`torch.nn.Dropout2d`、`torch.nn.Dropout3d` 的接口参数 p 置为0.
|
|
151
|
+
|
|
152
|
+
## 2 示例代码
|
|
153
|
+
|
|
154
|
+
### 2.1 快速上手
|
|
155
|
+
|
|
156
|
+
这个示例定义了一个 nn.Module 类型的简单网络,在进行数据采集时使用原型函数 PrecisionDebugger 传入 config_path 参数和 model 参数。
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
# 根据需要import包
|
|
160
|
+
import torch
|
|
161
|
+
import torch.nn as nn
|
|
162
|
+
import torch_npu # 需安装 torch_npu
|
|
163
|
+
import torch.nn.functional as F
|
|
164
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
165
|
+
# 在模型训练开始前固定随机性
|
|
166
|
+
seed_all()
|
|
167
|
+
|
|
168
|
+
torch.npu.set_device("npu:0")
|
|
169
|
+
# 定义网络
|
|
170
|
+
class ModuleOP(nn.Module):
|
|
171
|
+
def __init__(self) -> None:
|
|
172
|
+
super().__init__()
|
|
173
|
+
self.linear_1 = nn.Linear(in_features=8,out_features=4)
|
|
174
|
+
self.linear_2 = nn.Linear(in_features=4,out_features=2)
|
|
175
|
+
|
|
176
|
+
def forward(self,x):
|
|
177
|
+
x1 = self.linear_1(x)
|
|
178
|
+
x2 = self.linear_2(x1)
|
|
179
|
+
r1 = F.relu(x2)
|
|
180
|
+
return r1
|
|
181
|
+
|
|
182
|
+
if __name__ == "__main__":
|
|
183
|
+
module = ModuleOP()
|
|
184
|
+
# 注册工具
|
|
185
|
+
debugger = PrecisionDebugger('./config.json', model=module)
|
|
186
|
+
debugger.start()
|
|
187
|
+
x = torch.randn(10,8)
|
|
188
|
+
out = module(x)
|
|
189
|
+
loss = out.sum()
|
|
190
|
+
loss.backward()
|
|
191
|
+
debugger.stop()
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
### 2.2 采集完整的前反向数据
|
|
195
|
+
|
|
196
|
+
```Python
|
|
197
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
198
|
+
# 在模型训练开始前固定随机性
|
|
199
|
+
seed_all()
|
|
200
|
+
# 请勿将PrecisionDebugger的初始化流程插入到循环代码中
|
|
201
|
+
debugger = PrecisionDebugger(config_path="./config.json", dump_path="./dump_path")
|
|
202
|
+
# 模型、损失函数的定义及初始化等操作
|
|
203
|
+
# ...
|
|
204
|
+
# 数据集迭代的位置一般为模型训练开始的位置
|
|
205
|
+
for data, label in data_loader:
|
|
206
|
+
debugger.start() # 开启数据dump
|
|
207
|
+
# 如下是模型每个step执行的逻辑
|
|
208
|
+
output = model(data)
|
|
209
|
+
#...
|
|
210
|
+
loss.backward()
|
|
211
|
+
debugger.stop() # 关闭数据dump
|
|
212
|
+
debugger.step() # 结束一个step的dump
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 2.3 采集指定代码块的前反向数据
|
|
216
|
+
|
|
217
|
+
```Python
|
|
218
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
219
|
+
# 在模型训练开始前固定随机性
|
|
220
|
+
seed_all()
|
|
221
|
+
# 请勿将PrecisionDebugger的初始化流程插入到循环代码中
|
|
222
|
+
debugger = PrecisionDebugger(config_path="./config.json", dump_path="./dump_path")
|
|
223
|
+
|
|
224
|
+
# 模型、损失函数的定义及初始化等操作
|
|
225
|
+
# ...
|
|
226
|
+
# 数据集迭代的位置一般为模型训练开始的位置
|
|
227
|
+
for data, label in data_loader:
|
|
228
|
+
debugger.start() # 开启数据dump
|
|
229
|
+
# 如下是模型每个step执行的逻辑
|
|
230
|
+
output = model(data)
|
|
231
|
+
debugger.forward_backward_dump_end() # 插入该函数到start函数之后,只dump start函数到该函数之间代码的前反向数据,本函数到stop函数之间的数据则不dump
|
|
232
|
+
#...
|
|
233
|
+
loss.backward()
|
|
234
|
+
debugger.stop() # 关闭数据dump
|
|
235
|
+
debugger.step() # 结束一个step的dump
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 2.4 采集函数模块化数据
|
|
239
|
+
|
|
240
|
+
```Python
|
|
241
|
+
# 根据需要import包
|
|
242
|
+
import torch
|
|
243
|
+
import torch.nn as nn
|
|
244
|
+
import torch_npu # 需安装 torch_npu
|
|
245
|
+
import torch.nn.functional as F
|
|
246
|
+
from msprobe.pytorch import PrecisionDebugger, module_dump, module_dump_end
|
|
247
|
+
|
|
248
|
+
torch.npu.set_device("npu:0")
|
|
249
|
+
# 定义网络
|
|
250
|
+
class ModuleOP(nn.Module):
|
|
251
|
+
def __init__(self) -> None:
|
|
252
|
+
super().__init__()
|
|
253
|
+
self.linear_1 = nn.Linear(in_features=8, out_features=4)
|
|
254
|
+
self.linear_2 = nn.Linear(in_features=4, out_features=2)
|
|
255
|
+
|
|
256
|
+
def forward(self, x):
|
|
257
|
+
x1 = self.linear_1(x)
|
|
258
|
+
x2 = self.linear_2(x1)
|
|
259
|
+
r1 = F.relu(x2)
|
|
260
|
+
return r1
|
|
261
|
+
|
|
262
|
+
if __name__ == "__main__":
|
|
263
|
+
module = ModuleOP()
|
|
264
|
+
# 注册工具
|
|
265
|
+
debugger = PrecisionDebugger(config_path='./config.json')
|
|
266
|
+
debugger.start() # 开启数据dump
|
|
267
|
+
|
|
268
|
+
x = torch.randn(10, 8)
|
|
269
|
+
# ... # start和module_dump接口之间的数据正常dump
|
|
270
|
+
module_dump(module, "MyModuleOP") # 开启模块级精度数据dump
|
|
271
|
+
out = module(x) # module内部的child modules或API不会被dump
|
|
272
|
+
module_dump_end() # 关闭模块级精度数据dump
|
|
273
|
+
loss = out.sum() # module_dump_end和stop接口之间的数据正常dump
|
|
274
|
+
loss.backward()
|
|
275
|
+
|
|
276
|
+
debugger.stop() # 关闭数据dump
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## 3 dump 结果文件介绍
|
|
280
|
+
|
|
281
|
+
训练结束后,工具将 dump 的数据保存在 dump_path 参数指定的目录下。目录结构示例如下:
|
|
282
|
+
|
|
283
|
+
```Python
|
|
284
|
+
├── dump_path
|
|
285
|
+
│ ├── step0
|
|
286
|
+
│ | ├── rank0
|
|
287
|
+
│ | │ ├── dump_tensor_data
|
|
288
|
+
| | | | ├── Tensor.permute.1.forward.pt
|
|
289
|
+
| | | | ├── MyModule.0.forward.input.pt # 开启模块级精度数据dump时存在模块级的dump数据文件
|
|
290
|
+
| | | | ...
|
|
291
|
+
| | | | └── Fcuntion.linear.5.backward.output.pt
|
|
292
|
+
│ | | ├── dump.json # 保存前反向算子、算子的统计量信息或溢出算子信息。包含dump数据的API名称(命名格式为:`{api_type}_{api_name}_{API调用次数}_{前向反向}_{input/output}.{参数序号}`)、dtype、 shape、各数据的max、min、mean、L2norm统计信息以及当配置summary_mode="md5"时的md5数据。其中,“参数序号”表示该API下的第n个参数,例如1,则为第一个参数,若该参数为list格式,则根据list继续排序,例如1.1,表示该API的第1个参数的第1个子参数;L2norm表示L2范数(平方根)
|
|
293
|
+
│ | | ├── stack.json # 算子调用栈信息
|
|
294
|
+
│ | | └── construct.json # 分层分级结构
|
|
295
|
+
│ | ├── rank1
|
|
296
|
+
| | | ├── dump_tensor_data
|
|
297
|
+
| | | | └── ...
|
|
298
|
+
│ | | ├── dump.json
|
|
299
|
+
│ | | ├── stack.json
|
|
300
|
+
| | | └── construct.json
|
|
301
|
+
│ | ├── ...
|
|
302
|
+
│ | |
|
|
303
|
+
| | └── rank7
|
|
304
|
+
│ ├── step1
|
|
305
|
+
│ | ├── ...
|
|
306
|
+
│ ├── step2
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
dump 过程中,pt 文件在对应算子或者模块被执行后就会落盘,而 json 文件则需要在正常执行 PrecisionDebugger.stop() 后才会写入完整数据,异常的程序终止会保存终止前被执行算子的相关 npy 文件,可能会导致 json 文件中数据丢失。
|
|
310
|
+
|
|
311
|
+
其中 rank 为设备上各卡的 ID,每张卡上 dump 的数据会生成对应 dump 目录。非分布式场景下没有 rank ID,目录名称为 rank。
|
|
312
|
+
|
|
313
|
+
pt 文件保存的前缀和 PyTorch 对应关系如下:
|
|
314
|
+
|
|
315
|
+
| 前缀 | Torch模块 |
|
|
316
|
+
| ----------- | ------------------- |
|
|
317
|
+
| Tensor | torch.Tensor |
|
|
318
|
+
| Torch | torch |
|
|
319
|
+
| Functional | torch.nn.functional |
|
|
320
|
+
| NPU | NPU 亲和算子 |
|
|
321
|
+
| VF | torch._VF |
|
|
322
|
+
| Aten | torch.ops.aten |
|
|
323
|
+
| Distributed | torch.distributed |
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# MindSpore 场景的精度数据采集
|
|
2
|
+
|
|
3
|
+
msprobe 工具主要通过在训练脚本内添加 dump 接口、启动训练的方式采集精度数据。目前,静态图场景仅支持 kernel 级数据采集,对应 config.json 配置中的 "L2" level;动态图场景支持cell、API、kernel级数据采集,对应 config.json 配置中的 "L0"、"L1" 、"L2"、"mix" level。
|
|
4
|
+
|
|
5
|
+
需要注意,**动态图 kernel 级**("L2" level)精度数据采集对象为被 PSJit 或 PIJit 装饰的 Cell 或 function 内的算子,其被装饰部分实际以**静态图**模式执行,所以此场景下的工具使用方式与静态图场景完全相同。下文无特殊说明时,介绍的动态图场景不包括 kernel 级("L2" level)dump 情形。
|
|
6
|
+
|
|
7
|
+
精度数据采集功能的配置示例见[MindSpore 静态图场景下 task 配置为 statistics](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#21-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-statistics)、[MindSpore 静态图场景下 task 配置为 tensor](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#22-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-tensor)、[MindSpore 动态图场景下 task 配置为 statistics](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#31-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-statistics)、[MindSpore 动态图场景下 task 配置为 tensor](https://gitee.com/ascend/mstt/blob/master/debug/accuracy_tools/msprobe/docs/03.config_examples.md#32-task-%E9%85%8D%E7%BD%AE%E4%B8%BA-tensor)。
|
|
8
|
+
|
|
9
|
+
动态图 API 级 dump 时,本工具提供固定的 API 支持列表,仅支持对列表中的 API 进行精度数据采集。一般情况下,无需修改该列表,而是通过config.json中的scope/list字段进行 dump API 指定。若需要改变 API 支持列表,可以在 `msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml` 文件内手动修改,如下示例:
|
|
10
|
+
|
|
11
|
+
```yaml
|
|
12
|
+
ops: # ops为算子类别,找到对应的类别,在该类别下按照下列格式删除或添加API
|
|
13
|
+
- adaptive_avg_pool1d
|
|
14
|
+
- adaptive_avg_pool2d
|
|
15
|
+
- adaptive_avg_pool3d
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 1 接口介绍
|
|
19
|
+
|
|
20
|
+
### 1.1 msprobe.mindspore.PrecisionDebugger
|
|
21
|
+
|
|
22
|
+
**功能说明**:通过加载 dump 配置文件的方式来确定 dump 操作的详细配置。
|
|
23
|
+
|
|
24
|
+
**原型**:
|
|
25
|
+
|
|
26
|
+
```Python
|
|
27
|
+
PrecisionDebugger(config_path=None)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**参数说明**:
|
|
31
|
+
|
|
32
|
+
1. config_path:指定 dump 配置文件路径,string 类型。参数示例:"./config.json"。未配置该路径时,默认使用 [config.json](../config.json) 文件的默认配置,配置选项含义可见 [config.json 介绍](./02.config_introduction.md)。
|
|
33
|
+
|
|
34
|
+
#### 1.1.1 start
|
|
35
|
+
|
|
36
|
+
**功能说明**:启动精度数据采集。需在模型执行模式(静态图/动态图、O0/O1/O2编译等级)设置后调用。静态图场景下,必须在模型初始化及 mindspore.communication.init 调用前添加;动态图场景下,如果没有使用 [Model](https://gitee.com/link?target=https%3A%2F%2Fwww.mindspore.cn%2Ftutorials%2Fzh-CN%2Fr2.3.1%2Fadvanced%2Fmodel.html) 高阶 API 进行训练,则需要与 stop 函数一起添加在 for 循环内,否则只有需要传入model参数时,才使用该接口。
|
|
37
|
+
|
|
38
|
+
**原型**:
|
|
39
|
+
|
|
40
|
+
```Python
|
|
41
|
+
start(model=None)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**参数说明**:
|
|
45
|
+
|
|
46
|
+
1. model:指具体的 mindspore.nn.Cell,默认不配置。Cell级别("L0" level)dump 时,传入 model 可以采集 model 内的所有Cell 对象数据。API级别("L1" level)dump 时,传入 model 可以采集 model 内包含 primitive op 对象在内的所有 API 数据,若不传入 model 参数,则只采集非 primitive op 的 API 数据。
|
|
47
|
+
|
|
48
|
+
#### 1.1.2 stop
|
|
49
|
+
|
|
50
|
+
**功能说明**:停止数据采集。在 **start** 函数之后的任意位置添加。需要与 start 函数一起添加在 for 循环内。若需要 dump 反向数据,则需要添加在反向计算代码之后。**仅未使用 Model 高阶 API 的动态图场景支持。**
|
|
51
|
+
|
|
52
|
+
**原型**:
|
|
53
|
+
|
|
54
|
+
```Python
|
|
55
|
+
stop()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### 1.1.3 step
|
|
59
|
+
|
|
60
|
+
**功能说明**:在最后一个 **stop** 函数后或一个 step 训练结束的位置添加。**仅未使用 Model 高阶 API 的动态图场景支持。**
|
|
61
|
+
|
|
62
|
+
**原型**:
|
|
63
|
+
|
|
64
|
+
```Python
|
|
65
|
+
step()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### 1.1.4 forward_backward_dump_end
|
|
69
|
+
|
|
70
|
+
**功能说明**:在 **start** 函数和在 **stop** 函数之间调用,表示采集 **start** 到 **forward_backward_dump_end**之间的L1级别的正反向数据。
|
|
71
|
+
|
|
72
|
+
**仅支持L1级别数据采集场景。**
|
|
73
|
+
|
|
74
|
+
**L1级别数据中的jit数据采集行为不受此接口影响**
|
|
75
|
+
|
|
76
|
+
**仅未使用 Model 高阶 API 的动态图场景支持。**
|
|
77
|
+
|
|
78
|
+
**原型**:
|
|
79
|
+
|
|
80
|
+
```Python
|
|
81
|
+
forward_backward_dump_end()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 1.2 msprobe.mindspore.common.utils.MsprobeStep
|
|
85
|
+
|
|
86
|
+
**功能说明**:MindSpore Callback类,自动在每个step开始时调用start()接口,在每个step结束时调用stop()、step()接口。实现使用 Model 高阶 API 的动态图场景下 L0、L1 级别的精度数据采集控制,控制粒度为单个 **Step** ,而 PrecisionDebugger.start, PrecisionDebugger.stop 接口的控制粒度任意训练代码段。
|
|
87
|
+
|
|
88
|
+
**原型**:
|
|
89
|
+
|
|
90
|
+
```Python
|
|
91
|
+
MsprobeStep(debugger)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**参数说明**:
|
|
95
|
+
|
|
96
|
+
1. debugger:PrecisionDebugger对象。
|
|
97
|
+
|
|
98
|
+
### 1.3 msprobe.mindspore.seed_all
|
|
99
|
+
|
|
100
|
+
**功能说明**:用于固定网络中的随机性和开启确定性计算。
|
|
101
|
+
|
|
102
|
+
**原型**:
|
|
103
|
+
```python
|
|
104
|
+
seed_all(seed=1234, mode=False)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**参数说明**:
|
|
108
|
+
|
|
109
|
+
1. seed: 随机性种子,默认值:1234,非必选。参数示例: seed=1000。该参数用于 random、numpy.random, mindspore.common.Initializer、mindspore.nn.probability.distribution的随机数生成以及 Python 中 str、bytes、datetime 对象的 hash 算法。
|
|
110
|
+
|
|
111
|
+
2. mode:确定性计算使能,可配置 True 或 False,默认值:False,非必选。参数示例:mode=True。该参数设置为 True 后,将会开启算子确定性运行模式与归约类通信算子(AllReduce、ReduceScatter、Reduce)的确定性计算。注意:确定性计算会导致API执行性能降低,建议在发现模型多次执行结果不同的情况下开启。
|
|
112
|
+
|
|
113
|
+
## 2 示例代码
|
|
114
|
+
|
|
115
|
+
### 2.1 MindSpore 静态图场景
|
|
116
|
+
|
|
117
|
+
```Python
|
|
118
|
+
import mindspore as ms
|
|
119
|
+
ms.set_context(mode=ms.GRAPH_MODE, device_target="Ascend")
|
|
120
|
+
|
|
121
|
+
from msprobe.mindspore import PrecisionDebugger
|
|
122
|
+
debugger = PrecisionDebugger(config_path="./config.json")
|
|
123
|
+
debugger.start()
|
|
124
|
+
# 请勿将以上初始化流程置于模型实例化或mindspore.communication.init调用后
|
|
125
|
+
# ...
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 2.2 MindSpore 动态图场景
|
|
129
|
+
|
|
130
|
+
#### 2.2.1 未使用 Model 高阶 API(非 L2 级别)
|
|
131
|
+
|
|
132
|
+
```Python
|
|
133
|
+
import mindspore as ms
|
|
134
|
+
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
135
|
+
|
|
136
|
+
from msprobe.mindspore import PrecisionDebugger
|
|
137
|
+
debugger = PrecisionDebugger(config_path="./config.json")
|
|
138
|
+
|
|
139
|
+
# 模型、损失函数的定义以及初始化等操作
|
|
140
|
+
# ...
|
|
141
|
+
model = Network()
|
|
142
|
+
# 数据集迭代的地方往往是模型开始训练的地方
|
|
143
|
+
for data, label in data_loader:
|
|
144
|
+
debugger.start() # 进行L1级别下非primitive op采集时调用
|
|
145
|
+
# debugger.start(model) # 进行L0级别或L1级别下primitive op的数据采集时调用
|
|
146
|
+
# 如下是模型每个step执行的逻辑
|
|
147
|
+
grad_net = ms.grad(model)(data)
|
|
148
|
+
# ...
|
|
149
|
+
debugger.stop() # 关闭数据dump
|
|
150
|
+
debugger.step() # 结束一个step的dump
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### 2.2.2 未使用 Model 高阶 API(L2 级别)
|
|
154
|
+
|
|
155
|
+
```Python
|
|
156
|
+
import mindspore as ms
|
|
157
|
+
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
158
|
+
|
|
159
|
+
from msprobe.mindspore import PrecisionDebugger
|
|
160
|
+
debugger = PrecisionDebugger(config_path="./config.json")
|
|
161
|
+
debugger.start()
|
|
162
|
+
# 请勿将以上初始化流程置于模型实例化或mindspore.communication.init调用后
|
|
163
|
+
|
|
164
|
+
# 模型、损失函数的定义以及初始化等操作
|
|
165
|
+
# ...
|
|
166
|
+
model = Network()
|
|
167
|
+
# 数据集迭代的地方往往是模型开始训练的地方
|
|
168
|
+
for data, label in data_loader:
|
|
169
|
+
# 如下是模型每个step执行的逻辑
|
|
170
|
+
grad_net = ms.grad(model)(data)
|
|
171
|
+
# ...
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### 2.2.3 使用 Model 高阶 API(非 L2 级别)
|
|
175
|
+
|
|
176
|
+
```Python
|
|
177
|
+
import mindspore as ms
|
|
178
|
+
from mindspore.train import Model
|
|
179
|
+
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
180
|
+
|
|
181
|
+
from msprobe.mindspore import PrecisionDebugger
|
|
182
|
+
from msprobe.mindspore.common.utils import MsprobeStep
|
|
183
|
+
debugger = PrecisionDebugger(config_path="./config.json")
|
|
184
|
+
|
|
185
|
+
# 模型、损失函数的定义以及初始化等操作
|
|
186
|
+
# ...
|
|
187
|
+
|
|
188
|
+
model = Network()
|
|
189
|
+
# 只有进行L0级别下Cell对象或L1级别下primitive op的数据采集时才需要调用
|
|
190
|
+
# debugger.start(model)
|
|
191
|
+
trainer = Model(model, loss_fn=loss_fn, optimizer=optimizer, metrics={'accuracy'})
|
|
192
|
+
trainer.train(1, train_dataset, callbacks=[MsprobeStep(debugger)])
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### 2.2.4 使用 Model 高阶 API(L2 级别)
|
|
196
|
+
|
|
197
|
+
```Python
|
|
198
|
+
import mindspore as ms
|
|
199
|
+
from mindspore.train import Model
|
|
200
|
+
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
201
|
+
|
|
202
|
+
from msprobe.mindspore import PrecisionDebugger
|
|
203
|
+
debugger = PrecisionDebugger(config_path="./config.json")
|
|
204
|
+
debugger.start()
|
|
205
|
+
# 请勿将以上初始化流程置于模型实例化或mindspore.communication.init调用后
|
|
206
|
+
|
|
207
|
+
# 模型、损失函数的定义以及初始化等操作
|
|
208
|
+
# ...
|
|
209
|
+
|
|
210
|
+
model = Network()
|
|
211
|
+
trainer = Model(model, loss_fn=loss_fn, optimizer=optimizer, metrics={'accuracy'})
|
|
212
|
+
trainer.train(1, train_dataset)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## 3 dump 结果文件介绍
|
|
216
|
+
|
|
217
|
+
### 3.1 MindSpore 静态图场景
|
|
218
|
+
|
|
219
|
+
训练结束后,工具将 dump 的数据保存在 dump_path 参数指定的目录下。
|
|
220
|
+
|
|
221
|
+
- jit_level 为O0/O1时:
|
|
222
|
+
|
|
223
|
+
dump 结果目录请参见 MindSpore 官网中的[同步 Dump 数据对象目录](https://www.mindspore.cn/tutorials/experts/zh-CN/r2.3.1/debug/dump.html#%E6%95%B0%E6%8D%AE%E5%AF%B9%E8%B1%A1%E7%9B%AE%E5%BD%95%E5%92%8C%E6%95%B0%E6%8D%AE%E6%96%87%E4%BB%B6%E4%BB%8B%E7%BB%8D)。
|
|
224
|
+
|
|
225
|
+
- jit_level 为O2时:
|
|
226
|
+
|
|
227
|
+
dump 结果目录请参见 MindSpore 官网中的[异步 Dump 数据对象目录](https://www.mindspore.cn/tutorials/experts/zh-CN/r2.3.1/debug/dump.html#%E6%95%B0%E6%8D%AE%E5%AF%B9%E8%B1%A1%E7%9B%AE%E5%BD%95%E5%92%8C%E6%95%B0%E6%8D%AE%E6%96%87%E4%BB%B6%E4%BB%8B%E7%BB%8D-1)。
|
|
228
|
+
|
|
229
|
+
jit_level 请参见 [mindspore.set_context](https://www.mindspore.cn/docs/zh-CN/r2.3.1/api_python/mindspore/mindspore.set_context.html) 中的 jit_config 参数。
|
|
230
|
+
|
|
231
|
+
### 3.2 MindSpore 动态图场景
|
|
232
|
+
|
|
233
|
+
训练结束后,工具将 dump 的数据保存在dump_path参数指定的目录下。
|
|
234
|
+
|
|
235
|
+
dump结果目录结构示例如下:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
├── dump_path
|
|
239
|
+
│ ├── step0
|
|
240
|
+
│ | ├── rank0
|
|
241
|
+
│ | │ ├── dump_tensor_data
|
|
242
|
+
| | | | ├── MintFunctional.relu.0.backward.input.0.npy
|
|
243
|
+
| | | | ├── Mint.abs.0.forward.input.0.npy
|
|
244
|
+
| | | | ├── Functional.split.0.forward.input.0.npy
|
|
245
|
+
| | | | ├── Tensor.__add__.0.forward.output.0.npy
|
|
246
|
+
| | | | ...
|
|
247
|
+
| | | | ├── Jit.AlexNet.0.forward.input.0.npy
|
|
248
|
+
| | | | └── Cell.relu.ReLU.forward.0.input.0.npy # config.json文件配置level为L0时dump的cell模块级数据,命名格式为{Cell}_{cell_name}_{class_name}_{前向反向}.{index}.{input/output}.{参数序号}
|
|
249
|
+
│ | | ├── dump.json # 保存前反向算子、算子的统计量信息或溢出算子信息。包含dump数据的API名称(命名格式为:{api_type}_{api_name}_{API调用次数}_{前向反向}_{input/output}.{参数序号})、dtype、 shape、各数据的max、min、mean、L2norm统计信息以及当配置summary_mode="md5"时的md5数据。其中,“参数序号”表示该API下的第n个参数,例如1,则为第一个参数,若该参数为list格式,则根据list继续排序,例如1.1,表示该API的第1个参数的第1个子参数;L2norm表示L2范数(平方根)
|
|
250
|
+
│ | | ├── stack.json # 算子调用栈信息
|
|
251
|
+
│ | | └── construct.json # 分层分级结构,level为L1时,construct.json内容为空
|
|
252
|
+
│ | ├── rank1
|
|
253
|
+
| | | ├── dump_tensor_data
|
|
254
|
+
| | | | └── ...
|
|
255
|
+
│ | | ├── dump.json
|
|
256
|
+
│ | | ├── stack.json
|
|
257
|
+
| | | └── construct.json
|
|
258
|
+
│ | ├── ...
|
|
259
|
+
│ | |
|
|
260
|
+
| | └── rank7
|
|
261
|
+
│ ├── step1
|
|
262
|
+
│ | ├── ...
|
|
263
|
+
│ ├── step2
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
dump 过程中,npy 文件在对应算子或者模块被执行后就会落盘,而 json 文件则需要在正常执行 PrecisionDebugger.stop() 后才会写入完整数据,异常的程序终止会保存终止前被执行算子的相关 npy 文件,可能会导致 json 文件中数据丢失。
|
|
267
|
+
|
|
268
|
+
其中 rank 为设备上各卡的 ID,每张卡上 dump 的数据会生成对应 dump 目录。非分布式场景下没有 rank ID,目录名称为 rank。
|
|
269
|
+
|
|
270
|
+
动态图场景下使能 PSJit 或 PIJit,装饰特定 Cell 或 function,被装饰的部分会全部/部分使能**静态图**流程。
|
|
271
|
+
|
|
272
|
+
- PSJit 场景下 config.json 文件配置 level 为 L1 时,被 PSJit 装饰的部分也作为 API 被 dump 到对应目录;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel,其结果目录同jit_level 为 O0/O1 时的静态图 dump 相同。
|
|
273
|
+
- PIJit 场景下 config.json 文件配置 level 为 L1 时,会被还原为动态图,按 API 粒度进行 dump;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel。
|
|
274
|
+
|
|
275
|
+
npy 文件保存的前缀和 MindSpore 对应关系如下:
|
|
276
|
+
|
|
277
|
+
| 前缀 | MindSpore 模块 |
|
|
278
|
+
| -------------- | ---------------------------- |
|
|
279
|
+
| Tensor | mindspore.Tensor |
|
|
280
|
+
| Functional | mindspore.ops |
|
|
281
|
+
| Primitive | mindspore.ops.Primitive |
|
|
282
|
+
| Mint | mindspore.mint |
|
|
283
|
+
| MintFunctional | mindspore.mint.nn.functional |
|
|
284
|
+
| Jit | mindspore.jit |
|
|
285
|
+
| Cell | mindspore.nn.Cell |
|