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,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.overflow_check.overflow_check_tool_factory import OverflowCheckToolFactory
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestOverflowCheckToolFactory(TestCase):
|
|
25
|
+
|
|
26
|
+
def test_create(self):
|
|
27
|
+
json_config = {
|
|
28
|
+
"task": "overflow_check",
|
|
29
|
+
"dump_path": "/absolute_path",
|
|
30
|
+
"rank": [],
|
|
31
|
+
"step": [],
|
|
32
|
+
"level": "L2"
|
|
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
|
+
OverflowCheckToolFactory.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
|
+
OverflowCheckToolFactory.create(config)
|
|
47
|
+
self.assertEqual(str(context.exception), "Overflow check in not supported in this mode.")
|
|
48
|
+
|
|
49
|
+
config.level = "kernel"
|
|
50
|
+
dumper = OverflowCheckToolFactory.create(config)
|
|
51
|
+
self.assertEqual(dumper.dump_json["common_dump_settings"]["file_format"], "npy")
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
|
19
|
+
|
|
20
|
+
from msprobe.core.common_config import CommonConfig, BaseConfig
|
|
21
|
+
from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
|
|
22
|
+
from msprobe.mindspore.debugger.precision_debugger import PrecisionDebugger
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestPrecisionDebugger(TestCase):
|
|
26
|
+
def test_start(self):
|
|
27
|
+
class Handler:
|
|
28
|
+
called = False
|
|
29
|
+
|
|
30
|
+
def handle(self):
|
|
31
|
+
Handler.called = True
|
|
32
|
+
|
|
33
|
+
json_config = {
|
|
34
|
+
"task": "statistics",
|
|
35
|
+
"dump_path": "/absolute_path",
|
|
36
|
+
"rank": [],
|
|
37
|
+
"step": [],
|
|
38
|
+
"level": "L1"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
common_config = CommonConfig(json_config)
|
|
42
|
+
task_config = BaseConfig(json_config)
|
|
43
|
+
handler = Handler()
|
|
44
|
+
|
|
45
|
+
with patch("msprobe.mindspore.debugger.precision_debugger.parse_json_config",
|
|
46
|
+
return_value=[common_config, task_config]), \
|
|
47
|
+
patch("msprobe.mindspore.debugger.precision_debugger.TaskHandlerFactory.create", return_value=handler):
|
|
48
|
+
debugger = PrecisionDebugger()
|
|
49
|
+
debugger.start()
|
|
50
|
+
self.assertTrue(isinstance(debugger.config, DebuggerConfig))
|
|
51
|
+
self.assertTrue(Handler.called)
|
|
52
|
+
|
|
53
|
+
PrecisionDebugger._instance = None
|
|
54
|
+
with self.assertRaises(Exception) as context:
|
|
55
|
+
debugger.start()
|
|
56
|
+
self.assertEqual(str(context.exception), "No instance of PrecisionDebugger found.")
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
|
19
|
+
|
|
20
|
+
from msprobe.core.common_config import CommonConfig, BaseConfig
|
|
21
|
+
from msprobe.mindspore.debugger.debugger_config import DebuggerConfig
|
|
22
|
+
from msprobe.mindspore.dump.kernel_graph_dump import KernelGraphDump
|
|
23
|
+
from msprobe.mindspore.task_handler_factory import TaskHandlerFactory
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TestTaskHandlerFactory(TestCase):
|
|
27
|
+
|
|
28
|
+
def test_create(self):
|
|
29
|
+
class HandlerFactory:
|
|
30
|
+
def create(self):
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
tasks = {"statistics": HandlerFactory}
|
|
34
|
+
|
|
35
|
+
json_config = {
|
|
36
|
+
"task": "statistics",
|
|
37
|
+
"dump_path": "/absolute_path",
|
|
38
|
+
"rank": [],
|
|
39
|
+
"step": [],
|
|
40
|
+
"level": "L2"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
common_config = CommonConfig(json_config)
|
|
44
|
+
task_config = BaseConfig(json_config)
|
|
45
|
+
config = DebuggerConfig(common_config, task_config)
|
|
46
|
+
|
|
47
|
+
handler = TaskHandlerFactory.create(config)
|
|
48
|
+
self.assertTrue(isinstance(handler, KernelGraphDump))
|
|
49
|
+
|
|
50
|
+
with patch("msprobe.mindspore.task_handler_factory.TaskHandlerFactory.tasks", new=tasks):
|
|
51
|
+
with self.assertRaises(Exception) as context:
|
|
52
|
+
TaskHandlerFactory.create(config)
|
|
53
|
+
self.assertEqual(str(context.exception), "Can not find task handler")
|
|
54
|
+
|
|
55
|
+
config.task = "free_benchmark"
|
|
56
|
+
with self.assertRaises(Exception) as context:
|
|
57
|
+
TaskHandlerFactory.create(config)
|
|
58
|
+
self.assertEqual(str(context.exception), "valid task is needed.")
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import difflib
|
|
2
|
+
import os
|
|
3
|
+
import shutil
|
|
4
|
+
import unittest
|
|
5
|
+
import logging
|
|
6
|
+
from unittest.mock import patch
|
|
7
|
+
|
|
8
|
+
import pandas
|
|
9
|
+
|
|
10
|
+
from msprobe.pytorch.advisor.advisor import Advisor
|
|
11
|
+
from msprobe.pytorch.advisor.advisor_const import AdvisorConst
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestAdvisor(unittest.TestCase):
|
|
15
|
+
|
|
16
|
+
def setUp(self):
|
|
17
|
+
self.base_test_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
|
18
|
+
self.input_dir = os.path.join(self.base_test_dir, 'resources')
|
|
19
|
+
self.output_path = os.path.abspath(os.path.join(self.base_test_dir, 'test_output'))
|
|
20
|
+
|
|
21
|
+
os.makedirs(self.output_path, mode=0o700, exist_ok=True)
|
|
22
|
+
self.has_error = False
|
|
23
|
+
|
|
24
|
+
self.input_data = pandas.read_csv(os.path.join(self.input_dir, 'compare_result_20230703104808.csv'))
|
|
25
|
+
self.advisor = Advisor(self.input_data, self.output_path)
|
|
26
|
+
|
|
27
|
+
def tearDown(self) -> None:
|
|
28
|
+
shutil.rmtree(self.output_path, ignore_errors=True)
|
|
29
|
+
|
|
30
|
+
@patch("os.path.realpath")
|
|
31
|
+
def test_init(self, mock_realpath):
|
|
32
|
+
mock_realpath.return_value = 'real_output_path'
|
|
33
|
+
adv = Advisor(self.input_data, self.output_path)
|
|
34
|
+
self.assertEqual(adv.out_path, 'real_output_path')
|
|
35
|
+
|
|
36
|
+
def test_deterministic_advisor_when_api_in_need_determ_api(self):
|
|
37
|
+
msg = self.advisor.deterministic_advisor('', 'Functional.layer_norm.0.forward_input.0')
|
|
38
|
+
self.assertEqual(msg, AdvisorConst.DETERMINISTIC_SUGGEST)
|
|
39
|
+
|
|
40
|
+
def test_deterministic_advisor_when_api_not_in_need_determ_api(self):
|
|
41
|
+
mock_message = 'mock message'
|
|
42
|
+
msg = self.advisor.deterministic_advisor(mock_message, 'Functional.linear.0.forward_input.0')
|
|
43
|
+
self.assertEqual(msg, mock_message)
|
|
44
|
+
|
|
45
|
+
def test_batch_norm_advisor(self):
|
|
46
|
+
mock_message = 'mocked batch norm advisor message'
|
|
47
|
+
msg1 = self.advisor.batch_norm_advisor(mock_message, AdvisorConst.FUNC_BATCH_NORM + '' +
|
|
48
|
+
AdvisorConst.FORWARD_INPUT_1)
|
|
49
|
+
msg2 = self.advisor.batch_norm_advisor(mock_message, 'Functional.linear.0.forward_output.1')
|
|
50
|
+
self.assertEqual(msg1, AdvisorConst.BATCH_NORM_SUGGEST)
|
|
51
|
+
self.assertEqual(msg2, mock_message)
|
|
52
|
+
|
|
53
|
+
def test_gen_advisor_message(self):
|
|
54
|
+
self.assertIn(AdvisorConst.FORWARD_OUTPUT_SUGGEST, self.advisor.gen_advisor_message(
|
|
55
|
+
'Functional.linear.0.forward_output.1'))
|
|
56
|
+
self.assertIn(AdvisorConst.BACKWARD_INPUT_SUGGEST, self.advisor.gen_advisor_message(
|
|
57
|
+
'Functional.linear.0.backward_input.1'))
|
|
58
|
+
|
|
59
|
+
def test_advisor_summary_file(self):
|
|
60
|
+
self.advisor.analysis()
|
|
61
|
+
filenames = os.listdir(self.output_path)
|
|
62
|
+
for filename in filenames:
|
|
63
|
+
filename = os.path.join(self.output_path, filename)
|
|
64
|
+
self.result_check(os.path.join(self.input_dir, 'advisor.txt'), filename)
|
|
65
|
+
self.assertFalse(self.has_error)
|
|
66
|
+
|
|
67
|
+
def result_check(self, standard_file, output_file):
|
|
68
|
+
with open(standard_file, 'r', encoding='utf-8') as st_file:
|
|
69
|
+
standard_content = st_file.read().splitlines()
|
|
70
|
+
with open(output_file, 'r', encoding='utf-8') as out_file:
|
|
71
|
+
output_content = out_file.read().splitlines()
|
|
72
|
+
result = list(difflib.unified_diff(standard_content, output_content, n=0))
|
|
73
|
+
if result:
|
|
74
|
+
logging.basicConfig(level=logging.INFO)
|
|
75
|
+
logging.info('\n\n-------------------------------------------------------------------------')
|
|
76
|
+
logging.error(f'[ERROR] {output_file.replace(self.output_path, "")} advisor summary are inconsistent.')
|
|
77
|
+
logging.error('\n'.join(result))
|
|
78
|
+
logging.info('\n\n-------------------------------------------------------------------------')
|
|
79
|
+
self.has_error = True
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == '__main__':
|
|
83
|
+
unittest.main()
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from unittest.mock import patch
|
|
3
|
+
|
|
4
|
+
from msprobe.pytorch.api_accuracy_checker.common.utils import *
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestUtils(unittest.TestCase):
|
|
8
|
+
|
|
9
|
+
@patch('msprobe.pytorch.api_accuracy_checker.common.utils.get_file_content_bytes')
|
|
10
|
+
def test_get_json_contents_should_raise_exception(self, mock_get_file_content_bytes):
|
|
11
|
+
mock_get_file_content_bytes.return_value = 'not a dict'
|
|
12
|
+
with self.assertRaises(CompareException) as ce:
|
|
13
|
+
get_json_contents('')
|
|
14
|
+
self.assertEqual(ce.exception.code, CompareException.INVALID_FILE_ERROR)
|
|
15
|
+
|
|
16
|
+
def test_get_json_contents_should_return_json_obj(self):
|
|
17
|
+
test_dict = {"key": "value"}
|
|
18
|
+
file_name = 'test.json'
|
|
19
|
+
|
|
20
|
+
fd = os.open(file_name, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644)
|
|
21
|
+
with os.fdopen(fd, 'w') as f:
|
|
22
|
+
json.dump(test_dict, f)
|
|
23
|
+
self.assertEqual(get_json_contents(file_name), test_dict)
|
|
24
|
+
os.remove(file_name)
|
|
25
|
+
|
|
26
|
+
def test_write_csv(self):
|
|
27
|
+
test_file_name = 'test.csv'
|
|
28
|
+
test_data = [["name", "age"], ["Alice", "20"], ["Bob", "30"]]
|
|
29
|
+
write_csv(test_data, 'test.csv')
|
|
30
|
+
with open(test_file_name, 'r', encoding='utf-8-sig') as f:
|
|
31
|
+
reader = csv.reader(f)
|
|
32
|
+
for i, row in enumerate(reader):
|
|
33
|
+
self.assertEqual(row, test_data[i])
|
|
34
|
+
os.remove(test_file_name)
|
|
35
|
+
|
|
36
|
+
def test_check_need_convert(self):
|
|
37
|
+
self.assertEqual(check_need_convert('cross_entropy'), 'int32_to_int64')
|
|
38
|
+
self.assertIsNone(check_need_convert('linear'))
|
|
39
|
+
|
|
40
|
+
def test_check_object_type(self):
|
|
41
|
+
try:
|
|
42
|
+
check_object_type(123, int)
|
|
43
|
+
except Exception as e:
|
|
44
|
+
self.fail(f"check_object_type raised exception {e}")
|
|
45
|
+
|
|
46
|
+
def test_check_file_or_directory_path(self):
|
|
47
|
+
try:
|
|
48
|
+
check_file_or_directory_path(__file__)
|
|
49
|
+
except Exception as e:
|
|
50
|
+
self.fail(f"check_file_or_directory_path raised exception {e}")
|
|
51
|
+
|
|
52
|
+
def test_create_directory(self):
|
|
53
|
+
test_dir_name = 'test_dir'
|
|
54
|
+
create_directory(test_dir_name)
|
|
55
|
+
self.assertTrue(os.path.exists(test_dir_name))
|
|
56
|
+
os.rmdir(test_dir_name)
|
|
57
|
+
|
|
58
|
+
def test_get_file_content_bytes(self):
|
|
59
|
+
fd = os.open('test.txt', os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o644)
|
|
60
|
+
with os.fdopen(fd, 'w') as f:
|
|
61
|
+
f.write("Hello, World!")
|
|
62
|
+
self.assertEqual(get_file_content_bytes('test.txt'), b"Hello, World!")
|
|
63
|
+
os.remove('test.txt')
|
|
64
|
+
|
|
65
|
+
@patch('os.path.exists')
|
|
66
|
+
def test_check_file_or_dir_path_should_raise_exe_when_dir_path_not_existed(self, mock_path_exists):
|
|
67
|
+
mock_path_exists.return_value = False
|
|
68
|
+
with self.assertRaises(CompareException) as ce:
|
|
69
|
+
check_file_or_directory_path('', isdir=True)
|
|
70
|
+
self.assertEqual(ce.exception.code, CompareException.INVALID_PATH_ERROR)
|
|
71
|
+
|
|
72
|
+
@patch('os.path.exists')
|
|
73
|
+
@patch('os.path.isdir')
|
|
74
|
+
@patch('os.access')
|
|
75
|
+
def test_check_file_or_dir_path_should_pass_when_path_is_dir(self, mock_os_access, mock_path_is_dir,
|
|
76
|
+
mock_path_exists):
|
|
77
|
+
mock_os_access.return_value = True
|
|
78
|
+
mock_path_is_dir.return_value = True
|
|
79
|
+
mock_path_exists.return_value = True
|
|
80
|
+
check_file_or_directory_path('', isdir=True)
|
|
81
|
+
|
|
82
|
+
@patch('os.path.isfile')
|
|
83
|
+
@patch('os.access')
|
|
84
|
+
def test_check_file_or_dir_path_should_raise_exe_when_file_not_access(self, mock_os_access, mock_path_is_file):
|
|
85
|
+
mock_os_access.return_value = False
|
|
86
|
+
mock_path_is_file.return_value = True
|
|
87
|
+
with self.assertRaises(CompareException) as ce:
|
|
88
|
+
check_file_or_directory_path('', isdir=False)
|
|
89
|
+
self.assertEqual(ce.exception.code, CompareException.INVALID_PATH_ERROR)
|
|
90
|
+
|
|
91
|
+
def test_check_file_or_dir_path_should_pass_when_path_is_file(self):
|
|
92
|
+
with unittest.mock.patch('os.path.isfile', return_value=True), \
|
|
93
|
+
unittest.mock.patch('os.access', return_value=True):
|
|
94
|
+
check_file_or_directory_path('', isdir=False)
|
|
95
|
+
|
|
96
|
+
def test_api_info_preprocess_no_conversion_needed(self):
|
|
97
|
+
api_name = 'linear'
|
|
98
|
+
original_api_info = {'key': 'value'}
|
|
99
|
+
convert_type, processed_api_info = api_info_preprocess(api_name, original_api_info.copy())
|
|
100
|
+
self.assertIsNone(convert_type)
|
|
101
|
+
self.assertEqual(original_api_info, processed_api_info)
|
|
102
|
+
|
|
103
|
+
def test_api_info_preprocess_cross_entropy_positive(self):
|
|
104
|
+
api_name = 'cross_entropy'
|
|
105
|
+
api_info = {'args': [{'Name': 'logit'}, {'Name': 'labels', 'Min': 1}]}
|
|
106
|
+
convert_type, processed_api_info = api_info_preprocess(api_name, api_info.copy())
|
|
107
|
+
self.assertEqual(convert_type, 'int32_to_int64')
|
|
108
|
+
self.assertEqual(processed_api_info, api_info)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import os
|
|
3
|
+
from unittest.mock import patch
|
|
4
|
+
|
|
5
|
+
from msprobe.pytorch.api_accuracy_checker.common.config import Config
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestConfig(unittest.TestCase):
|
|
9
|
+
def setUp(self):
|
|
10
|
+
self.base_test_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
|
|
11
|
+
self.input_dir = os.path.join(self.base_test_dir, 'resources')
|
|
12
|
+
self.yaml_file = os.path.join(self.input_dir, "config.yaml")
|
|
13
|
+
self.cfg = Config(self.yaml_file)
|
|
14
|
+
|
|
15
|
+
def test_validate_valid_data(self):
|
|
16
|
+
for key, val in self.cfg.config.items():
|
|
17
|
+
validated_type = self.cfg.validate(key, val)
|
|
18
|
+
self.assertEqual(validated_type, val)
|
|
19
|
+
|
|
20
|
+
def test_validate_should_raise_when_invalid_type(self):
|
|
21
|
+
with self.assertRaises(ValueError):
|
|
22
|
+
self.cfg.validate('error_data_path', True)
|
|
23
|
+
|
|
24
|
+
def test_validate_should_raise_when_invalid_key(self):
|
|
25
|
+
with self.assertRaises(ValueError):
|
|
26
|
+
self.cfg.validate('invalid_key', 'mock_value')
|
|
27
|
+
|
|
28
|
+
def test_validate_precision(self):
|
|
29
|
+
self.assertEqual(self.cfg.validate('precision', 1), 1)
|
|
30
|
+
|
|
31
|
+
with self.assertRaises(ValueError):
|
|
32
|
+
self.cfg.validate('precision', -1)
|
|
33
|
+
|
|
34
|
+
def test_validate_white_list(self):
|
|
35
|
+
validate_white_list = ['conv1d', 'max_pool1d', 'dropout', '__add__']
|
|
36
|
+
self.assertEqual(self.cfg.validate('white_list', validate_white_list), validate_white_list)
|
|
37
|
+
|
|
38
|
+
with self.assertRaises(ValueError):
|
|
39
|
+
self.cfg.validate('white_list', ['invalid_api1', 'invalid_api2'])
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from msprobe.pytorch.api_accuracy_checker.compare import algorithm as alg
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestAlgorithmMethods(unittest.TestCase):
|
|
9
|
+
|
|
10
|
+
def setUp(self):
|
|
11
|
+
self.bench_data = np.array([1.0, 1.0, 9.0], dtype=np.float16)
|
|
12
|
+
self.device_data = np.array([5.0, 2.0, 1.0], dtype=np.float16)
|
|
13
|
+
self.abs_err = np.abs(self.device_data - self.bench_data)
|
|
14
|
+
self.rel_err_origin = np.abs(self.abs_err / self.bench_data)
|
|
15
|
+
eps = np.finfo(self.bench_data.dtype).eps
|
|
16
|
+
self.abs_bench = np.abs(self.bench_data)
|
|
17
|
+
self.abs_bench_with_eps = self.abs_bench + eps
|
|
18
|
+
self.rel_err = self.abs_err / self.abs_bench_with_eps
|
|
19
|
+
|
|
20
|
+
def test_cosine_sim(self):
|
|
21
|
+
cpu_output = np.array([1.0, 2.0, 3.0])
|
|
22
|
+
npu_output = np.array([1.0, 2.0, 3.0])
|
|
23
|
+
self.assertEqual(alg.cosine_sim(cpu_output, npu_output), (1.0, True, ''))
|
|
24
|
+
|
|
25
|
+
def test_get_rmse(self):
|
|
26
|
+
inf_nan_mask = [False, False, False]
|
|
27
|
+
self.assertAlmostEqual(alg.get_rmse(self.abs_err, inf_nan_mask), 5.196, 3)
|
|
28
|
+
|
|
29
|
+
def test_get_error_balance(self):
|
|
30
|
+
self.assertEqual(alg.get_error_balance(self.bench_data, self.device_data), 1 / 3)
|
|
31
|
+
|
|
32
|
+
def test_get_small_value_err_ratio(self):
|
|
33
|
+
small_value_mask = [True, True, True, False, True]
|
|
34
|
+
abs_err_greater_mask = [False, True, True, True, False]
|
|
35
|
+
self.assertEqual(alg.get_small_value_err_ratio(small_value_mask, abs_err_greater_mask), 0.5)
|
|
36
|
+
|
|
37
|
+
def get_rel_err(self):
|
|
38
|
+
eps = np.finfo(self.bench_data.dtype).eps
|
|
39
|
+
abs_bench = np.abs(self.bench_data)
|
|
40
|
+
abs_bench_with_eps = abs_bench + eps
|
|
41
|
+
small_value_mask = [False, False, False]
|
|
42
|
+
inf_nan_mask = [False, False, False]
|
|
43
|
+
rel_err = self.abs_err / abs_bench_with_eps
|
|
44
|
+
self.assertListEqual(list(alg.get_rel_err(self.abs_err, abs_bench_with_eps, small_value_mask, inf_nan_mask)),
|
|
45
|
+
list(rel_err))
|
|
46
|
+
|
|
47
|
+
def test_get_abs_err(self):
|
|
48
|
+
self.assertListEqual(list(alg.get_abs_err(self.bench_data, self.device_data)), [4.0, 1.0, 8.0])
|
|
49
|
+
|
|
50
|
+
def test_get_rel_err_origin(self):
|
|
51
|
+
self.assertListEqual(list(alg.get_rel_err_origin(self.abs_err, self.bench_data)), list(self.rel_err_origin))
|
|
52
|
+
|
|
53
|
+
def test_get_max_abs_err(self):
|
|
54
|
+
self.assertEqual(alg.get_max_abs_err(self.abs_err), (8.0, False))
|
|
55
|
+
|
|
56
|
+
def test_get_max_rel_err(self):
|
|
57
|
+
self.assertAlmostEqual(alg.get_max_rel_err(self.rel_err), 3.996, 3)
|
|
58
|
+
|
|
59
|
+
def test_get_mean_rel_err(self):
|
|
60
|
+
self.assertAlmostEqual(alg.get_mean_rel_err(self.rel_err), 1.961, 3)
|
|
61
|
+
|
|
62
|
+
def test_get_rel_err_ratio_thousandth(self):
|
|
63
|
+
b_value = np.array([1.0, 2.0, 3.0])
|
|
64
|
+
n_value = np.array([1.0, 2.0, 3.0])
|
|
65
|
+
abs_err = np.abs(b_value - n_value)
|
|
66
|
+
rel_err = alg.get_rel_err_origin(abs_err, b_value)
|
|
67
|
+
self.assertEqual(alg.get_rel_err_ratio(rel_err, 0.001), (1.0, True))
|
|
68
|
+
|
|
69
|
+
def test_get_rel_err_ratio_ten_thousandth(self):
|
|
70
|
+
b_value = np.array([1.0, 2.0, 3.0])
|
|
71
|
+
n_value = np.array([1.0, 2.0, 3.0])
|
|
72
|
+
abs_err = np.abs(b_value - n_value)
|
|
73
|
+
rel_err = alg.get_rel_err_origin(abs_err, b_value)
|
|
74
|
+
self.assertEqual(alg.get_rel_err_ratio(rel_err, 0.0001), (1.0, True))
|
|
75
|
+
|
|
76
|
+
def test_get_finite_and_infinite_mask(self):
|
|
77
|
+
both_finite_mask, inf_nan_mask = alg.get_finite_and_infinite_mask(self.bench_data, self.device_data)
|
|
78
|
+
self.assertListEqual(list(both_finite_mask), [True, True, True])
|
|
79
|
+
self.assertListEqual(list(inf_nan_mask), [False, False, False])
|
|
80
|
+
|
|
81
|
+
def test_get_small_value_mask(self):
|
|
82
|
+
b_value = np.array([1e-7, 1.0, 2e-6], dtype=np.float16)
|
|
83
|
+
abs_bench = np.abs(b_value)
|
|
84
|
+
both_finite_mask = [True, True, True]
|
|
85
|
+
small_value_mask = alg.get_small_value_mask(abs_bench, both_finite_mask, 1e-3)
|
|
86
|
+
self.assertListEqual(list(small_value_mask), [True, False, True])
|
|
87
|
+
|
|
88
|
+
def test_get_abs_bench_with_eps(self):
|
|
89
|
+
abs_bench, abs_bench_with_eps = alg.get_abs_bench_with_eps(self.bench_data, np.float16)
|
|
90
|
+
self.assertListEqual(list(abs_bench), list(self.abs_bench))
|
|
91
|
+
self.assertListEqual(list(abs_bench_with_eps), list(self.abs_bench_with_eps))
|
|
92
|
+
|
|
93
|
+
def test_check_inf_nan_value(self):
|
|
94
|
+
both_finite_mask, inf_nan_mask = alg.get_finite_and_infinite_mask(self.bench_data, self.device_data)
|
|
95
|
+
self.assertEqual(alg.check_inf_nan_value(inf_nan_mask, self.bench_data, self.device_data, np.float16, 0.001), 0)
|
|
96
|
+
|
|
97
|
+
def test_check_small_value(self):
|
|
98
|
+
a_value = np.array([1e-7, 1.0, 2e-6], dtype=np.float16)
|
|
99
|
+
b_value = np.array([1e-7, 1.0, 2e-6], dtype=np.float16)
|
|
100
|
+
abs_bench = np.abs(b_value)
|
|
101
|
+
both_finite_mask = [True, True, True]
|
|
102
|
+
abs_err = abs(a_value - b_value)
|
|
103
|
+
small_value_mask = alg.get_small_value_mask(abs_bench, both_finite_mask, 1e-3)
|
|
104
|
+
self.assertEqual(alg.check_small_value(abs_err, small_value_mask, 0.001), 0)
|
|
105
|
+
|
|
106
|
+
def test_check_norm_value(self):
|
|
107
|
+
both_finite_mask, inf_nan_mask = alg.get_finite_and_infinite_mask(self.bench_data, self.device_data)
|
|
108
|
+
small_value_mask = alg.get_small_value_mask(self.abs_bench, both_finite_mask, 1e-3)
|
|
109
|
+
normal_value_mask = np.logical_and(both_finite_mask, np.logical_not(small_value_mask))
|
|
110
|
+
print(normal_value_mask)
|
|
111
|
+
print(self.rel_err)
|
|
112
|
+
self.assertEqual(alg.check_norm_value(normal_value_mask, self.rel_err, 0.001), 1)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from msprobe.pytorch.api_accuracy_checker.compare.api_precision_compare import (
|
|
6
|
+
CompareConfig,
|
|
7
|
+
BenchmarkStandard,
|
|
8
|
+
check_csv_columns,
|
|
9
|
+
check_error_rate,
|
|
10
|
+
get_api_checker_result,
|
|
11
|
+
)
|
|
12
|
+
from msprobe.core.common.const import CompareConst
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestApiPrecisionCompare(unittest.TestCase):
|
|
16
|
+
|
|
17
|
+
def setUp(self):
|
|
18
|
+
# Setup paths and mock data
|
|
19
|
+
self.config = CompareConfig(
|
|
20
|
+
npu_csv_path='mock_npu.csv',
|
|
21
|
+
gpu_csv_path='mock_gpu.csv',
|
|
22
|
+
result_csv_path='result.csv',
|
|
23
|
+
details_csv_path='details.csv'
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
self.npu_data = pd.DataFrame({
|
|
27
|
+
'API_NAME': ['api1.forward', 'api1.backward'],
|
|
28
|
+
'DEVICE_DTYPE': ['float32', 'float32'],
|
|
29
|
+
'ERROR_RATE': ['0', '0.1'],
|
|
30
|
+
'SMALL_VALUE_ERROR_RATE': ['0.01', '0.02'],
|
|
31
|
+
'RMSE': ['0.1', '0.2'],
|
|
32
|
+
'MAX_REL_ERR': ['0.1', '0.2'],
|
|
33
|
+
'MEAN_REL_ERR': ['0.1', '0.2'],
|
|
34
|
+
'EB': ['0.1', '0.2']
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
self.gpu_data = pd.DataFrame({
|
|
38
|
+
'API_NAME': ['api1.forward', 'api1.backward'],
|
|
39
|
+
'DEVICE_DTYPE': ['float32', 'float32'],
|
|
40
|
+
'ERROR_RATE': ['0', '0'],
|
|
41
|
+
'SMALL_VALUE_ERROR_RATE': ['0.01', '0.01'],
|
|
42
|
+
'RMSE': ['0.1', '0.1'],
|
|
43
|
+
'MAX_REL_ERR': ['0.1', '0.1'],
|
|
44
|
+
'MEAN_REL_ERR': ['0.1', '0.1'],
|
|
45
|
+
'EB': ['0.1', '0.1']
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
def test_benchmark_standard_calc_ratio(self):
|
|
49
|
+
column_name = "TEST_COLUMN"
|
|
50
|
+
default_value = 0
|
|
51
|
+
result = BenchmarkStandard._calc_ratio(column_name, '2', '1', default_value)
|
|
52
|
+
self.assertEqual(result[0], 2.0)
|
|
53
|
+
|
|
54
|
+
result = BenchmarkStandard._calc_ratio(column_name, '0', '0', default_value)
|
|
55
|
+
self.assertEqual(result[0], 1.0)
|
|
56
|
+
|
|
57
|
+
def test_check_csv_columns(self):
|
|
58
|
+
with self.assertRaises(Exception):
|
|
59
|
+
check_csv_columns([], 'test_csv')
|
|
60
|
+
|
|
61
|
+
def test_check_error_rate(self):
|
|
62
|
+
result = check_error_rate('0')
|
|
63
|
+
self.assertEqual(result, CompareConst.PASS)
|
|
64
|
+
|
|
65
|
+
result = check_error_rate('0.1')
|
|
66
|
+
self.assertEqual(result, CompareConst.ERROR)
|
|
67
|
+
|
|
68
|
+
def test_get_api_checker_result(self):
|
|
69
|
+
result = get_api_checker_result([CompareConst.PASS, CompareConst.ERROR])
|
|
70
|
+
self.assertEqual(result, CompareConst.ERROR)
|
|
71
|
+
|
|
72
|
+
result = get_api_checker_result([CompareConst.PASS, CompareConst.PASS])
|
|
73
|
+
self.assertEqual(result, CompareConst.PASS)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == '__main__':
|
|
77
|
+
unittest.main()
|