forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
233 lines (219 loc) · 7.91 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
225
226
227
228
229
230
231
232
233
# Run Tests
import os
import sys
from pymongo import MongoClient
submodules = (
"test_paddle",
"test_functional",
"test_experimental",
"test_stateful",
"test_tensorflow",
"test_torch",
"test_jax",
"test_numpy",
"test_misc",
"test_scipy",
)
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],
}
result_config = {
"success": "https://img.shields.io/badge/-success-success",
"failure": "https://img.shields.io/badge/-failure-red",
}
def make_clickable(url, name):
return '<a href="{}" rel="noopener noreferrer" '.format(
url
) + 'target="_blank"><img src={}></a>'.format(name)
def get_submodule(test_path):
test_path = test_path.split("/")
for name in submodules:
if name in test_path:
if name == "test_functional":
coll = db_dict["test_functional/" + test_path[-2]]
elif name == "test_experimental":
coll = db_dict["test_experimental/" + test_path[-2]]
else:
coll = db_dict[name]
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,
):
key = submod + "." + backend
if backend_version is not None:
backend_version = backend_version.replace(".", "_")
key += "." + backend_version
if frontend_version is not None:
frontend_version = frontend_version.replace(".", "_")
key += "." + frontend_version
key += "." + test
collection.update_one(
{"_id": id},
{"$set": {key: result}},
upsert=True,
)
return
def remove_from_db(collection, id, submod, backend, test):
collection.update_one(
{"_id": id},
{"$unset": {submod + "." + backend + ".": test}},
)
return
def run_multiversion_testing():
failed = False
cluster = MongoClient(
f"mongodb+srv://deep-ivy:{mongo_key}@cluster0.qdvf8q3.mongodb.net/?retryWrites=true&w=majority" # noqa
)
db = cluster["Ivy_tests_multi"]
with open("tests_to_run", "r") as f:
for line in f:
test, backend = line.split(",")
backend = backend.strip("\n")
coll, submod, test_fn = get_submodule(test)
frontend_version = None
if ";" in backend:
# This is a frontend test
backend, frontend = backend.split(";")
frontend_version = "/".join(frontend.split("/")[1:])
command = f'docker run --rm --env REDIS_URL={redis_url} --env REDIS_PASSWD={redis_pass} -v "$(pwd)":/ivy -v "$(pwd)"/.hypothesis:/.hypothesis unifyai/multiversion:base /bin/bash -c "/opt/miniconda/envs/multienv/bin/python docker/multiversion_framework_directory.py {backend} {frontend} numpy/1.23.1; /opt/miniconda/envs/multienv/bin/python -m pytest --tb=short {test} --backend={backend} --frontend={frontend}" ' # noqa
ret = os.system(command)
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/multiversion:base'
" /opt/miniconda/envs/multienv/bin/python"
" docker/multiversion_framework_directory.py backend"
f" {backend};/opt/miniconda/envs/multienv/bin/python pytest"
f" --tb=short {test} --backend={backend.split('/')[0]}"
# noqa
)
if ret != 0:
res = make_clickable(run_id, result_config["failure"])
failed = True
else:
res = make_clickable(run_id, result_config["success"])
backend_list = backend.split("/")
backend_name = backend_list[0] + "\n"
backend_version = "/".join(backend_list[1:])
update_individual_test_results(
db[coll[0]],
coll[1],
submod,
backend_name,
test_fn,
res,
backend_version,
frontend_version,
)
if failed:
exit(1)
exit(0)
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]
if len(sys.argv) > 7 and sys.argv[7] != "null":
run_id = sys.argv[7]
else:
run_id = "https://github.com/unifyai/ivy/actions/runs/" + workflow_id
failed = False
# Gpu based testing
with_gpu = False
if gpu_flag == "true":
with_gpu = True
# multiversion testing
if version_flag == "true":
run_multiversion_testing()
cluster = MongoClient(
f"mongodb+srv://deep-ivy:{mongo_key}@cluster0.qdvf8q3.mongodb.net/?retryWrites=true&w=majority" # noqa
)
db_multi = cluster["Ivy_tests_multi"]
db_gpu = cluster["Ivy_tests_gpu"]
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")
sys.stdout.flush()
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 -m'
f" 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] == "numpy"
or coll[0] == "jax"
or coll[0] == "tensorflow"
or coll[0] == "torch"
or coll[0] == "paddle"
):
frontend_version = "latest-stable"
if not with_gpu:
update_individual_test_results(
db_multi[coll[0]],
coll[1],
submod,
backend,
test_fn,
res,
"latest-stable",
frontend_version,
)
else:
update_individual_test_results(
db_gpu[coll[0]],
coll[1],
submod,
backend,
test_fn,
res,
"latest-stable",
frontend_version,
)
if failed:
exit(1)