From 262e2458174195fddb5804f2ff0dff049b53b4c3 Mon Sep 17 00:00:00 2001 From: i-robot Date: Wed, 20 Aug 2025 01:33:21 +0000 Subject: [PATCH] =?UTF-8?q?!5114=20=E3=80=90bugfix=E3=80=91=E6=AF=94?= =?UTF-8?q?=E5=AF=B9=E9=AB=98=E4=BA=AE=E6=A0=87=E8=AE=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Merge=20pull=20request=20!5114=20from=20yi?= =?UTF-8?q?nglinwei/master?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msprobe/core/compare/highlight.py | 36 ++++++++++++------- .../core_ut/compare/test_cmp_highlight.py | 33 +++++++++-------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/debug/accuracy_tools/msprobe/core/compare/highlight.py b/debug/accuracy_tools/msprobe/core/compare/highlight.py index 6a48278d6b..71c32490b4 100644 --- a/debug/accuracy_tools/msprobe/core/compare/highlight.py +++ b/debug/accuracy_tools/msprobe/core/compare/highlight.py @@ -53,10 +53,12 @@ class CheckOrderMagnitude(HighlightCheck): api_in, api_out, num = info max_diff_index = get_header_index(CompareConst.MAX_DIFF if dump_mode == Const.SUMMARY else CompareConst.MAX_ABS_ERR, dump_mode) - if abs(api_in[max_diff_index]) > abs(api_out[max_diff_index]): + max_diff_in = abs(api_in[max_diff_index]) + max_diff_out = abs(api_out[max_diff_index]) + if max_diff_in > max_diff_out or (max_diff_in <= 1 or max_diff_out <= 1): return - in_order = 0 if abs(api_in[max_diff_index]) < 1 else math.log10(abs(api_in[max_diff_index])) - out_order = 0 if abs(api_out[max_diff_index]) < 1 else math.log10(abs(api_out[max_diff_index])) + in_order = 0 if max_diff_in < 1 else math.log10(max_diff_in) + out_order = 0 if max_diff_out < 1 else math.log10(max_diff_out) if out_order - in_order >= CompareConst.ORDER_MAGNITUDE_DIFF_YELLOW: add_highlight_row_info(color_columns.yellow, num, "maximum absolute error of both input/parameters and output exceed 1, " @@ -101,20 +103,28 @@ class CheckMaxRelativeDiff(HighlightCheck): """检查最大相对差异""" def apply(self, info, color_columns, dump_mode): + def get_number(data): + """统计量相对值如果为正常百分数据,str格式并以%结尾""" + if isinstance(data, str) and data.endswith("%"): + return float(data[:-1]) / 100 + return data + api_in, api_out, num = info - max_diff_index = get_header_index(CompareConst.MAX_DIFF, dump_mode) - bench_max_index = get_header_index(CompareConst.BENCH_MAX, dump_mode) - input_max_relative_diff = np.abs( - np.divide(api_in[max_diff_index], max(Const.FLOAT_EPSILON, api_in[bench_max_index]))) - output_max_relative_diff = np.abs( - np.divide(api_out[max_diff_index], max(Const.FLOAT_EPSILON, api_out[bench_max_index]))) - if not isinstance(input_max_relative_diff, (float, int)) or not isinstance(output_max_relative_diff, - (float, int)): + max_rel_diff = get_header_index(CompareConst.MAX_RELATIVE_ERR, dump_mode) + input_max_relative_diff = api_in[max_rel_diff] # 内部数据,长度总是和表头一致,不会越界 + output_max_relative_diff = api_out[max_rel_diff] + input_max_relative_diff = get_number(input_max_relative_diff) + output_max_relative_diff = get_number(output_max_relative_diff) + + if not isinstance(output_max_relative_diff, (float, int)): return if output_max_relative_diff > CompareConst.MAX_RELATIVE_OUT_RED: add_highlight_row_info(color_columns.red, num, "maximum relative error exceeds 0.5") - elif (output_max_relative_diff > CompareConst.MAX_RELATIVE_OUT_YELLOW and - input_max_relative_diff < CompareConst.MAX_RELATIVE_IN_YELLOW): + + if not isinstance(input_max_relative_diff, (float, int)): + return + if (output_max_relative_diff > CompareConst.MAX_RELATIVE_OUT_YELLOW and + input_max_relative_diff < CompareConst.MAX_RELATIVE_IN_YELLOW): add_highlight_row_info(color_columns.yellow, num, "The output's maximum relative error exceeds 0.1, " "while the input/parameter's is below 0.01") diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py index 733c5fd4c5..aeb7308d96 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_cmp_highlight.py @@ -37,19 +37,27 @@ summary_line_3 = ['Functional_batch_norm_0_forward.output.2', 'Functional_batch_ True, 'Warning', ''] line_input = ['Functional.batch.norm.0.forward.input.0', 'Functional.batch.norm.0.forward.input.0', 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, - 1, 0.5, 1, 1, 0.95, 1, 1, 1, 1, 1, 1.01, 1, 1, 1, + 1, 0.5, 1, 1, 0.95, 1, + 1, 1, 1, 1, + 1.01, 1, 1, 1, True, 'Yes', '', 'input', 'Functional.batch.norm.0.forward'] line_1 = ['Functional.batch.norm.0.forward.output.0', 'Functional.batch.norm.0.forward.output.0', 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, - 0.8, 0.5, 1, 1, 0.59, 1, 'nan', 0, 1, 1, 19, 1, 1, 1, + 0.8, 0.5, 1, 1, 0.59, 1, + 'nan', 0, 1, 1, + 19, 1, 1, 1, True, 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] line_2 = ['Functional.batch.norm.0.forward.output.1', 'Functional.batch.norm.0.forward.output.1', 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, - 0.9, 0.5, 1, 1, 0.8, 1, 0, 0.12, 0, 1, 1, 0.1, 1, 1, + 0.9, 0.5, 1, 1, 0.8, 1, + 0, 0.12, 0, 1, + 1, 0.1, 1, 1, True, 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] line_3 = ['Functional.batch.norm.0.forward.output.2', 'Functional.batch.norm.0.forward.output.2', 'torch.float16', 'torch.float32', [256, 256, 14, 14], [256, 256, 14, 14], True, True, - 0.8, 0.5, 1.1e+10, 1, 0.85, 1, 9, 0.12, 0, 1, 1, 0.1, 1, 1, + 0.8, 0.5, 1.1e+10, 1, 0.85, 1, + 9, 0.12, 0, 1, + 1, 0.1, 1, 1, True, 'Yes', '', 'output', 'Functional.batch.norm.0.forward'] base_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), f'test_highlight') @@ -174,8 +182,8 @@ class TestUtilsMethods(unittest.TestCase): red_lines, yellow_lines = [], [] color_columns = ColorColumns(red=red_lines, yellow=yellow_lines) - api_in = {8: 0, 20: 1} - api_out = {8: 0.6, 20: 1} + api_in = {12: '1%'} + api_out = {12: '60%'} num = 1 info = (api_in, api_out, num) CheckMaxRelativeDiff().apply(info, color_columns, dump_mode=Const.SUMMARY) @@ -189,8 +197,8 @@ class TestUtilsMethods(unittest.TestCase): red_lines, yellow_lines = [], [] color_columns = ColorColumns(red=red_lines, yellow=yellow_lines) - api_in = {8: 0.001, 20: 1} - api_out = {8: 0.2, 20: 1} + api_in = {12: '0.1%'} + api_out = {12: '20%'} num = 1 info = (api_in, api_out, num) CheckMaxRelativeDiff().apply(info, color_columns, dump_mode=Const.SUMMARY) @@ -204,8 +212,8 @@ class TestUtilsMethods(unittest.TestCase): red_lines, yellow_lines = [], [] color_columns = ColorColumns(red=red_lines, yellow=yellow_lines) - api_in = {8: 0.001, 20: np.nan} - api_out = {8: 0.2, 20: 1} + api_in = {12: '15000%'} + api_out = {12: '20%'} num = 1 info = (api_in, api_out, num) result = CheckMaxRelativeDiff().apply(info, color_columns, dump_mode=Const.SUMMARY) @@ -475,9 +483,6 @@ class TestUtilsMethods(unittest.TestCase): ], "yellow_lines": [ (2, ["The output's one thousandth err ratio decreases by more than 0.1 compared to the input/parameter's"]), - (3, [ - "maximum absolute error of both input/parameters and output exceed 1, " - "with the output larger by an order of magnitude", - "The output's cosine decreases by more than 0.1 compared to the input/parameter's"]) + (3, ["The output's cosine decreases by more than 0.1 compared to the input/parameter's"]) ] }) -- Gitee