From faba956542a1db16985bea7a95dfbdcfcde32a0b Mon Sep 17 00:00:00 2001 From: jiangchangting1 Date: Thu, 23 Nov 2023 08:19:49 +0000 Subject: [PATCH 1/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: jiangchangting1 --- .../api_accuracy_checker/compare/algorithm.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index 1d99f422fa4..1588096760b 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -25,6 +25,14 @@ class CompareColumn: def compare_torch_tensor(cpu_output, npu_output, compare_column): cpu_shape = cpu_output.shape npu_shape = npu_output.shape + npu_dtype = None + if npu_output.dtype == torch.bfloat16: + npu_dtype = torch.bfloat16 + cpu_output = cpu_output.to(torch.float32) + npu_output = npu_output.to(torch.float32) + npu_dtype = npu_output.dtype + cpu_output = cpu_output.numpy() + npu_output = npu_output.numpy() if cpu_shape != npu_shape: return CompareConst.ERROR, compare_column, f"The shape of bench{str(cpu_shape)} " \ f"and npu{str(npu_shape)} not equal." @@ -54,20 +62,20 @@ def compare_torch_tensor(cpu_output, npu_output, compare_column): return CompareConst.PASS, compare_column, message # rel err rel_err = get_rel_err(abs_err, b_value) - if n_value.dtype == np.float16: + if npu_dtype in [torch.float16, torch.bfloat16]: hundred_res, hundred_status = get_rel_err_ratio(rel_err, 0.01) compare_column.rel_err_hundredth = hundred_res if not hundred_status: return CompareConst.ERROR, compare_column, message thousand_res, thousand_status = get_rel_err_ratio(rel_err, 0.001) compare_column.rel_err_thousandth = thousand_res - if n_value.dtype == np.float16: + if npu_dtype in [torch.float16, torch.bfloat16]: if thousand_status: return CompareConst.PASS, compare_column, message return CompareConst.WARNING, compare_column, message ten_thousand_res, ten_thousand_status = get_rel_err_ratio(rel_err, 0.0001) compare_column.rel_err_ten_thousandth = ten_thousand_res - if n_value.dtype in [np.float32, np.float64]: + if n_value.dtype in [torch.float32, torch.float64]: if not thousand_status: return CompareConst.ERROR, compare_column, message if not ten_thousand_status: @@ -211,10 +219,7 @@ def compare_core(bench_out, npu_out): compare_column.bench_type = str(copy_bench_out.dtype) compare_column.npu_type = str(copy_npu_out.dtype) compare_column.shape = tuple(npu_out.shape) - if copy_npu_out.dtype == torch.bfloat16: - copy_bench_out = copy_bench_out.to(torch.float32) - copy_npu_out = copy_npu_out.to(torch.float32) - status, compare_result, message = compare_torch_tensor(copy_bench_out.numpy(), copy_npu_out.cpu().numpy(), + status, compare_result, message = compare_torch_tensor(copy_bench_out, copy_npu_out, compare_column) elif isinstance(bench_out, (bool, int, float, str)): compare_column.bench_dtype = str(type(bench_out)) -- Gitee From 2dc31f8ad7d0565ec71e90c4e0f9d31ddf2fb1ee Mon Sep 17 00:00:00 2001 From: jiangchangting1 Date: Thu, 23 Nov 2023 08:33:33 +0000 Subject: [PATCH 2/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: jiangchangting1 --- 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 1588096760b..94cf8d78a01 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -75,7 +75,7 @@ def compare_torch_tensor(cpu_output, npu_output, compare_column): return CompareConst.WARNING, compare_column, message ten_thousand_res, ten_thousand_status = get_rel_err_ratio(rel_err, 0.0001) compare_column.rel_err_ten_thousandth = ten_thousand_res - if n_value.dtype in [torch.float32, torch.float64]: + if npu_dtype in [torch.float32, torch.float64]: if not thousand_status: return CompareConst.ERROR, compare_column, message if not ten_thousand_status: -- Gitee From e8b29ef23edf2636e466d154c008c75ee08da0c0 Mon Sep 17 00:00:00 2001 From: jiangchangting1 Date: Fri, 24 Nov 2023 03:17:17 +0000 Subject: [PATCH 3/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: jiangchangting1 --- .../api_accuracy_checker/compare/algorithm.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py index 94cf8d78a01..05b280704b3 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -29,10 +29,11 @@ def compare_torch_tensor(cpu_output, npu_output, compare_column): if npu_output.dtype == torch.bfloat16: npu_dtype = torch.bfloat16 cpu_output = cpu_output.to(torch.float32) - npu_output = npu_output.to(torch.float32) - npu_dtype = npu_output.dtype + npu_output = npu_output.to(torch.float32) + else: + npu_dtype = npu_output.dtype cpu_output = cpu_output.numpy() - npu_output = npu_output.numpy() + npu_output = npu_output.cpu().numpy() if cpu_shape != npu_shape: return CompareConst.ERROR, compare_column, f"The shape of bench{str(cpu_shape)} " \ f"and npu{str(npu_shape)} not equal." -- Gitee From 4cbc2a93f9ca5f82b76ae16269149ab6c23c9c2c Mon Sep 17 00:00:00 2001 From: jiangchangting1 Date: Sat, 25 Nov 2023 06:23:22 +0000 Subject: [PATCH 4/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: jiangchangting1 --- .../accuracy_tools/api_accuracy_checker/compare/algorithm.py | 5 +---- 1 file changed, 1 insertion(+), 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 05b280704b3..29a34f2f7b1 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -25,13 +25,10 @@ class CompareColumn: def compare_torch_tensor(cpu_output, npu_output, compare_column): cpu_shape = cpu_output.shape npu_shape = npu_output.shape - npu_dtype = None + npu_dtype = npu_output.dtype if npu_output.dtype == torch.bfloat16: - npu_dtype = torch.bfloat16 cpu_output = cpu_output.to(torch.float32) npu_output = npu_output.to(torch.float32) - else: - npu_dtype = npu_output.dtype cpu_output = cpu_output.numpy() npu_output = npu_output.cpu().numpy() if cpu_shape != npu_shape: -- Gitee From dfcfdbb961086592e6db7f27f5389e637b880a48 Mon Sep 17 00:00:00 2001 From: jiangchangting1 Date: Sat, 25 Nov 2023 07:15:26 +0000 Subject: [PATCH 5/5] update debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py. Signed-off-by: jiangchangting1 --- 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 29a34f2f7b1..c01fa300ae0 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/algorithm.py @@ -26,7 +26,7 @@ def compare_torch_tensor(cpu_output, npu_output, compare_column): cpu_shape = cpu_output.shape npu_shape = npu_output.shape npu_dtype = npu_output.dtype - if npu_output.dtype == torch.bfloat16: + if npu_dtype == torch.bfloat16: cpu_output = cpu_output.to(torch.float32) npu_output = npu_output.to(torch.float32) cpu_output = cpu_output.numpy() -- Gitee