diff --git a/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_process.py b/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_process.py index c1c25ac938b1100162e2145299c311ef9b33ed62..2e152f4dba3a78ce7c933dd438d832bf7286699e 100644 --- a/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_process.py +++ b/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_process.py @@ -219,8 +219,16 @@ def cell_construct_wrapper(func, self): def sort_filenames(path): filenames = os.listdir(path) id_pattern = re.compile(rf'{CoreConst.REPLACEMENT_CHARACTER}(\d+){CoreConst.NUMPY_SUFFIX}$') - filenames.sort(key=lambda x: int(id_pattern.findall(x)[0])) - return filenames + # 只保留能提取到数字id的文件,避免数组越界 + valid_files = [] + for filename in filenames: + match = id_pattern.findall(filename) + if match and match[0].isdigit(): + valid_files.append(filename) + else: + logger.warning(f"File {filename} does not match the expected pattern and will be ignored.") + valid_files.sort(key=lambda x: int(id_pattern.findall(x)[0])) + return valid_files def rename_filename(path="", data_df=None): diff --git a/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_with_insert_gradient.py b/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_with_insert_gradient.py index a04ed970c133b43fa14cc668548b328e564faa75..bf43ee92d4980122a7ebe5d2995642f996c879fd 100644 --- a/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_with_insert_gradient.py +++ b/debug/accuracy_tools/msprobe/mindspore/dump/cell_dump_with_insert_gradient.py @@ -197,8 +197,16 @@ def cell_construct_wrapper(func, self): def sort_filenames(path): filenames = os.listdir(path) id_pattern = re.compile(rf'{CoreConst.REPLACEMENT_CHARACTER}(\d+){CoreConst.NUMPY_SUFFIX}$') - filenames.sort(key=lambda x: int(id_pattern.findall(x)[0])) - return filenames + # 只保留能提取到数字id的文件,避免数组越界 + valid_files = [] + for filename in filenames: + match = id_pattern.findall(filename) + if match and match[0].isdigit(): + valid_files.append(filename) + else: + logger.warning(f"File {filename} does not match the expected pattern and will be ignored.") + valid_files.sort(key=lambda x: int(id_pattern.findall(x)[0])) + return valid_files def rename_filename(path="", data_df=None):