From 67a1815f931654e02a5c6009e62e697333a8464a Mon Sep 17 00:00:00 2001 From: litian_drinksnow Date: Tue, 4 Jul 2023 19:37:49 +0800 Subject: [PATCH 1/3] add UT cases for compare --- ptdbg_ascend/test/ut/compare/test_compare.py | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ptdbg_ascend/test/ut/compare/test_compare.py diff --git a/ptdbg_ascend/test/ut/compare/test_compare.py b/ptdbg_ascend/test/ut/compare/test_compare.py new file mode 100644 index 00000000..2213df76 --- /dev/null +++ b/ptdbg_ascend/test/ut/compare/test_compare.py @@ -0,0 +1,46 @@ +import os +import unittest +from ptdbg_ascend.compare.acc_compare import compare_by_op, read_dump_path +from ptdbg_ascend.common.utils import CompareConst, CompareException, check_file_or_directory_path, \ + check_compare_param + + +class TestCompareFunctions(unittest.TestCase): + def test_compare_by_op_when_dump_file_not_found(self): + op_name = "Functional_conv2d_10_forward" + op_name_mapping_dict = { + 'Functional_conv2d_10_forward':[ + 'Functional_conv2d_10_forward.input.0', 'Functional_conv2d_10_forward.input.1' + ] + } + input_parma = {'npu_dump_data_dir':'npu_dump', 'bench_dump_data_dir':'gpu_dump'} + cos_sim, max_abs_err, err_msg = compare_by_op(op_name, op_name_mapping_dict, input_parma) + self.assertEqual(cos_sim, CompareConst.NAN) + self.assertEqual(max_abs_err, CompareConst.NAN) + self.assertIn('Dump file', err_msg) + self.assertIn('not found', err_msg) + + def test_read_dump_path_when_path_invalid(self): + noop_path = 'noop.path' + self.assertRaises(FileNotFoundError, read_dump_path, noop_path) + + def check_file_or_directory_path_when_file_is_invalid(self): + npu_pkl, npu_dump = 'noop.path', '../resources/compare/npu_dump.pkl' + self.assertRaises(CompareException, check_file_or_directory_path, npu_pkl, False) + self.assertRaises(CompareException, check_file_or_directory_path, npu_dump, True) + + def test_check_compare_param_when_param_invalid(self): + self.assertRaises(CompareException, check_compare_param, input_parma=['not a dict'], + output_path='', stack_mode=True, auto_analyze=False, suffix='') + self.assertRaises(CompareException, check_compare_param, input_parma={}, + output_path=233, stack_mode=True, auto_analyze=False, suffix='') + self.assertRaises(CompareException, check_compare_param, input_parma={}, + output_path='', stack_mode=3, auto_analyze=False, suffix='') + self.assertRaises(CompareException, check_compare_param, input_parma={}, + output_path='', stack_mode=True, auto_analyze=[], suffix='') + self.assertRaises(CompareException, check_compare_param, input_parma={}, + output_path='', stack_mode=True, auto_analyze=False, suffix=False) + +if __name__ == '__main__': + unittest.main() + \ No newline at end of file -- Gitee From 92175399904ef4fc4d0d88654d1339898d774240 Mon Sep 17 00:00:00 2001 From: litian_drinksnow Date: Wed, 5 Jul 2023 09:53:37 +0800 Subject: [PATCH 2/3] fix typo --- ptdbg_ascend/test/ut/compare/test_compare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ptdbg_ascend/test/ut/compare/test_compare.py b/ptdbg_ascend/test/ut/compare/test_compare.py index 2213df76..63b625cc 100644 --- a/ptdbg_ascend/test/ut/compare/test_compare.py +++ b/ptdbg_ascend/test/ut/compare/test_compare.py @@ -24,7 +24,7 @@ class TestCompareFunctions(unittest.TestCase): noop_path = 'noop.path' self.assertRaises(FileNotFoundError, read_dump_path, noop_path) - def check_file_or_directory_path_when_file_is_invalid(self): + def test_check_file_or_directory_path_when_file_is_invalid(self): npu_pkl, npu_dump = 'noop.path', '../resources/compare/npu_dump.pkl' self.assertRaises(CompareException, check_file_or_directory_path, npu_pkl, False) self.assertRaises(CompareException, check_file_or_directory_path, npu_dump, True) -- Gitee From 93dc17124a85fdda9980df0ca36a39f9bba49d99 Mon Sep 17 00:00:00 2001 From: litian_drinksnow Date: Thu, 6 Jul 2023 16:10:32 +0800 Subject: [PATCH 3/3] add fuzzy match and delete suffix UT --- ptdbg_ascend/test/ut/compare/test_compare.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ptdbg_ascend/test/ut/compare/test_compare.py b/ptdbg_ascend/test/ut/compare/test_compare.py index 63b625cc..9f0c6f8a 100644 --- a/ptdbg_ascend/test/ut/compare/test_compare.py +++ b/ptdbg_ascend/test/ut/compare/test_compare.py @@ -31,15 +31,15 @@ class TestCompareFunctions(unittest.TestCase): def test_check_compare_param_when_param_invalid(self): self.assertRaises(CompareException, check_compare_param, input_parma=['not a dict'], - output_path='', stack_mode=True, auto_analyze=False, suffix='') + output_path='', stack_mode=True, auto_analyze=False, fuzzy_match=False) self.assertRaises(CompareException, check_compare_param, input_parma={}, - output_path=233, stack_mode=True, auto_analyze=False, suffix='') + output_path=233, stack_mode=True, auto_analyze=False, fuzzy_match=False) self.assertRaises(CompareException, check_compare_param, input_parma={}, - output_path='', stack_mode=3, auto_analyze=False, suffix='') + output_path='', stack_mode=3, auto_analyze=False, fuzzy_match=False) self.assertRaises(CompareException, check_compare_param, input_parma={}, - output_path='', stack_mode=True, auto_analyze=[], suffix='') + output_path='', stack_mode=True, auto_analyze=[], fuzzy_match=False) self.assertRaises(CompareException, check_compare_param, input_parma={}, - output_path='', stack_mode=True, auto_analyze=False, suffix=False) + output_path='', stack_mode=True, auto_analyze=False, fuzzy_match='') if __name__ == '__main__': unittest.main() -- Gitee