summaryrefslogtreecommitdiff
path: root/compiler/one-cmds/one-prepare-venv.u1804
blob: 55c79c6e0293edcf66b3ba254cbb30b9582ff889 (plain)
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
#!/bin/bash

# Copyright (c) 2023 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.

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

if [ ! -f ${VENV_ACTIVATE} ]; then
  # Create python virtual enviornment
  python3.8 -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.12.1
VER_ONNX=1.14.0
VER_ONNXRUNTIME=1.15.0
VER_ONNX_TF=1.10.0
VER_PYDOT=1.4.2

# Install tensorflow

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

${VENV_PYTHON} -m pip ${PIP_OPTIONS} install --upgrade pip setuptools
if [ -n "${EXT_TENSORFLOW_WHL}" ]; then
  ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install ${EXT_TENSORFLOW_WHL}
else
  ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install tensorflow-cpu==${VER_TENSORFLOW}
fi
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install Pillow
# Fix version to that of TF release date
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install tensorflow_probability==0.20.1
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install tensorflow_addons==0.20.0

# Install PyTorch and ONNX related
# NOTE set ONE_PREPVENV_TORCH_STABLE to override 'torch_stable.html' URL.
#      torch_stable.html points to download URL of torch wheel file(s)
#      but sometimes the server gets unstable, especially from in-house CI.
TORCH_STABLE_URL="https://download.pytorch.org/whl/torch_stable.html"
if [[ ! -z "$ONE_PREPVENV_TORCH_STABLE" ]]; then
  TORCH_STABLE_URL="${ONE_PREPVENV_TORCH_STABLE}"
fi
# TODO remove torch message
echo "Torch from '${ONE_PREPVENV_TORCH_STABLE}' -> '${TORCH_STABLE_URL}'"
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install torch==1.13.1+cpu -f ${TORCH_STABLE_URL}

${VENV_PYTHON} -m pip ${PIP_OPTIONS} install onnx==${VER_ONNX}

${VENV_PYTHON} -m pip ${PIP_OPTIONS} install onnxruntime==${VER_ONNXRUNTIME}

# Provide install of custom onnx-tf
if [ -n "${EXT_ONNX_TF_WHL}" ]; then
  ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install ${EXT_ONNX_TF_WHL}
else
  ${VENV_PYTHON} -m pip ${PIP_OPTIONS} install onnx-tf==${VER_ONNX_TF}
fi

# Fix version to that of TF release date
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install --upgrade protobuf==4.23.3

# Install pydot for visq
${VENV_PYTHON} -m pip ${PIP_OPTIONS} install pydot==${VER_PYDOT}