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,345 @@
|
|
|
1
|
+
# 进行比对及结果展示
|
|
2
|
+
import os
|
|
3
|
+
from collections import namedtuple
|
|
4
|
+
import torch
|
|
5
|
+
import numpy as np
|
|
6
|
+
from msprobe.pytorch.common.log import logger
|
|
7
|
+
from msprobe.pytorch.api_accuracy_checker.common.utils import get_json_contents, write_csv
|
|
8
|
+
from msprobe.pytorch.api_accuracy_checker.compare.compare_utils import check_dtype_comparable, \
|
|
9
|
+
DETAIL_TEST_ROWS, precision_configs, BENCHMARK_COMPARE_SUPPORT_LIST, AbsoluteStandardApi, BinaryStandardApi, \
|
|
10
|
+
ULPStandardApi, ThousandthStandardApi, apis_threshold
|
|
11
|
+
from msprobe.pytorch.api_accuracy_checker.compare.compare_column import CompareColumn
|
|
12
|
+
from msprobe.pytorch.api_accuracy_checker.compare.algorithm import get_rmse, get_error_balance, get_max_rel_err, \
|
|
13
|
+
get_mean_rel_err, get_rel_err, get_abs_err, get_max_abs_err, get_rel_err_ratio, cosine_sim, get_rel_err_origin, \
|
|
14
|
+
get_small_value_err_ratio, get_finite_and_infinite_mask, get_small_value_mask, check_inf_nan_value, \
|
|
15
|
+
check_small_value, check_norm_value, get_abs_bench_with_eps, get_ulp_err
|
|
16
|
+
from msprobe.pytorch.api_accuracy_checker.common.config import msCheckerConfig
|
|
17
|
+
from msprobe.core.common.const import Const, CompareConst
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
ResultInfo = namedtuple('ResultInfo', ['full_api_name', 'fwd_success_status', 'bwd_success_status',
|
|
21
|
+
'fwd_compare_alg_results', 'bwd_compare_alg_results', 'rank'])
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
INDEX_TEST_RESULT__GROUP = 3
|
|
25
|
+
INDEX_FIRST_GROUP = 0
|
|
26
|
+
INDEX_MESSAGE = -1
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Comparator:
|
|
30
|
+
# consts for result csv
|
|
31
|
+
COLUMN_API_NAME = "API name"
|
|
32
|
+
COLUMN_FORWARD_SUCCESS = "Forward Test Success"
|
|
33
|
+
COLUMN_BACKWARD_SUCCESS = "Backward Test Success"
|
|
34
|
+
COLUMN_STACK_INFO = "Traceback callstack info"
|
|
35
|
+
|
|
36
|
+
def __init__(self, result_csv_path, details_csv_path, is_continue_run_ut, stack_info_json_path=None):
|
|
37
|
+
self.save_path = result_csv_path
|
|
38
|
+
self.detail_save_path = details_csv_path
|
|
39
|
+
if not is_continue_run_ut and not os.path.exists(self.save_path) and not os.path.exists(self.detail_save_path):
|
|
40
|
+
self.write_csv_title()
|
|
41
|
+
if stack_info_json_path:
|
|
42
|
+
self.stack_info = get_json_contents(stack_info_json_path)
|
|
43
|
+
else:
|
|
44
|
+
self.stack_info = None
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def print_pretest_result():
|
|
48
|
+
logger.info("Successfully completed run_ut/multi_run_ut.")
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def _compare_dropout(bench_output, device_output):
|
|
52
|
+
tensor_num = bench_output.numel()
|
|
53
|
+
if tensor_num >= 100:
|
|
54
|
+
if abs((bench_output == 0).sum() - (device_output == 0).cpu().sum()) / tensor_num < 0.1:
|
|
55
|
+
return CompareConst.PASS, 1
|
|
56
|
+
else:
|
|
57
|
+
return CompareConst.ERROR, 0
|
|
58
|
+
else:
|
|
59
|
+
return CompareConst.PASS, 1
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def _compare_builtin_type(bench_output, device_output, compare_column):
|
|
63
|
+
if not isinstance(bench_output, (bool, int, float, str)):
|
|
64
|
+
return CompareConst.PASS, compare_column, ""
|
|
65
|
+
if bench_output != device_output:
|
|
66
|
+
return CompareConst.ERROR, compare_column, ""
|
|
67
|
+
compare_column.error_rate = 0
|
|
68
|
+
return CompareConst.PASS, compare_column, ""
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def _compare_bool_tensor(bench_output, device_output):
|
|
72
|
+
error_nums = (bench_output != device_output).sum()
|
|
73
|
+
if bench_output.size == 0:
|
|
74
|
+
return CompareConst.NAN, CompareConst.ERROR, "There is not bench calculation result."
|
|
75
|
+
error_rate = float(error_nums / bench_output.size)
|
|
76
|
+
result = CompareConst.PASS if error_rate == 0 else CompareConst.ERROR
|
|
77
|
+
return error_rate, result, ""
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def _get_absolute_threshold_attribute(api_name, dtype):
|
|
81
|
+
small_value_threshold = apis_threshold.get(api_name).get(dtype).get('small_value')
|
|
82
|
+
small_value_atol = apis_threshold.get(api_name).get(dtype).get('small_value_atol')
|
|
83
|
+
rtol = apis_threshold.get(api_name).get(dtype).get('rtol')
|
|
84
|
+
return small_value_threshold, small_value_atol, rtol
|
|
85
|
+
|
|
86
|
+
def write_csv_title(self):
|
|
87
|
+
summary_test_rows = [[self.COLUMN_API_NAME, self.COLUMN_FORWARD_SUCCESS,
|
|
88
|
+
self.COLUMN_BACKWARD_SUCCESS, "Message"]]
|
|
89
|
+
if not os.path.exists(self.save_path):
|
|
90
|
+
write_csv(summary_test_rows, self.save_path)
|
|
91
|
+
if not os.path.exists(self.detail_save_path):
|
|
92
|
+
write_csv(DETAIL_TEST_ROWS, self.detail_save_path)
|
|
93
|
+
|
|
94
|
+
def write_summary_csv(self, test_result):
|
|
95
|
+
test_rows = []
|
|
96
|
+
if self.stack_info:
|
|
97
|
+
test_rows[0].append(self.COLUMN_STACK_INFO)
|
|
98
|
+
|
|
99
|
+
name = test_result[0]
|
|
100
|
+
df_row = list(test_result[:INDEX_TEST_RESULT__GROUP])
|
|
101
|
+
if test_result[1] == "SKIP":
|
|
102
|
+
df_row.append(test_result[INDEX_TEST_RESULT__GROUP][INDEX_FIRST_GROUP][INDEX_MESSAGE])
|
|
103
|
+
if self.stack_info:
|
|
104
|
+
stack_info = "\n".join(self.stack_info[name])
|
|
105
|
+
df_row.append(stack_info)
|
|
106
|
+
test_rows.append(df_row)
|
|
107
|
+
write_csv(test_rows, self.save_path)
|
|
108
|
+
|
|
109
|
+
def write_detail_csv(self, test_result):
|
|
110
|
+
test_rows = []
|
|
111
|
+
|
|
112
|
+
subject_prefix = test_result[0]
|
|
113
|
+
fwd_result = test_result[3]
|
|
114
|
+
bwd_result = test_result[4]
|
|
115
|
+
if isinstance(fwd_result, list):
|
|
116
|
+
for i, test_subject in enumerate(fwd_result):
|
|
117
|
+
subject = subject_prefix + ".forward.output." + str(i)
|
|
118
|
+
test_subject = ["{:.{}f}".format(item, msCheckerConfig.precision)
|
|
119
|
+
if isinstance(item, float) else item for item in test_subject]
|
|
120
|
+
test_rows.append([subject] + list(test_subject))
|
|
121
|
+
if isinstance(bwd_result, list):
|
|
122
|
+
for i, test_subject in enumerate(bwd_result):
|
|
123
|
+
subject = subject_prefix + ".backward.output." + str(i)
|
|
124
|
+
test_subject = ["{:.{}f}".format(item, msCheckerConfig.precision)
|
|
125
|
+
if isinstance(item, float) else item for item in test_subject]
|
|
126
|
+
test_rows.append([subject] + list(test_subject))
|
|
127
|
+
|
|
128
|
+
write_csv(test_rows, self.detail_save_path)
|
|
129
|
+
|
|
130
|
+
def record_results(self, args):
|
|
131
|
+
self.write_summary_csv(args)
|
|
132
|
+
self.write_detail_csv(args)
|
|
133
|
+
|
|
134
|
+
def compare_output(self, full_api_name, data_info):
|
|
135
|
+
_, api_name, _ = full_api_name.split(Const.SEP)
|
|
136
|
+
bench_output, device_output = data_info.bench_output, data_info.device_output
|
|
137
|
+
bench_grad, device_grad = data_info.bench_grad, data_info.device_grad
|
|
138
|
+
backward_message = data_info.backward_message
|
|
139
|
+
if "dropout" in full_api_name:
|
|
140
|
+
fwd_success_status, fwd_compare_alg_results = self._compare_dropout(bench_output, device_output)
|
|
141
|
+
else:
|
|
142
|
+
fwd_success_status, fwd_compare_alg_results = self._compare_core_wrapper(api_name, bench_output,
|
|
143
|
+
device_output)
|
|
144
|
+
if not (bench_grad and device_grad):
|
|
145
|
+
bwd_success_status, bwd_compare_alg_results = (CompareConst.SPACE, [])
|
|
146
|
+
else:
|
|
147
|
+
if "dropout" in full_api_name:
|
|
148
|
+
bwd_success_status, bwd_compare_alg_results = self._compare_dropout(bench_grad[0], device_grad[0])
|
|
149
|
+
else:
|
|
150
|
+
bwd_success_status, bwd_compare_alg_results = self._compare_core_wrapper(api_name, bench_grad,
|
|
151
|
+
device_grad)
|
|
152
|
+
if backward_message:
|
|
153
|
+
backward_column = CompareColumn()
|
|
154
|
+
bwd_compare_alg_results = [backward_column.to_column_value(CompareConst.SKIP, backward_message)]
|
|
155
|
+
else:
|
|
156
|
+
bwd_success_status = bwd_success_status if bwd_compare_alg_results is not None else CompareConst.SPACE
|
|
157
|
+
result_info = ResultInfo(full_api_name,
|
|
158
|
+
fwd_success_status,
|
|
159
|
+
bwd_success_status,
|
|
160
|
+
fwd_compare_alg_results,
|
|
161
|
+
bwd_compare_alg_results,
|
|
162
|
+
data_info.rank)
|
|
163
|
+
self.record_results(result_info)
|
|
164
|
+
return fwd_success_status == CompareConst.PASS, bwd_success_status == CompareConst.PASS \
|
|
165
|
+
or bwd_success_status == CompareConst.SPACE
|
|
166
|
+
|
|
167
|
+
def _compare_core_wrapper(self, api_name, bench_output, device_output):
|
|
168
|
+
detailed_result_total = []
|
|
169
|
+
test_final_success = CompareConst.PASS
|
|
170
|
+
if isinstance(bench_output, (list, tuple)):
|
|
171
|
+
status, compare_result, message = [], [], []
|
|
172
|
+
if len(bench_output) > len(device_output):
|
|
173
|
+
status = [CompareConst.ERROR]
|
|
174
|
+
message = ["bench and npu output structure is different."]
|
|
175
|
+
else:
|
|
176
|
+
device_output = device_output[:len(bench_output)]
|
|
177
|
+
for b_out_i, n_out_i in zip(bench_output, device_output):
|
|
178
|
+
status_i, compare_result_i, message_i = self._compare_core(api_name, b_out_i, n_out_i)
|
|
179
|
+
status.append(status_i)
|
|
180
|
+
compare_result.append(compare_result_i)
|
|
181
|
+
message.append(message_i)
|
|
182
|
+
else:
|
|
183
|
+
status, compare_result, message = self._compare_core(api_name, bench_output, device_output)
|
|
184
|
+
if not isinstance(status, list):
|
|
185
|
+
detailed_result_total.append(compare_result.to_column_value(status, message))
|
|
186
|
+
if status == CompareConst.ERROR:
|
|
187
|
+
test_final_success = CompareConst.ERROR
|
|
188
|
+
elif status == CompareConst.WARNING:
|
|
189
|
+
test_final_success = CompareConst.WARNING
|
|
190
|
+
else:
|
|
191
|
+
for item, item_status in enumerate(status):
|
|
192
|
+
detailed_result_total.append(compare_result[item].to_column_value(item_status, message[item]))
|
|
193
|
+
if item_status == CompareConst.ERROR:
|
|
194
|
+
test_final_success = CompareConst.ERROR
|
|
195
|
+
elif item_status == CompareConst.WARNING:
|
|
196
|
+
test_final_success = CompareConst.WARNING
|
|
197
|
+
return test_final_success, detailed_result_total
|
|
198
|
+
|
|
199
|
+
def _compare_core(self, api_name, bench_output, device_output):
|
|
200
|
+
compare_column = CompareColumn()
|
|
201
|
+
if not isinstance(bench_output, type(device_output)):
|
|
202
|
+
return CompareConst.ERROR, compare_column, "bench and npu output type is different."
|
|
203
|
+
elif isinstance(bench_output, dict):
|
|
204
|
+
b_keys, n_keys = set(bench_output.keys()), set(device_output.keys())
|
|
205
|
+
if b_keys != n_keys:
|
|
206
|
+
return CompareConst.ERROR, compare_column, "bench and npu output dict keys are different."
|
|
207
|
+
else:
|
|
208
|
+
status, compare_result, message = self._compare_core(api_name, list(bench_output.values()),
|
|
209
|
+
list(device_output.values()))
|
|
210
|
+
elif isinstance(bench_output, torch.Tensor):
|
|
211
|
+
copy_bench_out = bench_output.detach().clone()
|
|
212
|
+
copy_device_output = device_output.detach().clone()
|
|
213
|
+
compare_column.bench_type = str(copy_bench_out.dtype)
|
|
214
|
+
compare_column.npu_type = str(copy_device_output.dtype)
|
|
215
|
+
compare_column.shape = tuple(device_output.shape)
|
|
216
|
+
status, compare_result, message = self._compare_torch_tensor(api_name, copy_bench_out, copy_device_output,
|
|
217
|
+
compare_column)
|
|
218
|
+
elif isinstance(bench_output, (bool, int, float, str)):
|
|
219
|
+
compare_column.bench_type = str(type(bench_output))
|
|
220
|
+
compare_column.npu_type = str(type(device_output))
|
|
221
|
+
status, compare_result, message = self._compare_builtin_type(bench_output, device_output, compare_column)
|
|
222
|
+
elif bench_output is None:
|
|
223
|
+
return CompareConst.SKIP, compare_column, "Bench output is None, skip this test."
|
|
224
|
+
else:
|
|
225
|
+
return CompareConst.PASS, compare_column,
|
|
226
|
+
"Unexpected output type in compare_core: {}".format(type(bench_output))
|
|
227
|
+
|
|
228
|
+
return status, compare_result, message
|
|
229
|
+
|
|
230
|
+
def _compare_torch_tensor(self, api_name, bench_output, device_output, compare_column):
|
|
231
|
+
cpu_shape = bench_output.shape
|
|
232
|
+
npu_shape = device_output.shape
|
|
233
|
+
npu_dtype = device_output.dtype
|
|
234
|
+
if npu_dtype == torch.bfloat16:
|
|
235
|
+
bench_output = bench_output.to(torch.float32)
|
|
236
|
+
device_output = device_output.to(torch.float32)
|
|
237
|
+
bench_output = bench_output.numpy()
|
|
238
|
+
device_output = device_output.cpu().numpy()
|
|
239
|
+
if cpu_shape != npu_shape:
|
|
240
|
+
return CompareConst.ERROR, compare_column, f"The shape of bench{str(cpu_shape)} " \
|
|
241
|
+
f"and npu{str(npu_shape)} not equal."
|
|
242
|
+
if not check_dtype_comparable(bench_output, device_output):
|
|
243
|
+
return CompareConst.ERROR, compare_column, f"Bench out dtype is {bench_output.dtype} but " \
|
|
244
|
+
f"npu output dtype is {device_output.dtype}, cannot compare."
|
|
245
|
+
message = ""
|
|
246
|
+
if bench_output.dtype in [bool, np.uint8, np.int8, np.int16, np.uint16, np.uint32, np.int32,
|
|
247
|
+
np.int64, np.uint64]:
|
|
248
|
+
message += f"Compare algorithm is not supported for {bench_output.dtype} data. " \
|
|
249
|
+
f"Only judged by Error Rate."
|
|
250
|
+
err_rate, status, msg = self._compare_bool_tensor(bench_output, device_output)
|
|
251
|
+
message += msg + "\n"
|
|
252
|
+
compare_column.error_rate = err_rate
|
|
253
|
+
return status, compare_column, message
|
|
254
|
+
else:
|
|
255
|
+
status, compare_column, message = self._compare_float_tensor(api_name, bench_output, device_output,
|
|
256
|
+
compare_column, npu_dtype)
|
|
257
|
+
return status, compare_column, message
|
|
258
|
+
|
|
259
|
+
def _compare_float_tensor(self, api_name, bench_output, device_output, compare_column, dtype):
|
|
260
|
+
message = ""
|
|
261
|
+
abs_bench, abs_bench_with_eps = get_abs_bench_with_eps(bench_output, dtype)
|
|
262
|
+
abs_err = get_abs_err(bench_output, device_output)
|
|
263
|
+
rel_err_orign = get_rel_err_origin(abs_err, abs_bench_with_eps)
|
|
264
|
+
if api_name in ThousandthStandardApi:
|
|
265
|
+
thousand_res, thousand_status = get_rel_err_ratio(rel_err_orign, CompareConst.THOUSAND_RATIO_THRESHOLD)
|
|
266
|
+
compare_column.rel_err_thousandth = thousand_res
|
|
267
|
+
if str(dtype) in BENCHMARK_COMPARE_SUPPORT_LIST:
|
|
268
|
+
both_finite_mask, inf_nan_mask = get_finite_and_infinite_mask(bench_output, device_output)
|
|
269
|
+
if api_name in BinaryStandardApi:
|
|
270
|
+
err_rate, _, _ = self._compare_bool_tensor(bench_output, device_output)
|
|
271
|
+
compare_column.error_rate = err_rate
|
|
272
|
+
elif api_name in AbsoluteStandardApi:
|
|
273
|
+
small_value_threshold, small_value_atol, rtol = self._get_absolute_threshold_attribute(
|
|
274
|
+
api_name, str(dtype))
|
|
275
|
+
rel_err = abs_err / abs_bench_with_eps
|
|
276
|
+
small_value_mask = get_small_value_mask(abs_bench, both_finite_mask, small_value_threshold)
|
|
277
|
+
normal_value_mask = np.logical_and(both_finite_mask, np.logical_not(small_value_mask))
|
|
278
|
+
compare_column.inf_nan_error_ratio = check_inf_nan_value(inf_nan_mask, bench_output, device_output,
|
|
279
|
+
dtype, rtol)
|
|
280
|
+
compare_column.rel_err_ratio = check_norm_value(normal_value_mask, rel_err, rtol)
|
|
281
|
+
compare_column.abs_err_ratio = check_small_value(abs_err, small_value_mask, small_value_atol)
|
|
282
|
+
elif api_name in ULPStandardApi:
|
|
283
|
+
if bench_output.size == 0:
|
|
284
|
+
compare_column.max_ulp_error = 0
|
|
285
|
+
compare_column.mean_ulp_error = 0
|
|
286
|
+
compare_column.ulp_error_proportion = 0
|
|
287
|
+
else:
|
|
288
|
+
ulp_err = get_ulp_err(bench_output, device_output, dtype)
|
|
289
|
+
compare_column.max_ulp_error = np.max(ulp_err)
|
|
290
|
+
compare_column.mean_ulp_error = np.mean(ulp_err)
|
|
291
|
+
if dtype == torch.float32:
|
|
292
|
+
compare_column.ulp_error_proportion = np.sum(ulp_err > CompareConst.ULP_FLOAT32_THRESHOLD) / bench_output.size
|
|
293
|
+
else:
|
|
294
|
+
compare_column.ulp_error_proportion = np.sum(ulp_err > CompareConst.ULP_FLOAT16_THRESHOLD) / bench_output.size
|
|
295
|
+
else:
|
|
296
|
+
dtype_config = precision_configs.get(dtype)
|
|
297
|
+
small_value_mask = get_small_value_mask(abs_bench, both_finite_mask, dtype_config['small_value'][0])
|
|
298
|
+
abs_err_greater_mask = np.greater(abs_err, dtype_config['small_value_atol'][0])
|
|
299
|
+
compare_column.small_value_err_ratio = get_small_value_err_ratio(small_value_mask, abs_err_greater_mask)
|
|
300
|
+
rel_err = get_rel_err(abs_err, abs_bench_with_eps, small_value_mask, inf_nan_mask)
|
|
301
|
+
compare_column.RMSE = get_rmse(abs_err, np.logical_or(inf_nan_mask, small_value_mask))
|
|
302
|
+
compare_column.EB = get_error_balance(bench_output, device_output)
|
|
303
|
+
if rel_err.size == 0:
|
|
304
|
+
return CompareConst.ERROR, compare_column, "Relative error result list is empty."
|
|
305
|
+
compare_column.Max_rel_error = get_max_rel_err(rel_err)
|
|
306
|
+
compare_column.Mean_rel_error = get_mean_rel_err(rel_err)
|
|
307
|
+
|
|
308
|
+
cos_res, cos_status, msg = cosine_sim(bench_output, device_output)
|
|
309
|
+
compare_column.cosine_sim = cos_res
|
|
310
|
+
message += msg + "\n"
|
|
311
|
+
if not cos_status:
|
|
312
|
+
message += "Cosine similarity is less than 0.99, consider as error, skip other check and set to SPACE.\n"
|
|
313
|
+
return CompareConst.ERROR, compare_column, message
|
|
314
|
+
|
|
315
|
+
max_abs_res, max_abs_status = get_max_abs_err(abs_err)
|
|
316
|
+
compare_column.max_abs_err = max_abs_res
|
|
317
|
+
if max_abs_status:
|
|
318
|
+
message += "Max abs error is less than 0.001, consider as pass, skip other check and set to SPACE.\n"
|
|
319
|
+
return CompareConst.PASS, compare_column, message
|
|
320
|
+
|
|
321
|
+
if dtype in [torch.float16, torch.bfloat16]:
|
|
322
|
+
hundred_res, hundred_status = get_rel_err_ratio(rel_err_orign, CompareConst.HUNDRED_RATIO_THRESHOLD)
|
|
323
|
+
compare_column.rel_err_hundredth = hundred_res
|
|
324
|
+
if not hundred_status:
|
|
325
|
+
message += "Relative error is greater than 0.01, consider as error, skip other check and set to SPACE.\n"
|
|
326
|
+
return CompareConst.ERROR, compare_column, message
|
|
327
|
+
thousand_res, thousand_status = get_rel_err_ratio(rel_err_orign, CompareConst.THOUSAND_RATIO_THRESHOLD)
|
|
328
|
+
compare_column.rel_err_thousandth = thousand_res
|
|
329
|
+
if dtype in [torch.float16, torch.bfloat16]:
|
|
330
|
+
if thousand_status:
|
|
331
|
+
message += "Relative error is less than 0.001, consider as pass, skip other check and set to SPACE.\n"
|
|
332
|
+
return CompareConst.PASS, compare_column, message
|
|
333
|
+
message += "Relative error is greater than 0.001, consider as warning, skip other check and set to SPACE.\n"
|
|
334
|
+
return CompareConst.WARNING, compare_column, message
|
|
335
|
+
ten_thousand_res, ten_thousand_status = get_rel_err_ratio(rel_err_orign, CompareConst.TEN_THOUSAND_RATIO_THRESHOLD)
|
|
336
|
+
compare_column.rel_err_ten_thousandth = ten_thousand_res
|
|
337
|
+
if dtype in [torch.float32, torch.float64]:
|
|
338
|
+
if not thousand_status:
|
|
339
|
+
message += "Relative error is greater than 0.001, consider as error, skip other check and set to SPACE.\n"
|
|
340
|
+
return CompareConst.ERROR, compare_column, message
|
|
341
|
+
if not ten_thousand_status:
|
|
342
|
+
message += "Relative error is greater than 0.0001, consider as warning, skip other check and set to SPACE.\n"
|
|
343
|
+
return CompareConst.WARNING, compare_column, message
|
|
344
|
+
message += "Relative error is less than 0.0001, consider as pass.\n"
|
|
345
|
+
return CompareConst.PASS, compare_column, message
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from msprobe.core.common.const import CompareConst
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CompareColumn:
|
|
5
|
+
def __init__(self):
|
|
6
|
+
self.bench_type = CompareConst.SPACE
|
|
7
|
+
self.npu_type = CompareConst.SPACE
|
|
8
|
+
self.shape = CompareConst.SPACE
|
|
9
|
+
self.cosine_sim = CompareConst.SPACE
|
|
10
|
+
self.max_abs_err = CompareConst.SPACE
|
|
11
|
+
self.rel_err_hundredth = CompareConst.SPACE
|
|
12
|
+
self.rel_err_thousandth = CompareConst.SPACE
|
|
13
|
+
self.rel_err_ten_thousandth = CompareConst.SPACE
|
|
14
|
+
self.error_rate = CompareConst.SPACE
|
|
15
|
+
self.EB = CompareConst.SPACE
|
|
16
|
+
self.RMSE = CompareConst.SPACE
|
|
17
|
+
self.small_value_err_ratio = CompareConst.SPACE
|
|
18
|
+
self.Max_rel_error = CompareConst.SPACE
|
|
19
|
+
self.Mean_rel_error = CompareConst.SPACE
|
|
20
|
+
self.inf_nan_error_ratio = CompareConst.SPACE
|
|
21
|
+
self.rel_err_ratio = CompareConst.SPACE
|
|
22
|
+
self.abs_err_ratio = CompareConst.SPACE
|
|
23
|
+
self.max_ulp_error = CompareConst.SPACE
|
|
24
|
+
self.mean_ulp_error = CompareConst.SPACE
|
|
25
|
+
self.ulp_error_proportion = CompareConst.SPACE
|
|
26
|
+
|
|
27
|
+
def to_column_value(self, is_pass, message):
|
|
28
|
+
return [self.bench_type, self.npu_type, self.shape, self.cosine_sim, self.max_abs_err, self.rel_err_hundredth,
|
|
29
|
+
self.rel_err_thousandth, self.rel_err_ten_thousandth, self.error_rate, self.EB, self.RMSE,
|
|
30
|
+
self.small_value_err_ratio, self.Max_rel_error, self.Mean_rel_error, self.inf_nan_error_ratio,
|
|
31
|
+
self.rel_err_ratio, self.abs_err_ratio, self.max_ulp_error, self.mean_ulp_error,
|
|
32
|
+
self.ulp_error_proportion, is_pass, message]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ApiPrecisionOutputColumn:
|
|
36
|
+
def __init__(self):
|
|
37
|
+
self.api_name = CompareConst.SPACE
|
|
38
|
+
self.small_value_err_ratio = CompareConst.SPACE
|
|
39
|
+
self.small_value_err_status = CompareConst.SPACE
|
|
40
|
+
self.rmse_ratio = CompareConst.SPACE
|
|
41
|
+
self.rmse_status = CompareConst.SPACE
|
|
42
|
+
self.max_rel_err_ratio = CompareConst.SPACE
|
|
43
|
+
self.max_rel_err_status = CompareConst.SPACE
|
|
44
|
+
self.mean_rel_err_ratio = CompareConst.SPACE
|
|
45
|
+
self.mean_rel_err_status = CompareConst.SPACE
|
|
46
|
+
self.eb_ratio = CompareConst.SPACE
|
|
47
|
+
self.eb_status = CompareConst.SPACE
|
|
48
|
+
self.inf_nan_error_ratio = CompareConst.SPACE
|
|
49
|
+
self.inf_nan_error_ratio_status = CompareConst.SPACE
|
|
50
|
+
self.rel_err_ratio = CompareConst.SPACE
|
|
51
|
+
self.rel_err_ratio_status = CompareConst.SPACE
|
|
52
|
+
self.abs_err_ratio = CompareConst.SPACE
|
|
53
|
+
self.abs_err_ratio_status = CompareConst.SPACE
|
|
54
|
+
self.error_rate = CompareConst.SPACE
|
|
55
|
+
self.error_rate_status = CompareConst.SPACE
|
|
56
|
+
self.mean_ulp_err = CompareConst.SPACE
|
|
57
|
+
self.ulp_err_proportion = CompareConst.SPACE
|
|
58
|
+
self.ulp_err_proportion_ratio = CompareConst.SPACE
|
|
59
|
+
self.ulp_err_status = CompareConst.SPACE
|
|
60
|
+
self.rel_err_thousandth = CompareConst.SPACE
|
|
61
|
+
self.rel_err_thousandth_status = CompareConst.SPACE
|
|
62
|
+
self.compare_result = CompareConst.SPACE
|
|
63
|
+
self.compare_algorithm = CompareConst.SPACE
|
|
64
|
+
self.compare_message = CompareConst.SPACE
|
|
65
|
+
|
|
66
|
+
def to_column_value(self):
|
|
67
|
+
return [self.api_name, self.small_value_err_ratio, self.small_value_err_status, self.rmse_ratio,
|
|
68
|
+
self.rmse_status, self.max_rel_err_ratio, self.max_rel_err_status, self.mean_rel_err_ratio,
|
|
69
|
+
self.mean_rel_err_status, self.eb_ratio, self.eb_status, self.inf_nan_error_ratio,
|
|
70
|
+
self.inf_nan_error_ratio_status, self.rel_err_ratio, self.rel_err_ratio_status, self.abs_err_ratio,
|
|
71
|
+
self.abs_err_ratio_status, self.error_rate, self.error_rate_status, self.mean_ulp_err,
|
|
72
|
+
self.ulp_err_proportion, self.ulp_err_proportion_ratio, self.ulp_err_status, self.rel_err_thousandth,
|
|
73
|
+
self.rel_err_thousandth_status, self.compare_result, self.compare_algorithm, self.compare_message]
|
|
74
|
+
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import os
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
import torch
|
|
7
|
+
import yaml
|
|
8
|
+
from msprobe.core.common.utils import CompareException
|
|
9
|
+
from msprobe.core.common.const import Const
|
|
10
|
+
from msprobe.pytorch.common.log import logger
|
|
11
|
+
from msprobe.core.common.file_check import FileOpen
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
current_time = time.strftime("%Y%m%d%H%M%S")
|
|
15
|
+
API_PRECISION_COMPARE_RESULT_FILE_NAME = "api_precision_compare_result_" + current_time + ".csv"
|
|
16
|
+
API_PRECISION_COMPARE_DETAILS_FILE_NAME = "api_precision_compare_details_" + current_time + ".csv"
|
|
17
|
+
BENCHMARK_COMPARE_SUPPORT_LIST = ['torch.float16', 'torch.bfloat16', 'torch.float32']
|
|
18
|
+
API_PRECISION_COMPARE_UNSUPPORT_LIST = ['torch.float64', 'torch.complex64', 'torch.complex128']
|
|
19
|
+
ULP_COMPARE_SUPPORT_LIST = ['torch.float16', 'torch.bfloat16', 'torch.float32']
|
|
20
|
+
BINARY_COMPARE_UNSUPPORT_LIST = BENCHMARK_COMPARE_SUPPORT_LIST + API_PRECISION_COMPARE_UNSUPPORT_LIST
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
cur_path = os.path.dirname(os.path.realpath(__file__))
|
|
24
|
+
standard_yaml_path = os.path.join(cur_path, "api_precision_standard.yaml")
|
|
25
|
+
with FileOpen(standard_yaml_path, 'r') as f:
|
|
26
|
+
Apis = yaml.safe_load(f)
|
|
27
|
+
AbsoluteStandardApi = Apis.get('AbsoluteThreshStandard')
|
|
28
|
+
BinaryStandardApi = Apis.get('BinaryCompareStandard')
|
|
29
|
+
ULPStandardApi = Apis.get('ULPStandard')
|
|
30
|
+
ThousandthStandardApi = Apis.get('ThousandthStandard')
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
threshold_yaml_path = os.path.join(cur_path, "api_precision_threshold.yaml")
|
|
34
|
+
with FileOpen(threshold_yaml_path, 'r') as f:
|
|
35
|
+
apis_threshold = yaml.safe_load(f)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
DETAIL_TEST_ROWS = [[
|
|
39
|
+
"API Name", "Bench Dtype", "DEVICE Dtype", "Shape",
|
|
40
|
+
"余弦相似度",
|
|
41
|
+
"最大绝对误差",
|
|
42
|
+
"双百指标",
|
|
43
|
+
"双千指标",
|
|
44
|
+
"双万指标",
|
|
45
|
+
"二进制一致错误率",
|
|
46
|
+
"误差均衡性",
|
|
47
|
+
"均方根误差",
|
|
48
|
+
"小值域错误占比",
|
|
49
|
+
"相对误差最大值",
|
|
50
|
+
"相对误差平均值",
|
|
51
|
+
"inf/nan错误率",
|
|
52
|
+
"相对误差错误率",
|
|
53
|
+
"绝对误差错误率",
|
|
54
|
+
"ULP误差最大值",
|
|
55
|
+
"ULP误差平均值",
|
|
56
|
+
"ULP误差大于阈值占比",
|
|
57
|
+
"Status",
|
|
58
|
+
"Message"
|
|
59
|
+
]]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
precision_configs = {
|
|
63
|
+
torch.float16 : {
|
|
64
|
+
'small_value' : [
|
|
65
|
+
1e-3
|
|
66
|
+
],
|
|
67
|
+
'small_value_atol' : [
|
|
68
|
+
1e-5
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
torch.bfloat16: {
|
|
72
|
+
'small_value' : [
|
|
73
|
+
1e-3
|
|
74
|
+
],
|
|
75
|
+
'small_value_atol' : [
|
|
76
|
+
1e-5
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
torch.float32:{
|
|
80
|
+
'small_value' : [
|
|
81
|
+
1e-6
|
|
82
|
+
],
|
|
83
|
+
'small_value_atol' : [
|
|
84
|
+
1e-9
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
ULP_PARAMETERS = {
|
|
91
|
+
torch.float16 : {
|
|
92
|
+
'min_eb' : [
|
|
93
|
+
-14
|
|
94
|
+
],
|
|
95
|
+
'exponent_num' : [
|
|
96
|
+
10
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
torch.bfloat16 : {
|
|
100
|
+
'min_eb' : [
|
|
101
|
+
-126
|
|
102
|
+
],
|
|
103
|
+
'exponent_num' : [
|
|
104
|
+
7
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
torch.float32 : {
|
|
108
|
+
'min_eb' : [
|
|
109
|
+
-126
|
|
110
|
+
],
|
|
111
|
+
'exponent_num' : [
|
|
112
|
+
23
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class ApiPrecisionCompareColumn:
|
|
119
|
+
API_NAME = 'API Name'
|
|
120
|
+
DEVICE_DTYPE = 'DEVICE Dtype'
|
|
121
|
+
SMALL_VALUE_ERROR_RATE = '小值域错误占比'
|
|
122
|
+
RMSE = '均方根误差'
|
|
123
|
+
MAX_REL_ERR = '相对误差最大值'
|
|
124
|
+
MEAN_REL_ERR = '相对误差平均值'
|
|
125
|
+
EB = '误差均衡性'
|
|
126
|
+
SMALL_VALUE_ERROR_RATIO = '小值域错误比值'
|
|
127
|
+
SMALL_VALUE_ERROR_STATUS = '小值域判定结果'
|
|
128
|
+
RMSE_RATIO = '均方根误差比值'
|
|
129
|
+
RMSE_STATUS = '均方根误差判定结果'
|
|
130
|
+
MAX_REL_ERR_RATIO = '相对误差最大值比值'
|
|
131
|
+
MAX_REL_ERR_STATUS = '相对误差最大值判定结果'
|
|
132
|
+
MEAN_REL_ERR_RATIO = '相对误差平均值比值'
|
|
133
|
+
MEAN_REL_ERR_STATUS = '相对误差平均值判定结果'
|
|
134
|
+
EB_RATIO = '误差均衡性比值'
|
|
135
|
+
EB_STATUS = '误差均衡性判定结果'
|
|
136
|
+
ERROR_RATE = '二进制一致错误率'
|
|
137
|
+
ERROR_RATE_STATUS = '二进制一致错误率判定结果'
|
|
138
|
+
INF_NAN_ERROR_RATIO = 'inf/nan错误率'
|
|
139
|
+
INF_NAN_ERROR_RATIO_STATUS = 'inf/nan判定结果'
|
|
140
|
+
REL_ERR_RATIO = '相对误差错误率'
|
|
141
|
+
REL_ERR_RATIO_STATUS = '相对误差判定结果'
|
|
142
|
+
ABS_ERR_RATIO = '绝对误差错误率'
|
|
143
|
+
ABS_ERR_RATIO_STATUS = '绝对误差判定结果'
|
|
144
|
+
MEAN_ULP_ERR = 'ULP误差平均值'
|
|
145
|
+
ULP_ERR_PROPORTION = 'ULP误差大于阈值占比'
|
|
146
|
+
ULP_ERR_PROPORTION_RATIO = 'ULP误差大于阈值占比比值'
|
|
147
|
+
ULP_ERR_STATUS = 'ULP误差判定结果'
|
|
148
|
+
REL_ERR_THOUSANDTH = '双千指标'
|
|
149
|
+
REL_ERR_THOUSANDTH_STATUS = '双千指标判定结果'
|
|
150
|
+
FINAL_RESULT = '比对结果'
|
|
151
|
+
ALGORITHM = '比对算法'
|
|
152
|
+
FORWWARD_STATUS = 'Forward Test Success'
|
|
153
|
+
BACKWARD_STATUS = 'Backward Test Success'
|
|
154
|
+
MESSAGE = 'Message'
|
|
155
|
+
|
|
156
|
+
@staticmethod
|
|
157
|
+
def to_required_columns():
|
|
158
|
+
return [ApiPrecisionCompareColumn.API_NAME, ApiPrecisionCompareColumn.DEVICE_DTYPE,
|
|
159
|
+
ApiPrecisionCompareColumn.SMALL_VALUE_ERROR_RATE, ApiPrecisionCompareColumn.RMSE,
|
|
160
|
+
ApiPrecisionCompareColumn.MAX_REL_ERR, ApiPrecisionCompareColumn.MEAN_REL_ERR, ApiPrecisionCompareColumn.EB,
|
|
161
|
+
ApiPrecisionCompareColumn.ERROR_RATE, ApiPrecisionCompareColumn.INF_NAN_ERROR_RATIO,
|
|
162
|
+
ApiPrecisionCompareColumn.REL_ERR_RATIO, ApiPrecisionCompareColumn.ABS_ERR_RATIO,
|
|
163
|
+
ApiPrecisionCompareColumn.MEAN_ULP_ERR, ApiPrecisionCompareColumn.ULP_ERR_PROPORTION,
|
|
164
|
+
ApiPrecisionCompareColumn.REL_ERR_THOUSANDTH]
|
|
165
|
+
|
|
166
|
+
@staticmethod
|
|
167
|
+
def get_detail_csv_title():
|
|
168
|
+
return [ApiPrecisionCompareColumn.API_NAME,
|
|
169
|
+
ApiPrecisionCompareColumn.SMALL_VALUE_ERROR_RATIO, ApiPrecisionCompareColumn.SMALL_VALUE_ERROR_STATUS,
|
|
170
|
+
ApiPrecisionCompareColumn.RMSE_RATIO, ApiPrecisionCompareColumn.RMSE_STATUS,
|
|
171
|
+
ApiPrecisionCompareColumn.MAX_REL_ERR_RATIO, ApiPrecisionCompareColumn.MAX_REL_ERR_STATUS,
|
|
172
|
+
ApiPrecisionCompareColumn.MEAN_REL_ERR_RATIO, ApiPrecisionCompareColumn.MEAN_REL_ERR_STATUS,
|
|
173
|
+
ApiPrecisionCompareColumn.EB_RATIO, ApiPrecisionCompareColumn.EB_STATUS,
|
|
174
|
+
ApiPrecisionCompareColumn.INF_NAN_ERROR_RATIO, ApiPrecisionCompareColumn.INF_NAN_ERROR_RATIO_STATUS,
|
|
175
|
+
ApiPrecisionCompareColumn.REL_ERR_RATIO, ApiPrecisionCompareColumn.REL_ERR_RATIO_STATUS,
|
|
176
|
+
ApiPrecisionCompareColumn.ABS_ERR_RATIO, ApiPrecisionCompareColumn.ABS_ERR_RATIO_STATUS,
|
|
177
|
+
ApiPrecisionCompareColumn.ERROR_RATE, ApiPrecisionCompareColumn.ERROR_RATE_STATUS,
|
|
178
|
+
ApiPrecisionCompareColumn.MEAN_ULP_ERR, ApiPrecisionCompareColumn.ULP_ERR_PROPORTION,
|
|
179
|
+
ApiPrecisionCompareColumn.ULP_ERR_PROPORTION_RATIO, ApiPrecisionCompareColumn.ULP_ERR_STATUS,
|
|
180
|
+
ApiPrecisionCompareColumn.REL_ERR_THOUSANDTH, ApiPrecisionCompareColumn.REL_ERR_THOUSANDTH_STATUS,
|
|
181
|
+
ApiPrecisionCompareColumn.FINAL_RESULT, ApiPrecisionCompareColumn.ALGORITHM, ApiPrecisionCompareColumn.MESSAGE]
|
|
182
|
+
|
|
183
|
+
@staticmethod
|
|
184
|
+
def get_result_csv_title():
|
|
185
|
+
return [ApiPrecisionCompareColumn.API_NAME, ApiPrecisionCompareColumn.FORWWARD_STATUS,
|
|
186
|
+
ApiPrecisionCompareColumn.BACKWARD_STATUS, ApiPrecisionCompareColumn.MESSAGE]
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
CompareMessage = {
|
|
190
|
+
"topk" : "在npu上,topk的入参sorted=False时不生效,会返回有序tensor,而cpu上会返回无序tensor。 如果topk精度不达标,请检查是否是该原因导致的。"
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def check_dtype_comparable(x, y):
|
|
195
|
+
if x.dtype in Const.FLOAT_TYPE:
|
|
196
|
+
if y.dtype in Const.FLOAT_TYPE:
|
|
197
|
+
return True
|
|
198
|
+
return False
|
|
199
|
+
if x.dtype in Const.BOOL_TYPE:
|
|
200
|
+
if y.dtype in Const.BOOL_TYPE:
|
|
201
|
+
return True
|
|
202
|
+
return False
|
|
203
|
+
if x.dtype in Const.INT_TYPE:
|
|
204
|
+
if y.dtype in Const.INT_TYPE:
|
|
205
|
+
return True
|
|
206
|
+
return False
|
|
207
|
+
logger.warning(f"Compare: Unexpected dtype {x.dtype}, {y.dtype}")
|
|
208
|
+
return False
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def convert_str_to_float(input_data):
|
|
212
|
+
if isinstance(input_data, str) and input_data.strip() == "":
|
|
213
|
+
msg = 'ERROR: Input data is an empty string'
|
|
214
|
+
raise CompareException(CompareException.INVALID_DATA_ERROR, msg)
|
|
215
|
+
try:
|
|
216
|
+
float_data = float(input_data)
|
|
217
|
+
return float_data
|
|
218
|
+
except ValueError as e:
|
|
219
|
+
msg = 'ERROR: Input data cannot be converted to float'
|
|
220
|
+
raise CompareException(CompareException.INVALID_DATA_ERROR, msg) from e
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def is_inf_or_nan(x):
|
|
224
|
+
return math.isnan(x) or math.isinf(x)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def handle_infinity(x, y, column_name):
|
|
228
|
+
if math.isinf(x) and math.isinf(y):
|
|
229
|
+
if x == y:
|
|
230
|
+
return float("nan"), True, f"{column_name}同为同号inf或nan\n"
|
|
231
|
+
else:
|
|
232
|
+
return float("nan"), False, f"{column_name}inf或nan不一致\n"
|
|
233
|
+
else:
|
|
234
|
+
return float("nan"), False, f"{column_name}inf或nan不一致\n"
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def handle_nan(x, y, column_name):
|
|
238
|
+
if math.isnan(x) and math.isnan(y):
|
|
239
|
+
return float("nan"), True, f"{column_name}同为同号inf或nan\n"
|
|
240
|
+
else:
|
|
241
|
+
return float("nan"), False, f"{column_name}inf或nan不一致\n"
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def check_inf_or_nan(x, y, column_name):
|
|
245
|
+
if math.isinf(x) or math.isinf(y):
|
|
246
|
+
return handle_infinity(x, y, column_name)
|
|
247
|
+
else:
|
|
248
|
+
return handle_nan(x, y, column_name)
|
|
249
|
+
|
|
File without changes
|
|
File without changes
|