From 328a22a9bf4cf445ce8c703c4080a0aeecbc4250 Mon Sep 17 00:00:00 2001 From: s30048155 Date: Fri, 8 Dec 2023 16:44:05 +0800 Subject: [PATCH 1/8] add multi run ut --- .../api_accuracy_checker/README.md | 22 +++- .../api_accuracy_checker/compare/compare.py | 7 +- .../run_ut/multi_run_ut.py | 119 ++++++++++++++++++ .../api_accuracy_checker/run_ut/run_ut.py | 4 +- 4 files changed, 139 insertions(+), 13 deletions(-) create mode 100644 debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py diff --git a/debug/accuracy_tools/api_accuracy_checker/README.md b/debug/accuracy_tools/api_accuracy_checker/README.md index 53a904f529..a50a61e0e8 100644 --- a/debug/accuracy_tools/api_accuracy_checker/README.md +++ b/debug/accuracy_tools/api_accuracy_checker/README.md @@ -70,7 +70,7 @@ Ascend模型精度预检工具能在昇腾NPU上扫描用户训练模型中所 若有需要,用户可以通过msCheckerConfig.update_config来配置dump路径以及开启真实数据模式、指定dump某个step或配置API dump白名单,详细请参见“**msCheckerConfig.update_config**”。 -3. 将API信息输入给run_ut模块运行精度检测并比对,运行如下命令: +3. 将API信息输入给run_ut模块运行精度检测并比对,单进程运行如下命令: ```bash cd $ATT_HOME/debug/accuracy_tools/api_accuracy_checker/run_ut @@ -81,18 +81,30 @@ Ascend模型精度预检工具能在昇腾NPU上扫描用户训练模型中所 | -------------------------------- | ------------------------------------------------------------ | -------- | | -forward或--forward_input_file | 指定前向API信息文件forward_info_{pid}.json。 | 是 | | -backward或--backward_input_file | 指定反向API信息文件backward_info_{pid}.json。 | 是 | - | -save_error_data | 保存精度未达标的API输入输出数据。 | 否 | + | -s或--save_error_data | 保存精度未达标的API输入输出数据。 | 否 | | -o或--out_path | 指指定run_ut执行结果存盘路径,默认“./”(相对于run_ut的路径)。 | 否 | | -j或--jit_compile | 开启jit编译。 | 否 | | -d或--device | 指定Device ID,选择UT代码运行所在的卡,默认值为0。 | 否 | - | -csv_path或--result_csv_path | 指定本次运行中断时生成的accuracy_checking_result_{timestamp}.csv文件路径,执行run_ut中断时,若想从中断处继续执行,配置此参数即可。 | 否 | + | -c或--result_csv_path | 指定本次运行中断时生成的accuracy_checking_result_{timestamp}.csv文件路径,执行run_ut中断时,若想从中断处继续执行,配置此参数即可。 | 否 | run_ut执行结果包括`accuracy_checking_result_{timestamp}.csv`和`accuracy_checking_details_{timestamp}.csv`两个文件。`accuracy_checking_result_{timestamp}.csv`是API粒度的,标明每个API是否通过测试。建议用户先查看`accuracy_checking_result_{timestamp}.csv`文件,对于其中没有通过测试的或者特定感兴趣的API,根据其API name字段在`accuracy_checking_details_{timestamp}.csv`中查询其各个输出的达标情况以及比较指标。API达标情况介绍请参考“**API预检指标**”。 -4. 如果需要保存比对不达标的输入和输出数据,可以在run_ut执行命令结尾添加-save_error_data,例如: +4. 可使用多进程进行加速,多进程运行命令如下: ```bash - python run_ut.py -forward ./forward_info_0.json -backward ./backward_info_0.json -save_error_data + cd $ATT_HOME/debug/accuracy_tools/api_accuracy_checker/run_ut + python multi_run_ut.py -forward ./forward_info_0.json -backward ./backward_info_0.json + ``` + | 参数名称 | 说明 | 是否必选 | + | -------------------------------- | ------------------------------------------------------------ | -------- | + | -n或--num_splits | 指定本次运行中多进程的进程数量,默认为8 | 否 | + + 其他参数于run_ut相同 + +5. 如果需要保存比对不达标的输入和输出数据,可以在run_ut执行命令结尾添加--save_error_data或-s,例如: + + ```bash + python run_ut.py -forward ./forward_info_0.json -backward ./backward_info_0.json --save_error_data ``` 数据默认会存盘到'./ut_error_data'路径下(相对于启动run_ut的路径),有需要的话,用户可以通过msCheckerConfig.update_config来配置保存路径,参数为error_data_path。 diff --git a/debug/accuracy_tools/api_accuracy_checker/compare/compare.py b/debug/accuracy_tools/api_accuracy_checker/compare/compare.py index b95ec8fa3e..c2ba7dbfd7 100644 --- a/debug/accuracy_tools/api_accuracy_checker/compare/compare.py +++ b/debug/accuracy_tools/api_accuracy_checker/compare/compare.py @@ -18,12 +18,7 @@ class Comparator: def __init__(self, result_csv_path, details_csv_path, is_continue_run_ut, test_result_cnt=None, stack_info_json_path=None): self.save_path = result_csv_path self.detail_save_path = details_csv_path - if not is_continue_run_ut: - if os.path.exists(self.save_path): - raise ValueError(f"file {self.save_path} already exists, please remove it first or use a new dump path") - if os.path.exists(self.detail_save_path): - raise ValueError( - f"file {self.detail_save_path} already exists, please remove it first or use a new dump path") + if not is_continue_run_ut and not os.path.exists(self.save_path) and not os.path.exists(self.detail_save_path): self.write_csv_title() if stack_info_json_path: self.stack_info = get_json_contents(stack_info_json_path) diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py new file mode 100644 index 0000000000..17cb903303 --- /dev/null +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py @@ -0,0 +1,119 @@ +import subprocess +import json +import os +import argparse +import glob +import sys +from collections import namedtuple +from ptdbg_ascend.src.python.ptdbg_ascend.common.file_check_util import FileCheckConst, FileChecker, \ + check_file_suffix, check_link, FileOpen +from api_accuracy_checker.compare.compare import Comparator +from api_accuracy_checker.run_ut.run_ut import get_statistics_from_result_csv +from api_accuracy_checker.dump.info_dump import write_json + + +def split_json_file(input_file, num_splits): + with FileOpen(input_file, 'r') as file: + data = json.load(file) + + items = list(data.items()) + total_items = len(items) + + chunk_size = total_items // num_splits + split_files = [] + + for i in range(num_splits): + start = i * chunk_size + end = (i + 1) * chunk_size if i < num_splits - 1 else total_items + split_filename = os.path.join("./", f"temp_part{i}.json") + for item in items[start:end]: + write_json(split_filename,{item[0]:item[1]}) + split_files.append(split_filename) + + return split_files + + +ParallelUTConfig = namedtuple('ParallelUTConfig', ['forward_files', 'backward_files', 'out_path', 'num_splits', 'save_error_data_flag', 'jit_compile_flag', 'device_id', 'csv_file']) + + +def run_parallel_ut(config): + processes = [] + + def create_cmd(fwd, bwd): + cmd = [ + 'python', 'run_ut.py', + '-forward', fwd, + '-backward', bwd, + '-o', config.out_path, + '-d' if config.device_id else '', + str(config.device_id) if config.device_id else '', + '-j' if config.jit_compile_flag else '', + '-save_error_data' if config.save_error_data_flag else '', + '-c' if config.csv_file else '', + config.csv_file if config.csv_file else '' + ] + return [arg for arg in cmd if arg] + + commands = [create_cmd(fwd, config.backward_files[0]) for fwd in config.forward_files] + + for cmd in commands: + processes.append(subprocess.Popen(cmd)) + + for process in processes: + process.wait() + + for file in config.forward_files: + os.remove(file) + try: + process_csv_and_print_results(config.out_path, config.csv_file) + except FileNotFoundError as e: + print(f"Error: {e}") + except Exception as e: + print(f"An unexpected error occurred: {e}") + +def process_csv_and_print_results(out_path, csv_file=None): + csv_files = glob.glob(os.path.join(out_path, 'accuracy_checking_result_*.csv')) + if not csv_files: + raise FileNotFoundError("No CSV files found in the specified output path.") + latest_csv = max(csv_files, key=os.path.getmtime) + + comparator = Comparator(out_path,out_path,False) + comparator.test_result_cnt = get_statistics_from_result_csv(latest_csv) + comparator.print_pretest_result() + +def main(): + try: + parser = argparse.ArgumentParser(description='Run UT in parallel') + parser.add_argument('-forward', '--forward_input_file', required=True, help='The forward input JSON file.') + parser.add_argument('-backward', '--backward_input_file', required=True, help='The backward input JSON file.') + parser.add_argument('-o', '--out_path', default="./", help='The UT task result output path.') + parser.add_argument('-n', '--num_splits', type=int, choices=range(1, 21), default=10, help='Number of splits for parallel processing. Range: 1-8') + parser.add_argument('-save_error_data', action='store_true', help='Flag to save error data.') + parser.add_argument('-j', '--jit_compile', action='store_true', help='Flag to turn on jit compile.') + parser.add_argument('-d', '--device_id', type=int, default=0, help='Device id.') + parser.add_argument('-c', '--csv_file',type=str, help='CSV file to exclude APIs already tested.') + args = parser.parse_args() + + check_link(args.forward_input_file) + check_link(args.backward_input_file) + forward_file = os.path.realpath(args.forward_input_file) + backward_file = os.path.realpath(args.backward_input_file) + check_file_suffix(forward_file, FileCheckConst.JSON_SUFFIX) + check_file_suffix(backward_file, FileCheckConst.JSON_SUFFIX) + out_path = os.path.realpath(args.out_path) if args.out_path else "./" + out_path_checker = FileChecker(out_path, FileCheckConst.DIR, ability=FileCheckConst.WRITE_ABLE) + out_path = out_path_checker.common_check() + forward_splits = split_json_file(args.forward_input_file, args.num_splits) + backward_splits = [backward_file] * args.num_splits + + config = ParallelUTConfig(forward_splits, backward_splits, args.out_path, args.num_splits, args.save_error_data, args.jit_compile, args.device_id, args.csv_file) + run_parallel_ut(config) + except KeyboardInterrupt: + print("Interrupted by user, cleaning up temporary files...") + for file in glob.glob(f"temp_part*.json"): + os.remove(file) + print("Temporary files removed.") + sys.exit(1) + +if __name__ == '__main__': + main() diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py index fb885168d6..3f2d85816b 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py @@ -300,13 +300,13 @@ def _run_ut_parser(parser): parser.add_argument("-o", "--out_path", dest="out_path", default="", type=str, help=" The ut task result out path.", required=False) - parser.add_argument('-save_error_data', dest="save_error_data", action="store_true", + parser.add_argument('-s','--save_error_data', dest="save_error_data", action="store_true", help=" Save compare failed api output.", required=False) parser.add_argument("-j", "--jit_compile", dest="jit_compile", action="store_true", help=" whether to turn on jit compile", required=False) parser.add_argument("-d", "--device", dest="device_id", type=int, help=" set device id to run ut", default=0, required=False) - parser.add_argument("-csv_path", "--result_csv_path", dest="result_csv_path", default="", type=str, + parser.add_argument("-c", "--result_csv_path", dest="result_csv_path", default="", type=str, help=" The path of accuracy_checking_result_{timestamp}.csv, " "when run ut is interrupted, enter the file path to continue run ut.", required=False) -- Gitee From e363a4c447cd0e9eff191a3517f46c11e263f75d Mon Sep 17 00:00:00 2001 From: s30048155 Date: Fri, 8 Dec 2023 17:16:06 +0800 Subject: [PATCH 2/8] clean code --- .../run_ut/multi_run_ut.py | 63 +++++++++---------- .../api_accuracy_checker/run_ut/run_ut.py | 2 +- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py index 17cb903303..208fa65ccf 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py @@ -27,7 +27,7 @@ def split_json_file(input_file, num_splits): end = (i + 1) * chunk_size if i < num_splits - 1 else total_items split_filename = os.path.join("./", f"temp_part{i}.json") for item in items[start:end]: - write_json(split_filename,{item[0]:item[1]}) + write_json(split_filename, {item[0]: item[1]}) split_files.append(split_filename) return split_files @@ -71,49 +71,44 @@ def run_parallel_ut(config): except Exception as e: print(f"An unexpected error occurred: {e}") + def process_csv_and_print_results(out_path, csv_file=None): csv_files = glob.glob(os.path.join(out_path, 'accuracy_checking_result_*.csv')) if not csv_files: raise FileNotFoundError("No CSV files found in the specified output path.") latest_csv = max(csv_files, key=os.path.getmtime) - comparator = Comparator(out_path,out_path,False) + comparator = Comparator(out_path, out_path, False) comparator.test_result_cnt = get_statistics_from_result_csv(latest_csv) comparator.print_pretest_result() + def main(): - try: - parser = argparse.ArgumentParser(description='Run UT in parallel') - parser.add_argument('-forward', '--forward_input_file', required=True, help='The forward input JSON file.') - parser.add_argument('-backward', '--backward_input_file', required=True, help='The backward input JSON file.') - parser.add_argument('-o', '--out_path', default="./", help='The UT task result output path.') - parser.add_argument('-n', '--num_splits', type=int, choices=range(1, 21), default=10, help='Number of splits for parallel processing. Range: 1-8') - parser.add_argument('-save_error_data', action='store_true', help='Flag to save error data.') - parser.add_argument('-j', '--jit_compile', action='store_true', help='Flag to turn on jit compile.') - parser.add_argument('-d', '--device_id', type=int, default=0, help='Device id.') - parser.add_argument('-c', '--csv_file',type=str, help='CSV file to exclude APIs already tested.') - args = parser.parse_args() - - check_link(args.forward_input_file) - check_link(args.backward_input_file) - forward_file = os.path.realpath(args.forward_input_file) - backward_file = os.path.realpath(args.backward_input_file) - check_file_suffix(forward_file, FileCheckConst.JSON_SUFFIX) - check_file_suffix(backward_file, FileCheckConst.JSON_SUFFIX) - out_path = os.path.realpath(args.out_path) if args.out_path else "./" - out_path_checker = FileChecker(out_path, FileCheckConst.DIR, ability=FileCheckConst.WRITE_ABLE) - out_path = out_path_checker.common_check() - forward_splits = split_json_file(args.forward_input_file, args.num_splits) - backward_splits = [backward_file] * args.num_splits - - config = ParallelUTConfig(forward_splits, backward_splits, args.out_path, args.num_splits, args.save_error_data, args.jit_compile, args.device_id, args.csv_file) - run_parallel_ut(config) - except KeyboardInterrupt: - print("Interrupted by user, cleaning up temporary files...") - for file in glob.glob(f"temp_part*.json"): - os.remove(file) - print("Temporary files removed.") - sys.exit(1) + parser = argparse.ArgumentParser(description='Run UT in parallel') + parser.add_argument('-forward', '--forward_input_file', required=True, help='The forward input JSON file.') + parser.add_argument('-backward', '--backward_input_file', required=True, help='The backward input JSON file.') + parser.add_argument('-o', '--out_path', default="./", help='The UT task result output path.') + parser.add_argument('-n', '--num_splits', type=int, choices=range(1, 21), default=10, help='Number of splits for parallel processing. Range: 1-8') + parser.add_argument('-s', '--save_error_data', action='store_true', help='Flag to save error data.') + parser.add_argument('-j', '--jit_compile', action='store_true', help='Flag to turn on jit compile.') + parser.add_argument('-d', '--device_id', type=int, default=0, help='Device id.') + parser.add_argument('-c', '--csv_file', type=str, help='CSV file to exclude APIs already tested.') + args = parser.parse_args() + + check_link(args.forward_input_file) + check_link(args.backward_input_file) + forward_file = os.path.realpath(args.forward_input_file) + backward_file = os.path.realpath(args.backward_input_file) + check_file_suffix(forward_file, FileCheckConst.JSON_SUFFIX) + check_file_suffix(backward_file, FileCheckConst.JSON_SUFFIX) + out_path = os.path.realpath(args.out_path) if args.out_path else "./" + out_path_checker = FileChecker(out_path, FileCheckConst.DIR, ability=FileCheckConst.WRITE_ABLE) + out_path = out_path_checker.common_check() + forward_splits = split_json_file(args.forward_input_file, args.num_splits) + backward_splits = [backward_file] * args.num_splits + + config = ParallelUTConfig(forward_splits, backward_splits, args.out_path, args.num_splits, args.save_error_data, args.jit_compile, args.device_id, args.csv_file) + run_parallel_ut(config) if __name__ == '__main__': main() diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py index 3f2d85816b..27ec2a40b8 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/run_ut.py @@ -300,7 +300,7 @@ def _run_ut_parser(parser): parser.add_argument("-o", "--out_path", dest="out_path", default="", type=str, help=" The ut task result out path.", required=False) - parser.add_argument('-s','--save_error_data', dest="save_error_data", action="store_true", + parser.add_argument("-s", "--save_error_data", dest="save_error_data", action="store_true", help=" Save compare failed api output.", required=False) parser.add_argument("-j", "--jit_compile", dest="jit_compile", action="store_true", help=" whether to turn on jit compile", required=False) -- Gitee From a21654806eb14258edc94a61738075bda7b7828a Mon Sep 17 00:00:00 2001 From: s30048155 Date: Wed, 13 Dec 2023 09:18:49 +0800 Subject: [PATCH 3/8] revert --- .../accuracy_tools/api_accuracy_checker/README.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/README.md b/debug/accuracy_tools/api_accuracy_checker/README.md index a50a61e0e8..74e67e5cfc 100644 --- a/debug/accuracy_tools/api_accuracy_checker/README.md +++ b/debug/accuracy_tools/api_accuracy_checker/README.md @@ -92,19 +92,7 @@ Ascend模型精度预检工具能在昇腾NPU上扫描用户训练模型中所 4. 可使用多进程进行加速,多进程运行命令如下: ```bash - cd $ATT_HOME/debug/accuracy_tools/api_accuracy_checker/run_ut - python multi_run_ut.py -forward ./forward_info_0.json -backward ./backward_info_0.json - ``` - | 参数名称 | 说明 | 是否必选 | - | -------------------------------- | ------------------------------------------------------------ | -------- | - | -n或--num_splits | 指定本次运行中多进程的进程数量,默认为8 | 否 | - - 其他参数于run_ut相同 - -5. 如果需要保存比对不达标的输入和输出数据,可以在run_ut执行命令结尾添加--save_error_data或-s,例如: - - ```bash - python run_ut.py -forward ./forward_info_0.json -backward ./backward_info_0.json --save_error_data + python run_ut.py -forward ./forward_info_0.json -backward ./backward_info_0.json -save_error_data ``` 数据默认会存盘到'./ut_error_data'路径下(相对于启动run_ut的路径),有需要的话,用户可以通过msCheckerConfig.update_config来配置保存路径,参数为error_data_path。 -- Gitee From 5fdb778ca56691360aa4b0ee10f0c12d1e327d7b Mon Sep 17 00:00:00 2001 From: s30048155 Date: Wed, 13 Dec 2023 16:35:42 +0800 Subject: [PATCH 4/8] update --- .../api_accuracy_checker/run_ut/multi_run_ut.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py index 208fa65ccf..5d5980a30f 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py @@ -3,7 +3,6 @@ import json import os import argparse import glob -import sys from collections import namedtuple from ptdbg_ascend.src.python.ptdbg_ascend.common.file_check_util import FileCheckConst, FileChecker, \ check_file_suffix, check_link, FileOpen @@ -43,7 +42,8 @@ def run_parallel_ut(config): cmd = [ 'python', 'run_ut.py', '-forward', fwd, - '-backward', bwd, + '-backward' if bwd else '', + bwd if bwd else '', '-o', config.out_path, '-d' if config.device_id else '', str(config.device_id) if config.device_id else '', @@ -54,8 +54,7 @@ def run_parallel_ut(config): ] return [arg for arg in cmd if arg] - commands = [create_cmd(fwd, config.backward_files[0]) for fwd in config.forward_files] - + commands = [create_cmd(fwd, bwd) for fwd, bwd in zip(config.forward_files, config.backward_files)] for cmd in commands: processes.append(subprocess.Popen(cmd)) @@ -86,7 +85,7 @@ def process_csv_and_print_results(out_path, csv_file=None): def main(): parser = argparse.ArgumentParser(description='Run UT in parallel') parser.add_argument('-forward', '--forward_input_file', required=True, help='The forward input JSON file.') - parser.add_argument('-backward', '--backward_input_file', required=True, help='The backward input JSON file.') + parser.add_argument('-backward', '--backward_input_file', required=False, help='The backward input JSON file.') parser.add_argument('-o', '--out_path', default="./", help='The UT task result output path.') parser.add_argument('-n', '--num_splits', type=int, choices=range(1, 21), default=10, help='Number of splits for parallel processing. Range: 1-8') parser.add_argument('-s', '--save_error_data', action='store_true', help='Flag to save error data.') @@ -98,14 +97,14 @@ def main(): check_link(args.forward_input_file) check_link(args.backward_input_file) forward_file = os.path.realpath(args.forward_input_file) - backward_file = os.path.realpath(args.backward_input_file) + backward_file = os.path.realpath(args.backward_input_file) if args.backward_input_file else None check_file_suffix(forward_file, FileCheckConst.JSON_SUFFIX) check_file_suffix(backward_file, FileCheckConst.JSON_SUFFIX) out_path = os.path.realpath(args.out_path) if args.out_path else "./" out_path_checker = FileChecker(out_path, FileCheckConst.DIR, ability=FileCheckConst.WRITE_ABLE) out_path = out_path_checker.common_check() forward_splits = split_json_file(args.forward_input_file, args.num_splits) - backward_splits = [backward_file] * args.num_splits + backward_splits = [backward_file] * args.num_splits if backward_file else [None] * args.num_splits config = ParallelUTConfig(forward_splits, backward_splits, args.out_path, args.num_splits, args.save_error_data, args.jit_compile, args.device_id, args.csv_file) run_parallel_ut(config) -- Gitee From 3c1078bf26c3df91b0865266629ce52f8ab5b107 Mon Sep 17 00:00:00 2001 From: s30048155 Date: Thu, 14 Dec 2023 11:12:58 +0800 Subject: [PATCH 5/8] update --- .../api_accuracy_checker/run_ut/multi_run_ut.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py index 5d5980a30f..c9a056797d 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py @@ -1,6 +1,7 @@ import subprocess import json import os +import sys import argparse import glob from collections import namedtuple @@ -40,7 +41,7 @@ def run_parallel_ut(config): def create_cmd(fwd, bwd): cmd = [ - 'python', 'run_ut.py', + sys.executable, 'run_ut.py', '-forward', fwd, '-backward' if bwd else '', bwd if bwd else '', @@ -59,7 +60,7 @@ def run_parallel_ut(config): processes.append(subprocess.Popen(cmd)) for process in processes: - process.wait() + process.communicate() for file in config.forward_files: os.remove(file) -- Gitee From 51b3edd024ba504ae6c2588314ee804df567ee4b Mon Sep 17 00:00:00 2001 From: s30048155 Date: Fri, 15 Dec 2023 09:59:53 +0800 Subject: [PATCH 6/8] update --- .../api_accuracy_checker/run_ut/multi_run_ut.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py index c9a056797d..64dd371ffd 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py @@ -8,7 +8,7 @@ from collections import namedtuple from ptdbg_ascend.src.python.ptdbg_ascend.common.file_check_util import FileCheckConst, FileChecker, \ check_file_suffix, check_link, FileOpen from api_accuracy_checker.compare.compare import Comparator -from api_accuracy_checker.run_ut.run_ut import get_statistics_from_result_csv +from api_accuracy_checker.run_ut.run_ut import get_statistics_from_result_csv, _run_ut_parser from api_accuracy_checker.dump.info_dump import write_json @@ -60,7 +60,7 @@ def run_parallel_ut(config): processes.append(subprocess.Popen(cmd)) for process in processes: - process.communicate() + process.communicate(TimeoutError=30) for file in config.forward_files: os.remove(file) @@ -85,14 +85,8 @@ def process_csv_and_print_results(out_path, csv_file=None): def main(): parser = argparse.ArgumentParser(description='Run UT in parallel') - parser.add_argument('-forward', '--forward_input_file', required=True, help='The forward input JSON file.') - parser.add_argument('-backward', '--backward_input_file', required=False, help='The backward input JSON file.') - parser.add_argument('-o', '--out_path', default="./", help='The UT task result output path.') - parser.add_argument('-n', '--num_splits', type=int, choices=range(1, 21), default=10, help='Number of splits for parallel processing. Range: 1-8') - parser.add_argument('-s', '--save_error_data', action='store_true', help='Flag to save error data.') - parser.add_argument('-j', '--jit_compile', action='store_true', help='Flag to turn on jit compile.') - parser.add_argument('-d', '--device_id', type=int, default=0, help='Device id.') - parser.add_argument('-c', '--csv_file', type=str, help='CSV file to exclude APIs already tested.') + _run_ut_parser(parser) # 假设这是从run_ut.py导入的函数 + parser.add_argument('-n', '--num_splits', type=int, choices=range(1, 21), default=10, help='Number of splits for parallel processing. Range: 1-20') args = parser.parse_args() check_link(args.forward_input_file) -- Gitee From 0899afb288c27a72ce163b59be665082829c2fd4 Mon Sep 17 00:00:00 2001 From: s30048155 Date: Fri, 15 Dec 2023 10:00:11 +0800 Subject: [PATCH 7/8] update --- .../accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py index 64dd371ffd..f815d2e041 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py @@ -85,7 +85,7 @@ def process_csv_and_print_results(out_path, csv_file=None): def main(): parser = argparse.ArgumentParser(description='Run UT in parallel') - _run_ut_parser(parser) # 假设这是从run_ut.py导入的函数 + _run_ut_parser(parser) parser.add_argument('-n', '--num_splits', type=int, choices=range(1, 21), default=10, help='Number of splits for parallel processing. Range: 1-20') args = parser.parse_args() -- Gitee From 8974d67591615ed98af6928b123820ef605c1a17 Mon Sep 17 00:00:00 2001 From: s30048155 Date: Fri, 15 Dec 2023 16:10:46 +0800 Subject: [PATCH 8/8] update --- .../accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py index f815d2e041..2fa8fd47eb 100644 --- a/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py +++ b/debug/accuracy_tools/api_accuracy_checker/run_ut/multi_run_ut.py @@ -60,7 +60,7 @@ def run_parallel_ut(config): processes.append(subprocess.Popen(cmd)) for process in processes: - process.communicate(TimeoutError=30) + process.wait() for file in config.forward_files: os.remove(file) -- Gitee