forked from bytedance/ByteMLPerf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch.py
81 lines (71 loc) · 3.1 KB
/
launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python3
import os
import sys
import socket
import random
import argparse
import subprocess
import logging
import json
BYTE_MLPERF_ROOT = os.path.dirname(os.path.abspath(__file__))
os.chdir(BYTE_MLPERF_ROOT)
sys.path.insert(0, BYTE_MLPERF_ROOT)
from byte_mlperf.core.configs.workload_store import load_workload
logging.basicConfig(level=logging.INFO)
log = logging.getLogger("LANUCH")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
"--task",
default="",
help="The task going to be evaluted, refs to workloads/")
parser.add_argument(
"--hardware_type",
default="CPU",
help="The backend going to be evaluted, refs to backends/")
parser.add_argument("--compile_only",
action='store_true',
help="Task will stoped after compilation finished")
parser.add_argument("--show_task_list",
action='store_true',
help="Print all task names")
parser.add_argument("--show_hardware_list",
action='store_true',
help="Print all hardware bytemlperf supported")
args = parser.parse_args()
if args.show_task_list:
log.info("******************* Supported Task *******************")
for file in os.listdir('byte_mlperf/workloads'):
print(file[:-5])
if args.show_hardware_list:
log.info("***************** Supported Hardware Backend *****************")
for file in os.listdir('byte_mlperf/backends'):
if not file.endswith('.py') and not file.startswith('_'):
print(file)
if args.task:
log.info("******************* Pip Package Installing *******************")
subprocess.call([
'python3', '-m', 'pip', 'install', 'pip', '--upgrade', '--quiet'])
subprocess.call([
'python3', '-m', 'pip', 'install', '-r', 'byte_mlperf/requirements.txt', '--quiet'])
workload = load_workload(args.task)
with open("byte_mlperf/model_zoo/" + workload['model'] + '.json',
'r') as file:
model_info = json.load(file)
if not os.path.exists(model_info['model_path']):
subprocess.call([
'bash', 'byte_mlperf/prepare_model_and_dataset.sh',
model_info['model'], model_info['dataset_name'] or "None"])
# test numeric
if workload['test_numeric'] and not args.compile_only and not workload['compile_only']:
log.info("******************************************* Running CPU Numeric Checker... *******************************************")
subprocess.call([
'bash', 'byte_mlperf/backends/CPU/calculate_cpu_diff.sh',
workload['model'],
str(workload['batch_sizes'][0])
])
cmd = f'python3 byte_mlperf/core/perf_engine.py --hardware_type {args.hardware_type} --task {args.task}'
if args.compile_only:
cmd += '--compile_only'
exit_code = subprocess.call(cmd, shell=True)
sys.exit(exit_code)