mindstudio-probe 1.0.4__py3-none-any.whl → 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.1.dist-info}/METADATA +5 -5
- mindstudio_probe-1.1.1.dist-info/RECORD +341 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.1.dist-info}/WHEEL +1 -1
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.1.dist-info}/entry_points.txt +0 -1
- msprobe/README.md +84 -18
- msprobe/__init__.py +16 -1
- msprobe/config.json +1 -5
- msprobe/core/advisor/advisor.py +16 -11
- msprobe/core/advisor/advisor_const.py +6 -7
- msprobe/core/advisor/advisor_result.py +12 -12
- msprobe/core/common/const.py +164 -3
- msprobe/core/common/exceptions.py +26 -4
- msprobe/core/common/file_utils.py +196 -27
- msprobe/core/common/inplace_op_checker.py +53 -0
- msprobe/core/common/inplace_ops.yaml +251 -0
- msprobe/core/common/log.py +46 -18
- msprobe/core/common/utils.py +308 -209
- msprobe/core/common_config.py +60 -38
- msprobe/core/compare/acc_compare.py +332 -94
- msprobe/core/compare/check.py +104 -22
- msprobe/core/compare/compare_cli.py +42 -5
- msprobe/core/compare/highlight.py +162 -57
- msprobe/core/compare/layer_mapping/__init__.py +19 -0
- msprobe/core/compare/layer_mapping/data_scope_parser.py +235 -0
- msprobe/core/compare/layer_mapping/layer_mapping.py +242 -0
- msprobe/core/compare/layer_mapping/postprocess_pass.py +94 -0
- msprobe/core/compare/multiprocessing_compute.py +33 -8
- msprobe/core/compare/npy_compare.py +73 -29
- msprobe/core/compare/utils.py +306 -247
- msprobe/core/data_dump/data_collector.py +44 -43
- msprobe/core/data_dump/data_processor/base.py +88 -35
- msprobe/core/data_dump/data_processor/factory.py +20 -3
- msprobe/core/data_dump/data_processor/mindspore_processor.py +14 -8
- msprobe/core/data_dump/data_processor/pytorch_processor.py +180 -66
- msprobe/core/data_dump/json_writer.py +63 -42
- msprobe/core/data_dump/scope.py +143 -48
- msprobe/core/grad_probe/constant.py +31 -13
- msprobe/core/grad_probe/grad_compare.py +20 -4
- msprobe/core/grad_probe/utils.py +44 -3
- msprobe/core/overflow_check/abnormal_scene.py +185 -0
- msprobe/core/overflow_check/api_info.py +55 -0
- msprobe/core/overflow_check/checker.py +138 -0
- msprobe/core/overflow_check/filter.py +157 -0
- msprobe/core/overflow_check/ignore_rules.yaml +55 -0
- msprobe/core/overflow_check/level.py +22 -0
- msprobe/core/overflow_check/utils.py +28 -0
- msprobe/docs/01.installation.md +29 -9
- msprobe/docs/02.config_introduction.md +83 -84
- msprobe/docs/03.config_examples.md +3 -20
- msprobe/docs/04.kernel_dump_PyTorch.md +73 -0
- msprobe/docs/05.data_dump_PyTorch.md +143 -13
- msprobe/docs/06.data_dump_MindSpore.md +197 -88
- msprobe/docs/07.accuracy_checker_PyTorch.md +69 -46
- msprobe/docs/08.accuracy_checker_online_PyTorch.md +52 -17
- msprobe/docs/09.accuracy_checker_MindSpore.md +51 -15
- msprobe/docs/10.accuracy_compare_PyTorch.md +187 -99
- msprobe/docs/11.accuracy_compare_MindSpore.md +253 -31
- msprobe/docs/12.overflow_check_PyTorch.md +1 -1
- msprobe/docs/13.overflow_check_MindSpore.md +6 -6
- msprobe/docs/15.free_benchmarking_PyTorch.md +60 -55
- msprobe/docs/16.free_benchmarking_MindSpore.md +159 -0
- msprobe/docs/17.grad_probe.md +19 -22
- msprobe/docs/18.online_dispatch.md +89 -0
- msprobe/docs/19.monitor.md +468 -0
- msprobe/docs/20.monitor_performance_baseline.md +52 -0
- msprobe/docs/21.visualization_PyTorch.md +386 -0
- msprobe/docs/22.visualization_MindSpore.md +384 -0
- msprobe/docs/23.tool_function_introduction.md +28 -0
- msprobe/docs/{FAQ_PyTorch.md → FAQ.md} +25 -10
- msprobe/docs/data_dump_Mindspore/dynamic_graph_quick_start_example.md +211 -0
- msprobe/docs/img/compare_result.png +0 -0
- msprobe/docs/img/monitor/cpu_info.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 +16 -0
- msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +130 -138
- msprobe/mindspore/api_accuracy_checker/api_info.py +27 -5
- msprobe/mindspore/api_accuracy_checker/api_runner.py +43 -18
- msprobe/mindspore/api_accuracy_checker/base_compare_algorithm.py +21 -7
- msprobe/mindspore/api_accuracy_checker/checker_support_api.yaml +77 -0
- msprobe/mindspore/api_accuracy_checker/cmd_parser.py +63 -1
- msprobe/mindspore/api_accuracy_checker/compute_element.py +59 -24
- msprobe/mindspore/api_accuracy_checker/data_manager.py +264 -0
- msprobe/mindspore/api_accuracy_checker/main.py +27 -3
- msprobe/mindspore/api_accuracy_checker/multi_api_accuracy_checker.py +206 -0
- msprobe/mindspore/api_accuracy_checker/multi_data_manager.py +58 -0
- msprobe/mindspore/api_accuracy_checker/type_mapping.py +22 -5
- msprobe/mindspore/api_accuracy_checker/utils.py +34 -17
- msprobe/mindspore/cell_processor.py +58 -13
- msprobe/mindspore/common/const.py +35 -13
- msprobe/mindspore/common/log.py +5 -9
- msprobe/mindspore/common/utils.py +60 -5
- msprobe/mindspore/compare/distributed_compare.py +15 -28
- msprobe/mindspore/compare/ms_compare.py +319 -158
- msprobe/mindspore/compare/ms_graph_compare.py +99 -49
- msprobe/mindspore/debugger/debugger_config.py +20 -14
- msprobe/mindspore/debugger/precision_debugger.py +43 -13
- msprobe/mindspore/dump/dump_tool_factory.py +18 -1
- msprobe/mindspore/dump/hook_cell/api_registry.py +23 -3
- msprobe/mindspore/dump/hook_cell/primitive_hooks.py +203 -0
- msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +107 -10
- msprobe/mindspore/dump/hook_cell/wrap_api.py +21 -13
- msprobe/mindspore/dump/jit_dump.py +56 -20
- msprobe/mindspore/dump/kernel_graph_dump.py +19 -5
- msprobe/mindspore/dump/kernel_kbyk_dump.py +19 -6
- msprobe/mindspore/dym_loader/hook_dynamic_loader.cc +140 -0
- msprobe/mindspore/dym_loader/hook_dynamic_loader.h +53 -0
- msprobe/mindspore/free_benchmark/api_pynative_self_check.py +162 -41
- msprobe/mindspore/free_benchmark/common/config.py +15 -0
- msprobe/mindspore/free_benchmark/common/handler_params.py +15 -1
- msprobe/mindspore/free_benchmark/common/utils.py +37 -8
- msprobe/mindspore/free_benchmark/data/support_wrap_ops.yaml +0 -204
- msprobe/mindspore/free_benchmark/handler/base_handler.py +20 -5
- msprobe/mindspore/free_benchmark/handler/check_handler.py +21 -7
- msprobe/mindspore/free_benchmark/handler/fix_handler.py +18 -3
- msprobe/mindspore/free_benchmark/handler/handler_factory.py +21 -6
- msprobe/mindspore/free_benchmark/perturbation/add_noise.py +23 -8
- msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +29 -5
- msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +25 -10
- msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +45 -19
- msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +29 -8
- msprobe/mindspore/free_benchmark/perturbation/no_change.py +16 -1
- msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +22 -7
- msprobe/mindspore/free_benchmark/self_check_tool_factory.py +17 -2
- msprobe/mindspore/grad_probe/global_context.py +44 -14
- msprobe/mindspore/grad_probe/grad_analyzer.py +27 -13
- msprobe/mindspore/grad_probe/grad_monitor.py +16 -1
- msprobe/mindspore/grad_probe/grad_stat_csv.py +33 -5
- msprobe/mindspore/grad_probe/hook.py +24 -10
- msprobe/mindspore/grad_probe/utils.py +18 -5
- msprobe/mindspore/ms_config.py +22 -15
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +20 -6
- msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +15 -0
- msprobe/mindspore/runtime.py +15 -0
- msprobe/mindspore/service.py +75 -150
- msprobe/mindspore/task_handler_factory.py +15 -0
- msprobe/msprobe.py +24 -7
- msprobe/pytorch/__init__.py +23 -3
- msprobe/pytorch/api_accuracy_checker/common/config.py +81 -2
- msprobe/pytorch/api_accuracy_checker/common/utils.py +53 -21
- msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +19 -2
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +50 -25
- msprobe/pytorch/api_accuracy_checker/compare/compare.py +51 -21
- msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +23 -6
- msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +28 -8
- msprobe/pytorch/api_accuracy_checker/config.yaml +1 -1
- msprobe/pytorch/api_accuracy_checker/generate_op_script/config_op.json +9 -0
- msprobe/pytorch/api_accuracy_checker/generate_op_script/op_generator.py +454 -0
- msprobe/pytorch/api_accuracy_checker/generate_op_script/operator_replication.template +365 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +73 -33
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +44 -18
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +32 -11
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +122 -172
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +158 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +30 -24
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +68 -31
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +27 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/dump_dispatch.py +115 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +26 -9
- 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 +18 -3
- msprobe/pytorch/bench_functions/apply_adam_w.py +15 -0
- msprobe/pytorch/bench_functions/confusion_transpose.py +20 -1
- msprobe/pytorch/bench_functions/fast_gelu.py +15 -0
- msprobe/pytorch/bench_functions/layer_norm_eval.py +15 -0
- msprobe/pytorch/bench_functions/linear.py +15 -0
- msprobe/pytorch/bench_functions/matmul_backward.py +33 -6
- msprobe/pytorch/bench_functions/npu_fusion_attention.py +280 -157
- msprobe/pytorch/bench_functions/rms_norm.py +15 -0
- msprobe/pytorch/bench_functions/rotary_mul.py +32 -9
- msprobe/pytorch/bench_functions/scaled_mask_softmax.py +15 -0
- msprobe/pytorch/bench_functions/swiglu.py +29 -6
- msprobe/pytorch/common/__init__.py +15 -0
- msprobe/pytorch/common/log.py +18 -6
- msprobe/pytorch/common/parse_json.py +31 -16
- msprobe/pytorch/common/utils.py +96 -40
- msprobe/pytorch/compare/distributed_compare.py +13 -14
- msprobe/pytorch/compare/match.py +15 -0
- msprobe/pytorch/compare/pt_compare.py +44 -10
- msprobe/pytorch/debugger/debugger_config.py +69 -52
- msprobe/pytorch/debugger/precision_debugger.py +72 -24
- msprobe/pytorch/dump/kernel_dump/kernel_config.py +33 -0
- msprobe/pytorch/free_benchmark/__init__.py +20 -5
- msprobe/pytorch/free_benchmark/common/constant.py +15 -0
- msprobe/pytorch/free_benchmark/common/counter.py +15 -0
- msprobe/pytorch/free_benchmark/common/enums.py +43 -0
- msprobe/pytorch/free_benchmark/common/params.py +23 -1
- msprobe/pytorch/free_benchmark/common/utils.py +43 -5
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +47 -9
- msprobe/pytorch/free_benchmark/compare/single_benchmark.py +17 -0
- msprobe/pytorch/free_benchmark/main.py +19 -4
- msprobe/pytorch/free_benchmark/perturbed_layers/base_layer.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/layer_factory.py +19 -4
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +18 -1
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +21 -4
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +28 -2
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +19 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/no_change.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/npu_base_layser.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/run_cpu.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +65 -16
- msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +21 -5
- msprobe/pytorch/free_benchmark/result_handlers/handler_factory.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +19 -4
- msprobe/pytorch/function_factory.py +17 -2
- msprobe/pytorch/functional/module_dump.py +84 -0
- msprobe/pytorch/grad_probe/grad_monitor.py +23 -6
- msprobe/pytorch/grad_probe/grad_stat_csv.py +40 -10
- msprobe/pytorch/hook_module/__init__.py +16 -1
- msprobe/pytorch/hook_module/api_registry.py +13 -8
- msprobe/pytorch/hook_module/hook_module.py +17 -19
- msprobe/pytorch/hook_module/support_wrap_ops.yaml +1 -0
- msprobe/pytorch/hook_module/utils.py +4 -6
- msprobe/pytorch/hook_module/wrap_aten.py +12 -11
- msprobe/pytorch/hook_module/wrap_distributed.py +6 -7
- msprobe/pytorch/hook_module/wrap_functional.py +21 -20
- msprobe/pytorch/hook_module/wrap_npu_custom.py +9 -17
- msprobe/pytorch/hook_module/wrap_tensor.py +4 -6
- msprobe/pytorch/hook_module/wrap_torch.py +4 -6
- msprobe/pytorch/hook_module/wrap_vf.py +4 -6
- msprobe/pytorch/module_processer.py +18 -6
- msprobe/pytorch/monitor/anomaly_analyse.py +201 -0
- msprobe/pytorch/monitor/anomaly_detect.py +340 -0
- msprobe/pytorch/monitor/distributed/distributed_ops.yaml +19 -0
- msprobe/pytorch/monitor/distributed/stack_blacklist.yaml +5 -0
- msprobe/pytorch/monitor/distributed/wrap_distributed.py +272 -0
- msprobe/pytorch/monitor/features.py +108 -0
- msprobe/pytorch/monitor/module_hook.py +870 -0
- msprobe/pytorch/monitor/module_metric.py +193 -0
- msprobe/pytorch/monitor/module_spec_verifier.py +93 -0
- msprobe/pytorch/monitor/optimizer_collect.py +295 -0
- msprobe/pytorch/monitor/unittest/__init__.py +0 -0
- msprobe/pytorch/monitor/unittest/test_monitor.py +145 -0
- msprobe/pytorch/monitor/utils.py +250 -0
- msprobe/pytorch/monitor/visualizer.py +59 -0
- msprobe/pytorch/online_dispatch/__init__.py +2 -3
- msprobe/pytorch/online_dispatch/compare.py +38 -48
- msprobe/pytorch/online_dispatch/dispatch.py +50 -25
- msprobe/pytorch/online_dispatch/dump_compare.py +21 -9
- msprobe/pytorch/online_dispatch/single_compare.py +60 -39
- msprobe/pytorch/online_dispatch/torch_ops_config.yaml +9 -1
- msprobe/pytorch/online_dispatch/utils.py +48 -23
- msprobe/pytorch/parse.py +15 -0
- msprobe/pytorch/parse_tool/cli.py +5 -6
- msprobe/pytorch/parse_tool/lib/compare.py +19 -26
- msprobe/pytorch/parse_tool/lib/config.py +1 -1
- msprobe/pytorch/parse_tool/lib/parse_tool.py +4 -2
- msprobe/pytorch/parse_tool/lib/utils.py +40 -55
- msprobe/pytorch/parse_tool/lib/visualization.py +3 -1
- msprobe/pytorch/pt_config.py +192 -40
- msprobe/pytorch/service.py +110 -35
- msprobe/visualization/__init__.py +14 -0
- msprobe/visualization/builder/__init__.py +14 -0
- msprobe/visualization/builder/graph_builder.py +165 -0
- msprobe/visualization/builder/msprobe_adapter.py +205 -0
- msprobe/visualization/compare/__init__.py +14 -0
- msprobe/visualization/compare/graph_comparator.py +130 -0
- msprobe/visualization/compare/mode_adapter.py +211 -0
- msprobe/visualization/graph/__init__.py +14 -0
- msprobe/visualization/graph/base_node.py +124 -0
- msprobe/visualization/graph/graph.py +200 -0
- msprobe/visualization/graph/node_colors.py +95 -0
- msprobe/visualization/graph/node_op.py +39 -0
- msprobe/visualization/graph_service.py +214 -0
- msprobe/visualization/utils.py +232 -0
- mindstudio_probe-1.0.4.dist-info/RECORD +0 -276
- msprobe/docs/04.acl_config_examples.md +0 -76
- msprobe/mindspore/free_benchmark/decorator/dec_forward.py +0 -43
- msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +0 -107
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/ssl_config.py +0 -10
- msprobe/pytorch/functional/dump_module.py +0 -39
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.1.dist-info}/LICENSE +0 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.1.dist-info}/top_level.txt +0 -0
- /msprobe/{mindspore/free_benchmark/decorator → pytorch/monitor}/__init__.py +0 -0
- /msprobe/pytorch/{functional/data_processor.py → monitor/distributed/__init__.py} +0 -0
|
@@ -11,6 +11,8 @@ functional: # functional为算子类别,找到对应的类别,在该类别
|
|
|
11
11
|
- conv3d
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
+
删除API的场景:部分模型代码逻辑会存在API原生类型校验,工具执行dump操作时,对模型的API封装可能与模型的原生API类型不一致,此时可能引发校验失败,详见《[FAQ](FAQ.md)》中“异常情况”的第10和11条。
|
|
15
|
+
|
|
14
16
|
## 1 接口介绍
|
|
15
17
|
|
|
16
18
|
### 1.1 PrecisionDebugger
|
|
@@ -23,7 +25,7 @@ functional: # functional为算子类别,找到对应的类别,在该类别
|
|
|
23
25
|
PrecisionDebugger(config_path=None, task=None, dump_path=None, level=None, model=None, step=None)
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
1. config_path:指定 dump 配置文件路径;model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"
|
|
28
|
+
1. config_path:指定 dump 配置文件路径;model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"时,必须在该接口或 **start** 接口中配置该参数。其他参数均在 [config.json](../config.json) 文件中可配,详细配置可见 [config.json 介绍](./02.config_introduction.md)。
|
|
27
29
|
2. 此接口的参数均不是必要,且优先级高于 [config.json](../config.json) 文件中的配置,但可配置的参数相比 config.json 较少。
|
|
28
30
|
|
|
29
31
|
### 1.2 start
|
|
@@ -33,12 +35,15 @@ PrecisionDebugger(config_path=None, task=None, dump_path=None, level=None, model
|
|
|
33
35
|
**原型**:
|
|
34
36
|
|
|
35
37
|
```Python
|
|
36
|
-
debugger.start()
|
|
38
|
+
debugger.start(model=None)
|
|
37
39
|
```
|
|
38
40
|
|
|
41
|
+
1. model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"时,必须在该接口或 **PrecisionDebugger** 接口中配置该参数。
|
|
42
|
+
本接口中的 model 比 PrecisionDebugger 中 model 参数优先级更高,会覆盖 PrecisionDebugger 中的 model 参数。
|
|
43
|
+
|
|
39
44
|
### 1.3 stop
|
|
40
45
|
|
|
41
|
-
**功能说明**:停止精度数据采集。在 **start** 函数之后的任意位置添加。若需要 dump 反向数据,则需要添加在反向计算代码(如,loss.backward)之后。使用示例可参见 [2.1
|
|
46
|
+
**功能说明**:停止精度数据采集。在 **start** 函数之后的任意位置添加。若需要 dump 反向数据,则需要添加在反向计算代码(如,loss.backward)之后。使用示例可参见 [2.1 快速上手](#21-快速上手)和 [2.2 采集完整的前反向数据](#22-采集完整的前反向数据)。
|
|
42
47
|
|
|
43
48
|
**原型**:
|
|
44
49
|
|
|
@@ -66,9 +71,89 @@ forward_backward_dump_end()
|
|
|
66
71
|
debugger.step()
|
|
67
72
|
```
|
|
68
73
|
|
|
74
|
+
### 1.6 module_dump
|
|
75
|
+
|
|
76
|
+
**功能说明**:开启模块级精度数据dump。该接口为函数模块化接口,即只会dump输入的模块数据,不会dump子模块和模块内API的数据。
|
|
77
|
+
需要配合start、stop和step等接口使用。使用示例可参考[2.4 采集函数模块化数据](#24-采集函数模块化数据)
|
|
78
|
+
|
|
79
|
+
**原型**:
|
|
80
|
+
|
|
81
|
+
```Python
|
|
82
|
+
module_dump(module, module_name)
|
|
83
|
+
```
|
|
84
|
+
**参数说明**:
|
|
85
|
+
|
|
86
|
+
1. module: 网络中实例化好的nn.Module类对象。数据类型:torch.nn.Module。必选。
|
|
87
|
+
2. module_name:用户自定义该module名称,主要用于dump数据的命名。数据类型:str。必选。
|
|
88
|
+
|
|
89
|
+
### 1.7 module_dump_end
|
|
90
|
+
|
|
91
|
+
**功能说明**:结束模块级精度数据dump。在module_dump和module_dump_end之间的API或者Module,除了传入的module,其他数据均不会被dump。
|
|
92
|
+
在执行完module_dump_end后数据恢复正常的dump模式。
|
|
93
|
+
|
|
94
|
+
**原型**:
|
|
95
|
+
|
|
96
|
+
```Python
|
|
97
|
+
module_dump_end()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 1.8 seed_all
|
|
101
|
+
|
|
102
|
+
**功能说明**:对于网络中随机性的固定和确定性计算,msprobe工具提供了seed_all接口用于固定网络中的随机性和开启确定性计算。
|
|
103
|
+
|
|
104
|
+
**原型**:
|
|
105
|
+
```python
|
|
106
|
+
seed_all(seed=1234, mode=False)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**参数说明**:
|
|
110
|
+
|
|
111
|
+
1. seed: 随机性种子。参数示例: seed=1000。默认值:1234。非必选
|
|
112
|
+
2. mode:确定性计算模式。可配置True或False。参数示例:mode=True。默认为False。非必选(注意:确定性计算会导致API执行性能降低,建议在发现模型多次执行结果不同的情况下开启)
|
|
113
|
+
|
|
114
|
+
seed_all 函数可固定随机数的范围如下表。
|
|
115
|
+
|
|
116
|
+
| API | 固定随机数 |
|
|
117
|
+
| ---------------------------------------- | --------------------------- |
|
|
118
|
+
| os.environ['PYTHONHASHSEED'] = str(seed) | 禁止 Python 中的 hash 随机化 |
|
|
119
|
+
| os.environ['HCCL_DETERMINISTIC'] = True | 固定通信算子计算的确定性 |
|
|
120
|
+
| random.seed(seed) | 设置 random 随机生成器的种子 |
|
|
121
|
+
| np.random.seed(seed) | 设置 numpy 中随机生成器的种子 |
|
|
122
|
+
| torch.manual_seed(seed) | 设置当前 CPU 的随机种子 |
|
|
123
|
+
| torch.cuda.manual_seed(seed) | 设置当前 GPU 的随机种子 |
|
|
124
|
+
| torch.cuda.manual_seed_all(seed) | 设置所有 GPU 的随机种子 |
|
|
125
|
+
| torch_npu.npu.manual_seed(seed) | 设置当前 NPU 的随机种子 |
|
|
126
|
+
| torch_npu.npu.manual_seed_all(seed) | 设置所有 NPU 的随机种子 |
|
|
127
|
+
| torch.use_deterministic_algorithms(True) | CUDA/CANN 使能确定性计算(注意mode为True时才会调用该方法开启确定性 |
|
|
128
|
+
| torch.backends.cudnn.enable=False | 关闭 cuDNN |
|
|
129
|
+
| torch.backends.cudnn.benchmark=False | cuDNN 确定性地选择算法 |
|
|
130
|
+
| torch.backends.cudnn.deterministic=True | cuDNN 仅使用确定性的卷积算法 |
|
|
131
|
+
|
|
132
|
+
需要保证 CPU 或 GPU 以及 NPU 的模型输入完全一致,dump 数据的比对才有意义,seed_all 并不能保证模型输入完全一致,如下表所示场景需要保证输入的一致性。
|
|
133
|
+
|
|
134
|
+
| 场景 | 固定方法 |
|
|
135
|
+
| --------------- | ------------- |
|
|
136
|
+
| 数据集的 shuffle | 关闭 shuffle。 |
|
|
137
|
+
| dropout | 关闭 dropout。 |
|
|
138
|
+
|
|
139
|
+
关闭 shuffle 示例:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
train_loader = torch.utils.data.DataLoader(
|
|
143
|
+
train_dataset,
|
|
144
|
+
batch_size = batch_size,
|
|
145
|
+
shuffle = False,
|
|
146
|
+
num_workers = num_workers
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
关闭 dropout:
|
|
151
|
+
|
|
152
|
+
在使用 `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.
|
|
153
|
+
|
|
69
154
|
## 2 示例代码
|
|
70
155
|
|
|
71
|
-
### 2.1
|
|
156
|
+
### 2.1 快速上手
|
|
72
157
|
|
|
73
158
|
这个示例定义了一个 nn.Module 类型的简单网络,在进行数据采集时使用原型函数 PrecisionDebugger 传入 config_path 参数和 model 参数。
|
|
74
159
|
|
|
@@ -78,8 +163,9 @@ import torch
|
|
|
78
163
|
import torch.nn as nn
|
|
79
164
|
import torch_npu # 需安装 torch_npu
|
|
80
165
|
import torch.nn.functional as F
|
|
81
|
-
from msprobe.pytorch import PrecisionDebugger
|
|
82
|
-
|
|
166
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
167
|
+
# 在模型训练开始前固定随机性
|
|
168
|
+
seed_all()
|
|
83
169
|
|
|
84
170
|
torch.npu.set_device("npu:0")
|
|
85
171
|
# 定义网络
|
|
@@ -110,8 +196,9 @@ if __name__ == "__main__":
|
|
|
110
196
|
### 2.2 采集完整的前反向数据
|
|
111
197
|
|
|
112
198
|
```Python
|
|
113
|
-
from msprobe.pytorch import PrecisionDebugger
|
|
114
|
-
|
|
199
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
200
|
+
# 在模型训练开始前固定随机性
|
|
201
|
+
seed_all()
|
|
115
202
|
# 请勿将PrecisionDebugger的初始化流程插入到循环代码中
|
|
116
203
|
debugger = PrecisionDebugger(config_path="./config.json", dump_path="./dump_path")
|
|
117
204
|
# 模型、损失函数的定义及初始化等操作
|
|
@@ -130,8 +217,9 @@ for data, label in data_loader:
|
|
|
130
217
|
### 2.3 采集指定代码块的前反向数据
|
|
131
218
|
|
|
132
219
|
```Python
|
|
133
|
-
from msprobe.pytorch import PrecisionDebugger
|
|
134
|
-
|
|
220
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
221
|
+
# 在模型训练开始前固定随机性
|
|
222
|
+
seed_all()
|
|
135
223
|
# 请勿将PrecisionDebugger的初始化流程插入到循环代码中
|
|
136
224
|
debugger = PrecisionDebugger(config_path="./config.json", dump_path="./dump_path")
|
|
137
225
|
|
|
@@ -149,7 +237,46 @@ for data, label in data_loader:
|
|
|
149
237
|
debugger.step() # 结束一个step的dump
|
|
150
238
|
```
|
|
151
239
|
|
|
240
|
+
### 2.4 采集函数模块化数据
|
|
241
|
+
|
|
242
|
+
```Python
|
|
243
|
+
# 根据需要import包
|
|
244
|
+
import torch
|
|
245
|
+
import torch.nn as nn
|
|
246
|
+
import torch_npu # 需安装 torch_npu
|
|
247
|
+
import torch.nn.functional as F
|
|
248
|
+
from msprobe.pytorch import PrecisionDebugger, module_dump, module_dump_end
|
|
249
|
+
|
|
250
|
+
torch.npu.set_device("npu:0")
|
|
251
|
+
# 定义网络
|
|
252
|
+
class ModuleOP(nn.Module):
|
|
253
|
+
def __init__(self) -> None:
|
|
254
|
+
super().__init__()
|
|
255
|
+
self.linear_1 = nn.Linear(in_features=8, out_features=4)
|
|
256
|
+
self.linear_2 = nn.Linear(in_features=4, out_features=2)
|
|
152
257
|
|
|
258
|
+
def forward(self, x):
|
|
259
|
+
x1 = self.linear_1(x)
|
|
260
|
+
x2 = self.linear_2(x1)
|
|
261
|
+
r1 = F.relu(x2)
|
|
262
|
+
return r1
|
|
263
|
+
|
|
264
|
+
if __name__ == "__main__":
|
|
265
|
+
module = ModuleOP()
|
|
266
|
+
# 注册工具
|
|
267
|
+
debugger = PrecisionDebugger(config_path='./config.json')
|
|
268
|
+
debugger.start() # 开启数据dump
|
|
269
|
+
|
|
270
|
+
x = torch.randn(10, 8)
|
|
271
|
+
# ... # start和module_dump接口之间的数据正常dump
|
|
272
|
+
module_dump(module, "MyModuleOP") # 开启模块级精度数据dump
|
|
273
|
+
out = module(x) # module内部的child modules或API不会被dump
|
|
274
|
+
module_dump_end() # 关闭模块级精度数据dump
|
|
275
|
+
loss = out.sum() # module_dump_end和stop接口之间的数据正常dump
|
|
276
|
+
loss.backward()
|
|
277
|
+
|
|
278
|
+
debugger.stop() # 关闭数据dump
|
|
279
|
+
```
|
|
153
280
|
|
|
154
281
|
## 3 dump 结果文件介绍
|
|
155
282
|
|
|
@@ -164,7 +291,7 @@ for data, label in data_loader:
|
|
|
164
291
|
| | | | ├── MyModule.0.forward.input.pt # 开启模块级精度数据dump时存在模块级的dump数据文件
|
|
165
292
|
| | | | ...
|
|
166
293
|
| | | | └── Fcuntion.linear.5.backward.output.pt
|
|
167
|
-
│ | | ├── dump.json # 保存前反向算子、算子的统计量信息或溢出算子信息。包含dump数据的API名称(命名格式为:`{api_type}_{api_name}_{API调用次数}_{前向反向}_{input/output}.{参数序号}`)、dtype、 shape、各数据的max、min、mean、L2norm统计信息以及当配置summary_mode="md5"时的
|
|
294
|
+
│ | | ├── dump.json # 保存前反向算子、算子的统计量信息或溢出算子信息。包含dump数据的API名称(命名格式为:`{api_type}_{api_name}_{API调用次数}_{前向反向}_{input/output}.{参数序号}`)、dtype、 shape、各数据的max、min、mean、L2norm统计信息以及当配置summary_mode="md5"时的CRC-32数据。其中,“参数序号”表示该API下的第n个参数,例如1,则为第一个参数,若该参数为list格式,则根据list继续排序,例如1.1,表示该API的第1个参数的第1个子参数;L2norm表示L2范数(平方根)
|
|
168
295
|
│ | | ├── stack.json # 算子调用栈信息
|
|
169
296
|
│ | | └── construct.json # 分层分级结构
|
|
170
297
|
│ | ├── rank1
|
|
@@ -183,7 +310,7 @@ for data, label in data_loader:
|
|
|
183
310
|
|
|
184
311
|
dump 过程中,pt 文件在对应算子或者模块被执行后就会落盘,而 json 文件则需要在正常执行 PrecisionDebugger.stop() 后才会写入完整数据,异常的程序终止会保存终止前被执行算子的相关 npy 文件,可能会导致 json 文件中数据丢失。
|
|
185
312
|
|
|
186
|
-
其中 rank 为设备上各卡的 ID,每张卡上 dump 的数据会生成对应 dump 目录。非分布式场景下没有rank ID,目录名称为rank。
|
|
313
|
+
其中 rank 为设备上各卡的 ID,每张卡上 dump 的数据会生成对应 dump 目录。非分布式场景下没有 rank ID,目录名称为 rank。
|
|
187
314
|
|
|
188
315
|
pt 文件保存的前缀和 PyTorch 对应关系如下:
|
|
189
316
|
|
|
@@ -192,7 +319,10 @@ pt 文件保存的前缀和 PyTorch 对应关系如下:
|
|
|
192
319
|
| Tensor | torch.Tensor |
|
|
193
320
|
| Torch | torch |
|
|
194
321
|
| Functional | torch.nn.functional |
|
|
195
|
-
| NPU | NPU亲和算子 |
|
|
322
|
+
| NPU | NPU 亲和算子 |
|
|
196
323
|
| VF | torch._VF |
|
|
197
324
|
| Aten | torch.ops.aten |
|
|
198
325
|
| Distributed | torch.distributed |
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
@@ -1,21 +1,64 @@
|
|
|
1
|
-
# MindSpore 场景的精度数据采集
|
|
2
1
|
|
|
3
|
-
msprobe
|
|
2
|
+
# msprobe 工具 MindSpore场景精度数据采集指南
|
|
4
3
|
|
|
5
|
-
精度数据采集功能的配置示例见[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)。
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
## 1. 专业名词解释
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
* **静态图**:在编译时就确定网络结构,静态图模式拥有较高的训练性能,但难以调试。
|
|
8
|
+
* **动态图**:运行时动态构建网络,相较于静态图模式虽然易于调试,但难以高效执行。
|
|
9
|
+
* **高阶 API**:如 `mindspore.train.Model`,封装了训练过程的高级接口。
|
|
10
|
+
* **JIT(Just-In-Time 编译)**:MindSpore提供JIT(just-in-time)技术进一步进行性能优化。JIT模式会通过AST树解析的方式或者Python字节码解析的方式,将代码解析为一张中间表示图(IR,intermediate representation)。IR图作为该代码的唯一表示,编译器通过对该IR图的优化,来达到对代码的优化,提高运行性能。与动态图模式相对应,这种JIT的编译模式被称为静态图模式。
|
|
11
|
+
* **Primitive op**:MindSpore 中的基本算子,通常由 `mindspore.ops.Primitive` 定义,提供底层的算子操作接口。
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 2. 工具安装
|
|
15
|
+
|
|
16
|
+
请参见[《msprobe 工具安装指南》](./01.installation.md)。
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## 3. 快速入门
|
|
20
|
+
|
|
21
|
+
以下通过一个简单的示例,展示如何在 MindSpore 中使用 msprobe 工具进行精度数据采集。
|
|
22
|
+
|
|
23
|
+
您可以参考 [动态图快速入门示例](./data_dump_Mindspore/dynamic_graph_quick_start_example.md) 了解详细步骤。
|
|
24
|
+
|
|
25
|
+
## 4. 概述
|
|
15
26
|
|
|
16
|
-
|
|
27
|
+
msprobe 工具通过在训练脚本中添加 `PrecisionDebugger` 接口并启动训练的方式,采集模型在运行过程中的精度数据。该工具支持对MindSpore的静态图和动态图场景进行不同Level等级的精度数据采集。
|
|
17
28
|
|
|
18
|
-
|
|
29
|
+
|
|
30
|
+
## 5. 场景介绍
|
|
31
|
+
|
|
32
|
+
### 5.1 静态图场景
|
|
33
|
+
在静态图场景下,msprobe 仅支持 **L2 Level** 的数据采集。
|
|
34
|
+
- **L2 Level(Kernel 级)** :采集底层算子的输入输出数据,适用于深入分析算子级别的精度问题。
|
|
35
|
+
|
|
36
|
+
采集方式请参见[示例代码 > 静态图场景](#71-静态图场景)。详细介绍请参见[《config.json 配置文件介绍》](./02.config_introduction.md#11-通用配置)中的“level 参数”和[《config.json 配置示例》](./03.config_examples.md#2-mindspore-静态图场景) 中的“MindSpore 静态图场景”。
|
|
37
|
+
|
|
38
|
+
### 5.2 动态图场景
|
|
39
|
+
在动态图场景下,msprobe 支持 **L0** 、**L1** 、**mix** 、**L2 Level** 的数据采集,具体分为以下几种情况:
|
|
40
|
+
- **使用高阶 API(如 `Model 高阶API`)** :
|
|
41
|
+
- 需要使用 `MsprobeStep` 回调类来控制数据采集的启停,适用于 **L0** 、**L1** 、**mix** 、**L2** 数据采集。
|
|
42
|
+
|
|
43
|
+
- **未使用高阶 API** :
|
|
44
|
+
- 手动在训练循环中调用 `start`、`stop`、`step` 等接口,适用于 **L0** 、**L1** 、**mix** 、**L2** 数据采集。
|
|
45
|
+
|
|
46
|
+
采集方式请参见[示例代码 > 动态图场景](#72-动态图场景-)。
|
|
47
|
+
|
|
48
|
+
> **注意** :动态图模式下,使用 `PSJit` 或 `PIJit` 装饰的部分实际以静态图模式执行,此时的 **Kernel 级(L2 Level)** 数据采集方式与静态图场景相同。
|
|
49
|
+
- **L0 Level(Cell 级)** :采集 `Cell` 对象的数据,适用于需要分析特定网络模块的情况。
|
|
50
|
+
|
|
51
|
+
- **L1 Level(API 级)** :采集 MindSpore API 的输入输出数据,适用于定位 API 层面的精度问题。
|
|
52
|
+
|
|
53
|
+
- **mix(模块级 + API 级)** :在 `L0` 和 `L1` 级别的基础上同时采集模块级和 API 级数据,适用于需要分析模块和 API 层面精度问题的场景。
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
详细介绍请参见[《config.json 配置文件介绍》](./02.config_introduction.md#11-通用配置)中的“level 参数”和[《config.json 配置示例》](./03.config_examples.md#3-mindspore-动态图场景) 中的“MindSpore 动态图场景”。
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## 6 接口介绍
|
|
60
|
+
|
|
61
|
+
### 6.1 msprobe.mindspore.PrecisionDebugger
|
|
19
62
|
|
|
20
63
|
**功能说明**:通过加载 dump 配置文件的方式来确定 dump 操作的详细配置。
|
|
21
64
|
|
|
@@ -25,12 +68,13 @@ ops: # ops为算子类别,找到对应的类别,在该类别下按照下列
|
|
|
25
68
|
PrecisionDebugger(config_path=None)
|
|
26
69
|
```
|
|
27
70
|
|
|
71
|
+
**参数说明**:
|
|
72
|
+
|
|
28
73
|
1. config_path:指定 dump 配置文件路径,string 类型。参数示例:"./config.json"。未配置该路径时,默认使用 [config.json](../config.json) 文件的默认配置,配置选项含义可见 [config.json 介绍](./02.config_introduction.md)。
|
|
29
74
|
|
|
30
|
-
####
|
|
75
|
+
#### 6.1.1 start
|
|
31
76
|
|
|
32
|
-
**功能说明**:启动精度数据采集。需在模型执行模式(静态图/动态图、O0/O1/O2
|
|
33
|
-
静态图场景下,必须在模型初始化及 mindspore.communication.init 调用前添加;动态图场景下,如果进行kernel级别("L2" level)dump或没有使用 [Model](https://www.mindspore.cn/tutorials/zh-CN/r2.3.1/advanced/model.html) 高阶 API 进行训练,则需要与 stop 函数一起添加在 for 循环内,否则只有需要传入model参数时,才使用该接口。
|
|
77
|
+
**功能说明**:启动精度数据采集。需在模型执行模式(静态图/动态图、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参数时,才使用该接口。
|
|
34
78
|
|
|
35
79
|
**原型**:
|
|
36
80
|
|
|
@@ -38,9 +82,11 @@ PrecisionDebugger(config_path=None)
|
|
|
38
82
|
start(model=None)
|
|
39
83
|
```
|
|
40
84
|
|
|
41
|
-
|
|
85
|
+
**参数说明**:
|
|
42
86
|
|
|
43
|
-
|
|
87
|
+
1. model:指具体的 mindspore.nn.Cell对象,默认不配置。Cell级别("L0" level)dump 与 "mix" level dump 时,必须传入 model 才可以采集 model 内的所有Cell 对象数据。API级别("L1" level)dump 时,传入 model 可以采集 model 内包含 primitive op 对象在内的所有 API 数据,若不传入 model 参数,则只采集非 primitive op 的 API 数据。
|
|
88
|
+
|
|
89
|
+
#### 6.1.2 stop
|
|
44
90
|
|
|
45
91
|
**功能说明**:停止数据采集。在 **start** 函数之后的任意位置添加。需要与 start 函数一起添加在 for 循环内。若需要 dump 反向数据,则需要添加在反向计算代码之后。**仅未使用 Model 高阶 API 的动态图场景支持。**
|
|
46
92
|
|
|
@@ -50,7 +96,7 @@ start(model=None)
|
|
|
50
96
|
stop()
|
|
51
97
|
```
|
|
52
98
|
|
|
53
|
-
####
|
|
99
|
+
#### 6.1.3 step
|
|
54
100
|
|
|
55
101
|
**功能说明**:在最后一个 **stop** 函数后或一个 step 训练结束的位置添加。**仅未使用 Model 高阶 API 的动态图场景支持。**
|
|
56
102
|
|
|
@@ -60,9 +106,25 @@ stop()
|
|
|
60
106
|
step()
|
|
61
107
|
```
|
|
62
108
|
|
|
63
|
-
|
|
109
|
+
#### 6.1.4 forward_backward_dump_end
|
|
110
|
+
|
|
111
|
+
**功能说明**:在 **start** 函数和在 **stop** 函数之间调用,表示采集 **start** 到 **forward_backward_dump_end**之间的L1级别的正反向数据。
|
|
112
|
+
|
|
113
|
+
**仅支持L1级别数据采集场景。**
|
|
114
|
+
|
|
115
|
+
**L1级别数据中的jit数据采集行为不受此接口影响。**
|
|
116
|
+
|
|
117
|
+
**仅未使用 Model 高阶 API 的动态图场景支持。**
|
|
118
|
+
|
|
119
|
+
**原型**:
|
|
120
|
+
|
|
121
|
+
```Python
|
|
122
|
+
forward_backward_dump_end()
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### 6.2 msprobe.mindspore.common.utils.MsprobeStep
|
|
64
126
|
|
|
65
|
-
**功能说明**:MindSpore Callback类,自动在每个step开始时调用start()接口,在每个step结束时调用stop()、step()接口。实现使用 Model 高阶 API 的动态图场景下 L0、L1 级别的精度数据采集控制,控制粒度为单个 **Step** ,而 PrecisionDebugger.start, PrecisionDebugger.stop 接口的控制粒度任意训练代码段。
|
|
127
|
+
**功能说明**:MindSpore Callback类,自动在每个step开始时调用start()接口,在每个step结束时调用stop()、step()接口。实现使用 Model 高阶 API 的动态图场景下 L0、L1、mix 级别的精度数据采集控制,控制粒度为单个 **Step** ,而 PrecisionDebugger.start, PrecisionDebugger.stop 接口的控制粒度任意训练代码段。
|
|
66
128
|
|
|
67
129
|
**原型**:
|
|
68
130
|
|
|
@@ -70,28 +132,55 @@ step()
|
|
|
70
132
|
MsprobeStep(debugger)
|
|
71
133
|
```
|
|
72
134
|
|
|
135
|
+
**参数说明**:
|
|
136
|
+
|
|
73
137
|
1. debugger:PrecisionDebugger对象。
|
|
74
138
|
|
|
75
|
-
|
|
139
|
+
### 6.3 msprobe.mindspore.seed_all
|
|
76
140
|
|
|
77
|
-
|
|
141
|
+
**功能说明**:用于固定网络中的随机性和开启确定性计算。
|
|
78
142
|
|
|
79
|
-
|
|
143
|
+
**原型**:
|
|
144
|
+
```python
|
|
145
|
+
seed_all(seed=1234, mode=False, rm_dropout=True)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**参数说明**:
|
|
149
|
+
|
|
150
|
+
1. seed: 随机性种子,默认值:1234,非必选。参数示例: seed=1000。该参数用于 random、numpy.random, mindspore.common.Initializer、mindspore.nn.probability.distribution的随机数生成以及 Python 中 str、bytes、datetime 对象的 hash 算法。
|
|
151
|
+
|
|
152
|
+
2. mode:确定性计算使能,可配置 True 或 False,默认值:False,非必选。参数示例:mode=True。该参数设置为 True 后,将会开启算子确定性运行模式与归约类通信算子(AllReduce、ReduceScatter、Reduce)的确定性计算。注意:确定性计算会导致API执行性能降低,建议在发现模型多次执行结果不同的情况下开启。
|
|
153
|
+
|
|
154
|
+
3. rm_dropout:控制dropout失效的开关。可配置 True 或 False,默认值:True,非必选。参数示例:rm_dropout=True。该参数设置为 True 后,将会使mindspore.ops.Dropout,mindspore.ops.Dropout2D,mindspore.ops.Dropout3D,mindspore.mint.nn.Dropout和mindspore.mint.nn.functional.dropout失效,以避免因随机dropout造成的网络随机性。建议在采集mindspore数据前开启。注意:通过rm_dropout控制dropout失效或生效需要在初始化Dropout实例前调用才能生效。
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
## 7. 示例代码
|
|
160
|
+
|
|
161
|
+
### 7.1 静态图场景
|
|
162
|
+
|
|
163
|
+
```python
|
|
80
164
|
import mindspore as ms
|
|
81
165
|
ms.set_context(mode=ms.GRAPH_MODE, device_target="Ascend")
|
|
82
166
|
|
|
83
167
|
from msprobe.mindspore import PrecisionDebugger
|
|
84
168
|
debugger = PrecisionDebugger(config_path="./config.json")
|
|
85
169
|
debugger.start()
|
|
86
|
-
# 请勿将以上初始化流程置于模型实例化或mindspore.communication.init调用后
|
|
170
|
+
# 请勿将以上初始化流程置于模型实例化或 mindspore.communication.init 调用后
|
|
171
|
+
# 模型定义和训练代码
|
|
87
172
|
# ...
|
|
173
|
+
|
|
88
174
|
```
|
|
89
175
|
|
|
90
|
-
###
|
|
176
|
+
### 7.2 动态图场景
|
|
91
177
|
|
|
92
|
-
####
|
|
178
|
+
#### 7.2.1 L0 ,L1, mix 级别
|
|
93
179
|
|
|
94
|
-
|
|
180
|
+
##### 7.2.1.1 未使用 Model 高阶 API
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
```python
|
|
95
184
|
import mindspore as ms
|
|
96
185
|
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
97
186
|
|
|
@@ -103,60 +192,66 @@ debugger = PrecisionDebugger(config_path="./config.json")
|
|
|
103
192
|
model = Network()
|
|
104
193
|
# 数据集迭代的地方往往是模型开始训练的地方
|
|
105
194
|
for data, label in data_loader:
|
|
106
|
-
debugger.start() # 进行L1级别下非primitive op采集时调用
|
|
107
|
-
# debugger.start(model) # 进行L0级别或L1级别下primitive op的数据采集时调用
|
|
108
|
-
# 如下是模型每个step执行的逻辑
|
|
195
|
+
debugger.start() # 进行 L1 级别下非 primitive op 采集时调用
|
|
196
|
+
# debugger.start(model) # 进行 L0, mix 级别或 L1 级别下 primitive op 的数据采集时调用
|
|
197
|
+
# 如下是模型每个 step 执行的逻辑
|
|
109
198
|
grad_net = ms.grad(model)(data)
|
|
110
199
|
# ...
|
|
111
|
-
debugger.stop() # 关闭数据dump
|
|
112
|
-
debugger.step() #
|
|
200
|
+
debugger.stop() # 关闭数据 dump
|
|
201
|
+
debugger.step() # 更新迭代数
|
|
113
202
|
```
|
|
114
203
|
|
|
115
|
-
|
|
204
|
+
##### 7.2.1.2 使用 Model 高阶 API
|
|
116
205
|
|
|
117
|
-
|
|
206
|
+
|
|
207
|
+
```python
|
|
118
208
|
import mindspore as ms
|
|
209
|
+
from mindspore.train import Model
|
|
119
210
|
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
120
211
|
|
|
121
212
|
from msprobe.mindspore import PrecisionDebugger
|
|
213
|
+
from msprobe.mindspore.common.utils import MsprobeStep
|
|
122
214
|
debugger = PrecisionDebugger(config_path="./config.json")
|
|
123
|
-
debugger.start()
|
|
124
|
-
# 请勿将以上初始化流程置于模型实例化或mindspore.communication.init调用后
|
|
125
215
|
|
|
126
216
|
# 模型、损失函数的定义以及初始化等操作
|
|
127
217
|
# ...
|
|
218
|
+
|
|
128
219
|
model = Network()
|
|
129
|
-
#
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
# ...
|
|
220
|
+
# 只有进行 L0 级别下 Cell 对象,mix 级别,L1 级别下 primitive op 的数据采集时才需要调用
|
|
221
|
+
# debugger.start(model)
|
|
222
|
+
trainer = Model(model, loss_fn=loss_fn, optimizer=optimizer, metrics={'accuracy'})
|
|
223
|
+
trainer.train(1, train_dataset, callbacks=[MsprobeStep(debugger)])
|
|
134
224
|
```
|
|
135
225
|
|
|
136
|
-
#### 2.2
|
|
226
|
+
#### 7.2.2 L2 级别
|
|
137
227
|
|
|
138
|
-
|
|
228
|
+
##### 7.2.2.1 未使用 Model 高阶 API
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
```python
|
|
139
232
|
import mindspore as ms
|
|
140
|
-
from mindspore.train import Model
|
|
141
233
|
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
142
234
|
|
|
143
235
|
from msprobe.mindspore import PrecisionDebugger
|
|
144
|
-
from msprobe.mindspore.common.utils import MsprobeStep
|
|
145
236
|
debugger = PrecisionDebugger(config_path="./config.json")
|
|
237
|
+
debugger.start()
|
|
238
|
+
# 请勿将以上初始化流程置于模型实例化或 mindspore.communication.init 调用后
|
|
146
239
|
|
|
147
240
|
# 模型、损失函数的定义以及初始化等操作
|
|
148
241
|
# ...
|
|
149
|
-
|
|
150
242
|
model = Network()
|
|
151
|
-
#
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
243
|
+
# 数据集迭代的地方往往是模型开始训练的地方
|
|
244
|
+
for data, label in data_loader:
|
|
245
|
+
# 如下是模型每个 step 执行的逻辑
|
|
246
|
+
grad_net = ms.grad(model)(data)
|
|
247
|
+
# ...
|
|
155
248
|
```
|
|
156
249
|
|
|
157
|
-
#### 2.2.4 使用 Model 高阶 API(L2 级别)
|
|
158
250
|
|
|
159
|
-
|
|
251
|
+
##### 7.2.2.2 使用 Model 高阶 API
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
```python
|
|
160
255
|
import mindspore as ms
|
|
161
256
|
from mindspore.train import Model
|
|
162
257
|
ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
@@ -164,7 +259,7 @@ ms.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend")
|
|
|
164
259
|
from msprobe.mindspore import PrecisionDebugger
|
|
165
260
|
debugger = PrecisionDebugger(config_path="./config.json")
|
|
166
261
|
debugger.start()
|
|
167
|
-
# 请勿将以上初始化流程置于模型实例化或mindspore.communication.init调用后
|
|
262
|
+
# 请勿将以上初始化流程置于模型实例化或 mindspore.communication.init 调用后
|
|
168
263
|
|
|
169
264
|
# 模型、损失函数的定义以及初始化等操作
|
|
170
265
|
# ...
|
|
@@ -174,29 +269,17 @@ trainer = Model(model, loss_fn=loss_fn, optimizer=optimizer, metrics={'accuracy'
|
|
|
174
269
|
trainer.train(1, train_dataset)
|
|
175
270
|
```
|
|
176
271
|
|
|
177
|
-
##
|
|
178
|
-
|
|
179
|
-
### 3.1 MindSpore 静态图场景
|
|
180
|
-
|
|
181
|
-
训练结束后,工具将 dump 的数据保存在 dump_path 参数指定的目录下。
|
|
272
|
+
## 8. dump 结果文件介绍
|
|
182
273
|
|
|
183
|
-
|
|
274
|
+
### 8.1 静态图场景
|
|
184
275
|
|
|
185
|
-
|
|
276
|
+
训练结束后,数据将保存在 `dump_path` 指定的目录下,目录结构请参见 MindSpore 官方文档中的[数据对象目录](https://www.mindspore.cn/docs/zh-CN/r2.4.0/model_train/debug/dump.html)。
|
|
186
277
|
|
|
187
|
-
|
|
278
|
+
### 8.2 动态图场景
|
|
188
279
|
|
|
189
|
-
|
|
280
|
+
dump 结果目录结构示例如下:
|
|
190
281
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
### 3.2 MindSpore 动态图场景
|
|
194
|
-
|
|
195
|
-
训练结束后,工具将 dump 的数据保存在dump_path参数指定的目录下。
|
|
196
|
-
|
|
197
|
-
dump结果目录结构示例如下:
|
|
198
|
-
|
|
199
|
-
```bash
|
|
282
|
+
```lua
|
|
200
283
|
├── dump_path
|
|
201
284
|
│ ├── step0
|
|
202
285
|
│ | ├── rank0
|
|
@@ -204,11 +287,13 @@ dump结果目录结构示例如下:
|
|
|
204
287
|
| | | | ├── MintFunctional.relu.0.backward.input.0.npy
|
|
205
288
|
| | | | ├── Mint.abs.0.forward.input.0.npy
|
|
206
289
|
| | | | ├── Functional.split.0.forward.input.0.npy
|
|
290
|
+
| | | | ├── Tensor.__add__.0.forward.output.0.npy
|
|
207
291
|
| | | | ...
|
|
208
|
-
| | | |
|
|
209
|
-
| | | |
|
|
210
|
-
|
|
211
|
-
│ | | ├──
|
|
292
|
+
| | | | ├── Jit.AlexNet.0.forward.input.0.npy
|
|
293
|
+
| | | | ├── Primitive.conv2d.Conv2D.0.forward.input.0.npy
|
|
294
|
+
| | | | └── Cell.relu.ReLU.forward.0.input.0.npy
|
|
295
|
+
│ | | ├── dump.json # 保存前反向API、API的统计量信息或溢出API信息。包含dump数据的API名称或Cell名称(Api命名格式为:{api_type}_{api_name}_{API调用次数}_{前向反向}_{input/output}.{参数序号},Cell命名格式为:{Cell}_{cell_name}_{class_name}_{前向反向}.{index}.{input/output}.{参数序号})、dtype、 shape、各数据的max、min、mean、L2norm统计信息以及当配置summary_mode="md5"时的CRC-32数据。其中,“参数序号”表示该API或Cell下的第n个参数,例如1,则为第一个参数,若该参数为list格式,则根据list继续排序,例如1.1,表示该API或Cell的第1个参数的第1个子参数;L2norm表示L2范数(平方根)。
|
|
296
|
+
│ | | ├── stack.json # API 调用栈信息
|
|
212
297
|
│ | | └── construct.json # 分层分级结构,level为L1时,construct.json内容为空
|
|
213
298
|
│ | ├── rank1
|
|
214
299
|
| | | ├── dump_tensor_data
|
|
@@ -224,20 +309,44 @@ dump结果目录结构示例如下:
|
|
|
224
309
|
│ ├── step2
|
|
225
310
|
```
|
|
226
311
|
|
|
227
|
-
|
|
312
|
+
* `rank`:设备 ID,每张卡的数据保存在对应的 `rank{ID}` 目录下。非分布式场景下没有 rank ID,目录名称为 rank。
|
|
313
|
+
* `dump_tensor_data`:保存采集到的张量数据。
|
|
314
|
+
* `dump.json`:记录模块或 API 的统计信息。
|
|
315
|
+
* `stack.json`:API调用栈信息。
|
|
316
|
+
* `construct.json`:分层分级结构信息。
|
|
317
|
+
|
|
318
|
+
dump 过程中,npy 文件在对应API或者模块被执行后就会落盘,而 json 文件则需要在正常执行 PrecisionDebugger.stop() 后才会写入完整数据,因此,程序异常终止时,被执行API对应的 npy 文件已被保存,但 json 文件中的数据可能丢失。
|
|
319
|
+
|
|
320
|
+
动态图场景下使能 PSJit 或 PIJit,装饰特定 Cell 或 function,被装饰的部分会全部/部分使能**静态图**流程。
|
|
228
321
|
|
|
229
|
-
|
|
322
|
+
- PSJit 场景下 config.json 文件配置 level 为 L1 时,被 PSJit 装饰的部分也作为 API 被 dump 到对应目录;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel,其结果目录同jit_level 为 O0/O1 时的静态图 dump 相同。
|
|
323
|
+
- PIJit 场景下 config.json 文件配置 level 为 L1 时,会被还原为动态图,按 API 粒度进行 dump;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel。
|
|
230
324
|
|
|
231
|
-
动态图场景下使能 PSJit 或 PIJit,装饰特定 Cell 或 function,被装饰的部分会全部/部分使能**静态图**流程。PSJit 场景下 config.json 文件配置 level 为 L1 时,被 PSJit 装饰的部分也作为 API 被 dump 到对应目录;配置 level 为 L2 时,则只会 dump 用户网络中静态图流程下的相关 kernel, 其结果目录同jit_level 为 O0/O1 时的静态图 dump 相同。PIJit 场景开启 dump 工具后,会被还原为动态图,按 API 粒度进行 dump。
|
|
232
325
|
|
|
233
|
-
npy
|
|
326
|
+
npy文件名的前缀含义如下:
|
|
327
|
+
|
|
328
|
+
| 前缀 | 含义 |
|
|
329
|
+
| -------------- |------------------------------|
|
|
330
|
+
| Tensor | mindspore.Tensor API数据 |
|
|
331
|
+
| Functional | mindspore.ops API数据 |
|
|
332
|
+
| Primitive | mindspore.ops.Primitive API数据 |
|
|
333
|
+
| Mint | mindspore.mint API数据 |
|
|
334
|
+
| MintFunctional | mindspore.mint.nn.functional API数据 |
|
|
335
|
+
| Jit | 被"jit"装饰的模块或函数数据 |
|
|
336
|
+
| Cell | mindspore.nn.Cell 类(模块)数据 |
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
## 9.补充说明
|
|
341
|
+
|
|
342
|
+
### 9.1 修改 API 支持列表
|
|
343
|
+
|
|
344
|
+
动态图 API 级 dump 时,本工具提供固定的 API 支持列表,仅支持对列表中的 API 进行精度数据采集。一般情况下,无需修改该列表,而是通过config.json中的scope/list字段进行 dump API 指定。若需要改变 API 支持列表,可以在 `msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml` 文件内手动修改,如下示例:
|
|
345
|
+
|
|
346
|
+
```yaml
|
|
347
|
+
ops:
|
|
348
|
+
- adaptive_avg_pool1d
|
|
349
|
+
- adaptive_avg_pool2d
|
|
350
|
+
- adaptive_avg_pool3d
|
|
351
|
+
```
|
|
234
352
|
|
|
235
|
-
| 前缀 | MindSpore 模块 |
|
|
236
|
-
| -------------- | ---------------------------- |
|
|
237
|
-
| Tensor | mindspore.Tensor |
|
|
238
|
-
| Functional | mindspore.ops |
|
|
239
|
-
| Primitive | mindspore.ops.Primitive |
|
|
240
|
-
| Mint | mindspore.mint |
|
|
241
|
-
| MintFunctional | mindspore.mint.nn.functional |
|
|
242
|
-
| Jit | mindspore.jit |
|
|
243
|
-
| Cell | mindspore.nn.Cell |
|