diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_overflow_check.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_overflow_check.py index 03e4e545aafb020091a68dd80ed36e3f8ede4004..15453f6c18ee2b337c358eb36851e8f8fedbce23 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_overflow_check.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_overflow_check.py @@ -122,7 +122,7 @@ def _run_ut_parser(parser): help=" The api param tool backward result file: generate from api param tool, " "a json file.", required=False) - parser.add_argument("-c", "--jit_compile", dest="jit_compile", help=" whether to turn on jit compile", + parser.add_argument("-j", "--jit_compile", dest="jit_compile", help=" whether to turn on jit compile", default=False, required=False) parser.add_argument("-d", "--device", dest="device_id", type=int, help=" set NPU device id to run ut", default=0, required=False) diff --git a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/utils.py b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/utils.py index e6787c467e0dc964f8d7184891d4e762288f3da1..30fe40a95be7492ca187b2a041d1c83a4e55a354 100644 --- a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/utils.py +++ b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/common/utils.py @@ -651,3 +651,14 @@ def check_file_valid(file_path): if file_path.endswith(Const.NUMPY_SUFFIX) and file_size > Const.TEN_GB: print_error_log('The file {} size is greater than 10GB.'.format(file_path)) raise CompareException(CompareException.INVALID_PATH_ERROR) + + +def check_path_before_create(path): + if len(os.path.realpath(path)) > Const.DIRECTORY_LENGTH or len(os.path.basename(path)) > \ + Const.FILE_NAME_LENGTH: + print_error_log('The file path length exceeds limit.') + raise CompareException(CompareException.INVALID_PATH_ERROR) + + if not re.match(Const.FILE_PATTERN, os.path.realpath(path)): + print_error_log('The file path {} contains special characters.'.format(path)) + raise CompareException(CompareException.INVALID_PATH_ERROR) diff --git a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/dump/utils.py b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/dump/utils.py index 87904bdb8cd5bdd2241aab6a0f7cdbcba5972f80..e6cfa1f444b67b4a2b4371f7639cefc4334dfca8 100644 --- a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/dump/utils.py +++ b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/dump/utils.py @@ -8,7 +8,7 @@ import torch from ..dump import dump from ..common.utils import print_error_log, CompareException, DumpException, Const, get_time, print_info_log, \ check_mode_valid, get_api_name_from_matcher, check_switch_valid, check_dump_mode_valid, check_summary_only_valid, generate_compare_script, \ - check_is_npu, check_file_valid, make_dump_path_if_not_exists + check_is_npu, check_file_valid, make_dump_path_if_not_exists, check_path_before_create from ..common.file_check_util import FileChecker, FileCheckConst, check_path_length, check_path_pattern_vaild from ..common.version import __version__ @@ -254,6 +254,7 @@ def make_dump_data_dir(dump_file_name): dump_path, file_name = os.path.split(os.path.realpath(dump_file_name)) name_body, name_extension = os.path.splitext(file_name) output_dir = os.path.join(dump_path, f"{name_body}") + check_path_before_create(output_dir) if not os.path.exists(output_dir): Path(output_dir).mkdir(mode=0o750, exist_ok=True) else: diff --git a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dispatch.py b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dispatch.py index 328b25b88851a4548f1f9455923ad5eed4dd4a00..53f104d45e41833eeece4184204ca21137cdb458 100644 --- a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dispatch.py +++ b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/online_dispatch/dispatch.py @@ -14,7 +14,8 @@ except ImportError: else: is_npu = True -from ..common.utils import Const, CompareConst, add_time_as_suffix, check_file_or_directory_path +from ..common.utils import Const, CompareConst, add_time_as_suffix, check_file_or_directory_path, \ + check_path_before_create from ..common.version import __version__ from .dump_compare import dispatch_workflow, dispatch_multiprocess, error_call, TimeStatistics, \ DispatchRunParam, save_csv @@ -56,6 +57,8 @@ class PtdbgDispatch(TorchDispatchMode): self.root_npu_path = os.path.join(self.root_path, f'npu') file_name = add_time_as_suffix(f'compare_result_rank{self.device_id}') self.csv_path = os.path.join(self.root_path, file_name) + check_path_before_create(self.root_cpu_path) + check_path_before_create(self.root_npu_path) Path(self.root_cpu_path).mkdir(mode=0o750, parents=True, exist_ok=True) Path(self.root_npu_path).mkdir(mode=0o750, parents=True, exist_ok=True) @@ -158,8 +161,13 @@ class PtdbgDispatch(TorchDispatchMode): logger_error("Please confirm you run environment installed torch_npu!") return func(*args, **kwargs) - aten_api = func.__name__.split(".")[0] - aten_api_overload_name = func.__name__.split(".")[1] + func_name_split_list = func.__name__.split(".") + aten_api = func_name_split_list[0] + try: + aten_api_overload_name = func_name_split_list[1] + except IndexError: + logger_error(f"Please check the func name {func.__name__}!") + return func(*args, **kwargs) if aten_api in self.aten_ops_blacklist: npu_out = func(*args, **kwargs) diff --git a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/parse_tool/lib/utils.py b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/parse_tool/lib/utils.py index 02cf0a215a032e5d1a7a0deddadd0e56ea39a100..c58374d044b085e1b328efb5983553ec7dd07077 100644 --- a/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/parse_tool/lib/utils.py +++ b/debug/accuracy_tools/ptdbg_ascend/src/python/ptdbg_ascend/parse_tool/lib/utils.py @@ -104,6 +104,7 @@ class Util: path = self.path_strip(path) if os.path.exists(path): return + self.check_path_name(path) try: os.makedirs(path, mode=0o750) except OSError as e: @@ -221,3 +222,12 @@ class Util: else: self.log.error("The file path %s is invalid" % path) raise ParseException(ParseException.PARSE_INVALID_PATH_ERROR) + + def check_path_name(self, path): + if len(os.path.realpath(path)) > Const.DIRECTORY_LENGTH or len(os.path.basename(path)) > \ + Const.FILE_NAME_LENGTH: + self.log.error('The file path length exceeds limit.') + raise ParseException(ParseException.PARSE_INVALID_PATH_ERROR) + if not re.match(Const.FILE_PATTERN, os.path.realpath(path)): + self.log.error('The file path {} contains special characters.'.format(path)) + raise ParseException(ParseException.PARSE_INVALID_PATH_ERROR)