forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
224 lines (211 loc) · 7.44 KB
/
run_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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# Run Tests
import os
import sys
from pymongo import MongoClient
import requests
from run_tests_CLI.get_all_tests import BACKENDS
submodules = (
"test_paddle",
"test_tensorflow",
"test_torch",
"test_jax",
"test_numpy",
"test_functional",
"test_experimental",
"test_stateful",
"test_misc",
"test_scipy",
"test_pandas",
"test_mindspore",
"test_onnx",
"test_sklearn",
"test_xgboost",
)
db_dict = {
"test_functional/test_core": ["core", 10],
"test_experimental/test_core": ["exp_core", 11],
"test_functional/test_nn": ["nn", 12],
"test_experimental/test_nn": ["exp_nn", 13],
"test_stateful": ["stateful", 14],
"test_torch": ["torch", 15],
"test_jax": ["jax", 16],
"test_tensorflow": ["tensorflow", 17],
"test_numpy": ["numpy", 18],
"test_misc": ["misc", 19],
"test_paddle": ["paddle", 20],
"test_scipy": ["scipy", 21],
"test_pandas": ["pandas", 22],
"test_mindspore": ["mindspore", 23],
"test_onnx": ["onnx", 24],
"test_sklearn": ["sklearn", 25],
"test_xgboost": ["xgboost", 26],
}
result_config = {
"success": "https://img.shields.io/badge/-success-success",
"failure": "https://img.shields.io/badge/-failure-red",
}
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 make_clickable(url, name):
return (
f'<a href="{url}" rel="noopener noreferrer" '
+ f'target="_blank"><img src={name}></a>'
)
def get_submodule(test_path):
test_path = test_path.split("/")
for name in submodules:
if name in test_path:
if name == "test_functional":
if len(test_path) > 3 and test_path[3] == "test_experimental":
coll = db_dict[f"test_experimental/{test_path[4]}"]
else:
coll = db_dict[f"test_functional/{test_path[-2]}"]
else:
coll = db_dict[name]
break
submod_test = test_path[-1]
submod, test_fn = submod_test.split("::")
submod = submod.replace("test_", "").replace(".py", "")
return coll, submod, test_fn
def update_individual_test_results(
collection,
id,
submod,
backend,
test,
result,
backend_version=None,
frontend_version=None,
device=None,
):
key = f"{submod}.{backend}"
if backend_version is not None:
backend_version = backend_version.replace(".", "_")
key += f".{backend_version}"
if frontend_version is not None:
frontend_version = frontend_version.replace(".", "_")
key += f".{frontend_version}"
key += f".{test}"
if device:
key += f".{device}"
collection.update_one(
{"_id": id},
{"$set": {key: result}},
upsert=True,
)
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}"
failed = False
# GPU Testing
with_gpu = False
if gpu_flag == "true":
with_gpu = True
if priority_flag == "true":
priority_flag = True
else:
priority_flag = False
cluster = MongoClient(
f"mongodb+srv://deep-ivy:{mongo_key}@cluster0.qdvf8q3.mongodb.net/?retryWrites=true&w=majority" # noqa
)
db = cluster["Ivy_tests_multi_gpu"]
db_priority = cluster["Ivy_tests_priority"]
if with_gpu:
os.system("docker pull unifyai/multicuda:base_and_requirements")
with open("tests_to_run", "r") as f:
for line in f:
test, backend = line.split(",")
coll, submod, test_fn = get_submodule(test)
print(f"\n{'*' * 100}")
print(f"{line[:-1]}")
print(f"{'*' * 100}\n")
backend_version = "latest-stable"
sys.stdout.flush()
if version_flag == "true":
backends = [backend.strip()]
[backend_name, backend_version] = backend.split("/")
other_backends = [
fw for fw in BACKENDS if (fw != backend_name and fw != "paddle")
]
for backend in other_backends:
backends.append(backend + "/" + get_latest_package_version(backend))
print("Backends:", backends)
ret = os.system(
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} --backend={backend}"'
)
else:
if with_gpu:
ret = os.system(
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} --device=gpu:0 -B={backend}"
# noqa
)
else:
ret = os.system(
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} --backend {backend}"
# noqa
)
if ret != 0:
res = make_clickable(run_id, result_config["failure"])
failed = True
else:
res = make_clickable(run_id, result_config["success"])
frontend_version = None
if coll[0] in ["numpy", "jax", "tensorflow", "torch", "paddle"]:
frontend_version = "latest-stable"
if priority_flag:
print("Updating Priority DB")
update_individual_test_results(
db_priority[coll[0]],
coll[1],
submod,
backend,
test_fn,
res,
"latest-stable",
frontend_version,
"gpu" if with_gpu else "cpu",
)
else:
print(backend_version)
update_individual_test_results(
db[coll[0]],
coll[1],
submod,
backend,
test_fn,
res,
backend_version,
frontend_version,
"gpu" if with_gpu else "cpu",
)
if failed:
exit(1)