forked from pytorch/ort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·51 lines (37 loc) · 1.76 KB
/
build.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
import argparse
import os
import sys
import subprocess
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument(
"--wheel_file", help="wheel filename used to test. skip build wheel and install")
return parser.parse_args()
def run_subprocess(args, cwd=None):
if isinstance(args, str):
raise ValueError("args should be a sequence of strings, not a string")
return subprocess.run(args, cwd=cwd, shell=False, check=True)
def run_ort_module_tests(cwd, source_dir):
args = [sys.executable, os.path.join(source_dir, 'tests/bert_for_sequence_classification.py')]
run_subprocess(args, cwd)
def build_wheel(cwd, source_dir):
args = [sys.executable, os.path.join(source_dir, 'setup.py'), 'bdist_wheel']
run_subprocess(args, cwd)
def main():
cmd_line_args = parse_arguments()
source_dir = os.path.realpath(os.path.dirname(__file__))
cwd = os.path.normpath(os.path.join(source_dir, ".."))
if not cmd_line_args.wheel_file:
build_wheel(source_dir, source_dir)
else:
print("cmd_line_args.wheel_file: ", cmd_line_args.wheel_file)
print("With Devops pipeline, please confirm that the wheel file matches the one being built from a previous step.")
run_subprocess([sys.executable, "-m", "pip", "install", "--upgrade", cmd_line_args.wheel_file], cwd)
run_subprocess([sys.executable, "-m", "torch_ort.configure"], cwd)
# installing requirements-test.txt
requirements_path = os.path.join(source_dir, 'tests', 'requirements-test.txt')
run_subprocess([sys.executable, "-m", "pip", "install", "-r", requirements_path], cwd)
# testing torch-ort
run_ort_module_tests(source_dir, source_dir)
if __name__ == "__main__":
sys.exit(main())