From bd150c3cf5ee5389efde2dcdc65c2c6bfe28c603 Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Wed, 6 Aug 2025 09:30:29 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=92=E5=BD=92?= =?UTF-8?q?=E6=B7=B1=E5=BA=A6=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msprobe/core/common/const.py | 2 +- .../msprobe/core/data_dump/json_writer.py | 38 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/debug/accuracy_tools/msprobe/core/common/const.py b/debug/accuracy_tools/msprobe/core/common/const.py index 5a5c779ff82..58e0c693242 100644 --- a/debug/accuracy_tools/msprobe/core/common/const.py +++ b/debug/accuracy_tools/msprobe/core/common/const.py @@ -54,7 +54,7 @@ class Const: SIX_SEGMENT = 6 SEVEN_SEGMENT = 7 - MAX_DEPTH = 10 + MAX_DEPTH = 50 CPU_QUARTER = 4 DUMP_MAX_DEPTH = 50 diff --git a/debug/accuracy_tools/msprobe/core/data_dump/json_writer.py b/debug/accuracy_tools/msprobe/core/data_dump/json_writer.py index 740b7452f24..79c6202bca6 100644 --- a/debug/accuracy_tools/msprobe/core/data_dump/json_writer.py +++ b/debug/accuracy_tools/msprobe/core/data_dump/json_writer.py @@ -65,6 +65,26 @@ class DataWriter: if is_new_file: change_mode(file_path, FileCheckConst.DATA_FILE_AUTHORITY) + @recursion_depth_decorator("JsonWriter: DataWriter._replace_crc32_placeholders") + def _replace_crc32_placeholders(self, data, crc32_results): + """ + 遍历 JSON 结构,将所有 md5_index 占位符替换成真实的 CRC32 + """ + if isinstance(data, dict): + for k, v in list(data.items()): + if k == Const.MD5_INDEX and isinstance(v, int): + idx = v + # 防越界 + crc = crc32_results[idx] if idx < len(crc32_results) else None + # 删除占位符,改成真实字段 + del data[k] + data[Const.MD5] = crc + else: + self._replace_crc32_placeholders(v, crc32_results) + elif isinstance(data, (list, tuple)): + for item in data: + self._replace_crc32_placeholders(item, crc32_results) + @recursion_depth_decorator("JsonWriter: DataWriter._replace_stat_placeholders") def _replace_stat_placeholders(self, data, stat_result): if isinstance(data, dict): @@ -324,21 +344,3 @@ class DataWriter: if self.cache_debug: self.write_debug_info_json(self.debug_file_path) - def _replace_crc32_placeholders(self, data, crc32_results): - """ - 遍历 JSON 结构,将所有 md5_index 占位符替换成真实的 CRC32 - """ - if isinstance(data, dict): - for k, v in list(data.items()): - if k == Const.MD5_INDEX and isinstance(v, int): - idx = v - # 防越界 - crc = crc32_results[idx] if idx < len(crc32_results) else None - # 删除占位符,改成真实字段 - del data[k] - data[Const.MD5] = crc - else: - self._replace_crc32_placeholders(v, crc32_results) - elif isinstance(data, (list, tuple)): - for item in data: - self._replace_crc32_placeholders(item, crc32_results) -- Gitee From 9a936986b5f5165db178fde93437428510f348e8 Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Fri, 8 Aug 2025 09:48:00 +0800 Subject: [PATCH 02/11] 51 --- .../msprobe/test/core_ut/compare/test_acc_compare_check.py | 2 +- .../msprobe/test/core_ut/compare/test_acc_compare_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py index 1a0a33f7997..aca755a1828 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py @@ -75,7 +75,7 @@ class TestUtilsMethods(unittest.TestCase): self.assertEqual(context.exception.code, CompareException.INVALID_CHAR_ERROR) def test_check_json_key_value_max_depth(self): - result = check_json_key_value(input_output, op_name, depth=11) + result = check_json_key_value(input_output, op_name, depth=51) self.assertEqual(result, None) def test_valid_key_value_type_shape(self): diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py index 9d418ae5e4e..8cc44ab5e80 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py @@ -396,7 +396,7 @@ class TestUtilsMethods(unittest.TestCase): def test_op_item_parse_max_depth(self): with self.assertRaises(CompareException) as context: - op_item_parse(parse_item, parse_op_name, 'input', depth=11) + op_item_parse(parse_item, parse_op_name, 'input', depth=51) self.assertEqual(context.exception.code, CompareException.RECURSION_LIMIT_ERROR) def test_get_rela_diff_summary_mode_float_or_int(self): -- Gitee From 247467e6ee11d931a409201ad146ba6cdb4737e0 Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Fri, 8 Aug 2025 15:15:20 +0800 Subject: [PATCH 03/11] Update test_common_utils.py --- .../api_accuracy_checker/common/test_common_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py b/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py index a5d83ba3830..940142a2838 100644 --- a/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py +++ b/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py @@ -34,7 +34,12 @@ class TestUtils(unittest.TestCase): tensor = torch.randn(10, 10) with self.assertRaises(DumpException) as context: self.processor._save_recursive("test_api", [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, - [tensor, [tensor, [tensor, [tensor]]]]]]]]]]], 0) + [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor + ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], 0) self.assertTrue(isinstance(context.exception, DumpException)) self.assertEqual(context.exception.code, DumpException.RECURSION_LIMIT_ERROR) -- Gitee From cd4043c75c1e27174bf30c0ea31853c5cf3fdd67 Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Wed, 13 Aug 2025 09:22:17 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=92=E5=BD=92?= =?UTF-8?q?=E6=B7=B1=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- debug/accuracy_tools/msprobe/core/common/const.py | 4 ++-- .../common/test_common_utils.py | 13 ------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/debug/accuracy_tools/msprobe/core/common/const.py b/debug/accuracy_tools/msprobe/core/common/const.py index 58e0c693242..224240b2240 100644 --- a/debug/accuracy_tools/msprobe/core/common/const.py +++ b/debug/accuracy_tools/msprobe/core/common/const.py @@ -54,9 +54,9 @@ class Const: SIX_SEGMENT = 6 SEVEN_SEGMENT = 7 - MAX_DEPTH = 50 + MAX_DEPTH = 999 CPU_QUARTER = 4 - DUMP_MAX_DEPTH = 50 + DUMP_MAX_DEPTH = 999 EXTERN_INPUT_LIST_MAX_LEN = 100 MAX_PROCESS_NUM = 128 diff --git a/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py b/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py index 940142a2838..212a558b605 100644 --- a/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py +++ b/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py @@ -29,19 +29,6 @@ class TestUtils(unittest.TestCase): self.processor.save_tensors_in_element(api_name, tensor) file_path = os.path.join(self.save_path, f'{api_name}.0.pt') self.assertTrue(os.path.exists(file_path)) - - def test_recursion_limit_error(self): - tensor = torch.randn(10, 10) - with self.assertRaises(DumpException) as context: - self.processor._save_recursive("test_api", [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, - [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, - [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, - [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, - [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, - [tensor, [tensor, [tensor, [tensor - ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], 0) - self.assertTrue(isinstance(context.exception, DumpException)) - self.assertEqual(context.exception.code, DumpException.RECURSION_LIMIT_ERROR) def test_save_recursive_non_tensor_types(self): api_name = "test_api" -- Gitee From 95df2d90afdf9b150dc455dd24581059119faadf Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Thu, 14 Aug 2025 10:19:19 +0800 Subject: [PATCH 05/11] 1 --- .../msprobe/test/core_ut/compare/test_acc_compare_check.py | 2 +- .../msprobe/test/core_ut/compare/test_acc_compare_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py index aca755a1828..05b196d2329 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py @@ -75,7 +75,7 @@ class TestUtilsMethods(unittest.TestCase): self.assertEqual(context.exception.code, CompareException.INVALID_CHAR_ERROR) def test_check_json_key_value_max_depth(self): - result = check_json_key_value(input_output, op_name, depth=51) + result = check_json_key_value(input_output, op_name, depth=1000) self.assertEqual(result, None) def test_valid_key_value_type_shape(self): diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py index 8cc44ab5e80..96b650a2b9d 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py @@ -396,7 +396,7 @@ class TestUtilsMethods(unittest.TestCase): def test_op_item_parse_max_depth(self): with self.assertRaises(CompareException) as context: - op_item_parse(parse_item, parse_op_name, 'input', depth=51) + op_item_parse(parse_item, parse_op_name, 'input', depth=1000) self.assertEqual(context.exception.code, CompareException.RECURSION_LIMIT_ERROR) def test_get_rela_diff_summary_mode_float_or_int(self): -- Gitee From 224dee5276c355af0453d4ef24423543d2c30733 Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Thu, 14 Aug 2025 11:20:29 +0800 Subject: [PATCH 06/11] 1 --- debug/accuracy_tools/msprobe/core/common/log.py | 7 +++++++ .../msprobe/mindspore/api_accuracy_checker/api_runner.py | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/debug/accuracy_tools/msprobe/core/common/log.py b/debug/accuracy_tools/msprobe/core/common/log.py index f20d25d991e..4ce19e4961c 100644 --- a/debug/accuracy_tools/msprobe/core/common/log.py +++ b/debug/accuracy_tools/msprobe/core/common/log.py @@ -89,6 +89,13 @@ class BaseLogger: self.error(msg) raise exception + def warning_log_with_exp(self, msg, exception): + """ + 打印警告日志并抛出指定异常 + """ + self.warning(msg) + raise exception + def _print_log(self, level, msg, end='\n'): current_rank = self.get_rank() current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) diff --git a/debug/accuracy_tools/msprobe/mindspore/api_accuracy_checker/api_runner.py b/debug/accuracy_tools/msprobe/mindspore/api_accuracy_checker/api_runner.py index 8ec8125f75b..8ebe4e47b84 100644 --- a/debug/accuracy_tools/msprobe/mindspore/api_accuracy_checker/api_runner.py +++ b/debug/accuracy_tools/msprobe/mindspore/api_accuracy_checker/api_runner.py @@ -153,17 +153,17 @@ class ApiRunner: api_name_list = api_name_str.split(Const.SEP) if len(api_name_list) != 3: err_msg = f"ApiRunner.get_info_from_name failed: api_name_str: {api_name_str} is not in defined format" - logger.error_log_with_exp(err_msg, ApiAccuracyCheckerException(ApiAccuracyCheckerException.WrongValue)) + logger.warning_log_with_exp(err_msg, ApiAccuracyCheckerException(ApiAccuracyCheckerException.WrongValue)) api_type_str, api_sub_name = api_name_list[0], api_name_list[1] if api_type_str not in [MsCompareConst.MINT, MsCompareConst.MINT_FUNCTIONAL, MsCompareConst.TENSOR_API, MsCompareConst.FUNCTIONAL_API] \ and api_platform == Const.MS_FRAMEWORK: err_msg = f"ApiRunner.get_info_from_name failed: not mint, mint.nn.functional or Tensor api" - logger.error_log_with_exp(err_msg, ApiAccuracyCheckerException(ApiAccuracyCheckerException.WrongValue)) + logger.warning_log_with_exp(err_msg, ApiAccuracyCheckerException(ApiAccuracyCheckerException.WrongValue)) if api_type_str not in MsCompareConst.MT_VALID_API_TYPES and api_platform == Const.MT_FRAMEWORK: err_msg = f"ApiRunner.get_info_from_name failed: not torch, functional or Tensor api" - logger.error_log_with_exp(err_msg, ApiAccuracyCheckerException(ApiAccuracyCheckerException.WrongValue)) + logger.warning_log_with_exp(err_msg, ApiAccuracyCheckerException(ApiAccuracyCheckerException.WrongValue)) return api_type_str, api_sub_name @staticmethod -- Gitee From 24612b9e779c327b1128b0a10b413785eb6f279b Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Thu, 14 Aug 2025 14:24:18 +0800 Subject: [PATCH 07/11] Update test_utils.py --- debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py index 7a62d9f0257..0e63bc4609e 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py @@ -359,6 +359,7 @@ class TestUtils(TestCase): self.assertEqual(stack, {'stack_key': 'stack_value'}) self.assertEqual(construct, {'construct_key': 'construct_value'}) + @patch.object(Const, "MAX_DEPTH", 10) @patch.object(logger, "error") def test_recursion_depth_decorator(self, mock_error): # 测试递归深度限制函数 -- Gitee From febc7d5caf1116111885799bab56bb9107b403cc Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Thu, 14 Aug 2025 14:34:01 +0800 Subject: [PATCH 08/11] 1 --- .../common/test_common_utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py b/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py index 212a558b605..8d3a922421e 100644 --- a/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py +++ b/debug/accuracy_tools/msprobe/test/pytorch_ut/api_accuracy_checker/common/test_common_utils.py @@ -30,6 +30,19 @@ class TestUtils(unittest.TestCase): file_path = os.path.join(self.save_path, f'{api_name}.0.pt') self.assertTrue(os.path.exists(file_path)) + @patch.object(Const, "MAX_DEPTH", 50) + def test_recursion_limit_error(self): + tensor = torch.randn(10, 10) + with self.assertRaises(DumpException) as context: + self.processor._save_recursive("test_api", [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, [tensor, + [tensor, [tensor, [tensor, [tensor + ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], 0) + self.assertTrue(isinstance(context.exception, DumpException)) + self.assertEqual(context.exception.code, DumpException.RECURSION_LIMIT_ERROR) + def test_save_recursive_non_tensor_types(self): api_name = "test_api" non_tensor = [None, [True, [42, [3.14, ["test", [slice(0, 10)]]]]]] -- Gitee From 9a0137dd3a8ab81356b5f392e56c3604ed7b03bc Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Thu, 14 Aug 2025 16:04:12 +0800 Subject: [PATCH 09/11] 1 --- .../msprobe/test/core_ut/common/test_utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py index 0e63bc4609e..068666b5711 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py @@ -365,7 +365,7 @@ class TestUtils(TestCase): # 测试递归深度限制函数 recursion_list = [[]] temp_list = recursion_list[0] - for _ in range(Const.MAX_DEPTH): + for _ in range(Const.MAX_DEPTH + 1): temp_list.append([]) temp_list = temp_list[0] temp_list.append(0) @@ -509,12 +509,13 @@ class TestIsSaveVariableValid(unittest.TestCase): def setUp(self): self.valid_special_types = (int, float, str, bool) + @patch.object(Const, "DUMP_MAX_DEPTH", 5) def test_is_save_variable_valid_DepthExceeded_ReturnsFalse(self): - # 创建一个深度超过 Const.DUMP_MAX_DEPTH 的嵌套结构 - nested_structure = [0] * Const.DUMP_MAX_DEPTH - for _ in range(Const.DUMP_MAX_DEPTH): - nested_structure = [nested_structure] - self.assertFalse(is_save_variable_valid(nested_structure, self.valid_special_types)) + # 构造深度 = 阈值 + 1 + nested = [0] * 3 + for _ in range(Const.DUMP_MAX_DEPTH + 1): # 注意 +1,确保“超过”阈值 + nested = [nested] + self.assertFalse(is_save_variable_valid(nested, self.valid_special_types)) def test_is_save_variable_valid_ValidSpecialTypes_ReturnsTrue(self): for valid_type in self.valid_special_types: -- Gitee From 11b32d6365fea181ef5589ab74c20df97d5c3499 Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Thu, 14 Aug 2025 16:26:19 +0800 Subject: [PATCH 10/11] Update test_utils.py --- .../msprobe/test/core_ut/common/test_utils.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py index 068666b5711..98b8a233885 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py @@ -362,22 +362,25 @@ class TestUtils(TestCase): @patch.object(Const, "MAX_DEPTH", 10) @patch.object(logger, "error") def test_recursion_depth_decorator(self, mock_error): - # 测试递归深度限制函数 + # 构造深度 = MAX_DEPTH + 1,且最深层仍有 test_list[0] 可取 recursion_list = [[]] - temp_list = recursion_list[0] + temp = recursion_list[0] for _ in range(Const.MAX_DEPTH + 1): - temp_list.append([]) - temp_list = temp_list[0] - temp_list.append(0) + temp.append([]) # 让当前层的 [0] 指向更深一层 + temp = temp[0] + temp.append([]) # ☆ 关键:给“最深层”也再塞一个子列表,避免取 [0] 报 IndexError + call_record = [] + @recursion_depth_decorator("test func_info") - def recursion_func(test_list, call_record): - call_record.append(1) - if isinstance(test_list, list): - recursion_func(test_list[0], call_record) + def recursion_func(lst, record): + record.append(1) + if isinstance(lst, list): + recursion_func(lst[0], record) + with self.assertRaises(MsprobeException) as context: recursion_func(recursion_list, call_record) - # 执行超过限制的递归函数会触发异常、且函数成功调用次数等于限制次数 + self.assertEqual(context.exception.code, MsprobeException.RECURSION_LIMIT_ERROR) mock_error.assert_called_with("call test func_info exceeds the recursion limit.") self.assertEqual(len(call_record), Const.MAX_DEPTH) -- Gitee From 42a35989d3fab559d98de26b9fec2c5bfaa37950 Mon Sep 17 00:00:00 2001 From: mnhdxnh Date: Thu, 14 Aug 2025 17:38:10 +0800 Subject: [PATCH 11/11] 1 --- .../msprobe/core/common/const.py | 4 +-- .../msprobe/test/core_ut/common/test_utils.py | 26 ++++++++----------- .../core_ut/compare/test_acc_compare_check.py | 2 +- .../core_ut/compare/test_acc_compare_utils.py | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/debug/accuracy_tools/msprobe/core/common/const.py b/debug/accuracy_tools/msprobe/core/common/const.py index 224240b2240..ed70da506aa 100644 --- a/debug/accuracy_tools/msprobe/core/common/const.py +++ b/debug/accuracy_tools/msprobe/core/common/const.py @@ -54,9 +54,9 @@ class Const: SIX_SEGMENT = 6 SEVEN_SEGMENT = 7 - MAX_DEPTH = 999 + MAX_DEPTH = 400 CPU_QUARTER = 4 - DUMP_MAX_DEPTH = 999 + DUMP_MAX_DEPTH = 400 EXTERN_INPUT_LIST_MAX_LEN = 100 MAX_PROCESS_NUM = 128 diff --git a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py index 98b8a233885..c9214d762fc 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/common/test_utils.py @@ -359,28 +359,24 @@ class TestUtils(TestCase): self.assertEqual(stack, {'stack_key': 'stack_value'}) self.assertEqual(construct, {'construct_key': 'construct_value'}) - @patch.object(Const, "MAX_DEPTH", 10) @patch.object(logger, "error") def test_recursion_depth_decorator(self, mock_error): - # 构造深度 = MAX_DEPTH + 1,且最深层仍有 test_list[0] 可取 + # 测试递归深度限制函数 recursion_list = [[]] - temp = recursion_list[0] - for _ in range(Const.MAX_DEPTH + 1): - temp.append([]) # 让当前层的 [0] 指向更深一层 - temp = temp[0] - temp.append([]) # ☆ 关键:给“最深层”也再塞一个子列表,避免取 [0] 报 IndexError - + temp_list = recursion_list[0] + for _ in range(Const.MAX_DEPTH): + temp_list.append([]) + temp_list = temp_list[0] + temp_list.append(0) call_record = [] - @recursion_depth_decorator("test func_info") - def recursion_func(lst, record): - record.append(1) - if isinstance(lst, list): - recursion_func(lst[0], record) - + def recursion_func(test_list, call_record): + call_record.append(1) + if isinstance(test_list, list): + recursion_func(test_list[0], call_record) with self.assertRaises(MsprobeException) as context: recursion_func(recursion_list, call_record) - + # 执行超过限制的递归函数会触发异常、且函数成功调用次数等于限制次数 self.assertEqual(context.exception.code, MsprobeException.RECURSION_LIMIT_ERROR) mock_error.assert_called_with("call test func_info exceeds the recursion limit.") self.assertEqual(len(call_record), Const.MAX_DEPTH) diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py index 05b196d2329..60c72bcb68a 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_check.py @@ -75,7 +75,7 @@ class TestUtilsMethods(unittest.TestCase): self.assertEqual(context.exception.code, CompareException.INVALID_CHAR_ERROR) def test_check_json_key_value_max_depth(self): - result = check_json_key_value(input_output, op_name, depth=1000) + result = check_json_key_value(input_output, op_name, depth=401) self.assertEqual(result, None) def test_valid_key_value_type_shape(self): diff --git a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py index 96b650a2b9d..95002983ade 100644 --- a/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py +++ b/debug/accuracy_tools/msprobe/test/core_ut/compare/test_acc_compare_utils.py @@ -396,7 +396,7 @@ class TestUtilsMethods(unittest.TestCase): def test_op_item_parse_max_depth(self): with self.assertRaises(CompareException) as context: - op_item_parse(parse_item, parse_op_name, 'input', depth=1000) + op_item_parse(parse_item, parse_op_name, 'input', depth=401) self.assertEqual(context.exception.code, CompareException.RECURSION_LIMIT_ERROR) def test_get_rela_diff_summary_mode_float_or_int(self): -- Gitee