mindstudio-probe 1.0.4__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.4.dist-info → mindstudio_probe-1.1.0.dist-info}/METADATA +1 -1
- mindstudio_probe-1.1.0.dist-info/RECORD +287 -0
- msprobe/README.md +46 -16
- msprobe/__init__.py +16 -1
- msprobe/config.json +0 -2
- msprobe/core/advisor/advisor.py +8 -8
- msprobe/core/advisor/advisor_const.py +6 -7
- msprobe/core/advisor/advisor_result.py +12 -12
- msprobe/core/common/const.py +64 -3
- msprobe/core/common/exceptions.py +2 -2
- msprobe/core/common/file_utils.py +54 -9
- msprobe/core/common/inplace_op_checker.py +38 -0
- msprobe/core/common/inplace_ops.yaml +251 -0
- msprobe/core/common/log.py +21 -11
- msprobe/core/common/utils.py +153 -167
- msprobe/core/common_config.py +18 -25
- msprobe/core/compare/acc_compare.py +209 -36
- msprobe/core/compare/check.py +102 -17
- msprobe/core/compare/compare_cli.py +21 -1
- msprobe/core/compare/highlight.py +41 -5
- msprobe/core/compare/multiprocessing_compute.py +33 -8
- msprobe/core/compare/npy_compare.py +21 -6
- msprobe/core/compare/utils.py +82 -48
- msprobe/core/data_dump/data_collector.py +31 -32
- msprobe/core/data_dump/data_processor/base.py +45 -22
- msprobe/core/data_dump/data_processor/factory.py +20 -3
- msprobe/core/data_dump/data_processor/mindspore_processor.py +11 -5
- msprobe/core/data_dump/data_processor/pytorch_processor.py +24 -7
- msprobe/core/data_dump/json_writer.py +63 -42
- msprobe/core/data_dump/scope.py +32 -16
- msprobe/core/grad_probe/constant.py +4 -0
- msprobe/core/grad_probe/grad_compare.py +2 -3
- msprobe/core/grad_probe/utils.py +16 -3
- msprobe/docs/01.installation.md +19 -9
- msprobe/docs/02.config_introduction.md +52 -80
- msprobe/docs/03.config_examples.md +3 -13
- msprobe/docs/04.acl_config_examples.md +11 -9
- msprobe/docs/05.data_dump_PyTorch.md +140 -12
- msprobe/docs/06.data_dump_MindSpore.md +47 -5
- msprobe/docs/07.accuracy_checker_PyTorch.md +57 -34
- msprobe/docs/08.accuracy_checker_online_PyTorch.md +51 -11
- msprobe/docs/09.accuracy_checker_MindSpore.md +8 -8
- msprobe/docs/10.accuracy_compare_PyTorch.md +181 -99
- msprobe/docs/11.accuracy_compare_MindSpore.md +162 -31
- msprobe/docs/13.overflow_check_MindSpore.md +1 -1
- msprobe/docs/15.free_benchmarking_PyTorch.md +59 -53
- msprobe/docs/16.free_benchmarking_MindSpore.md +140 -0
- msprobe/docs/17.grad_probe.md +14 -16
- msprobe/docs/18.online_dispatch.md +89 -0
- msprobe/docs/{FAQ_PyTorch.md → FAQ.md} +22 -10
- 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 +1 -0
- msprobe/mindspore/api_accuracy_checker/api_accuracy_checker.py +35 -11
- msprobe/mindspore/api_accuracy_checker/api_info.py +7 -0
- msprobe/mindspore/cell_processor.py +27 -3
- msprobe/mindspore/common/const.py +2 -0
- msprobe/mindspore/common/utils.py +18 -2
- msprobe/mindspore/compare/distributed_compare.py +9 -22
- msprobe/mindspore/compare/layer_mapping.py +146 -0
- msprobe/mindspore/compare/modify_mapping.py +107 -0
- msprobe/mindspore/compare/ms_compare.py +173 -35
- msprobe/mindspore/compare/ms_graph_compare.py +27 -11
- msprobe/mindspore/debugger/debugger_config.py +16 -13
- msprobe/mindspore/debugger/precision_debugger.py +37 -13
- msprobe/mindspore/dump/dump_tool_factory.py +16 -1
- msprobe/mindspore/dump/hook_cell/api_registry.py +11 -1
- msprobe/mindspore/dump/hook_cell/primitive_hooks.py +206 -0
- msprobe/mindspore/dump/hook_cell/support_wrap_ops.yaml +82 -10
- msprobe/mindspore/dump/hook_cell/wrap_api.py +21 -13
- msprobe/mindspore/dump/jit_dump.py +41 -17
- msprobe/mindspore/dump/kernel_graph_dump.py +19 -3
- msprobe/mindspore/dump/kernel_kbyk_dump.py +19 -4
- msprobe/mindspore/free_benchmark/api_pynative_self_check.py +19 -4
- msprobe/mindspore/free_benchmark/common/config.py +15 -0
- msprobe/mindspore/free_benchmark/common/handler_params.py +15 -0
- msprobe/mindspore/free_benchmark/common/utils.py +19 -5
- msprobe/mindspore/free_benchmark/decorator/dec_forward.py +16 -2
- msprobe/mindspore/free_benchmark/decorator/decorator_factory.py +18 -3
- msprobe/mindspore/free_benchmark/handler/base_handler.py +18 -3
- msprobe/mindspore/free_benchmark/handler/check_handler.py +18 -3
- msprobe/mindspore/free_benchmark/handler/fix_handler.py +15 -0
- msprobe/mindspore/free_benchmark/handler/handler_factory.py +18 -3
- msprobe/mindspore/free_benchmark/perturbation/add_noise.py +22 -7
- msprobe/mindspore/free_benchmark/perturbation/base_perturbation.py +15 -0
- msprobe/mindspore/free_benchmark/perturbation/bit_noise.py +22 -7
- msprobe/mindspore/free_benchmark/perturbation/exchange_value.py +44 -18
- msprobe/mindspore/free_benchmark/perturbation/improve_precision.py +18 -4
- msprobe/mindspore/free_benchmark/perturbation/no_change.py +16 -1
- msprobe/mindspore/free_benchmark/perturbation/perturbation_factory.py +20 -5
- msprobe/mindspore/free_benchmark/self_check_tool_factory.py +15 -0
- msprobe/mindspore/grad_probe/global_context.py +18 -8
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +20 -4
- msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +15 -0
- msprobe/mindspore/service.py +42 -123
- msprobe/pytorch/__init__.py +20 -1
- msprobe/pytorch/api_accuracy_checker/common/config.py +19 -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 +47 -21
- 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/run_ut/data_generate.py +67 -32
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +26 -5
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +19 -2
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +51 -125
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +146 -3
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/attl.py +21 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/client.py +78 -33
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/device_dispatch.py +27 -4
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/dump_dispatch.py +110 -0
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/server.py +36 -11
- 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 +15 -0
- 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 +21 -6
- msprobe/pytorch/bench_functions/npu_fusion_attention.py +180 -151
- msprobe/pytorch/bench_functions/rms_norm.py +15 -0
- msprobe/pytorch/bench_functions/rotary_mul.py +28 -9
- msprobe/pytorch/bench_functions/scaled_mask_softmax.py +15 -0
- msprobe/pytorch/bench_functions/swiglu.py +20 -5
- msprobe/pytorch/common/__init__.py +15 -0
- msprobe/pytorch/common/log.py +18 -6
- msprobe/pytorch/common/parse_json.py +26 -11
- msprobe/pytorch/common/utils.py +40 -35
- msprobe/pytorch/compare/distributed_compare.py +11 -11
- msprobe/pytorch/compare/match.py +15 -0
- msprobe/pytorch/compare/pt_compare.py +38 -6
- msprobe/pytorch/debugger/debugger_config.py +52 -39
- msprobe/pytorch/debugger/precision_debugger.py +72 -24
- msprobe/pytorch/free_benchmark/__init__.py +20 -5
- msprobe/pytorch/free_benchmark/common/enums.py +28 -0
- msprobe/pytorch/free_benchmark/common/params.py +15 -0
- msprobe/pytorch/free_benchmark/common/utils.py +17 -1
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +28 -7
- msprobe/pytorch/free_benchmark/compare/single_benchmark.py +15 -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 +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +15 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +26 -2
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +15 -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 +55 -16
- msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +15 -0
- msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +15 -0
- 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_stat_csv.py +2 -2
- 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/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 +10 -11
- 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 +17 -2
- msprobe/pytorch/online_dispatch/compare.py +11 -12
- msprobe/pytorch/online_dispatch/single_compare.py +7 -7
- msprobe/pytorch/online_dispatch/torch_ops_config.yaml +8 -0
- msprobe/pytorch/online_dispatch/utils.py +1 -4
- msprobe/pytorch/parse.py +15 -0
- msprobe/pytorch/parse_tool/cli.py +5 -6
- msprobe/pytorch/parse_tool/lib/compare.py +9 -10
- msprobe/pytorch/parse_tool/lib/parse_tool.py +3 -0
- msprobe/pytorch/parse_tool/lib/utils.py +28 -24
- msprobe/pytorch/parse_tool/lib/visualization.py +1 -1
- msprobe/pytorch/pt_config.py +167 -38
- msprobe/pytorch/service.py +97 -32
- mindstudio_probe-1.0.4.dist-info/RECORD +0 -276
- msprobe/pytorch/api_accuracy_checker/tensor_transport_layer/ssl_config.py +0 -10
- msprobe/pytorch/functional/data_processor.py +0 -0
- msprobe/pytorch/functional/dump_module.py +0 -39
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/LICENSE +0 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/WHEEL +0 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/entry_points.txt +0 -0
- {mindstudio_probe-1.0.4.dist-info → mindstudio_probe-1.1.0.dist-info}/top_level.txt +0 -0
|
@@ -3,24 +3,22 @@
|
|
|
3
3
|
- 当调用 **PrecisionDebugger** 接口执行 dump 或其他操作时,需要使用 [config.json](../config.json) 文件;当未指定 config.json 时,将使用默认配置。
|
|
4
4
|
- msprobe 成功安装后,config.json 一般位于如下目录:
|
|
5
5
|
```
|
|
6
|
-
/home
|
|
6
|
+
/home/xxx/miniconda3/envs/xxx/lib/python3.xx/site-packages/msprobe/
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## 1 参数介绍
|
|
10
10
|
|
|
11
11
|
### 1.1 通用配置
|
|
12
12
|
|
|
13
|
-
|
|
|
13
|
+
| 参数 | 解释 | 是否必选 |
|
|
14
14
|
| ----------------- | ---------------- | -------- |
|
|
15
|
-
| task | dump 的任务类型,str
|
|
16
|
-
| dump_path | 设置 dump 数据目录路径,str 类型。<br/> **配置示例**:"dump_path": "./dump_path"。
|
|
17
|
-
| rank |
|
|
18
|
-
| step |
|
|
19
|
-
| level | dump 级别,str
|
|
20
|
-
| acl_config | kernel dump 的配置文件,str
|
|
21
|
-
|
|
|
22
|
-
| is_deterministic | 确定性计算模式,bool 类型,仅 PyTorch 场景支持。可取值 true(开启)或 false(关闭),默认关闭。<br/> 即使在相同的硬件和输入下,API 多次执行的结果也可能不同,开启确定性计算是为了保证在相同的硬件和输入下,API 多次执行的结果相同。<br/>确定性计算会导致 API 执行性能降低,建议在发现模型多次执行结果不同的情况下开启。<br/> rnn 类算子、ReduceSum、ReduceMean 等算子可能与确定性计算存在冲突,若开启确定性计算后多次执行的结果不相同,则考虑存在这些算子。<br/> **配置示例**:"is_deterministic": true。<br/> | 否 |
|
|
23
|
-
| enable_dataloader | 自动控制开关,bool 类型,仅 PyTorch 场景支持。可取值 true(开启)或 false(关闭),默认为 false。配置为 True 后自动识别 step 参数指定的迭代,并在该迭代执行完成后退出训练,此时 start、stop 和 step 函数可不配置,开启该开关要求训练脚本是通过 torch.utils.data.dataloader 方式加载数据。仅支持 PyTorch 单卡训练使用,分布式训练场景下存在数据 dump 不全问题,**下个版本即将废弃该功能**。 | 否 |
|
|
15
|
+
| task | dump 的任务类型,str 类型。可选参数:<br/> "statistics":仅采集统计信息,默认值;<br/> "tensor":采集统计信息和完全复刻整网的真实数据;<br/> "run_ut":精度预检,仅 PyTorch 场景支持,采集数据时勿选;<br/> "overflow_check":溢出检测;<br/> "free_benchmark":无标杆比对。<br/> 根据 task 参数取值的不同,可以配置不同场景参数,详见:<br/>[1.2 task 配置为 statistics](#12-task-配置为-statistics),<br/>[1.3 task 配置为 tensor](#13-task-配置为-tensor),<br/>[1.4 task 配置为 run_ut](#14-task-配置为-run_ut),<br/>[1.5 task 配置为 overflow_check](#15-task-配置为-overflow_check),<br/>[1.6 task 配置为 free_benchmark](#16-task-配置为-free_benchmark)。 <br/> **配置示例**:"task": "tensor"。 | 否 |
|
|
16
|
+
| dump_path | 设置 dump 数据目录路径,str 类型。<br/> **配置示例**:"dump_path": "./dump_path"。 | 是 |
|
|
17
|
+
| rank | 指定对某张卡上的数据进行采集,list[Union[int, str]] 类型,默认未配置(表示采集所有卡的数据),应配置元素为 ≥0 的整数或类似"4-6"的字符串,且须配置实际可用的 Rank ID。<br/> PyTorch 场景: Rank ID 从 0 开始计数,最大取值为所有节点可用卡总数-1,若所配置的值大于实际训练所运行的卡的 Rank ID,则 dump 数据为空,比如当前环境 Rank ID 为 0 到 7,实际训练运行 0 到 3 卡,此时若配置 Rank ID 为 4 或不存在的 10 等其他值,dump 数据为空。<br/> MindSpore 场景:所有节点的 Rank ID 均从 0 开始计数,最大取值为每个节点可用卡总数-1,config.json 配置一次 rank 参数对所有节点同时生效。<br/>**配置示例**:"rank": [1, "4-6"]。 | 否 |
|
|
18
|
+
| step | 指定采集某个 step 的数据,list[Union[int, str]] 类型。默认未配置,表示采集所有 step 数据。采集特定 step 时,须指定为训练脚本中存在的 step,可逐个配置,也可以指定范围。<br/> **配置示例**:"step": [0, 1 , 2, "4-6"]。 | 否 |
|
|
19
|
+
| level | dump 级别,str 类型,根据不同级别采集不同数据。可选参数:<br/>"L0":dump 模块级精度数据,仅 PyTorch 与 MindSpore 动态图场景支持,使用背景详见 [1.1.1 模块级精度数据 dump 说明](#111-模块级精度数据-dump-说明);<br/>"L1":dump API 级精度数据,默认值,仅 PyTorch 与 MindSpore 动态图场景支持;<br/>"L2":dump kernel 级精度数据,PyTorch 场景下须配置 acl_config 参数;<br/>"mix":dump module 模块级和 API 级精度数据,即"L0"+"L1",仅 PyTorch 与 MindSpore 动态图场景支持。<br/> **配置示例**:"level": "L1"。 | 否 |
|
|
20
|
+
| acl_config | kernel dump 的配置文件,str 类型。当 PyTorch 场景的 level 取"L2"时,该参数必选;level 为其他值时,该参数不选。<br/> **配置示例**:acl_config="./acl_config.json"。具体配置见[ acl_config 示例](./04.acl_config_examples.md)。 | 否 |
|
|
21
|
+
| enable_dataloader | 自动控制开关,bool 类型,仅 PyTorch 场景支持。可选参数 true(开启)或 false(关闭),默认为 false。配置为 true 后自动识别 step 参数指定的迭代,并在该迭代执行完成后退出训练,此时 start、stop 和 step 函数可不配置,开启该开关要求训练脚本是通过 torch.utils.data.dataloader 方式加载数据。仅支持 PyTorch 单卡训练使用,分布式训练场景下存在数据 dump 不全问题。 | 否 |
|
|
24
22
|
|
|
25
23
|
#### 1.1.1 模块级精度数据 dump 说明
|
|
26
24
|
|
|
@@ -32,79 +30,50 @@
|
|
|
32
30
|
|
|
33
31
|
模块指的是继承 nn.Module 类(PyTorch场景)或 nn.Cell 类(MindSpore场景)的子类,通常情况下这类模块就是一个小模型,可以被视为一个整体,dump 数据时以模块为粒度进行 dump。
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
seed_all 函数可固定随机数的范围如下表。
|
|
38
|
-
|
|
39
|
-
| API | 固定随机数 |
|
|
40
|
-
| ---------------------------------------- | --------------------------- |
|
|
41
|
-
| os.environ['PYTHONHASHSEED'] = str(seed) | 禁止 Python 中的 hash 随机化 |
|
|
42
|
-
| random.seed(seed) | 设置 random 随机生成器的种子 |
|
|
43
|
-
| np.random.seed(seed) | 设置 numpy 中随机生成器的种子 |
|
|
44
|
-
| torch.manual_seed(seed) | 设置当前 CPU 的随机种子 |
|
|
45
|
-
| torch.cuda.manual_seed(seed) | 设置当前 GPU 的随机种子 |
|
|
46
|
-
| torch.cuda.manual_seed_all(seed) | 设置所有 GPU 的随机种子 |
|
|
47
|
-
| torch_npu.npu.manual_seed(seed) | 设置当前 NPU 的随机种子 |
|
|
48
|
-
| torch_npu.npu.manual_seed_all(seed) | 设置所有 NPU 的随机种子 |
|
|
49
|
-
| torch.backends.cudnn.enable=False | 关闭 cuDNN |
|
|
50
|
-
| torch.backends.cudnn.benchmark=False | cuDNN 确定性地选择算法 |
|
|
51
|
-
| torch.backends.cudnn.deterministic=True | cuDNN 仅使用确定性的卷积算法 |
|
|
52
|
-
|
|
53
|
-
需要保证 CPU 或 GPU 以及 NPU 的模型输入完全一致,dump 数据的比对才有意义,seed_all 并不能保证模型输入完全一致,如下表所示场景需要保证输入的一致性。
|
|
54
|
-
|
|
55
|
-
| 场景 | 固定方法 |
|
|
56
|
-
| --------------- | ------------- |
|
|
57
|
-
| 数据集的 shuffle | 关闭 shuffle。 |
|
|
58
|
-
| dropout | 关闭 dropout。 |
|
|
59
|
-
|
|
60
|
-
关闭 shuffle 示例:
|
|
61
|
-
|
|
62
|
-
```python
|
|
63
|
-
train_loader = torch.utils.data.DataLoader(
|
|
64
|
-
train_dataset,
|
|
65
|
-
batch_size = batch_size,
|
|
66
|
-
shuffle = False,
|
|
67
|
-
num_workers = num_workers
|
|
68
|
-
)
|
|
69
|
-
```
|
|
33
|
+
### 1.2 task 配置为 statistics
|
|
70
34
|
|
|
71
|
-
|
|
35
|
+
<table>
|
|
36
|
+
<tr><th>参数</th><th>解释</th><th>是否必选</th></tr>
|
|
37
|
+
<tr><td>scope</td><td>PyTorch 和 MindSpore 动态图场景 dump 范围,list[str] 类型,默认未配置(list 也未配置时表示 dump 所有 API 的数据)。该参数可以在 [ ] 内配置两个模块名或 API 名,用于锁定区间,dump 该范围内的数据;也可以在 [ ] 内配置一个模块名,表示dump此模块内部的API或子模块数据(仅level配置为mix时支持配置一个模块名)。<br/><b>配置示例</b>:"scope": ["MyModuleOP1", "MyModuleOP2"]或"scope": ["MyModuleOP1"]。与 level 参数取值相关,level 为 L0 和 mix 级别时,可配置模块名;level 为 L1 级别时,可配置 API 名。</td><td>否</td></tr>
|
|
38
|
+
<tr><td rowspan="4">list</td><td>自定义采集的算子列表,list[str] 类型,默认未配置(scope 也未配置时表示 dump 所有 API 的数据),包含以下配置方法:</td><td rowspan="4">否</td></tr>
|
|
39
|
+
<tr><td>PyTorch 和 MindSpore 动态图场景配置具体的 API 全称,dump 该 API 数据。<br/><b>配置示例</b>:"list": ["Tensor.permute.1.forward", "Tensor.transpose.2.forward", "Torch.relu.3.backward"]。</td></tr>
|
|
40
|
+
<tr><td>PyTorch 和 MindSpore 动态图场景指定某一类 API,dump 某一类的 API 级别输入输出数据。<br/><b>配置示例</b>:"list": ["relu"]。</td></tr>
|
|
41
|
+
<tr><td>MindSpore 静态图场景配置 kernel_name,可以是算子的名称列表,也可以指定算子类型("level": "L2"时不支持),还可以配置算子名称的正则表达式(当字符串符合“name-regex(xxx)”格式时,后台则会将其作为正则表达式。<br/><b>配置示例</b>:list: ["name-regex(Default/.+)"]<br/>可匹配算子名称以“Default/”开头的所有算子。</td></tr>
|
|
42
|
+
<tr><td rowspan="3">data_mode</td><td>dump 数据过滤,str 类型。</td><td rowspan="3">否</td></tr>
|
|
43
|
+
<tr><td>PyTorch 场景:支持"all"、"forward"、"backward"、"input"和"output",表示仅采集包含"forward"、"backward"、"input"和"output"字段的数据。<br/> <b>配置示例</b>:"data_mode": ["backward"] 或 "data_mode": ["forward", "backward"]。默认为["all"],即保存所有 dump 的数据。除了 all 参数只能单独配置外,其他参数可以自由组合。</td></tr>
|
|
44
|
+
<tr><td>MindSpore 场景:仅支持"all"、"input"和"output"参数,且各参数只能单独配置,不支持自由组合。<br/><b>配置示例</b>:"data_mode": ["all"]。</td></tr>
|
|
45
|
+
<tr><td>summary_mode</td><td>控制 dump 文件输出的模式,str 类型,仅 PyTorch 场景支持,可选参数:<br/> md5:dump 输出包含 md5 值以及 API 统计信息的 dump.json 文件,用于验证数据的完整性;<br/> statistics:dump 仅输出包含 API 统计信息的 dump.json 文件,默认值。<br/><b>配置示例</b>:"summary_mode": "md5"。</td><td>否</td></tr>
|
|
46
|
+
</table>
|
|
72
47
|
|
|
73
|
-
在使用 `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。
|
|
74
48
|
|
|
75
|
-
### 1.2 task 配置为 statistics
|
|
76
49
|
|
|
77
|
-
| 参数名 | 解释 | 是否必选 |
|
|
78
|
-
| ------------ | ------------------- | -------- |
|
|
79
|
-
| scope | PyTorch 和 MindSpore 动态图场景 dump 范围,list[str] 类型,默认未配置(list 也未配置时表示 dump 所有 API 的数据)。该参数在 [ ] 内配置两个模块名或 API 名,用于锁定区间,dump 该范围内的数据。<br/>**配置示例**:"scope": ["MyModuleOP1", "MyModuleOP2"]。与 level 参数取值相关,level 为 L0 和 mix 级别时,可配置模块名;level 为 L1 级别时,可配置 API 名。MindSpore 动态图场景当前仅支持配置为 API 名。 | 否 |
|
|
80
|
-
| list | 自定义 dump 范围,list[str] 类型,默认未配置(scope 也未配置时表示 dump 所有 API 的数据)。包含如下配置方法:<br> PyTorch 和 MindSpore 动态图场景配置具体的 API 全称,dump 该 API 数据。<br/>**配置示例**:"list": ["Tensor.permute.1.forward", "Tensor.transpose.2.forward", "Torch.relu.3.backward"]。<br/> <hr> PyTorch 和 MindSpore 动态图场景指定某一类 API,dump 某一类的 API 级别输入输出数据。<br/>**配置示例**:"list": ["relu"]。<hr> MindSpore 静态图场景配置 kernel_name,可以是算子的名称列表,也可以指定算子类型("level": "L2"时不支持),还可以配置算子名称的正则表达式(当字符串符合“name-regex(xxx)”格式时,后台则会将其作为正则表达式。例如,“name-regex(Default/.+)”可匹配算子名称以“Default/”开头的所有算子)。 | 否 |
|
|
81
|
-
| data_mode | dump 数据过滤,str 类型。<br/><hr>PyTorch 场景:支持"all"、"forward"、"backward"、"input"和"output",表示仅保存 dump 的数据中文件名包含"forward"、"backward"、"input"和"output"的前向、反向、输入或输出的 dump 文件。<br/> **配置示例**:"data_mode": ["all"]。 <hr>MindSpore 场景:仅支持"all"、"input"和"output"参数,且各参数只能单独配置,不支持自由组合。<br/>**配置示例**:"data_mode": ["backward"] 或 "data_mode": ["forward", "backward"]。默认为["all"],即保存所有 dump 的数据。除了 all 参数只能单独配置外,其他参数可以自由组合。 | 否 |
|
|
82
|
-
| summary_mode | 控制 dump 文件输出的模式,str 类型,仅 PyTorch 场景支持,可取值,<br/> md5:dump 输出包含 md5 值以及 API 统计信息的 dump.json 文件,用于验证数据的完整性;<br/> statistics:dump 仅输出包含 API 统计信息的 dump.json 文件,默认值。<br/> **配置示例**:"summary_mode": "md5"。 | 否 |
|
|
83
50
|
|
|
84
51
|
### 1.3 task 配置为 tensor
|
|
85
52
|
|
|
86
|
-
|
|
|
53
|
+
| 参数 | 解释 | 是否必选 |
|
|
87
54
|
| -------------- | ---------------------- | -------- |
|
|
88
55
|
| scope | 与[ 1.2 task 配置为 statistics ](#12-task-配置为-statistics)中的解释相同。 | 否 |
|
|
56
|
+
| list | 与[ 1.2 task 配置为 statistics ](#12-task-配置为-statistics)中的解释相同。 | 否 |
|
|
57
|
+
| backward_input | 首次运行训练采集得到反向 API 输入的 dump 文件,list[str] 类型,仅支持 PyTorch 场景的 kernel dump,默认未配置。例如,若需要采集 Functional.conv2d.1 API 反向过程的输入输出,则需要在 dump 目录下查找命名包含 Functional.conv2d.1、backward 和 input 字段的 dump 文件。<br/>**配置示例**:"backward_input": ["./npu_dump/step0/rank0/dump_tensor_data/Functional.conv2d.1.backward.input.0.pt"] | 否 |
|
|
89
58
|
| list | 与[ 1.2 task 配置为 statistics ](#12-task-配置为-statistics)中的解释相同。另外,<br/> PyTorch 和 MindSpore 动态图场景配置 kernel_api,dump 前向和反向 API 的kernel_api 级别数据,其中 dump 反向 API 时需要配置 **backward_input** 参数。<br/>**前向 API 配置示例**:"list": ["Tensor.permute.1.forward"];<br/>**反向 API 配置示例**:"list": ["Tensor.permute.1.forward"], "backward.input": ["./npu_dump/step0/rank0/Functional.conv2d.1.backward.input.0.pt"]。<br/> | 否 |
|
|
90
|
-
| backward_input | 该输入文件为首次运行训练 dump 得到反向 API 输入的 dump 文件,str 类型,仅 PyTorch 场景支持,默认未配置。例如若需要 dump Functional.conv2d.1 API 的反向过程的输入输出,则需要在 dump 目录下查找命名包含 Functional.conv2d.1、backward 和 input 字段的 dump 文件。<br/>**配置示例**:"backward_input": ["./npu_dump/step0/rank0/Functional.conv2d.1.backward.input.0.pt"] | 否 |
|
|
59
|
+
| backward_input | 该输入文件为首次运行训练 dump 得到反向 API 输入的 dump 文件,list[str] 类型,仅 PyTorch 场景支持,默认未配置。例如若需要 dump Functional.conv2d.1 API 的反向过程的输入输出,则需要在 dump 目录下查找命名包含 Functional.conv2d.1、backward 和 input 字段的 dump 文件。<br/>**配置示例**:"backward_input": ["./npu_dump/step0/rank0/Functional.conv2d.1.backward.input.0.pt"] | 否 |
|
|
91
60
|
| data_mode | 与[ 1.2 task 配置为 statistics ](#12-task-配置为-statistics)中的解释相同 | 否 |
|
|
92
|
-
| file_format |
|
|
93
|
-
| online_run_ut<sup>a
|
|
94
|
-
| nfs_path<sup>a
|
|
95
|
-
| host<sup>a
|
|
96
|
-
| port<sup>a
|
|
61
|
+
| file_format | tensor 数据的保存格式,str 类型,仅支持 MindSpore 静态图场景的 L2,不支持 L0 和 L1。可选参数:<br/> "bin":dump 的 tensor 文件为二进制格式;<br/>"npy":dump 的 tensor 文件后缀为 .npy,默认值。 | 否 |
|
|
62
|
+
| online_run_ut<sup>a</sup> | 在线预检模式开关,bool 类型,可选参数 true(开启)、false(关闭),默认未配置,表示关闭。配置为 true 表示开启在线预检。| 否 |
|
|
63
|
+
| nfs_path<sup>a</sup> | 在线预检模式共享存储目录路径,str 类型,用于 GPU 设备和 NPU 设备间进行通信。仅在 online_run_ut 字段配置为 true 时生效,配置该参数后 host 和 port 不生效。 | 否 |
|
|
64
|
+
| host<sup>a</sup> | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的局域网 IP 地址。仅在 online_run_ut 字段配置为 true 时生效,局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。 | 否 |
|
|
65
|
+
| port<sup>a</sup> | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,NPU 侧须配置为 GPU 侧的端口号。仅在 online_run_ut 字段配置为 true 时生效,局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。| 否 |
|
|
97
66
|
|
|
98
67
|
**a**:online_run_ut、nfs_path、host、port 等字段仅在线预检场景 NPU 机器生效。
|
|
99
68
|
|
|
100
69
|
### 1.4 task 配置为 run_ut
|
|
101
70
|
|
|
102
|
-
|
|
|
71
|
+
| 参数 | 解释 | 是否必选 |
|
|
103
72
|
| --------------- | ------------------------ | ------------ |
|
|
104
73
|
| white_list<sup>a</sup> | API dump 白名单,仅对指定的 API 进行 dump。<br/>**配置示例**:"white_list": ["conv1d", "conv2d"]。默认未配置白名单,即 dump 全量 API 数据。 | 否 |
|
|
105
74
|
| black_list<sup>a</sup> | API dump 黑名单,被指定的 API 不进行 dump。<br/>**配置示例**:"black_list": ["conv1d", "conv2d"]。默认未配置黑名单,即 dump 全量 API 数据。 | 否 |
|
|
106
75
|
| error_data_path | 配置保存精度未达标的 API 输入输出数据路径,默认为当前路径。<br/>**配置示例**:"error_data_path": "./"。 | 否 |
|
|
107
|
-
| is_online<sup>b</sup> | 在线预检模式开关,bool
|
|
76
|
+
| is_online<sup>b</sup> | 在线预检模式开关,bool 类型,可选参数 true(开启)、false(关闭),默认关闭。 | 否 |
|
|
108
77
|
| nfs_path<sup>b</sup> | 在线预检模式共享存储目录路径,str 类型,用于 GPU 设备和 NPU 设备间进行通信。配置该参数后 host 和 port 不生效,仅在 is_online 字段配置为 true 时生效。 | 否 |
|
|
109
78
|
| host<sup>b</sup> | 在线预检模式局域网场景信息接收端 IP,str 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机地址 127.0.0.1 或本机局域网 IP。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。仅在 is_online 字段配置为 true 时生效。 | 否 |
|
|
110
79
|
| port<sup>b</sup> | 在线预检模式局域网场景信息接收端端口号,int 类型,用于 GPU 设备和 NPU 设备间进行通信,GPU 侧配置为本机可用端口。局域网场景时,不能配置 nfs_path 参数,否则局域网场景不生效。仅在 is_online 字段配置为 true 时生效。| 否 |
|
|
@@ -116,12 +85,12 @@ num_workers = num_workers
|
|
|
116
85
|
|
|
117
86
|
### 1.5 task 配置为 overflow_check
|
|
118
87
|
|
|
119
|
-
PyTorch 与 MindSpore 动态图场景下,"level"须为"L1";MindSpore 静态图场景下,"level"须为"L2"。
|
|
88
|
+
PyTorch 与 MindSpore 动态图场景下,"level"须为"L1";MindSpore 静态图场景下,"level"须为"L2",且模型编译优化等级(jit_level)须为"O2"。
|
|
120
89
|
|
|
121
|
-
|
|
|
90
|
+
| 参数 | 解释 | 是否必选 |
|
|
122
91
|
| ------------- | ---------------------- | -------- |
|
|
123
92
|
| overflow_nums | 最大溢出次数,int 类型,默认为 1,仅 PyTorch 与 MindSpore 动态图场景支持。表示第 N 次溢出后,不再进行溢出检测。过程中检测到溢出 API 对应的 输入输出 数据均 dump。<br/>**配置示例**:"overflow_nums": 3。配置为 -1 时,表示持续检测溢出直到训练结束。 | 否 |
|
|
124
|
-
| check_mode |
|
|
93
|
+
| check_mode | 溢出类型,str 类型,仅 MindSpore 场景支持,可选参数:<br/>"aicore":开启 AI Core 的溢出检测,不支持 MindSpore v2.3.0 以上版本;<br/>"atomic":开启 Atomic 的溢出检测,不支持 MindSpore v2.3.0 以上版本;<br/>"all":开启算子的溢出检测,默认值。<br/>**配置示例**:"check_mode": "all"。 | 否 |
|
|
125
94
|
|
|
126
95
|
### 1.6 task 配置为 free_benchmark
|
|
127
96
|
|
|
@@ -133,18 +102,21 @@ PyTorch 与 MindSpore 动态图场景下,"level"须为"L1";MindSpore 静态
|
|
|
133
102
|
|
|
134
103
|
- 建议配置白名单(配置 scope 或 list)控制少量 API 进行无标杆比对,一次对过多 API 执行无标杆比对可能导致显存溢出或性能膨胀。
|
|
135
104
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
105
|
+
<table>
|
|
106
|
+
<tr><th>参数</th><th>解释</th><th>是否必选</th></tr>
|
|
107
|
+
<tr><td>scope</td><td>自定义检测 API 列表(仅 PyTorch 场景支持),list[str] 类型,默认值为空列表,当 list 也为空列表时,表示检测所有 API。需要在 [ ] 内配置具体 API 名(在 dump 的结果中查看)。与 list 参数不能同时配置。<br/><b>配置示例</b>:"scope": ["Torch.matmul.0.forward", "Tensor.pow.4.forward"]。</td><td>否</td></tr>
|
|
108
|
+
<tr><td rowspan="3">list</td><td>自定义检测 API 类型或 API 名称,list[str] 类型,默认值为空列表,表示检测所有 API(PyTorch 场景下还需 scope 也为空列表)。与 scope 参数不能同时配置。</td><td rowspan="3">否</td></tr>
|
|
109
|
+
<tr><td>PyTorch 场景:指定某一类 API,对某一类的 API 进行无标杆比对。<br/><b>配置示例</b>:"list": ["relu"]。</td></tr>
|
|
110
|
+
<tr><td>MindSpore 场景:指定 API 名称,对列表中的 API 进行检测。<br/><b>配置示例</b>:"list": ["mindspore.mint.div", "mindspore.ops.bmm", "mindspore.Tensor.__add__"]。</td></tr>
|
|
111
|
+
<tr><td>fuzz_device</td><td>标杆设备,str 类型。可选参数:<br/> "npu":无标杆,通过添加扰动因子进行比对,默认值;<br/> "cpu":以 CPU 为标杆,pert_mode 须配置为"to_cpu"(仅 PyTorch 场景支持)。<br/><b>配置示例</b>:"fuzz_device": "npu"。</td><td>否</td></tr>
|
|
112
|
+
<tr><td>pert_mode</td><td>无标杆扰动因子,str 类型。可选参数:<br/> "improve_precision":对输入做升精度,默认值;<br/> "add_noise":对输入增加噪声;<br/> "no_change":不加扰动直接二次执行;<br/> "bit_noise":输入的末位比特翻转,MindSpore 场景不支持 BF16 类型的向量;<br/> "change_value":输入的张量首尾值调换;<br/> "to_cpu":在 CPU 等价执行(仅 PyTorch 场景支持)。<br/><b>配置示例</b>:"pert_mode": "improve_precision"。</td><td>否</td></tr>
|
|
113
|
+
<tr><td>handler_type</td><td>处理类型,可选参数:<br/> "check":进行无标杆比对检查,默认值;<br/> "fix":将扰动后的 API 输出结果覆盖原始 API 输出结果,尝试将 Loss 曲线恢复正常,该模式下不支持预热功能与反向过程,且仅支持"improve_precision"、"to_cpu"( PyTorch 场景)两种扰动因子。<br/> <b>配置示例</b>:"handler_type": "check"。</td><td>否</td></tr>
|
|
114
|
+
<tr><td>fuzz_level</td><td>无标杆数据 dump 级别,即选择比对结果文件应输出的表头属性,当前仅支持取值为:"L1"。输出结果详见 <a href="#161-无标杆比对数据存盘格式">1.6.1 无标杆比对数据存盘格式</a>。</td><td>否</td></tr>
|
|
115
|
+
<tr><td>fuzz_stage</td><td>比对过程,选择对 API 前向或反向进行无标杆比对,可选参数:<br/> "forward":前向,默认值;<br/> "backward":反向, 仅 PyTorch 场景支持。当 fuzz_stage 为 "backward" 时,handler_type 只能为 "check"。<br/> <b>配置示例</b>:"fuzz_stage": "backward"。</td><td>否</td></tr>
|
|
116
|
+
<tr><td>if_preheat</td><td>预热功能(仅 PyTorch 场景支持),bool 类型。开启功能后工具可以根据每次迭代的输出调整精度算法的阈值,从而更准确地找出存在精度问题的 API。当"handler_type": "fix"时,不支持预热。可选参数:<br/> true(开启)或 false(关闭),默认关闭。<br/> <b>配置示例</b>:"if_preheat": "true"。</td><td>否</td></tr>
|
|
117
|
+
<tr><td>preheat_step</td><td>开启预热的迭代数量(仅 PyTorch 场景支持),int 类型,默认值为 15。须配置 "if_preheat": "true"。</td><td>否</td></tr>
|
|
118
|
+
<tr><td>max_sample</td><td>每个算子预热的采样次数的最大阈值(仅 PyTorch 场景支持),int 类型,默认值为 20。须配置 "if_preheat": "true"。</td><td>否</td></tr>
|
|
119
|
+
</table>
|
|
148
120
|
|
|
149
121
|
#### 1.6.1 无标杆比对数据存盘格式
|
|
150
122
|
|
|
@@ -152,7 +124,7 @@ PyTorch 与 MindSpore 动态图场景下,"level"须为"L1";MindSpore 静态
|
|
|
152
124
|
|
|
153
125
|

|
|
154
126
|
|
|
155
|
-
| 字段 |
|
|
127
|
+
| 字段 | 解释 |
|
|
156
128
|
| ------------ | --------------------- |
|
|
157
129
|
| rank | Rank ID,int 类型。 |
|
|
158
130
|
| pert_mode | 扰动因子的类型,string 类型。 |
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
"rank": [],
|
|
14
14
|
"step": [],
|
|
15
15
|
"level": "L1",
|
|
16
|
-
"seed": 1234,
|
|
17
|
-
"is_deterministic": false,
|
|
18
16
|
"enable_dataloader": false,
|
|
19
17
|
|
|
20
18
|
"statistics": {
|
|
@@ -35,15 +33,13 @@
|
|
|
35
33
|
"rank": [],
|
|
36
34
|
"step": [],
|
|
37
35
|
"level": "L1",
|
|
38
|
-
"seed": 1234,
|
|
39
|
-
"is_deterministic": false,
|
|
40
36
|
"enable_dataloader": false,
|
|
41
37
|
|
|
42
38
|
"tensor": {
|
|
43
39
|
"scope": [],
|
|
44
40
|
"list":[],
|
|
45
41
|
"data_mode": ["all"],
|
|
46
|
-
"backward_input":
|
|
42
|
+
"backward_input": []
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
```
|
|
@@ -57,8 +53,6 @@
|
|
|
57
53
|
"rank": [],
|
|
58
54
|
"step": [],
|
|
59
55
|
"level": "L1",
|
|
60
|
-
"seed": 1234,
|
|
61
|
-
"is_deterministic": false,
|
|
62
56
|
"enable_dataloader": false,
|
|
63
57
|
|
|
64
58
|
"run_ut": {
|
|
@@ -78,8 +72,6 @@
|
|
|
78
72
|
"rank": [],
|
|
79
73
|
"step": [],
|
|
80
74
|
"level": "L1",
|
|
81
|
-
"seed": 1234,
|
|
82
|
-
"is_deterministic": false,
|
|
83
75
|
"enable_dataloader": false,
|
|
84
76
|
|
|
85
77
|
"overflow_check": {
|
|
@@ -97,8 +89,6 @@
|
|
|
97
89
|
"rank": [],
|
|
98
90
|
"step": [],
|
|
99
91
|
"level": "L1",
|
|
100
|
-
"seed": 1234,
|
|
101
|
-
"is_deterministic": false,
|
|
102
92
|
"enable_dataloader": false,
|
|
103
93
|
|
|
104
94
|
"free_benchmark": {
|
|
@@ -116,7 +106,7 @@
|
|
|
116
106
|
}
|
|
117
107
|
```
|
|
118
108
|
|
|
119
|
-
## 2 MindSpore 静态图场景
|
|
109
|
+
## 2 MindSpore 静态图场景
|
|
120
110
|
|
|
121
111
|
### 2.1 task 配置为 statistics
|
|
122
112
|
|
|
@@ -149,7 +139,7 @@
|
|
|
149
139
|
"tensor": {
|
|
150
140
|
"list":[],
|
|
151
141
|
"data_mode": ["all"],
|
|
152
|
-
"backward_input":
|
|
142
|
+
"backward_input": []
|
|
153
143
|
}
|
|
154
144
|
}
|
|
155
145
|
```
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"rank": [0],
|
|
15
15
|
"step": [0],
|
|
16
16
|
"is_deterministic": false,
|
|
17
|
+
|
|
17
18
|
"tensor": {
|
|
18
19
|
"scope": ["Tensor.__mul__.10.forward"],
|
|
19
20
|
"list":[],
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
|
|
30
31
|
执行反向 kernel dump 前需要先使用工具 dump 该 API 的反向输入,保存 pt 文件,"backward_input"参数中传入该 pt 文件路径。
|
|
31
32
|
|
|
32
|
-
"scope"配置为反向API名称,仅支持配置一个API。
|
|
33
|
+
"scope"配置为反向 API 名称,仅支持配置一个 API。
|
|
33
34
|
|
|
34
35
|
```json
|
|
35
36
|
{
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"rank": [0],
|
|
40
41
|
"step": [0],
|
|
41
42
|
"is_deterministic": false,
|
|
43
|
+
|
|
42
44
|
"tensor": {
|
|
43
45
|
"scope": ["Tensor.__mul__.10.backward"],
|
|
44
46
|
"list":[],
|
|
@@ -56,13 +58,13 @@
|
|
|
56
58
|
|
|
57
59
|
```json
|
|
58
60
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
"dump":
|
|
62
|
+
{
|
|
63
|
+
"dump_list":[],
|
|
64
|
+
"dump_path":"./dump/output",
|
|
65
|
+
"dump_mode":"all",
|
|
66
|
+
"dump_op_switch":"on"
|
|
67
|
+
}
|
|
66
68
|
}
|
|
67
69
|
```
|
|
68
70
|
|
|
@@ -73,4 +75,4 @@
|
|
|
73
75
|
| dump_list | 待 dump 数据的 API 模型。为空,无需配置。 |
|
|
74
76
|
| dump_path | dump 数据文件存储到运行环境的目录,主要配置的是 kernel 级数据的存放路径。支持配置绝对路径或相对路径。dump_path 须为已存在目录。 |
|
|
75
77
|
| dump_mode | dump 数据模式,可取值,<br/> output:dump API 的输出数据,默认值;<br/> input:dump API 的输入数据;<br/> all:dump API 的输入、输出数据。 |
|
|
76
|
-
| dump_op_switch | 单 API 模型 dump 数据开关,可取值,<br> off:关闭单API模型dump,默认值;<br> on:开启单API模型dump。 |
|
|
78
|
+
| dump_op_switch | 单 API 模型 dump 数据开关,可取值,<br> off:关闭单 API 模型 dump,默认值;<br> on:开启单 API 模型 dump。 |
|
|
@@ -23,7 +23,7 @@ functional: # functional为算子类别,找到对应的类别,在该类别
|
|
|
23
23
|
PrecisionDebugger(config_path=None, task=None, dump_path=None, level=None, model=None, step=None)
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
1. config_path:指定 dump 配置文件路径;model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"
|
|
26
|
+
1. config_path:指定 dump 配置文件路径;model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"时,必须在该接口或 **start** 接口中配置该参数。其他参数均在 [config.json](../config.json) 文件中可配,详细配置可见 [config.json 介绍](./02.config_introduction.md)。
|
|
27
27
|
2. 此接口的参数均不是必要,且优先级高于 [config.json](../config.json) 文件中的配置,但可配置的参数相比 config.json 较少。
|
|
28
28
|
|
|
29
29
|
### 1.2 start
|
|
@@ -33,12 +33,15 @@ PrecisionDebugger(config_path=None, task=None, dump_path=None, level=None, model
|
|
|
33
33
|
**原型**:
|
|
34
34
|
|
|
35
35
|
```Python
|
|
36
|
-
debugger.start()
|
|
36
|
+
debugger.start(model=None)
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
1. model:指定具体的 torch.nn.Module,默认未配置,level 配置为"L0"或"mix"时,必须在该接口或 **PrecisionDebugger** 接口中配置该参数。
|
|
40
|
+
本接口中的 model 比 PrecisionDebugger 中 model 参数优先级更高,会覆盖 PrecisionDebugger 中的 model 参数。
|
|
41
|
+
|
|
39
42
|
### 1.3 stop
|
|
40
43
|
|
|
41
|
-
**功能说明**:停止精度数据采集。在 **start** 函数之后的任意位置添加。若需要 dump 反向数据,则需要添加在反向计算代码(如,loss.backward)之后。使用示例可参见 [2.1
|
|
44
|
+
**功能说明**:停止精度数据采集。在 **start** 函数之后的任意位置添加。若需要 dump 反向数据,则需要添加在反向计算代码(如,loss.backward)之后。使用示例可参见 [2.1 快速上手](#21-快速上手)和 [2.2 采集完整的前反向数据](#22-采集完整的前反向数据)。
|
|
42
45
|
|
|
43
46
|
**原型**:
|
|
44
47
|
|
|
@@ -66,9 +69,89 @@ forward_backward_dump_end()
|
|
|
66
69
|
debugger.step()
|
|
67
70
|
```
|
|
68
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
|
+
|
|
69
152
|
## 2 示例代码
|
|
70
153
|
|
|
71
|
-
### 2.1
|
|
154
|
+
### 2.1 快速上手
|
|
72
155
|
|
|
73
156
|
这个示例定义了一个 nn.Module 类型的简单网络,在进行数据采集时使用原型函数 PrecisionDebugger 传入 config_path 参数和 model 参数。
|
|
74
157
|
|
|
@@ -78,8 +161,9 @@ import torch
|
|
|
78
161
|
import torch.nn as nn
|
|
79
162
|
import torch_npu # 需安装 torch_npu
|
|
80
163
|
import torch.nn.functional as F
|
|
81
|
-
from msprobe.pytorch import PrecisionDebugger
|
|
82
|
-
|
|
164
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
165
|
+
# 在模型训练开始前固定随机性
|
|
166
|
+
seed_all()
|
|
83
167
|
|
|
84
168
|
torch.npu.set_device("npu:0")
|
|
85
169
|
# 定义网络
|
|
@@ -110,8 +194,9 @@ if __name__ == "__main__":
|
|
|
110
194
|
### 2.2 采集完整的前反向数据
|
|
111
195
|
|
|
112
196
|
```Python
|
|
113
|
-
from msprobe.pytorch import PrecisionDebugger
|
|
114
|
-
|
|
197
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
198
|
+
# 在模型训练开始前固定随机性
|
|
199
|
+
seed_all()
|
|
115
200
|
# 请勿将PrecisionDebugger的初始化流程插入到循环代码中
|
|
116
201
|
debugger = PrecisionDebugger(config_path="./config.json", dump_path="./dump_path")
|
|
117
202
|
# 模型、损失函数的定义及初始化等操作
|
|
@@ -130,8 +215,9 @@ for data, label in data_loader:
|
|
|
130
215
|
### 2.3 采集指定代码块的前反向数据
|
|
131
216
|
|
|
132
217
|
```Python
|
|
133
|
-
from msprobe.pytorch import PrecisionDebugger
|
|
134
|
-
|
|
218
|
+
from msprobe.pytorch import PrecisionDebugger, seed_all
|
|
219
|
+
# 在模型训练开始前固定随机性
|
|
220
|
+
seed_all()
|
|
135
221
|
# 请勿将PrecisionDebugger的初始化流程插入到循环代码中
|
|
136
222
|
debugger = PrecisionDebugger(config_path="./config.json", dump_path="./dump_path")
|
|
137
223
|
|
|
@@ -149,7 +235,46 @@ for data, label in data_loader:
|
|
|
149
235
|
debugger.step() # 结束一个step的dump
|
|
150
236
|
```
|
|
151
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)
|
|
152
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
|
+
```
|
|
153
278
|
|
|
154
279
|
## 3 dump 结果文件介绍
|
|
155
280
|
|
|
@@ -183,7 +308,7 @@ for data, label in data_loader:
|
|
|
183
308
|
|
|
184
309
|
dump 过程中,pt 文件在对应算子或者模块被执行后就会落盘,而 json 文件则需要在正常执行 PrecisionDebugger.stop() 后才会写入完整数据,异常的程序终止会保存终止前被执行算子的相关 npy 文件,可能会导致 json 文件中数据丢失。
|
|
185
310
|
|
|
186
|
-
其中 rank 为设备上各卡的 ID,每张卡上 dump 的数据会生成对应 dump 目录。非分布式场景下没有rank ID,目录名称为rank。
|
|
311
|
+
其中 rank 为设备上各卡的 ID,每张卡上 dump 的数据会生成对应 dump 目录。非分布式场景下没有 rank ID,目录名称为 rank。
|
|
187
312
|
|
|
188
313
|
pt 文件保存的前缀和 PyTorch 对应关系如下:
|
|
189
314
|
|
|
@@ -192,7 +317,10 @@ pt 文件保存的前缀和 PyTorch 对应关系如下:
|
|
|
192
317
|
| Tensor | torch.Tensor |
|
|
193
318
|
| Torch | torch |
|
|
194
319
|
| Functional | torch.nn.functional |
|
|
195
|
-
| NPU | NPU亲和算子 |
|
|
320
|
+
| NPU | NPU 亲和算子 |
|
|
196
321
|
| VF | torch._VF |
|
|
197
322
|
| Aten | torch.ops.aten |
|
|
198
323
|
| Distributed | torch.distributed |
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|