forked from espnet/espnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_longformer.sh
executable file
·68 lines (57 loc) · 1.56 KB
/
install_longformer.sh
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
#!/usr/bin/env bash
set -euo pipefail
if [ $# != 0 ]; then
echo "Usage: $0"
exit 1;
fi
if ! python -c "import packaging.version" &> /dev/null; then
python3 -m pip install packaging
fi
torch_version=$(python3 -c "import torch; print(torch.__version__)")
python_36_plus=$(python3 <<EOF
from packaging.version import parse as V
import sys
if V("{}.{}.{}".format(*sys.version_info[:3])) >= V("3.6"):
print("true")
else:
print("false")
EOF
)
python_310_plus=$(python3 <<EOF
from packaging.version import parse as V
import sys
if V("{}.{}.{}".format(*sys.version_info[:3])) >= V("3.10"):
print("true")
else:
print("false")
EOF
)
pt_plus(){
python3 <<EOF
import sys
from packaging.version import parse as L
if L('$torch_version') >= L('$1'):
print("true")
else:
print("false")
EOF
}
echo "[INFO] torch_version=${torch_version}"
if "${python_310_plus}"; then
echo "[WARNING] python>=3.10 is not supported. The install for longformer is skipped."
elif ! "${python_36_plus}"; then
echo "[ERROR] python<3.6 is not supported"
exit 1
else
if $(pt_plus 1.8.0); then
python -m pip install git+https://github.com/roshansh-cmu/longformer.git
else
echo "[WARNING] Longformer requires pytorch>=1.8.*"
fi
fi
# Check the pytorch version is not changed from the original version
current_torch_version="$(python3 -c 'import torch; print(torch.__version__)')"
if [ ${torch_version} != "${current_torch_version}" ]; then
echo "[ERROR] The torch version has been changed. Please report to espnet administrators"
exit 1
fi