diff --git a/debug/accuracy_tools/api_accuracy_checker/__init__.py b/debug/accuracy_tools/api_accuracy_checker/__init__.py index aac6483f7ed1a005e02ce36009473c25fcfdc4aa..22c3634838883ae8d91737ce3b2788b43dc1712b 100644 --- a/debug/accuracy_tools/api_accuracy_checker/__init__.py +++ b/debug/accuracy_tools/api_accuracy_checker/__init__.py @@ -16,6 +16,6 @@ # ============================================================================== """ -from .common.utils import seed_all +from api_accuracy_checker.common.utils import seed_all seed_all() __all__ = [] diff --git a/debug/accuracy_tools/api_accuracy_checker/common/utils.py b/debug/accuracy_tools/api_accuracy_checker/common/utils.py index fa4540c58ef843e7ab7f4e759b986d9193b69355..8ca6381ce9e582c28bcfea58a53952dba9488e9a 100644 --- a/debug/accuracy_tools/api_accuracy_checker/common/utils.py +++ b/debug/accuracy_tools/api_accuracy_checker/common/utils.py @@ -549,7 +549,7 @@ def check_input_file_valid(input_path, max_file_size=MAX_JSON_FILE_SIZE): def check_need_convert(api_name): convert_type = None - for key, value in Const.CONVERT_API: + for key, value in Const.CONVERT_API.items(): if api_name not in value: continue else: diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index 88df23cacacd5b17b5ed5f4e6ccd23183d9ff80f..a79125d832b39e9074c8dff9d3eb5c24f2003c4d 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -2,8 +2,8 @@ import torch import numpy as np -from .compare_utils import CompareConst -from ..common.utils import print_warn_log, Const +from api_accuracy_checker.compare.compare_utils import CompareConst +from api_accuracy_checker.common.utils import print_warn_log, Const def compare_torch_tensor(cpu_output, npu_output, compare_alg): if cpu_output.dtype == torch.bool: @@ -11,7 +11,7 @@ def compare_torch_tensor(cpu_output, npu_output, compare_alg): return compare_alg(cpu_output, npu_output) -def compare_bool_tensor(cpu_output, npu_output, compare_alg): +def compare_bool_tensor(cpu_output, npu_output): error_rate = CompareConst.NAN cpu_shape = cpu_output.shape npu_shape = npu_output.shape @@ -88,7 +88,7 @@ def flatten_compare_result(result): def compare_core(bench_out, npu_out, alg): if type(bench_out) != type(npu_out): raise ValueError("bench and npu output type is different") - if isinstance(bench_out, list, tuple): + if isinstance(bench_out, (list, tuple)): compare_result, test_success = [], True if len(bench_out) != len(npu_out): raise ValueError("bench and npu output structure is different") diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/compare.py b/debug/accuracy_tools/api_accuracy_checker/compare/compare.py index ae869e208e25a96cd363b71762f9d1399a8db8d2..b877bc50d4d71ed8d9b5550bab245ae6f5c87bb6 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/compare.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/compare.py @@ -1,9 +1,9 @@ # 进行比对及结果展示 import os from prettytable import PrettyTable -from .algorithm import compare_core, cosine_sim, cosine_standard -from ..common.utils import get_json_contents, print_error_log, print_info_log, write_csv -from .compare_utils import CompareConst +from api_accuracy_checker.compare.algorithm import compare_core, cosine_sim, cosine_standard +from api_accuracy_checker.common.utils import get_json_contents, print_error_log, print_info_log, write_csv +from api_accuracy_checker.compare.compare_utils import CompareConst class Comparator: TEST_FILE_NAME = "pretest_result.csv" @@ -79,5 +79,5 @@ class Comparator: def _compare_core_wrapper(self, bench_out, npu_out): name = self.compare_alg_names[0] - detailed_result, test_success = compare_core(bench_out, npu_out, self.compare_lag[name][0]) + detailed_result, test_success = compare_core(bench_out, npu_out, self.compare_alg[name][0]) return test_success, detailed_result \ No newline at end of file diff --git a/debug/accuracy_tools/api_accuracy_checker/dump/__init__.py b/debug/accuracy_tools/api_accuracy_checker/dump/__init__.py index 397b31422b8c50489f4aa9afab7b09e0da5e864f..ea27681ec2cf441506bd997539da8755673c978d 100644 --- a/debug/accuracy_tools/api_accuracy_checker/dump/__init__.py +++ b/debug/accuracy_tools/api_accuracy_checker/dump/__init__.py @@ -1,7 +1,7 @@ -from ..hook_module.register_hook import initialize_hook -from .dump import pretest_hook -from .info_dump import initialize_output_json -from .utils import set_dump_switch +from api_accuracy_checker.hook_module.register_hook import initialize_hook +from api_accuracy_checker.dump.dump import pretest_hook +from api_accuracy_checker.dump.info_dump import initialize_output_json +from api_accuracy_checker.dump.utils import set_dump_switch initialize_hook(pretest_hook) diff --git a/debug/accuracy_tools/api_accuracy_checker/dump/api_info.py b/debug/accuracy_tools/api_accuracy_checker/dump/api_info.py index ea27248cf35d53c37623375addb93e89a676ffa4..cff12e6b84abd03489706880fb6cfd89f5334906 100644 --- a/debug/accuracy_tools/api_accuracy_checker/dump/api_info.py +++ b/debug/accuracy_tools/api_accuracy_checker/dump/api_info.py @@ -2,8 +2,10 @@ import inspect import torch import torch_npu -from .utils import DumpUtil, DumpConst, write_npy -from ..common.utils import print_error_log +from api_accuracy_checker.common.config import msCheckerConfig +from api_accuracy_checker.common.utils import print_error_log +from api_accuracy_checker.common.config import msCheckerConfig +from api_accuracy_checker.dump.utils import write_npy class APIInfo: def __init__(self, api_name): @@ -46,7 +48,10 @@ class APIInfo: single_arg.update({'requires_grad': arg.requires_grad}) else: - npy_path = write_npy(self.api_name, arg.contiguous().cpu().detach().numpy()) + dump_path = msCheckerConfig.dump_path + real_data_path = os.path.join(dump_path, 'real_data') + file_path = os.path.join(real_data_path, self.api_name) + npy_path = write_npy(file_path, arg.contiguous().cpu().detach().numpy()) single_arg.update({'type' : 'torch.Tensor'}) single_arg.update({'datapath' : npy_path}) single_arg.update({'requires_grad': arg.requires_grad}) diff --git a/debug/accuracy_tools/api_accuracy_checker/dump/dump.py b/debug/accuracy_tools/api_accuracy_checker/dump/dump.py index ade72d3ebae88b5cf22e2f79577a21a5f4312ffb..e69c4b50ef548b51a816f5a5c2bfd9c50b4ae2e4 100644 --- a/debug/accuracy_tools/api_accuracy_checker/dump/dump.py +++ b/debug/accuracy_tools/api_accuracy_checker/dump/dump.py @@ -24,10 +24,10 @@ import torch import threading -from .api_info import ForwardAPIInfo, BackwardAPIInfo -from .info_dump import write_api_info_json -from .utils import DumpConst, DumpUtil -from ..common.utils import print_warn_log, print_info_log, print_error_log +from api_accuracy_checker.dump.api_info import ForwardAPIInfo, BackwardAPIInfo +from api_accuracy_checker.dump.info_dump import write_api_info_json +from api_accuracy_checker.dump.utils import DumpConst, DumpUtil +from api_accuracy_checker.common.utils import print_warn_log, print_info_log, print_error_log def pretest_info_dump(name, out_feat, module, phase): if not DumpUtil.dump_switch: diff --git a/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py b/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py index dc60fd2cb7dbfbf735c843371362fd2721e2a3f1..3a4ba69399528c5ca61b0aedf8212dab6f55e516 100644 --- a/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py +++ b/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py @@ -51,6 +51,9 @@ def initialize_output_json(): dump_path = DumpUtil.dump_path check_file_or_directory_path(dump_path,True) files = ['forward_info.json', 'backward_info.json', 'stack_info.json'] + if msCheckerConfig.real_data: + real_data_path = os.path.join(dump_path, 'real_data') + check_file_or_directory_path(real_data_path, True) for file in files: file_path = os.path.join(dump_path, file) if os.path.exists(file_path): diff --git a/debug/accuracy_tools/api_accuracy_checker/dump/utils.py b/debug/accuracy_tools/api_accuracy_checker/dump/utils.py index f9c7eeaf27ccd15f2183edcd54dd1e0fc86c670f..0dd469f47d477a79a125f00be4875a8435a492ea 100644 --- a/debug/accuracy_tools/api_accuracy_checker/dump/utils.py +++ b/debug/accuracy_tools/api_accuracy_checker/dump/utils.py @@ -3,7 +3,7 @@ import shutil import sys from pathlib import Path import numpy as np -from ..common.utils import print_error_log, CompareException, DumpException, Const, get_time, print_info_log, \ +from api_accuracy_checker.common.utils import print_error_log, CompareException, DumpException, Const, get_time, print_info_log, \ check_mode_valid, get_api_name_from_matcher class DumpConst: diff --git a/debug/accuracy_tools/api_accuracy_checker/hook_module/register_hook.py b/debug/accuracy_tools/api_accuracy_checker/hook_module/register_hook.py index ec5b4b55c6cc6990841bffc51193cb7063caaf6d..e59e3af66a4e5dfce0c386b312265b34ef0b77ee 100644 --- a/debug/accuracy_tools/api_accuracy_checker/hook_module/register_hook.py +++ b/debug/accuracy_tools/api_accuracy_checker/hook_module/register_hook.py @@ -16,7 +16,7 @@ """ import torch -from . import wrap_torch, wrap_functional, wrap_tensor +from api_accuracy_checker.hook_module import wrap_torch, wrap_functional, wrap_tensor def initialize_hook(hook): diff --git a/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_functional.py b/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_functional.py index 0eff94c34135f1fd979f1710437d9a1e8ce1f4f5..0429a6a4e74a5512dc8ea0a154f9ed7f4358959c 100644 --- a/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_functional.py +++ b/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_functional.py @@ -20,8 +20,8 @@ import os import torch import yaml -from .hook_module import HOOKModule -from ..common.utils import torch_device_guard +from api_accuracy_checker.hook_module.hook_module import HOOKModule +from api_accuracy_checker.common.utils import torch_device_guard cur_path = os.path.dirname(os.path.realpath(__file__)) yaml_path = os.path.join(cur_path, "support_wrap_ops.yaml") diff --git a/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_tensor.py b/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_tensor.py index 07fbca8711d6a0ec8047c38f75f9b77b7c8e42a9..012c659bd64be76fbea09cdefeff355dc5916cae 100644 --- a/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_tensor.py +++ b/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_tensor.py @@ -20,8 +20,8 @@ import os import torch import yaml -from .hook_module import HOOKModule -from ..common.utils import torch_device_guard +from api_accuracy_checker.hook_module.hook_module import HOOKModule +from api_accuracy_checker.common.utils import torch_device_guard cur_path = os.path.dirname(os.path.realpath(__file__)) yaml_path = os.path.join(cur_path, "support_wrap_ops.yaml") diff --git a/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_torch.py b/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_torch.py index 4684e40d8bcc37ee304ea22d2c8cf04d0372ef94..4903e56385afe1b7a1d2d24c196339bd7651ce9b 100644 --- a/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_torch.py +++ b/debug/accuracy_tools/api_accuracy_checker/hook_module/wrap_torch.py @@ -20,8 +20,8 @@ import os import torch import yaml -from .hook_module import HOOKModule -from ..common.utils import torch_device_guard +from api_accuracy_checker.hook_module.hook_module import HOOKModule +from api_accuracy_checker.common.utils import torch_device_guard cur_path = os.path.dirname(os.path.realpath(__file__)) yaml_path = os.path.join(cur_path, "support_wrap_ops.yaml") diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/data_generate.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/data_generate.py index 0ca84b8971bc285b76948c50db168087d0a24248..9b34e51c4fe674b5e4ef02df2f1130489f367d2b 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/data_generate.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/data_generate.py @@ -19,7 +19,7 @@ import os import torch import numpy as np -from ..common.utils import Const, check_file_or_directory_path, check_object_type, print_warn_log, print_error_log, \ +from api_accuracy_checker.common.utils import check_file_or_directory_path, check_object_type, print_warn_log, print_error_log, \ CompareException TENSOR_DATA_LIST = ["torch.Tensor", "torch.nn.parameter.Parameter"] diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py index c25b2e1f3b59f6f5b51f73dd6b0a4059427d318c..c71b32cefe02418bc4148545d862921c18a7c773 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py @@ -1,12 +1,12 @@ import argparse import os import sys -sys.path.append("..") +import torch_npu import yaml import torch -from data_generate import gen_api_params, gen_args -from common.utils import print_info_log, print_warn_log, get_json_contents, check_need_convert -from compare.compare import Comparator +from api_accuracy_checker.run_ut.data_generate import gen_api_params, gen_args +from api_accuracy_checker.common.utils import print_info_log, print_warn_log, get_json_contents +from api_accuracy_checker.compare.compare import Comparator cur_path = os.path.dirname(os.path.realpath(__file__)) yaml_path = os.path.join(cur_path, "../hook_module/support_wrap_ops.yaml")