From 46b81ba2ee8d874bc48b64d59efa6357afaa778d Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 02:27:29 +0000 Subject: [PATCH 01/10] update precision/api_ut_tools/dump/info_dump.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/info_dump.py | 49 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/precision/api_ut_tools/dump/info_dump.py b/precision/api_ut_tools/dump/info_dump.py index 2cbd1750f1f..7a5cb910791 100644 --- a/precision/api_ut_tools/dump/info_dump.py +++ b/precision/api_ut_tools/dump/info_dump.py @@ -1 +1,48 @@ -# 基于api——info信息,将其落盘为json文件 \ No newline at end of file +import os +import json +import numpy as np +from .utils import DumpUtil +from .api_info import ForwardAPIInfo, BackwardAPIInfo + +def write_api_info_json(api_info): + dump_path = DumpUtil.dump_path + check_path(dump_path) + + if isinstance(api_info, ForwardAPIInfo): + file_path = os.path.join(dump_path, 'forward_info.json') + stack_file_path = os.path.join(dump_path, 'stack_info.json') + write_json(file_path, api_info.api_info_struct) + write_json(stack_file_path, api_info.stack_info_struct) + + elif isinstance(api_info, BackwardAPIInfo): + file_path = os.path.join(dump_path, 'backward_info.json') + write_json(file_path, api_info.grads_info_struct) + else: + raise ValueError("Invalid api_info type") + +def check_path(dump_path): + if not os.path.exists(dump_path): + raise ValueError("Path does not exist") + +def write_npy(name, tensor): + dump_path = DumpUtil.dump_path + check_path(dump_path) + npy_folder = os.path.join(dump_path, 'npy') + if not os.path.exists(npy_folder): + os.makedirs(npy_folder, mode=0o750) + npy_path = os.path.join(npy_folder, name) + np.save(npy_path, tensor) + +def write_json(file_path, data): + if not os.path.exists(file_path): + with open(file_path, 'w') as f: + f.write("{\n}") + with open(file_path, 'a+') as f: + f.seek(0, os.SEEK_END) + f.seek(f.tell() - 1, os.SEEK_SET) + f.truncate() + if f.tell() > 3: + f.seek(f.tell() - 1, os.SEEK_SET) + f.truncate() + f.write(',\n') + f.write(json.dumps(data)[1:-1] + '\n}') \ No newline at end of file -- Gitee From a40bd84ddd9fb4347e49a09f614cc3781ee2a7e5 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 07:17:24 +0000 Subject: [PATCH 02/10] update precision/api_ut_tools/dump/info_dump.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/info_dump.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/precision/api_ut_tools/dump/info_dump.py b/precision/api_ut_tools/dump/info_dump.py index 7a5cb910791..2d38ada6276 100644 --- a/precision/api_ut_tools/dump/info_dump.py +++ b/precision/api_ut_tools/dump/info_dump.py @@ -12,17 +12,17 @@ def write_api_info_json(api_info): file_path = os.path.join(dump_path, 'forward_info.json') stack_file_path = os.path.join(dump_path, 'stack_info.json') write_json(file_path, api_info.api_info_struct) - write_json(stack_file_path, api_info.stack_info_struct) + write_json(stack_file_path, api_info.stack_info_struct, indent=4) elif isinstance(api_info, BackwardAPIInfo): file_path = os.path.join(dump_path, 'backward_info.json') - write_json(file_path, api_info.grads_info_struct) + write_json(file_path, api_info.grad_info_struct) else: - raise ValueError("Invalid api_info type") + raise ValueError(f"Invalid api_info type {type(api_info)}") def check_path(dump_path): if not os.path.exists(dump_path): - raise ValueError("Path does not exist") + raise ValueError(f"Path {dump_path} does not exist") def write_npy(name, tensor): dump_path = DumpUtil.dump_path @@ -33,7 +33,7 @@ def write_npy(name, tensor): npy_path = os.path.join(npy_folder, name) np.save(npy_path, tensor) -def write_json(file_path, data): +def write_json(file_path, data, indent=None): if not os.path.exists(file_path): with open(file_path, 'w') as f: f.write("{\n}") @@ -45,4 +45,4 @@ def write_json(file_path, data): f.seek(f.tell() - 1, os.SEEK_SET) f.truncate() f.write(',\n') - f.write(json.dumps(data)[1:-1] + '\n}') \ No newline at end of file + f.write(json.dumps(data, indent=indent)[1:-1] + '\n}') \ No newline at end of file -- Gitee From 6eebd04f8d5169bd1648234e9db44db7462b355f Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 07:36:04 +0000 Subject: [PATCH 03/10] update precision/api_ut_tools/dump/info_dump.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/info_dump.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/precision/api_ut_tools/dump/info_dump.py b/precision/api_ut_tools/dump/info_dump.py index 2d38ada6276..73a5abc5792 100644 --- a/precision/api_ut_tools/dump/info_dump.py +++ b/precision/api_ut_tools/dump/info_dump.py @@ -6,8 +6,7 @@ from .api_info import ForwardAPIInfo, BackwardAPIInfo def write_api_info_json(api_info): dump_path = DumpUtil.dump_path - check_path(dump_path) - + initialize_output_json(dump_path) if isinstance(api_info, ForwardAPIInfo): file_path = os.path.join(dump_path, 'forward_info.json') stack_file_path = os.path.join(dump_path, 'stack_info.json') @@ -20,17 +19,16 @@ def write_api_info_json(api_info): else: raise ValueError(f"Invalid api_info type {type(api_info)}") -def check_path(dump_path): - if not os.path.exists(dump_path): - raise ValueError(f"Path {dump_path} does not exist") - def write_npy(name, tensor): dump_path = DumpUtil.dump_path - check_path(dump_path) + if not os.path.exists(dump_path): + raise ValueError(f"Path {dump_path} does not exist") npy_folder = os.path.join(dump_path, 'npy') if not os.path.exists(npy_folder): os.makedirs(npy_folder, mode=0o750) npy_path = os.path.join(npy_folder, name) + if os.path.exists(npy_path): + raise ValueError(f"File {npy_path} already exists") np.save(npy_path, tensor) def write_json(file_path, data, indent=None): @@ -45,4 +43,13 @@ def write_json(file_path, data, indent=None): f.seek(f.tell() - 1, os.SEEK_SET) f.truncate() f.write(',\n') - f.write(json.dumps(data, indent=indent)[1:-1] + '\n}') \ No newline at end of file + f.write(json.dumps(data, indent=indent)[1:-1] + '\n}') + +def initialize_output_json(dump_path): + if not os.path.exists(dump_path): + raise ValueError(f"Path {dump_path} does not exist") + files = ['forward_info.json', 'backward_info.json', 'stack_info.json'] + for file in files: + file_path = os.path.join(dump_path, file) + if os.path.exists(file_path): + raise ValueError(f"file {file_path} already exists, please remove it first or use a new dump path") \ No newline at end of file -- Gitee From 7126605ebba486b1a4e0ff71c1d12135dbaad00e Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 08:26:34 +0000 Subject: [PATCH 04/10] add precision/api_ut_tools/dump. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/config.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 precision/api_ut_tools/dump/config.py diff --git a/precision/api_ut_tools/dump/config.py b/precision/api_ut_tools/dump/config.py new file mode 100644 index 00000000000..e69de29bb2d -- Gitee From 032066dd6fe7ad66426a08b599f11a28e5a4c176 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 08:26:44 +0000 Subject: [PATCH 05/10] update precision/api_ut_tools/dump/config.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/config.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/precision/api_ut_tools/dump/config.py b/precision/api_ut_tools/dump/config.py index e69de29bb2d..54d5e5e7a10 100644 --- a/precision/api_ut_tools/dump/config.py +++ b/precision/api_ut_tools/dump/config.py @@ -0,0 +1,26 @@ +import yaml + +class Config: + def __init__(self, dump_path=None, jit_compile=None, compile_option=None, comparison_algorithm=None, real_data=None): + self.dump_path = dump_path + self.jit_compile = jit_compile + self.compile_option = compile_option + self.comparison_algorithm = comparison_algorithm + self.real_data = real_data + + def read_yaml(self, file_path, user_input=None): + if user_input: + self.dump_path = user_input.get('dump_path', self.dump_path) + self.jit_compile = user_input.get('jit_compile', self.jit_compile) + self.compile_option = user_input.get('compile_option', self.compile_option) + self.comparison_algorithm = user_input.get('comparison_algorithm', self.comparison_algorithm) + self.real_data = user_input.get('real_data', self.real_data) + + else: + with open(file_path, 'r') as file: + data = yaml.safe_load(file) + self.dump_path = data.get('dump_path', self.dump_path) + self.jit_compile = data.get('jit_compile', self.jit_compile) + self.compile_option = data.get('compile_option', self.compile_option) + self.comparison_algorithm = data.get('comparison_algorithm', self.comparison_algorithm) + self.real_data = data.get('real_data', self.real_data) \ No newline at end of file -- Gitee From 7c6065c97d9a8c38a77683510d64273faf51ded3 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 08:42:34 +0000 Subject: [PATCH 06/10] update precision/api_ut_tools/dump/config.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/config.py | 40 ++++++++++++--------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/precision/api_ut_tools/dump/config.py b/precision/api_ut_tools/dump/config.py index 54d5e5e7a10..19f51362b84 100644 --- a/precision/api_ut_tools/dump/config.py +++ b/precision/api_ut_tools/dump/config.py @@ -1,26 +1,22 @@ import yaml +import os class Config: - def __init__(self, dump_path=None, jit_compile=None, compile_option=None, comparison_algorithm=None, real_data=None): - self.dump_path = dump_path - self.jit_compile = jit_compile - self.compile_option = compile_option - self.comparison_algorithm = comparison_algorithm - self.real_data = real_data + def __init__(self, yaml_file): + if not os.path.exists(yaml_file): + raise ValueError(f"File {yaml_file} does not exist") + with open(yaml_file, 'r') as file: + config = yaml.safe_load(file) + self.dump_path = config['dump_path'] + self.jit_compile = config['jit_compile'] + self.compile_option = config['compile_option'] + self.compare_algorithm = config['compare_algorithm'] + self.real_data = config['real_data'] + self.dump_step = config['dump_step'] - def read_yaml(self, file_path, user_input=None): - if user_input: - self.dump_path = user_input.get('dump_path', self.dump_path) - self.jit_compile = user_input.get('jit_compile', self.jit_compile) - self.compile_option = user_input.get('compile_option', self.compile_option) - self.comparison_algorithm = user_input.get('comparison_algorithm', self.comparison_algorithm) - self.real_data = user_input.get('real_data', self.real_data) - - else: - with open(file_path, 'r') as file: - data = yaml.safe_load(file) - self.dump_path = data.get('dump_path', self.dump_path) - self.jit_compile = data.get('jit_compile', self.jit_compile) - self.compile_option = data.get('compile_option', self.compile_option) - self.comparison_algorithm = data.get('comparison_algorithm', self.comparison_algorithm) - self.real_data = data.get('real_data', self.real_data) \ No newline at end of file + def update_config(self, **kwargs): + for key, value in kwargs.items(): + if hasattr(self, key): + setattr(self, key, value) + else: + raise ValueError(f"Invalid key {key}") \ No newline at end of file -- Gitee From 4c029acf8660ceb6105706d7ab2c5c650a0bad46 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 10:32:50 +0000 Subject: [PATCH 07/10] update precision/api_ut_tools/dump/config.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/precision/api_ut_tools/dump/config.py b/precision/api_ut_tools/dump/config.py index 19f51362b84..504d9ec85f7 100644 --- a/precision/api_ut_tools/dump/config.py +++ b/precision/api_ut_tools/dump/config.py @@ -14,6 +14,16 @@ class Config: self.real_data = config['real_data'] self.dump_step = config['dump_step'] + def __str__(self): + return ( + f"dump_path={self.dump_path}\n" + f"jit_compile={self.jit_compile}\n" + f"compile_option={self.compile_option}\n" + f"compare_algorithm={self.compare_algorithm}\n" + f"real_data={self.real_data}\n" + f"dump_step={self.dump_step}\n" + ) + def update_config(self, **kwargs): for key, value in kwargs.items(): if hasattr(self, key): -- Gitee From 98207fe781b9818551a4dfe960fbc31660c8599b Mon Sep 17 00:00:00 2001 From: sunyiming Date: Thu, 27 Jul 2023 10:33:08 +0000 Subject: [PATCH 08/10] update precision/api_ut_tools/dump/config.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/precision/api_ut_tools/dump/config.py b/precision/api_ut_tools/dump/config.py index 504d9ec85f7..c32f66d7ec3 100644 --- a/precision/api_ut_tools/dump/config.py +++ b/precision/api_ut_tools/dump/config.py @@ -29,4 +29,4 @@ class Config: if hasattr(self, key): setattr(self, key, value) else: - raise ValueError(f"Invalid key {key}") \ No newline at end of file + raise ValueError(f"Invalid key '{key}'") \ No newline at end of file -- Gitee From 31a5db1d47508a4af1e36c987bfdc595475c6920 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Tue, 1 Aug 2023 00:57:13 +0000 Subject: [PATCH 09/10] update precision/api_ut_tools/dump/info_dump.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/info_dump.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/precision/api_ut_tools/dump/info_dump.py b/precision/api_ut_tools/dump/info_dump.py index 73a5abc5792..36df2a05ffd 100644 --- a/precision/api_ut_tools/dump/info_dump.py +++ b/precision/api_ut_tools/dump/info_dump.py @@ -5,8 +5,8 @@ from .utils import DumpUtil from .api_info import ForwardAPIInfo, BackwardAPIInfo def write_api_info_json(api_info): + initialize_output_json() dump_path = DumpUtil.dump_path - initialize_output_json(dump_path) if isinstance(api_info, ForwardAPIInfo): file_path = os.path.join(dump_path, 'forward_info.json') stack_file_path = os.path.join(dump_path, 'stack_info.json') @@ -45,7 +45,8 @@ def write_json(file_path, data, indent=None): f.write(',\n') f.write(json.dumps(data, indent=indent)[1:-1] + '\n}') -def initialize_output_json(dump_path): +def initialize_output_json(): + dump_path = DumpUtil.dump_path if not os.path.exists(dump_path): raise ValueError(f"Path {dump_path} does not exist") files = ['forward_info.json', 'backward_info.json', 'stack_info.json'] -- Gitee From 13853b44b46cacfa908010430b16413dabbeffe8 Mon Sep 17 00:00:00 2001 From: sunyiming Date: Tue, 1 Aug 2023 00:57:42 +0000 Subject: [PATCH 10/10] update precision/api_ut_tools/dump/utils.py. Signed-off-by: sunyiming --- precision/api_ut_tools/dump/utils.py | 215 ++++----------------------- 1 file changed, 27 insertions(+), 188 deletions(-) diff --git a/precision/api_ut_tools/dump/utils.py b/precision/api_ut_tools/dump/utils.py index e5773e097cf..c09950c5daf 100644 --- a/precision/api_ut_tools/dump/utils.py +++ b/precision/api_ut_tools/dump/utils.py @@ -2,7 +2,7 @@ import os import shutil import sys from pathlib import Path - +import numpy as np from ..common.utils import print_error_log, CompareException, DumpException, Const, get_time, print_info_log, \ check_mode_valid, get_api_name_from_matcher @@ -12,19 +12,33 @@ dump_count = 0 range_begin_flag, range_end_flag = False, False +class DumpConst: + delimiter = '*' + forward = 'forward' + backward = 'backward' + + +def write_npy(name, tensor): + dump_path = DumpUtil.dump_path + check_path(dump_path) + npy_folder = os.path.join(dump_path, 'npy') + if not os.path.exists(npy_folder): + os.makedirs(npy_folder, mode=0o750) + npy_path = os.path.join(npy_folder, name) + np.save(npy_path, tensor) + full_path = os.path.abspath(npy_path+'.npy') + return full_path + +def check_path(dump_path): + if not os.path.exists(dump_path): + raise ValueError(f"Path {dump_path} does not exist") + + + class DumpUtil(object): - dump_data_dir = None - dump_path = None + save_real_data = False + dump_path = './random_data_jsons' dump_switch = None - dump_switch_mode = Const.ALL - dump_switch_scope = [] - dump_init_enable = False - dump_api_list = [] - dump_filter_switch = None - dump_mode = Const.ALL - backward_input = {} - dump_dir_tag = 'ptdbg_dump' - dump_config = None @staticmethod def set_dump_path(save_path): @@ -32,191 +46,16 @@ class DumpUtil(object): DumpUtil.dump_init_enable = True @staticmethod - def set_dump_config(dump_config): - DumpUtil.dump_config = dump_config - - @staticmethod - def set_dump_switch(switch, mode, scope, api_list, filter_switch, dump_mode): + def set_dump_switch(switch): DumpUtil.dump_switch = switch - DumpUtil.dump_switch_mode = mode - DumpUtil.dump_init_enable = True - DumpUtil.dump_switch_scope = scope - DumpUtil.dump_api_list = [api.lower() for api in api_list] - DumpUtil.dump_filter_switch = filter_switch - DumpUtil.dump_mode = dump_mode - if mode == Const.ACL: - DumpUtil.dump_switch_scope = [api_name.replace("backward", "forward") for api_name in scope] - - def check_list_or_acl_mode(name_prefix): - global dump_count - for item in DumpUtil.dump_switch_scope: - if name_prefix.startswith(item): - dump_count = dump_count + 1 - return True - - def check_range_mode(name_prefix): - global range_begin_flag - global range_end_flag - if name_prefix.startswith(DumpUtil.dump_switch_scope[0]): - range_begin_flag = True - return True - if name_prefix.startswith(DumpUtil.dump_switch_scope[1]): - range_end_flag = True - return True - if range_begin_flag and not range_end_flag: - return True - return False - - def check_stack_mode(name_prefix): - if len(DumpUtil.dump_switch_scope) == 0: - return True - elif len(DumpUtil.dump_switch_scope) == 1: - return name_prefix.startswith(DumpUtil.dump_switch_scope[0]) - elif len(DumpUtil.dump_switch_scope) == 2: - return DumpUtil.check_range_mode(name_prefix) - else: - print_error_log("dump scope is invalid, Please set the scope mode in" - " set_dump_switch with 'all', 'list', 'range', 'stack', 'acl', 'api_list'!") - return False - - check_mapper = { - Const.LIST: check_list_or_acl_mode, - Const.ACL: check_list_or_acl_mode, - Const.RANGE: check_range_mode, - Const.STACK: check_stack_mode - } - @staticmethod - def check_switch_scope(name_prefix): - if DumpUtil.dump_switch_mode in DumpUtil.check_mapper: - check_func = DumpUtil.check_mapper[DumpUtil.dump_switch_mode] - return check_func(name_prefix) - return False @staticmethod def get_dump_path(): if DumpUtil.dump_path: return DumpUtil.dump_path - if DumpUtil.dump_switch_mode == Const.ALL: - raise RuntimeError("get_dump_path: the file path is empty," - " you must use set_dump_path to set a valid dump path!!!") - else: - dir_path = os.path.realpath("./") - dump_file_name = "scope_dump_{}_{}_{}.pkl".format( - DumpUtil.dump_switch_mode, DumpUtil.dump_switch_scope[0], get_time()) - DumpUtil.dump_path = os.path.join(dir_path, dump_file_name) - return DumpUtil.dump_path - @staticmethod def get_dump_switch(): return DumpUtil.dump_switch == "ON" - -def set_dump_path(fpath=None, dump_tag='ptdbg_dump'): - if fpath is None: - raise RuntimeError("set_dump_path '{}' error, please set a valid filename".format(fpath)) - return - real_path = os.path.realpath(fpath) - if not os.path.isdir(real_path): - print_error_log( - "set_dump_path '{}' error, the path is not a directory please set a valid directory.".format(real_path)) - raise DumpException(DumpException.INVALID_PATH_ERROR) - DumpUtil.set_dump_path(real_path) - DumpUtil.dump_dir_tag = dump_tag - - -def generate_dump_path_str(): - if DumpUtil.dump_switch_mode == 'acl': - if DumpUtil.dump_config == '': - print_error_log("Please provide dump config for register hook before turning on dump switch!") - raise DumpException(DumpException.NONE_ERROR) - dump_path = f"according to dump config {DumpUtil.dump_config}" - else: - dump_path = f"to {DumpUtil.dump_path}" - return dump_path - - -def set_dump_switch(switch, mode=Const.ALL, scope=[], api_list=[], filter_switch=Const.ON, dump_mode=Const.ALL): - try: - check_mode_valid(mode) - assert switch in ["ON", "OFF"], "Please set dump switch with 'ON' or 'OFF'." - assert filter_switch in ["ON", "OFF"], "Please set filter_switch with 'ON' or 'OFF'." - assert dump_mode in ["all", "forward", "backward"], \ - "Please set dump_mode with 'all' or 'forward' or 'backward'." - if mode == Const.RANGE: - assert len(scope) == 2, "set_dump_switch, scope param set invalid, it's must be [start, end]." - if mode == Const.LIST: - assert len(scope) != 0, "set_dump_switch, scope param set invalid, it's should not be an empty list." - if mode == Const.STACK: - assert len(scope) <= 2, "set_dump_switch, scope param set invalid, it's must be [start, end] or []." - if mode == Const.ACL: - assert len(scope) == 1, \ - "set_dump_switch, scope param set invalid, only one api name is supported in acl mode." - if mode == Const.API_LIST: - assert isinstance(api_list, list) and len(api_list) >= 1, \ - "Current dump mode is 'api_list', but the content of api_list parameter is empty or valid." - except (CompareException, AssertionError) as err: - print_error_log(str(err)) - sys.exit() - - if switch == "OFF": - dump_path_str = generate_dump_path_str() - DumpUtil.set_dump_switch(switch, mode=mode, scope=scope, api_list=api_list, - filter_switch=filter_switch, dump_mode=dump_mode) - if switch == "ON": - dump_path_str = generate_dump_path_str() - - global dump_count - if switch == "ON": - print_info_log(f"Dump switch is turned on. Dump data will be saved {dump_path_str}. ") - if mode == Const.LIST: - dump_count = 0 - else: - print_info_log(f"Dump switch is turned off. Dump data has been saved {dump_path_str}. ") - if mode == Const.LIST: - print_info_log("The number of matched dump is {}".format(dump_count)) - -def _set_dump_switch4api_list(name): - if DumpUtil.dump_api_list: - api_name = get_api_name_from_matcher(name) - DumpUtil.dump_switch = "ON" if api_name in DumpUtil.dump_api_list else "OFF" - - -def set_backward_input(backward_input): - for index, api_name in enumerate(DumpUtil.dump_switch_scope): - DumpUtil.backward_input[api_name] = backward_input[index] - - -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}") - if not os.path.exists(output_dir): - os.mkdir(output_dir, mode=0o750) - else: - shutil.rmtree(output_dir, ignore_errors=True) - os.mkdir(output_dir, mode=0o750) - return output_dir - - -def make_dump_dirs(rank): - dump_file_name, dump_file_name_body = "dump.pkl", "dump" - dump_root_dir = DumpUtil.dump_path if DumpUtil.dump_path else "./" - tag_dir = os.path.join(dump_root_dir, DumpUtil.dump_dir_tag + f'_v{__version__}') - Path(tag_dir).mkdir(mode=0o750, parents=True, exist_ok=True) - rank_dir = os.path.join(tag_dir, 'rank' + str(rank)) - if not os.path.exists(rank_dir): - os.mkdir(rank_dir, mode=0o750) - DumpUtil.dump_dir = rank_dir - dump_file_path = os.path.join(rank_dir, dump_file_name) - DumpUtil.set_dump_path(dump_file_path) - - -def check_writable(dump_file): - if not os.access(dump_file, os.W_OK): - print_error_log( - 'The path {} does not have permission to write. Please check the path permission'.format( - dump_file)) - raise DumpException(DumpException.INVALID_PATH_ERROR) - -- Gitee