From 88f397c677e17a3357091cd5e44e5ebba13b5937 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Wed, 1 Nov 2023 02:28:55 +0000 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9int=E7=AD=89=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BD=99=E5=BC=A6=E7=9B=B8=E4=BC=BC=E5=BA=A6=E4=B8=BA?= =?UTF-8?q?0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunyiming --- debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index cca521a296d..e4ec0362892 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -170,6 +170,8 @@ def compare_core(bench_out, npu_out, alg): copy_bench_out = copy_bench_out.to(torch.float32) copy_npu_out = copy_npu_out.to(torch.float32) compare_result, test_success, msg = compare_torch_tensor(copy_bench_out.numpy(), copy_npu_out.cpu().numpy(), alg) + if copy_bench_out.dtype in [torch.bool, torch.uint8, torch.int8, torch.int16, torch.uint16, torch.uint32, torch.int32, torch.int64, torch.uint64] and alg == cosine_sim: + compare_result = CompareConst.NA elif isinstance(bench_out, (bool, int, float, str)): compare_result, test_success, msg = compare_builtin_type(bench_out, npu_out) bench_dtype = str(type(bench_out)) -- Gitee From 9017765d8da9a3e4d5feb369dd7b1665dd4fdf80 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Wed, 1 Nov 2023 03:08:57 +0000 Subject: [PATCH 2/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: sunyiming --- debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index e4ec0362892..2530049ba3d 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -171,7 +171,7 @@ def compare_core(bench_out, npu_out, alg): copy_npu_out = copy_npu_out.to(torch.float32) compare_result, test_success, msg = compare_torch_tensor(copy_bench_out.numpy(), copy_npu_out.cpu().numpy(), alg) if copy_bench_out.dtype in [torch.bool, torch.uint8, torch.int8, torch.int16, torch.uint16, torch.uint32, torch.int32, torch.int64, torch.uint64] and alg == cosine_sim: - compare_result = CompareConst.NA + compare_result = np.nan elif isinstance(bench_out, (bool, int, float, str)): compare_result, test_success, msg = compare_builtin_type(bench_out, npu_out) bench_dtype = str(type(bench_out)) -- Gitee From 3c95ad13d192ab3f094f6e4f36a2fd168f7f9a1b Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 2 Nov 2023 02:30:56 +0000 Subject: [PATCH 3/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: sunyiming --- debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index 2530049ba3d..595548f4b9c 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -170,7 +170,7 @@ def compare_core(bench_out, npu_out, alg): copy_bench_out = copy_bench_out.to(torch.float32) copy_npu_out = copy_npu_out.to(torch.float32) compare_result, test_success, msg = compare_torch_tensor(copy_bench_out.numpy(), copy_npu_out.cpu().numpy(), alg) - if copy_bench_out.dtype in [torch.bool, torch.uint8, torch.int8, torch.int16, torch.uint16, torch.uint32, torch.int32, torch.int64, torch.uint64] and alg == cosine_sim: + if copy_bench_out.dtype in [torch.bool, torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64] and alg == cosine_sim: compare_result = np.nan elif isinstance(bench_out, (bool, int, float, str)): compare_result, test_success, msg = compare_builtin_type(bench_out, npu_out) -- Gitee From 88e12253bd865ceb6b8765ec40148b75bd17d1e9 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 2 Nov 2023 06:31:36 +0000 Subject: [PATCH 4/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: sunyiming --- .../api_accuracy_checker/compare/algorithm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index 595548f4b9c..89649f81232 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -8,9 +8,11 @@ from api_accuracy_checker.common.utils import Const def compare_torch_tensor(cpu_output, npu_output, compare_alg): if not check_dtype_comparable(cpu_output, npu_output): - return CompareConst.NAN, False, f"Bench out dtype is {cpu_output.dtype} but\ + return CompareConst.NA, False, f"Bench out dtype is {cpu_output.dtype} but\ npu output dtype is {npu_output.dtype}, cannot compare." if cpu_output.dtype in [bool, np.uint8, np.int8, np.int16, np.uint16, np.uint32, np.int32, np.int64, np.uint64]: + if compare_alg == cosine_sim: + return CompareConst.NA, False, f"Compare algorithm {compare_alg.__name__} is not supported for {cpu_output.dtype} data." return compare_bool_tensor(cpu_output, npu_output) return compare_alg(cpu_output, npu_output) @@ -18,7 +20,7 @@ def compare_bool_tensor(cpu_output, npu_output): cpu_shape = cpu_output.shape npu_shape = npu_output.shape if cpu_shape != npu_shape: - return CompareConst.NAN, False, "" + return CompareConst.NA, False, "" error_nums = (cpu_output != npu_output).sum() error_rate = float(error_nums / cpu_output.size) return error_rate, error_rate == 0, "" @@ -170,8 +172,6 @@ def compare_core(bench_out, npu_out, alg): copy_bench_out = copy_bench_out.to(torch.float32) copy_npu_out = copy_npu_out.to(torch.float32) compare_result, test_success, msg = compare_torch_tensor(copy_bench_out.numpy(), copy_npu_out.cpu().numpy(), alg) - if copy_bench_out.dtype in [torch.bool, torch.uint8, torch.int8, torch.int16, torch.int32, torch.int64] and alg == cosine_sim: - compare_result = np.nan elif isinstance(bench_out, (bool, int, float, str)): compare_result, test_success, msg = compare_builtin_type(bench_out, npu_out) bench_dtype = str(type(bench_out)) -- Gitee From fa6e93dcc22a1f0beb71a4a0ebfb3d4c58cf2030 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 2 Nov 2023 06:34:05 +0000 Subject: [PATCH 5/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: sunyiming --- .../api_accuracy_checker/compare/algorithm.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index 89649f81232..e78e8fd4861 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -29,10 +29,10 @@ def get_msg_and_handle_value(b_value, n_value): msg = "" if not isinstance(b_value, np.ndarray) or not isinstance(n_value, np.ndarray): msg = f"Max rel err only support numpy array! The actual type is {type(b_value)}, {type(n_value)}." - return CompareConst.NAN, False, msg + return CompareConst.NA, False, msg if b_value.shape != n_value.shape: msg = f"Shape of bench and npu outputs don't match. bench: {b_value.shape}, npu: {n_value.shape}." - return CompareConst.NAN, False, msg + return CompareConst.NA, False, msg if n_value.dtype in Const.FLOAT_TYPE: zero_mask = (n_value == 0) @@ -106,10 +106,10 @@ def cosine_sim(cpu_output, npu_output): return cos, True, msg elif n_value_max <= np.finfo(float).eps: msg = "All the data is zero in npu dump data." - return CompareConst.NAN, False, msg + return CompareConst.NA, False, msg elif b_value_max <= np.finfo(float).eps: msg = "All the data is zero in bench dump data." - return CompareConst.NAN, False, msg + return CompareConst.NA, False, msg else: n_value = n_value_max.astype(float) / n_value_max b_value = b_value_max.astype(float) / b_value_max @@ -128,7 +128,7 @@ def compare_builtin_type(bench_out, npu_out): if not isinstance(bench_out, (bool, int, float, str)): return CompareConst.NA, True, "" if bench_out != npu_out: - return CompareConst.NAN, False, "" + return CompareConst.NA, False, "" return True, True, "" def flatten_compare_result(result): -- Gitee