mindstudio-probe 1.0.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.1.dist-info/LICENSE +201 -0
- mindstudio_probe-1.0.1.dist-info/METADATA +30 -0
- mindstudio_probe-1.0.1.dist-info/RECORD +228 -0
- mindstudio_probe-1.0.1.dist-info/WHEEL +5 -0
- mindstudio_probe-1.0.1.dist-info/entry_points.txt +2 -0
- mindstudio_probe-1.0.1.dist-info/top_level.txt +1 -0
- msprobe/README.md +182 -0
- msprobe/__init__.py +0 -0
- msprobe/config/README.md +397 -0
- msprobe/config/config.json +28 -0
- msprobe/config/img/free_benchmark.png +0 -0
- msprobe/core/common/const.py +241 -0
- msprobe/core/common/exceptions.py +88 -0
- msprobe/core/common/file_check.py +265 -0
- msprobe/core/common/log.py +55 -0
- msprobe/core/common/utils.py +516 -0
- msprobe/core/common_config.py +58 -0
- msprobe/core/data_dump/data_collector.py +140 -0
- msprobe/core/data_dump/data_processor/base.py +245 -0
- msprobe/core/data_dump/data_processor/factory.py +61 -0
- msprobe/core/data_dump/data_processor/pytorch_processor.py +346 -0
- msprobe/core/data_dump/json_writer.py +116 -0
- msprobe/core/data_dump/scope.py +178 -0
- msprobe/mindspore/__init__.py +1 -0
- msprobe/mindspore/debugger/__init__.py +0 -0
- msprobe/mindspore/debugger/debugger_config.py +51 -0
- msprobe/mindspore/debugger/precision_debugger.py +32 -0
- msprobe/mindspore/doc/dump.md +65 -0
- msprobe/mindspore/dump/__init__.py +0 -0
- msprobe/mindspore/dump/api_kbk_dump.py +55 -0
- msprobe/mindspore/dump/dump_tool_factory.py +38 -0
- msprobe/mindspore/dump/kernel_graph_dump.py +60 -0
- msprobe/mindspore/ms_config.py +78 -0
- msprobe/mindspore/overflow_check/__init__.py +0 -0
- msprobe/mindspore/overflow_check/kernel_graph_overflow_check.py +45 -0
- msprobe/mindspore/overflow_check/overflow_check_tool_factory.py +32 -0
- msprobe/mindspore/task_handler_factory.py +21 -0
- msprobe/msprobe.py +67 -0
- msprobe/pytorch/__init__.py +4 -0
- msprobe/pytorch/advisor/advisor.py +124 -0
- msprobe/pytorch/advisor/advisor_const.py +59 -0
- msprobe/pytorch/advisor/advisor_result.py +58 -0
- msprobe/pytorch/api_accuracy_checker/.keep +0 -0
- msprobe/pytorch/api_accuracy_checker/__init__.py +0 -0
- msprobe/pytorch/api_accuracy_checker/common/.keep +0 -0
- msprobe/pytorch/api_accuracy_checker/common/__init__.py +0 -0
- msprobe/pytorch/api_accuracy_checker/common/config.py +50 -0
- msprobe/pytorch/api_accuracy_checker/common/utils.py +224 -0
- msprobe/pytorch/api_accuracy_checker/compare/__init__.py +0 -0
- msprobe/pytorch/api_accuracy_checker/compare/algorithm.py +216 -0
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_compare.py +545 -0
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_standard.yaml +133 -0
- msprobe/pytorch/api_accuracy_checker/compare/api_precision_threshold.yaml +390 -0
- msprobe/pytorch/api_accuracy_checker/compare/compare.py +345 -0
- msprobe/pytorch/api_accuracy_checker/compare/compare_column.py +74 -0
- msprobe/pytorch/api_accuracy_checker/compare/compare_utils.py +249 -0
- msprobe/pytorch/api_accuracy_checker/config.yaml +4 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/.keep +0 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/__init__.py +0 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/data_generate.py +328 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/multi_run_ut.py +203 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/run_overflow_check.py +127 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut.py +493 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/run_ut_utils.py +7 -0
- msprobe/pytorch/api_accuracy_checker/run_ut/torch_ut_setting.json +5 -0
- msprobe/pytorch/common/__init__.py +2 -0
- msprobe/pytorch/common/compare_script.template +14 -0
- msprobe/pytorch/common/log.py +32 -0
- msprobe/pytorch/common/parse_json.py +37 -0
- msprobe/pytorch/common/utils.py +224 -0
- msprobe/pytorch/compare/acc_compare.py +1024 -0
- msprobe/pytorch/compare/distributed_compare.py +111 -0
- msprobe/pytorch/compare/highlight.py +100 -0
- msprobe/pytorch/compare/mapping.yaml +607 -0
- msprobe/pytorch/compare/match.py +36 -0
- msprobe/pytorch/compare/npy_compare.py +244 -0
- msprobe/pytorch/debugger/__init__.py +0 -0
- msprobe/pytorch/debugger/debugger_config.py +86 -0
- msprobe/pytorch/debugger/precision_debugger.py +95 -0
- msprobe/pytorch/doc/FAQ.md +193 -0
- msprobe/pytorch/doc/api_accuracy_checker.md +269 -0
- msprobe/pytorch/doc/atat/321/207/342/226/223/342/225/233/321/205/342/225/221/320/266/321/205/342/225/226/320/265/321/205/320/225/342/225/226/321/206/320/245/342/226/221/321/206/320/235/320/276dump/321/206/320/260/320/227/321/205/320/227/320/226/321/206/320/220/320/267/321/210/320/223/342/225/234/321/205/320/257/342/225/221/321/207/342/225/221/342/224/220/321/206/320/232/320/265/321/205/320/241/320/232.md +182 -0
- msprobe/pytorch/doc/dump.md +207 -0
- msprobe/pytorch/doc/img/BLOOM-7B_1.png +0 -0
- msprobe/pytorch/doc/img/BLOOM-7B_2.png +0 -0
- msprobe/pytorch/doc/img/BLOOM-7B_3.png +0 -0
- msprobe/pytorch/doc/img/BLOOM-7B_4.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_1.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_2.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_3.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_4.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_5.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_6.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_7.png +0 -0
- msprobe/pytorch/doc/img/GPT-3_8.png +0 -0
- msprobe/pytorch/doc/img/YOLOV5S_1.png +0 -0
- msprobe/pytorch/doc/img/YOLOV5S_2.png +0 -0
- msprobe/pytorch/doc/img/accuracy_checking_details.png +0 -0
- msprobe/pytorch/doc/img/accuracy_checking_result.png +0 -0
- msprobe/pytorch/doc/img/api_precision_compare_details.png +0 -0
- msprobe/pytorch/doc/img/api_precision_compare_result.png +0 -0
- msprobe/pytorch/doc/img/auto_analyze_log.png +0 -0
- msprobe/pytorch/doc/img/compare_result_pkl.png +0 -0
- msprobe/pytorch/doc/img/compare_result_pkl_md5.png.png +0 -0
- msprobe/pytorch/doc/img/cpu_info.png +0 -0
- msprobe/pytorch/doc/img/module_compare.png +0 -0
- msprobe/pytorch/doc/parse_tool.md +286 -0
- msprobe/pytorch/doc/ptdbg_ascend_compare.md +176 -0
- msprobe/pytorch/doc/ptdbg_ascend_overview.md +68 -0
- msprobe/pytorch/doc/ptdbg_ascend_quickstart.md +381 -0
- msprobe/pytorch/doc/run_overflow_check.md +25 -0
- 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 +90 -0
- msprobe/pytorch/free_benchmark/__init__.py +8 -0
- msprobe/pytorch/free_benchmark/common/__init__.py +0 -0
- msprobe/pytorch/free_benchmark/common/constant.py +67 -0
- msprobe/pytorch/free_benchmark/common/counter.py +72 -0
- msprobe/pytorch/free_benchmark/common/enums.py +37 -0
- msprobe/pytorch/free_benchmark/common/params.py +129 -0
- msprobe/pytorch/free_benchmark/common/utils.py +98 -0
- msprobe/pytorch/free_benchmark/compare/grad_saver.py +183 -0
- msprobe/pytorch/free_benchmark/compare/single_benchmark.py +104 -0
- msprobe/pytorch/free_benchmark/main.py +102 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/__init__.py +0 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/base_layer.py +13 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/layer_factory.py +41 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/__init__.py +0 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/add_noise.py +90 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/bit_noise.py +104 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/change_value.py +63 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/improve_precision.py +68 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/no_change.py +28 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/npu/npu_base_layser.py +45 -0
- msprobe/pytorch/free_benchmark/perturbed_layers/run_cpu.py +19 -0
- msprobe/pytorch/free_benchmark/result_handlers/__init__.py +0 -0
- msprobe/pytorch/free_benchmark/result_handlers/base_handler.py +203 -0
- msprobe/pytorch/free_benchmark/result_handlers/check_handler.py +39 -0
- msprobe/pytorch/free_benchmark/result_handlers/fix_handler.py +24 -0
- msprobe/pytorch/free_benchmark/result_handlers/handler_factory.py +31 -0
- msprobe/pytorch/free_benchmark/result_handlers/preheat_handler.py +170 -0
- msprobe/pytorch/functional/__init__.py +0 -0
- msprobe/pytorch/functional/data_processor.py +0 -0
- msprobe/pytorch/functional/dump_module.py +39 -0
- msprobe/pytorch/hook_module/__init__.py +1 -0
- msprobe/pytorch/hook_module/api_registry.py +161 -0
- msprobe/pytorch/hook_module/hook_module.py +109 -0
- msprobe/pytorch/hook_module/support_wrap_ops.yaml +1876 -0
- msprobe/pytorch/hook_module/utils.py +29 -0
- msprobe/pytorch/hook_module/wrap_aten.py +100 -0
- msprobe/pytorch/hook_module/wrap_distributed.py +75 -0
- msprobe/pytorch/hook_module/wrap_functional.py +108 -0
- msprobe/pytorch/hook_module/wrap_npu_custom.py +73 -0
- msprobe/pytorch/hook_module/wrap_tensor.py +72 -0
- msprobe/pytorch/hook_module/wrap_torch.py +88 -0
- msprobe/pytorch/hook_module/wrap_vf.py +64 -0
- msprobe/pytorch/module_processer.py +98 -0
- msprobe/pytorch/online_dispatch/__init__.py +20 -0
- msprobe/pytorch/online_dispatch/compare.py +236 -0
- msprobe/pytorch/online_dispatch/dispatch.py +274 -0
- msprobe/pytorch/online_dispatch/dump_compare.py +186 -0
- msprobe/pytorch/online_dispatch/single_compare.py +391 -0
- msprobe/pytorch/online_dispatch/torch_ops_config.yaml +50 -0
- msprobe/pytorch/online_dispatch/utils.py +187 -0
- msprobe/pytorch/parse.py +4 -0
- msprobe/pytorch/parse_tool/__init__.py +0 -0
- msprobe/pytorch/parse_tool/cli.py +32 -0
- msprobe/pytorch/parse_tool/lib/__init__.py +0 -0
- msprobe/pytorch/parse_tool/lib/compare.py +259 -0
- msprobe/pytorch/parse_tool/lib/config.py +51 -0
- msprobe/pytorch/parse_tool/lib/file_desc.py +31 -0
- msprobe/pytorch/parse_tool/lib/interactive_cli.py +102 -0
- msprobe/pytorch/parse_tool/lib/parse_exception.py +54 -0
- msprobe/pytorch/parse_tool/lib/parse_tool.py +158 -0
- msprobe/pytorch/parse_tool/lib/utils.py +367 -0
- msprobe/pytorch/parse_tool/lib/visualization.py +90 -0
- msprobe/pytorch/pt_config.py +93 -0
- msprobe/pytorch/service.py +167 -0
- msprobe/test/core_ut/common/test_utils.py +345 -0
- msprobe/test/core_ut/data_dump/test_data_collector.py +47 -0
- msprobe/test/core_ut/data_dump/test_json_writer.py +183 -0
- msprobe/test/core_ut/data_dump/test_scope.py +151 -0
- msprobe/test/core_ut/test_common_config.py +152 -0
- msprobe/test/core_ut/test_file_check.py +218 -0
- msprobe/test/core_ut/test_log.py +109 -0
- msprobe/test/mindspore_ut/test_api_kbk_dump.py +51 -0
- msprobe/test/mindspore_ut/test_debugger_config.py +42 -0
- msprobe/test/mindspore_ut/test_dump_tool_factory.py +51 -0
- msprobe/test/mindspore_ut/test_kernel_graph_dump.py +66 -0
- msprobe/test/mindspore_ut/test_kernel_graph_overflow_check.py +63 -0
- msprobe/test/mindspore_ut/test_ms_config.py +69 -0
- msprobe/test/mindspore_ut/test_overflow_check_tool_factory.py +51 -0
- msprobe/test/mindspore_ut/test_precision_debugger.py +56 -0
- msprobe/test/mindspore_ut/test_task_handler_factory.py +58 -0
- msprobe/test/pytorch_ut/advisor/test_advisor.py +83 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py +108 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/common/test_config.py +39 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_algorithm.py +112 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_api_precision_compare.py +77 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare.py +125 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare_column.py +10 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/compare/test_compare_utils.py +43 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/dump.json +179 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/forward.json +63 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_data_generate.py +99 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_multi_run_ut.py +115 -0
- msprobe/test/pytorch_ut/api_accuracy_checker/run_ut/test_run_ut.py +72 -0
- msprobe/test/pytorch_ut/compare/test_acc_compare.py +17 -0
- msprobe/test/pytorch_ut/free_benchmark/perturbed_layers/test_perturbed_layser.py +105 -0
- msprobe/test/pytorch_ut/free_benchmark/result_handlers/test_result_handler.py +121 -0
- msprobe/test/pytorch_ut/free_benchmark/test_main.py +101 -0
- msprobe/test/pytorch_ut/functional/test_dump_module.py +15 -0
- msprobe/test/pytorch_ut/hook_module/test_api_registry.py +130 -0
- msprobe/test/pytorch_ut/hook_module/test_hook_module.py +42 -0
- msprobe/test/pytorch_ut/hook_module/test_wrap_aten.py +65 -0
- msprobe/test/pytorch_ut/hook_module/test_wrap_distributed.py +35 -0
- msprobe/test/pytorch_ut/hook_module/test_wrap_functional.py +20 -0
- msprobe/test/pytorch_ut/hook_module/test_wrap_tensor.py +35 -0
- msprobe/test/pytorch_ut/hook_module/test_wrap_torch.py +43 -0
- msprobe/test/pytorch_ut/hook_module/test_wrap_vf.py +11 -0
- msprobe/test/pytorch_ut/test_pt_config.py +69 -0
- msprobe/test/pytorch_ut/test_service.py +59 -0
- msprobe/test/resources/advisor.txt +3 -0
- msprobe/test/resources/compare_result_20230703104808.csv +9 -0
- msprobe/test/resources/compare_result_without_accuracy.csv +9 -0
- msprobe/test/resources/config.yaml +3 -0
- msprobe/test/resources/npu_test.pkl +8 -0
- msprobe/test/run_test.sh +30 -0
- msprobe/test/run_ut.py +58 -0
- msprobe/test/test_module_processer.py +64 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from unittest import TestCase
|
|
20
|
+
from unittest.mock import patch, MagicMock
|
|
21
|
+
|
|
22
|
+
from msprobe.core.common.log import logger
|
|
23
|
+
from msprobe.core.common.const import FileCheckConst
|
|
24
|
+
from msprobe.core.common.exceptions import FileCheckException
|
|
25
|
+
from msprobe.core.common.file_check import (check_link,
|
|
26
|
+
check_path_length,
|
|
27
|
+
check_path_exists,
|
|
28
|
+
check_path_readability,
|
|
29
|
+
check_path_writability,
|
|
30
|
+
check_path_executable,
|
|
31
|
+
check_other_user_writable,
|
|
32
|
+
check_path_owner_consistent,
|
|
33
|
+
check_path_pattern_vaild,
|
|
34
|
+
check_file_size,
|
|
35
|
+
check_common_file_size,
|
|
36
|
+
check_file_suffix,
|
|
37
|
+
check_path_type)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class TestFileCheckUtil(TestCase):
|
|
41
|
+
@patch.object(logger, "error")
|
|
42
|
+
def test_check_link(self, mock_logger_error):
|
|
43
|
+
with patch("msprobe.core.common.file_check.os.path.islink", return_value=True):
|
|
44
|
+
with self.assertRaises(FileCheckException) as context:
|
|
45
|
+
check_link("link_path")
|
|
46
|
+
self.assertEqual(str(context.exception),
|
|
47
|
+
FileCheckException.err_strs.get(FileCheckException.SOFT_LINK_ERROR))
|
|
48
|
+
mock_logger_error.assert_called_with("The file path link_path is a soft link.")
|
|
49
|
+
|
|
50
|
+
@patch.object(logger, "error")
|
|
51
|
+
def test_check_path_length(self, mock_logger_error):
|
|
52
|
+
path = "P" * (FileCheckConst.DIRECTORY_LENGTH + 1)
|
|
53
|
+
with self.assertRaises(FileCheckException) as context:
|
|
54
|
+
check_path_length(path)
|
|
55
|
+
self.assertEqual(str(context.exception),
|
|
56
|
+
FileCheckException.err_strs.get(FileCheckException.ILLEGAL_PATH_ERROR))
|
|
57
|
+
mock_logger_error.assert_called_with("The file path length exceeds limit.")
|
|
58
|
+
|
|
59
|
+
path = "P" * (FileCheckConst.FILE_NAME_LENGTH + 1)
|
|
60
|
+
with self.assertRaises(FileCheckException) as context:
|
|
61
|
+
check_path_length(path)
|
|
62
|
+
self.assertEqual(str(context.exception),
|
|
63
|
+
FileCheckException.err_strs.get(FileCheckException.ILLEGAL_PATH_ERROR))
|
|
64
|
+
mock_logger_error.assert_called_with("The file path length exceeds limit.")
|
|
65
|
+
|
|
66
|
+
path = "P" * (FileCheckConst.FILE_NAME_LENGTH - 5)
|
|
67
|
+
with self.assertRaises(FileCheckException) as context:
|
|
68
|
+
check_path_length(path, name_length=FileCheckConst.FILE_NAME_LENGTH - 6)
|
|
69
|
+
self.assertEqual(str(context.exception),
|
|
70
|
+
FileCheckException.err_strs.get(FileCheckException.ILLEGAL_PATH_ERROR))
|
|
71
|
+
mock_logger_error.assert_called_with("The file path length exceeds limit.")
|
|
72
|
+
|
|
73
|
+
@patch.object(logger, "error")
|
|
74
|
+
def test_check_path_exists(self, mock_logger_error):
|
|
75
|
+
with patch("msprobe.core.common.file_check.os.path.exists", return_value=False):
|
|
76
|
+
with self.assertRaises(FileCheckException) as context:
|
|
77
|
+
check_path_exists("file_path")
|
|
78
|
+
self.assertEqual(str(context.exception),
|
|
79
|
+
FileCheckException.err_strs.get(FileCheckException.ILLEGAL_PATH_ERROR))
|
|
80
|
+
mock_logger_error.assert_called_with("The file path file_path does not exist.")
|
|
81
|
+
|
|
82
|
+
@patch.object(logger, "error")
|
|
83
|
+
def test_check_path_readability(self, mock_logger_error):
|
|
84
|
+
path = "file_path"
|
|
85
|
+
with patch("msprobe.core.common.file_check.os.access", return_value=False):
|
|
86
|
+
with self.assertRaises(FileCheckException) as context:
|
|
87
|
+
check_path_readability(path)
|
|
88
|
+
self.assertEqual(str(context.exception),
|
|
89
|
+
FileCheckException.err_strs.get(FileCheckException.FILE_PERMISSION_ERROR))
|
|
90
|
+
mock_logger_error.assert_called_with(f"The file path {path} is not readable.")
|
|
91
|
+
|
|
92
|
+
mock_access = MagicMock()
|
|
93
|
+
mock_access.return_value = True
|
|
94
|
+
with patch("msprobe.core.common.file_check.os.access", new=mock_access):
|
|
95
|
+
check_path_readability(path)
|
|
96
|
+
self.assertEqual(mock_access.call_args[0], (path, os.R_OK))
|
|
97
|
+
|
|
98
|
+
@patch.object(logger, "error")
|
|
99
|
+
def test_check_path_writability(self, mock_logger_error):
|
|
100
|
+
path = "file_path"
|
|
101
|
+
with patch("msprobe.core.common.file_check.os.access", return_value=False):
|
|
102
|
+
with self.assertRaises(FileCheckException) as context:
|
|
103
|
+
check_path_writability(path)
|
|
104
|
+
self.assertEqual(str(context.exception),
|
|
105
|
+
FileCheckException.err_strs.get(FileCheckException.FILE_PERMISSION_ERROR))
|
|
106
|
+
mock_logger_error.assert_called_with(f"The file path {path} is not writable.")
|
|
107
|
+
|
|
108
|
+
mock_access = MagicMock()
|
|
109
|
+
mock_access.return_value = True
|
|
110
|
+
with patch("msprobe.core.common.file_check.os.access", new=mock_access):
|
|
111
|
+
check_path_writability(path)
|
|
112
|
+
self.assertEqual(mock_access.call_args[0], (path, os.W_OK))
|
|
113
|
+
|
|
114
|
+
@patch.object(logger, "error")
|
|
115
|
+
def test_check_path_executable(self, mock_logger_error):
|
|
116
|
+
path = "file_path"
|
|
117
|
+
with patch("msprobe.core.common.file_check.os.access", return_value=False):
|
|
118
|
+
with self.assertRaises(FileCheckException) as context:
|
|
119
|
+
check_path_executable(path)
|
|
120
|
+
self.assertEqual(str(context.exception),
|
|
121
|
+
FileCheckException.err_strs.get(FileCheckException.FILE_PERMISSION_ERROR))
|
|
122
|
+
mock_logger_error.assert_called_with(f"The file path {path} is not executable.")
|
|
123
|
+
|
|
124
|
+
mock_access = MagicMock()
|
|
125
|
+
mock_access.return_value = True
|
|
126
|
+
with patch("msprobe.core.common.file_check.os.access", new=mock_access):
|
|
127
|
+
check_path_executable(path)
|
|
128
|
+
self.assertEqual(mock_access.call_args[0], (path, os.X_OK))
|
|
129
|
+
|
|
130
|
+
@patch.object(logger, "error")
|
|
131
|
+
def test_check_other_user_writable(self, mock_logger_error):
|
|
132
|
+
class TestStat:
|
|
133
|
+
def __init__(self, mode):
|
|
134
|
+
self.st_mode = mode
|
|
135
|
+
|
|
136
|
+
path = "file_path"
|
|
137
|
+
mock_stat = TestStat(0o002)
|
|
138
|
+
with patch("msprobe.core.common.file_check.os.stat", return_value=mock_stat):
|
|
139
|
+
with self.assertRaises(FileCheckException) as context:
|
|
140
|
+
check_other_user_writable(path)
|
|
141
|
+
self.assertEqual(str(context.exception),
|
|
142
|
+
FileCheckException.err_strs.get(FileCheckException.FILE_PERMISSION_ERROR))
|
|
143
|
+
mock_logger_error.assert_called_with(f"The file path {path} may be insecure "
|
|
144
|
+
"because other users have write permissions. ")
|
|
145
|
+
|
|
146
|
+
@patch.object(logger, "error")
|
|
147
|
+
def test_check_path_owner_consistent(self, mock_logger_error):
|
|
148
|
+
file_path = os.path.realpath(__file__)
|
|
149
|
+
file_owner = os.stat(file_path).st_uid
|
|
150
|
+
with patch("msprobe.core.common.file_check.os.getuid", return_value=file_owner+1):
|
|
151
|
+
with self.assertRaises(FileCheckException) as context:
|
|
152
|
+
check_path_owner_consistent(file_path)
|
|
153
|
+
self.assertEqual(str(context.exception),
|
|
154
|
+
FileCheckException.err_strs.get(FileCheckException.FILE_PERMISSION_ERROR))
|
|
155
|
+
mock_logger_error.assert_called_with(f"The file path {file_path} may be insecure "
|
|
156
|
+
"because is does not belong to you.")
|
|
157
|
+
|
|
158
|
+
@patch.object(logger, "error")
|
|
159
|
+
def test_check_path_pattern_vaild(self, mock_logger_error):
|
|
160
|
+
path = "path"
|
|
161
|
+
mock_re_match = MagicMock()
|
|
162
|
+
mock_re_match.return_value = False
|
|
163
|
+
with patch("msprobe.core.common.file_check.re.match", new=mock_re_match):
|
|
164
|
+
with self.assertRaises(FileCheckException) as context:
|
|
165
|
+
check_path_pattern_vaild(path)
|
|
166
|
+
self.assertEqual(str(context.exception),
|
|
167
|
+
FileCheckException.err_strs.get(FileCheckException.ILLEGAL_PATH_ERROR))
|
|
168
|
+
mock_logger_error.assert_called_with(f"The file path {path} contains special characters.")
|
|
169
|
+
mock_re_match.assert_called_with(FileCheckConst.FILE_VALID_PATTERN, path)
|
|
170
|
+
|
|
171
|
+
@patch.object(logger, "error")
|
|
172
|
+
def test_check_file_size(self, mock_logger_error):
|
|
173
|
+
file_path = os.path.realpath(__file__)
|
|
174
|
+
file_size = os.path.getsize(file_path)
|
|
175
|
+
max_size = file_size
|
|
176
|
+
with self.assertRaises(FileCheckException) as context:
|
|
177
|
+
check_file_size(file_path, max_size)
|
|
178
|
+
self.assertEqual(str(context.exception),
|
|
179
|
+
FileCheckException.err_strs.get(FileCheckException.FILE_TOO_LARGE_ERROR))
|
|
180
|
+
mock_logger_error.assert_called_with(f"The size of file path {file_path} exceeds {max_size} bytes.")
|
|
181
|
+
|
|
182
|
+
def test_check_common_file_size(self):
|
|
183
|
+
mock_check_file_size = MagicMock()
|
|
184
|
+
with patch("msprobe.core.common.file_check.os.path.isfile", return_value=True), \
|
|
185
|
+
patch("msprobe.core.common.file_check.check_file_size", new=mock_check_file_size):
|
|
186
|
+
for suffix, max_size in FileCheckConst.FILE_SIZE_DICT.items():
|
|
187
|
+
check_common_file_size(suffix)
|
|
188
|
+
mock_check_file_size.assert_called_with(suffix, max_size)
|
|
189
|
+
|
|
190
|
+
@patch.object(logger, "error")
|
|
191
|
+
def test_check_file_suffix(self, mock_logger_error):
|
|
192
|
+
file_path = "file_path"
|
|
193
|
+
suffix = "suffix"
|
|
194
|
+
with self.assertRaises(FileCheckException) as context:
|
|
195
|
+
check_file_suffix(file_path, suffix)
|
|
196
|
+
self.assertEqual(str(context.exception),
|
|
197
|
+
FileCheckException.err_strs.get(FileCheckException.INVALID_FILE_ERROR))
|
|
198
|
+
mock_logger_error.assert_called_with(f"The {file_path} should be a {suffix} file!")
|
|
199
|
+
|
|
200
|
+
@patch.object(logger, "error")
|
|
201
|
+
def test_check_path_type(self, mock_logger_error):
|
|
202
|
+
file_path = "file_path"
|
|
203
|
+
|
|
204
|
+
with patch("msprobe.core.common.file_check.os.path.isfile", return_value=False), \
|
|
205
|
+
patch("msprobe.core.common.file_check.os.path.isdir", return_value=True):
|
|
206
|
+
with self.assertRaises(FileCheckException) as context:
|
|
207
|
+
check_path_type(file_path, FileCheckConst.FILE)
|
|
208
|
+
self.assertEqual(str(context.exception),
|
|
209
|
+
FileCheckException.err_strs.get(FileCheckException.INVALID_FILE_ERROR))
|
|
210
|
+
mock_logger_error.assert_called_with(f"The {file_path} should be a file!")
|
|
211
|
+
|
|
212
|
+
with patch("msprobe.core.common.file_check.os.path.isfile", return_value=True), \
|
|
213
|
+
patch("msprobe.core.common.file_check.os.path.isdir", return_value=False):
|
|
214
|
+
with self.assertRaises(FileCheckException) as context:
|
|
215
|
+
check_path_type(file_path, FileCheckConst.DIR)
|
|
216
|
+
self.assertEqual(str(context.exception),
|
|
217
|
+
FileCheckException.err_strs.get(FileCheckException.INVALID_FILE_ERROR))
|
|
218
|
+
mock_logger_error.assert_called_with(f"The {file_path} should be a dictionary!")
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
from unittest import TestCase
|
|
18
|
+
from unittest.mock import patch, MagicMock
|
|
19
|
+
|
|
20
|
+
from msprobe.core.common.log import BaseLogger, logger
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class TestLog(TestCase):
|
|
24
|
+
@patch("msprobe.core.common.log.print")
|
|
25
|
+
def test__print_log(self, mock_print):
|
|
26
|
+
logger._print_log("level", "msg")
|
|
27
|
+
self.assertIn("[level] msg", mock_print.call_args[0][0])
|
|
28
|
+
self.assertEqual("\n", mock_print.call_args[1].get("end"))
|
|
29
|
+
|
|
30
|
+
logger._print_log("level", "msg", end="end")
|
|
31
|
+
self.assertIn("[level] msg", mock_print.call_args[0][0])
|
|
32
|
+
self.assertEqual("end", mock_print.call_args[1].get("end"))
|
|
33
|
+
|
|
34
|
+
@patch.object(BaseLogger, "_print_log")
|
|
35
|
+
def test_print_info_log(self, mock__print_log):
|
|
36
|
+
logger.info("info_msg")
|
|
37
|
+
mock__print_log.assert_called_with("INFO", "info_msg")
|
|
38
|
+
|
|
39
|
+
@patch.object(BaseLogger, "_print_log")
|
|
40
|
+
def test_print_warn_log(self, mock__print_log):
|
|
41
|
+
logger.warning("warn_msg")
|
|
42
|
+
mock__print_log.assert_called_with("WARNING", "warn_msg")
|
|
43
|
+
|
|
44
|
+
@patch.object(BaseLogger, "_print_log")
|
|
45
|
+
def test_print_error_log(self, mock__print_log):
|
|
46
|
+
logger.error("error_msg")
|
|
47
|
+
mock__print_log.assert_called_with("ERROR", "error_msg")
|
|
48
|
+
|
|
49
|
+
@patch.object(BaseLogger, "error")
|
|
50
|
+
def test_error_log_with_exp(self, mock_error):
|
|
51
|
+
with self.assertRaises(Exception) as context:
|
|
52
|
+
logger.error_log_with_exp("msg", Exception("Exception"))
|
|
53
|
+
self.assertEqual(str(context.exception), "Exception")
|
|
54
|
+
mock_error.assert_called_with("msg")
|
|
55
|
+
|
|
56
|
+
@patch.object(BaseLogger, "get_rank")
|
|
57
|
+
def test_on_rank_0(self, mock_get_rank):
|
|
58
|
+
mock_func = MagicMock()
|
|
59
|
+
func_rank_0 = logger.on_rank_0(mock_func)
|
|
60
|
+
|
|
61
|
+
mock_get_rank.return_value = 1
|
|
62
|
+
func_rank_0()
|
|
63
|
+
mock_func.assert_not_called()
|
|
64
|
+
|
|
65
|
+
mock_get_rank.return_value = 0
|
|
66
|
+
func_rank_0()
|
|
67
|
+
mock_func.assert_called()
|
|
68
|
+
|
|
69
|
+
mock_func = MagicMock()
|
|
70
|
+
func_rank_0 = logger.on_rank_0(mock_func)
|
|
71
|
+
mock_get_rank.return_value = None
|
|
72
|
+
func_rank_0()
|
|
73
|
+
mock_func.assert_called()
|
|
74
|
+
|
|
75
|
+
@patch.object(BaseLogger, "get_rank")
|
|
76
|
+
def test_info_on_rank_0(self, mock_get_rank):
|
|
77
|
+
mock_print = MagicMock()
|
|
78
|
+
with patch("msprobe.core.common.log.print", new=mock_print):
|
|
79
|
+
mock_get_rank.return_value = 0
|
|
80
|
+
logger.info_on_rank_0("msg")
|
|
81
|
+
self.assertIn("[INFO] msg", mock_print.call_args[0][0])
|
|
82
|
+
|
|
83
|
+
mock_get_rank.return_value = 1
|
|
84
|
+
logger.info_on_rank_0("msg")
|
|
85
|
+
mock_print.assert_called_once()
|
|
86
|
+
|
|
87
|
+
@patch.object(BaseLogger, "get_rank")
|
|
88
|
+
def test_error_on_rank_0(self, mock_get_rank):
|
|
89
|
+
mock_print = MagicMock()
|
|
90
|
+
with patch("msprobe.core.common.log.print", new=mock_print):
|
|
91
|
+
mock_get_rank.return_value = 0
|
|
92
|
+
logger.error_on_rank_0("msg")
|
|
93
|
+
self.assertIn("[ERROR] msg", mock_print.call_args[0][0])
|
|
94
|
+
|
|
95
|
+
mock_get_rank.return_value = 1
|
|
96
|
+
logger.error_on_rank_0("msg")
|
|
97
|
+
mock_print.assert_called_once()
|
|
98
|
+
|
|
99
|
+
@patch.object(BaseLogger, "get_rank")
|
|
100
|
+
def test_warning_on_rank_0(self, mock_get_rank):
|
|
101
|
+
mock_print = MagicMock()
|
|
102
|
+
with patch("msprobe.core.common.log.print", new=mock_print):
|
|
103
|
+
mock_get_rank.return_value = 0
|
|
104
|
+
logger.warning_on_rank_0("msg")
|
|
105
|
+
self.assertIn("[WARNING] msg", mock_print.call_args[0][0])
|
|
106
|
+
|
|
107
|
+
mock_get_rank.return_value = 1
|
|
108
|
+
logger.warning_on_rank_0("msg")
|
|
109
|
+
mock_print.assert_called_once()
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from unittest import TestCase
|
|
20
|
+
from unittest.mock import patch
|
|
21
|
+
|
|
22
|
+
from msprobe.core.common_config import CommonConfig, BaseConfig
|
|
23
|
+
from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
|
|
24
|
+
from msprobe.mindspore.dump.api_kbk_dump import ApiKbkDump
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TestApiKbkDump(TestCase):
|
|
28
|
+
|
|
29
|
+
def test_handle(self):
|
|
30
|
+
json_config = {
|
|
31
|
+
"task": "statistics",
|
|
32
|
+
"dump_path": "/absolute_path",
|
|
33
|
+
"rank": [],
|
|
34
|
+
"step": [0, 2],
|
|
35
|
+
"level": "L1"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
common_config = CommonConfig(json_config)
|
|
39
|
+
task_config = BaseConfig(json_config)
|
|
40
|
+
config = DebuggerConfig(common_config, task_config)
|
|
41
|
+
dumper = ApiKbkDump(config)
|
|
42
|
+
self.assertEqual(dumper.dump_json["common_dump_settings"]["iteration"], "0|2")
|
|
43
|
+
|
|
44
|
+
os.environ["MS_ACL_DUMP_CFG_PATH"] = "path"
|
|
45
|
+
with patch("msprobe.mindspore.dump.api_kbk_dump.make_dump_path_if_not_exists"), \
|
|
46
|
+
patch("msprobe.mindspore.dump.api_kbk_dump.FileOpen"), \
|
|
47
|
+
patch("msprobe.mindspore.dump.api_kbk_dump.json.dump"), \
|
|
48
|
+
patch("msprobe.mindspore.dump.api_kbk_dump.logger.info"):
|
|
49
|
+
dumper.handle()
|
|
50
|
+
self.assertEqual(os.environ.get("GRAPH_OP_RUN"), "1")
|
|
51
|
+
self.assertEqual(os.environ.get("MS_ACL_DUMP_CFG_PATH"), None)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
from unittest import TestCase
|
|
18
|
+
|
|
19
|
+
from msprobe.core.common.const import Const
|
|
20
|
+
from msprobe.core.common_config import CommonConfig, BaseConfig
|
|
21
|
+
from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestDebuggerConfig(TestCase):
|
|
25
|
+
def test_init(self):
|
|
26
|
+
json_config = {
|
|
27
|
+
"dump_path": "/absolute_path",
|
|
28
|
+
"rank": [],
|
|
29
|
+
"step": [],
|
|
30
|
+
"level": "L1"
|
|
31
|
+
}
|
|
32
|
+
common_config = CommonConfig(json_config)
|
|
33
|
+
task_config = BaseConfig(json_config)
|
|
34
|
+
debugger_config = DebuggerConfig(common_config, task_config)
|
|
35
|
+
self.assertEqual(debugger_config.task, Const.STATISTICS)
|
|
36
|
+
self.assertEqual(debugger_config.file_format, "npy")
|
|
37
|
+
self.assertEqual(debugger_config.check_mode, "all")
|
|
38
|
+
|
|
39
|
+
common_config.dump_path = "./path"
|
|
40
|
+
with self.assertRaises(Exception) as context:
|
|
41
|
+
DebuggerConfig(common_config, task_config)
|
|
42
|
+
self.assertEqual(str(context.exception), "Dump path must be absolute path.")
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
from unittest import TestCase
|
|
18
|
+
|
|
19
|
+
from msprobe.core.common_config import CommonConfig, BaseConfig
|
|
20
|
+
from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
|
|
21
|
+
from msprobe.mindspore.dump.dump_tool_factory import DumpToolFactory
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestDumpToolFactory(TestCase):
|
|
25
|
+
|
|
26
|
+
def test_create(self):
|
|
27
|
+
json_config = {
|
|
28
|
+
"task": "statistics",
|
|
29
|
+
"dump_path": "/absolute_path",
|
|
30
|
+
"rank": [],
|
|
31
|
+
"step": [0, 2],
|
|
32
|
+
"level": "L1"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
common_config = CommonConfig(json_config)
|
|
36
|
+
task_config = BaseConfig(json_config)
|
|
37
|
+
config = DebuggerConfig(common_config, task_config)
|
|
38
|
+
|
|
39
|
+
config.level = "module"
|
|
40
|
+
with self.assertRaises(Exception) as context:
|
|
41
|
+
DumpToolFactory.create(config)
|
|
42
|
+
self.assertEqual(str(context.exception), "valid level is needed.")
|
|
43
|
+
|
|
44
|
+
config.level = "cell"
|
|
45
|
+
with self.assertRaises(Exception) as context:
|
|
46
|
+
DumpToolFactory.create(config)
|
|
47
|
+
self.assertEqual(str(context.exception), "Cell dump in not supported now.")
|
|
48
|
+
|
|
49
|
+
config.level = "kernel"
|
|
50
|
+
dumper = DumpToolFactory.create(config)
|
|
51
|
+
self.assertEqual(dumper.dump_json["common_dump_settings"]["net_name"], "Net")
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from unittest import TestCase
|
|
20
|
+
from unittest.mock import patch
|
|
21
|
+
|
|
22
|
+
from msprobe.core.common_config import CommonConfig, BaseConfig
|
|
23
|
+
from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
|
|
24
|
+
from msprobe.mindspore.dump.kernel_graph_dump import KernelGraphDump
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TestKernelGraphDump(TestCase):
|
|
28
|
+
|
|
29
|
+
def test_handle(self):
|
|
30
|
+
json_config = {
|
|
31
|
+
"task": "tensor",
|
|
32
|
+
"dump_path": "/absolute_path",
|
|
33
|
+
"rank": [],
|
|
34
|
+
"step": [0, 2],
|
|
35
|
+
"level": "L2"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
common_config = CommonConfig(json_config)
|
|
39
|
+
task_config = BaseConfig(json_config)
|
|
40
|
+
task_config.data_mode = ["output"]
|
|
41
|
+
task_config.file_format = "bin"
|
|
42
|
+
config = DebuggerConfig(common_config, task_config)
|
|
43
|
+
dumper = KernelGraphDump(config)
|
|
44
|
+
self.assertEqual(dumper.dump_json["common_dump_settings"]["iteration"], "0|2")
|
|
45
|
+
self.assertEqual(dumper.dump_json["common_dump_settings"]["file_format"], "bin")
|
|
46
|
+
self.assertEqual(dumper.dump_json["common_dump_settings"]["input_output"], 2)
|
|
47
|
+
|
|
48
|
+
with patch("msprobe.mindspore.dump.kernel_graph_dump.make_dump_path_if_not_exists"), \
|
|
49
|
+
patch("msprobe.mindspore.dump.kernel_graph_dump.FileOpen"), \
|
|
50
|
+
patch("msprobe.mindspore.dump.kernel_graph_dump.json.dump"), \
|
|
51
|
+
patch("msprobe.mindspore.dump.kernel_graph_dump.logger.info"):
|
|
52
|
+
|
|
53
|
+
os.environ["GRAPH_OP_RUN"] = "1"
|
|
54
|
+
with self.assertRaises(Exception) as context:
|
|
55
|
+
dumper.handle()
|
|
56
|
+
self.assertEqual(str(context.exception), "Must run in graph mode, not kbk mode")
|
|
57
|
+
if "GRAPH_OP_RUN" in os.environ:
|
|
58
|
+
del os.environ["GRAPH_OP_RUN"]
|
|
59
|
+
|
|
60
|
+
dumper.handle()
|
|
61
|
+
self.assertIn("kernel_graph_dump.json", os.environ.get("MS_ACL_DUMP_CFG_PATH"))
|
|
62
|
+
|
|
63
|
+
if "MINDSPORE_DUMP_CONFIG" in os.environ:
|
|
64
|
+
del os.environ["MINDSPORE_DUMP_CONFIG"]
|
|
65
|
+
if "MS_ACL_DUMP_CFG_PATH" in os.environ:
|
|
66
|
+
del os.environ["MS_ACL_DUMP_CFG_PATH"]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from unittest import TestCase
|
|
20
|
+
from unittest.mock import patch
|
|
21
|
+
|
|
22
|
+
from msprobe.core.common_config import CommonConfig, BaseConfig
|
|
23
|
+
from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
|
|
24
|
+
from msprobe.mindspore.overflow_check.kernel_graph_overflow_check import KernelGraphOverflowCheck
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class TestKernelGraphOverflowCheck(TestCase):
|
|
28
|
+
|
|
29
|
+
def test_handle(self):
|
|
30
|
+
json_config = {
|
|
31
|
+
"task": "overflow_check",
|
|
32
|
+
"dump_path": "/absolute_path",
|
|
33
|
+
"rank": [],
|
|
34
|
+
"step": [],
|
|
35
|
+
"level": "L2"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
common_config = CommonConfig(json_config)
|
|
39
|
+
task_config = BaseConfig(json_config)
|
|
40
|
+
task_config.check_mode = "atomic"
|
|
41
|
+
config = DebuggerConfig(common_config, task_config)
|
|
42
|
+
checker = KernelGraphOverflowCheck(config)
|
|
43
|
+
self.assertEqual(checker.dump_json["common_dump_settings"]["op_debug_mode"], 2)
|
|
44
|
+
|
|
45
|
+
os.environ["MS_ACL_DUMP_CFG_PATH"] = "path"
|
|
46
|
+
with patch("msprobe.mindspore.overflow_check.kernel_graph_overflow_check.make_dump_path_if_not_exists"), \
|
|
47
|
+
patch("msprobe.mindspore.overflow_check.kernel_graph_overflow_check.FileOpen"), \
|
|
48
|
+
patch("msprobe.mindspore.overflow_check.kernel_graph_overflow_check.json.dump"), \
|
|
49
|
+
patch("msprobe.mindspore.overflow_check.kernel_graph_overflow_check.logger.info"):
|
|
50
|
+
|
|
51
|
+
os.environ["GRAPH_OP_RUN"] = "1"
|
|
52
|
+
with self.assertRaises(Exception) as context:
|
|
53
|
+
checker.handle()
|
|
54
|
+
self.assertEqual(str(context.exception), "Must run in graph mode, not kbk mode")
|
|
55
|
+
if "GRAPH_OP_RUN" in os.environ:
|
|
56
|
+
del os.environ["GRAPH_OP_RUN"]
|
|
57
|
+
|
|
58
|
+
checker.handle()
|
|
59
|
+
self.assertIn("kernel_graph_overflow_check.json", os.environ.get("MINDSPORE_DUMP_CONFIG"))
|
|
60
|
+
self.assertEqual(os.environ.get("MS_ACL_DUMP_CFG_PATH"), None)
|
|
61
|
+
|
|
62
|
+
if "MINDSPORE_DUMP_CONFIG" in os.environ:
|
|
63
|
+
del os.environ["MINDSPORE_DUMP_CONFIG"]
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# Copyright (C) 2024-2024. Huawei Technologies Co., Ltd. All rights reserved.
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
"""
|
|
17
|
+
from unittest import TestCase
|
|
18
|
+
from unittest.mock import patch, mock_open
|
|
19
|
+
|
|
20
|
+
from msprobe.core.common.const import Const
|
|
21
|
+
from msprobe.mindspore.ms_config import (parse_json_config, parse_task_config,
|
|
22
|
+
TensorConfig, StatisticsConfig, OverflowCheck)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestMsConfig(TestCase):
|
|
26
|
+
def test_parse_json_config(self):
|
|
27
|
+
mock_json_data = {
|
|
28
|
+
"dump_path": "./dump/",
|
|
29
|
+
"rank": [],
|
|
30
|
+
"step": [],
|
|
31
|
+
"level": "L1",
|
|
32
|
+
"seed": 1234,
|
|
33
|
+
"statistics": {
|
|
34
|
+
"scope": [],
|
|
35
|
+
"list": [],
|
|
36
|
+
"data_mode": ["all"],
|
|
37
|
+
"summary_mode": "statistics"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
with patch("msprobe.mindspore.ms_config.FileOpen", mock_open(read_data='')), \
|
|
41
|
+
patch("msprobe.mindspore.ms_config.json.load", return_value=mock_json_data):
|
|
42
|
+
common_config, task_config = parse_json_config("./config.json")
|
|
43
|
+
self.assertEqual(common_config.task, Const.STATISTICS)
|
|
44
|
+
self.assertEqual(task_config.data_mode, ["all"])
|
|
45
|
+
|
|
46
|
+
with self.assertRaises(Exception) as context:
|
|
47
|
+
parse_json_config(None)
|
|
48
|
+
self.assertEqual(str(context.exception), "json file path is None")
|
|
49
|
+
|
|
50
|
+
def test_parse_task_config(self):
|
|
51
|
+
mock_json_config = {
|
|
52
|
+
"tensor": None,
|
|
53
|
+
"statistics": None,
|
|
54
|
+
"overflow_check": None,
|
|
55
|
+
"free_benchmark": None
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
task_config = parse_task_config("tensor", mock_json_config)
|
|
59
|
+
self.assertTrue(isinstance(task_config, TensorConfig))
|
|
60
|
+
|
|
61
|
+
task_config = parse_task_config("statistics", mock_json_config)
|
|
62
|
+
self.assertTrue(isinstance(task_config, StatisticsConfig))
|
|
63
|
+
|
|
64
|
+
task_config = parse_task_config("overflow_check", mock_json_config)
|
|
65
|
+
self.assertTrue(isinstance(task_config, OverflowCheck))
|
|
66
|
+
|
|
67
|
+
with self.assertRaises(Exception) as context:
|
|
68
|
+
parse_task_config("free_benchmark", mock_json_config)
|
|
69
|
+
self.assertEqual(str(context.exception), "task is invalid.")
|