forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_manual_tests.py
184 lines (163 loc) · 7.32 KB
/
run_manual_tests.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Run Tests
import os
import sys
from pymongo import MongoClient
import requests
import json
def get_latest_package_version(package_name):
try:
url = f"https://pypi.org/pypi/{package_name}/json"
response = requests.get(url)
response.raise_for_status()
package_info = response.json()
return package_info["info"]["version"]
except requests.exceptions.RequestException:
print(f"Error: Failed to fetch package information for {package_name}.")
return None
def get_submodule_and_function_name(test_path, is_frontend_test=False):
submodule_test = test_path.split("/")[-1]
submodule, test_function = submodule_test.split("::")
submodule = submodule.replace("test_", "").replace(".py", "")
function_name = test_function[5:]
if is_frontend_test:
with open(test_path.split("::")[0]) as test_file:
test_file_content = test_file.read()
test_name = test_function.split(",")[0]
test_function_idx = test_file_content.find(f"def {test_name}")
function_name = test_file_content[
test_file_content[:test_function_idx].rfind('fn_tree="') + 9 :
].split('"')[0]
return submodule, function_name
if __name__ == "__main__":
redis_url = sys.argv[1]
redis_pass = sys.argv[2]
mongo_key = sys.argv[3]
version_flag = sys.argv[4]
gpu_flag = sys.argv[5]
workflow_id = sys.argv[6]
priority_flag = sys.argv[7]
if len(sys.argv) > 8 and sys.argv[8] != "null":
run_id = sys.argv[8]
else:
run_id = f"https://github.com/unifyai/ivy/actions/runs/{workflow_id}"
device = "cpu"
if gpu_flag == "true":
device = "gpu"
status = dict()
cluster = MongoClient(
f"mongodb+srv://deep-ivy:{mongo_key}@cluster0.qdvf8q3.mongodb.net/?retryWrites=true&w=majority" # noqa
)
db = cluster["ci_dashboard"]
if device == "gpu":
os.system("docker pull unifyai/multicuda:base_and_requirements")
with open("tests_to_run", "r") as f:
for line in f:
print(f"\n{'*' * 100}")
print(f"{line[:-1]}")
print(f"{'*' * 100}\n")
backends = ["all"]
test_arg = line.split(",")
if len(test_arg) > 1:
backends = [test_arg[1].strip()]
if backends[0] == "all":
backends = ["numpy", "jax", "tensorflow", "torch", "paddle"]
test_path = test_arg[0].strip()
is_frontend_test = "test_frontends" in test_path
collection = db["frontend_tests"] if is_frontend_test else db["ivy_tests"]
submodule, function_name = get_submodule_and_function_name(
test_path, is_frontend_test
)
versions = dict()
for backend in backends:
versions[backend] = get_latest_package_version(backend).replace(
".", "_"
)
if version_flag == "true":
# This would most probably break at the moment
[backend, backend_version] = backend.split("/")
versions[backend] = backend_version.replace(".", "_")
command = (
f"docker run --rm --env REDIS_URL={redis_url} --env"
f' REDIS_PASSWD={redis_pass} -v "$(pwd)":/ivy -v'
' "$(pwd)"/.hypothesis:/.hypothesis'
' unifyai/multiversion:latest /bin/bash -c "cd docker;python'
f" multiversion_framework_directory.py {' '.join(backends)};cd"
f' ..;pytest --tb=short {test_path} --backend={backend}"'
)
elif device == "gpu":
command = (
f"docker run --rm --gpus all --env REDIS_URL={redis_url} --env"
f' REDIS_PASSWD={redis_pass} -v "$(pwd)":/ivy -v'
' "$(pwd)"/.hypothesis:/.hypothesis'
" unifyai/multicuda:base_and_requirements python3 -m pytest"
f" --tb=short {test_path} --device=gpu:0 -B={backend}"
)
else:
command = (
f"docker run --rm --env REDIS_URL={redis_url} --env"
f' REDIS_PASSWD={redis_pass} -v "$(pwd)":/ivy -v'
' "$(pwd)"/.hypothesis:/.hypothesis unifyai/ivy:latest python3'
f" -m pytest --tb=short {test_path} --backend {backend}"
)
sys.stdout.flush()
status[backend] = not os.system(command)
if status[backend]:
command = (
f"docker run --rm --env REDIS_URL={redis_url} --env"
f' REDIS_PASSWD={redis_pass} -v "$(pwd)":/ivy -v'
' "$(pwd)"/.hypothesis:/.hypothesis unifyai/ivy:latest python3'
f" -m pytest --tb=short {test_path} --backend"
f" {backend} --num-examples 1 --with-transpile"
)
os.system(command)
report_path = os.path.join(
__file__[: __file__.rfind(os.sep)], "report.json"
)
report_content = {}
if os.path.exists(report_path):
report_content = json.load(open(report_path))
backend_specific_info = dict()
test_info = {
"_id": function_name,
"test_path": test_path,
"submodule": submodule,
}
prefix_str = ""
if is_frontend_test:
frontend = test_path[test_path.find("test_frontends") :].split(os.sep)[
1
][5:]
frontend_version = get_latest_package_version(frontend).replace(
".", "_"
)
test_info["frontend"] = frontend
if report_content:
test_info = {
**test_info,
"fw_time": report_content["fw_time"],
"ivy_nodes": report_content["ivy_nodes"],
}
prefix_str = f"{frontend_version}."
for backend in status:
test_info[
f"{prefix_str}{backend}.{versions[backend]}.status.{device}"
] = status[backend]
test_info[
f"{prefix_str}{backend}.{versions[backend]}.workflow.{device}"
] = run_id
if status[backend] and report_content:
updates = {
"nodes": report_content["nodes"][backend],
"time": report_content["time"][backend],
"args": report_content["args"][backend],
"kwargs": report_content["kwargs"][backend],
}
for key, value in updates.items():
test_info[
f"{prefix_str}{backend}.{versions[backend]}.{key}"
] = value
id = test_info.pop("_id")
print(collection.update_one({"_id": id}, {"$set": test_info}, upsert=True))
status.clear()
if any(not result for _, result in status.items()):
exit(1)