forked from arogozhnikov/einops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
78 lines (64 loc) · 1.98 KB
/
test.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
"""
Usage: python test.py
1. Installs part of dependencies (make sure `which pip` points to correct location)
2. Installs current version of einops in editable mode
3. Runs tests
"""
import os
import sys
from subprocess import Popen, PIPE
from pathlib import Path
__author__ = 'Alex Rogozhnikov'
def run(cmd, **env):
# keeps printing output when testing
cmd = cmd.split(' ') if isinstance(cmd, str) else cmd
p = Popen(cmd, cwd=str(Path(__file__).parent), env={**os.environ, **env})
p.communicate()
return p.returncode
# check we have nvidia-smi
import shutil
have_cuda = False
if shutil.which('nvidia-smi') is not None:
output, _ = Popen('nvidia-smi'.split(' '), stdout=PIPE).communicate()
if b'failed because' not in output:
have_cuda = True
# install cupy. It can't be installed without cuda available (with compilers).
skip_cupy = not have_cuda
if not skip_cupy:
return_code = run('pip install cupy --pre --progress-bar off')
assert return_code == 0
# install dependencies
dependencies = [
'numpy',
'mxnet==1.*',
'torch',
'tensorflow',
'chainer',
'jax',
'jaxlib',
'flax',
'nbformat',
'nbconvert',
'jupyter',
'parameterized',
'pillow',
'pytest',
]
assert 0 == run('pip install {} --progress-bar off'.format(' '.join(dependencies)))
# oneflow provides wheels for linux, but not mac, so it is tested only on linux
skip_oneflow = 'linux' not in sys.platform
skip_oneflow = True
if not skip_oneflow:
# oneflow installation: https://github.com/Oneflow-Inc/oneflow#install-with-pip-package
assert 0 == run('pip install -f https://release.oneflow.info oneflow==0.7.0+cpu --user')
# install einops
assert 0 == run('pip install -e .')
return_code = run(
'python -m pytest tests',
EINOPS_SKIP_CUPY='1' if skip_cupy else '0',
EINOPS_SKIP_ONEFLOW='1' if skip_oneflow else '0',
)
assert return_code == 0
if __name__ == '__main__':
# minor convenience for lazy me to start debugging in pycharm
pass