forked from Samsung/ONE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathone-prepare-venv
More file actions
127 lines (107 loc) · 4.26 KB
/
Copy pathone-prepare-venv
File metadata and controls
127 lines (107 loc) · 4.26 KB
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
#!/bin/bash
# Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE check if we can use python3.10 for Ubuntu 20.04.
# use +e as python3.10 may not exist in the system and 'command' will return error.
set +e
PYTHON_CANDIDATES=("python3.12" "python3.10" "python3")
for py in "${PYTHON_CANDIDATES[@]}"; do
PYTHON3_EXEC=$(command -v "$py")
if [[ -n "${PYTHON3_EXEC}" ]]; then
break
fi
done
if [[ -z "${PYTHON3_EXEC}" ]]; then
echo "Error one-prepare-venv: python3 not found"
exit 1
fi
set -e
DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_ACTIVATE=${DRIVER_PATH}/venv/bin/activate
# NOTE please use venv's python instead of python after `source activation`.
# This script is called by debian maintainer script, i.e. `postinst`.
# Since debian maintainer script is called with sudo, `source activation` is ignored.
VENV_PYTHON=${DRIVER_PATH}/venv/bin/python
# Check if existing venv/bin/python is old version and delete if so
if [ -f ${VENV_PYTHON} ]; then
PYTHON_VER=$(${VENV_PYTHON} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" )
if [[ "$PYTHON_VER" == "3.8" ]]; then
echo "Cleaning old venv with python $PYTHON_VER ..."
rm -rf "${DRIVER_PATH}/venv"
fi
fi
if [ ! -f ${VENV_ACTIVATE} ]; then
# Create python virtual enviornment
${PYTHON3_EXEC} -m venv "${DRIVER_PATH}/venv"
fi
# NOTE version
# - https://github.com/onnx/onnx/blob/master/docs/Versioning.md
# - https://github.com/onnx/onnx-tensorflow/blob/master/Versioning.md
VER_TENSORFLOW=2.19.0
VER_ONNX=1.18.0
VER_ONNXRUNTIME=1.21.1
VER_PYDOT=1.4.2
VER_TORCH="2.7.0"
VER_PROTOBUF="5.29.4"
VER_NUMPY="1.26.4"
VER_TICO="0.1.0"
PYTHON_VER=$(${VENV_PYTHON} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" )
echo "Setting package version for python $PYTHON_VER"
if [[ "$PYTHON_VER" == "3.10" ]]; then
: # TODO change vesions
elif [[ "$PYTHON_VER" == "3.12" ]]; then
: # TODO change vesions
else
echo "Error one-prepare-venv: Unsupported python $PYTHON_VER"
exit 1
fi
PIP_TRUSTED_HOST="--trusted-host pypi.org "
PIP_TRUSTED_HOST+="--trusted-host pypi.python.org "
PIP_TRUSTED_HOST+="--trusted-host files.pythonhosted.org "
PIP_TRUSTED_HOST+="--trusted-host download.pytorch.org "
PIP_TIMEOUT="--default-timeout=1000 "
PIP_OPTIONS="${PIP_TIMEOUT} ${PIP_TRUSTED_HOST}"
# NOTE $ONE_PREPVENV_PIP_OPTION is to provide additional PIP options
# such as ceritificate file behind firewall
# ex) ONE_PREPVENV_PIP_OPTION="--cert SomePrivateCetificate.crt" ./one-prepare-venv
if [[ ! -z "$ONE_PREPVENV_PIP_OPTION" ]]; then
PIP_OPTIONS+=" ${ONE_PREPVENV_PIP_OPTION} "
fi
# Install PyTorch and ONNX related
# NOTE set ONE_PREPVENV_TORCH_SOURCE to override options for source URL.
TORCH_SOURCE_OPTION=""
if [[ -n "$ONE_PREPVENV_PIP_OPTION" ]]; then
echo "ONE_PREPVENV_PIP_OPTION is set; skipping default torch source option."
elif [[ -n "$ONE_PREPVENV_TORCH_SOURCE" ]]; then
TORCH_SOURCE_OPTION="${ONE_PREPVENV_TORCH_SOURCE}"
else
TORCH_SOURCE_OPTION="--extra-index-url https://download.pytorch.org/whl/cpu"
fi
echo "Torch source option: '${TORCH_SOURCE_OPTION}'"
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install --upgrade pip setuptools
PY_PKGS_TF="tensorflow-cpu"
CPU_ARCH=$(uname -m)
if [[ "$CPU_ARCH" == "aarch64" ]]; then
PY_PKGS_TF="tensorflow"
fi
PYTHON_PACKAGES="${PY_PKGS_TF}==${VER_TENSORFLOW} "
PYTHON_PACKAGES+="Pillow "
PYTHON_PACKAGES+="torch==${VER_TORCH} "
PYTHON_PACKAGES+="onnx==${VER_ONNX} "
PYTHON_PACKAGES+="onnxruntime==${VER_ONNXRUNTIME} "
PYTHON_PACKAGES+="protobuf==${VER_PROTOBUF} "
PYTHON_PACKAGES+="pydot==${VER_PYDOT} "
PYTHON_PACKAGES+="numpy==${VER_NUMPY} "
PYTHON_PACKAGES+="tico==${VER_TICO} "
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install --upgrade ${PYTHON_PACKAGES} ${TORCH_SOURCE_OPTION}