forked from flagos-ai/FlagGems
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·131 lines (114 loc) · 2.86 KB
/
setup.sh
File metadata and controls
executable file
·131 lines (114 loc) · 2.86 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
128
129
130
131
#!/bin/bash
SUPPORTED_VENDORS=(
"ascend"
"enflame"
"hygon"
"iluvatar"
"kunlunxin"
"metax"
"mthreads"
"nvidia"
"spacemit"
"thead"
"tsingmicro"
)
# TODO: Add thead PPU
declare -A PYTHON_SUPPORTED=(
["ascend"]="3.11"
["enflame"]="3.12"
["hygon"]="3.10"
["iluvatar"]="3.10"
["kunlunxin"]="3.10"
["metax"]="3.12"
["mthreads"]="3.10"
["nvidia"]="3.12"
["spacemit"]="3.12"
["tsingmicro"]="3.10"
)
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
valid_vendor() {
needle=$1
for item in "${SUPPORTED_VENDORS[@]}" ; do
[ $item == "$needle" ] && return 0
done
return 1
}
# Validate argument count
[ "$#" -eq 1 ] || { echo "Please specify <VENDOR>"; exit 1; }
# Validate vendor name
VENDOR=${1}
valid_vendor $VENDOR
if [ "$?" != 0 ]; then
echo "Invalid vendor '${VENDOR}' specified ..."
echo "Please specify one of: ${SUPPORTED_VENDORS[@]}"
exit 1
fi
printf "Checking vendor ... ${VENDOR} $GREEN[OK]$NC\n"
printf "Detecting pyenv ... "
pyenv_version=$(pyenv --version 2>/dev/null | awk '{print $NF}')
if [ "$?" != 0 ]; then
# pyenv not installed
printf "NOT FOUND $GREEN[OK]$NC\n"
else
printf "${pyenv_version} $GREEN[OK]$NC\n"
if [ x"$PYENV_ROOT" == x ]; then
# Initialize pyenv virtual environment
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - bash)"
fi
fi
# Validate Python version
printf "Checking Python version ... "
python_version=$(python --version 2>/dev/null | awk '{print $NF}')
expected_version=${PYTHON_SUPPORTED[$VENDOR]}
if [[ "$python_version" == *"$expected_version"* ]]; then
printf "${python_version} $GREEN[OK]$NC\n"
else
printf "${python_version}, expecting '${expected_version}.*' $RED[FAILED]$NC"
exit 1
fi
# Validate uv install
printf "Checking uv ... "
uv_version=$(uv --version 2>/dev/null | cut -d ' ' -f 2)
if [ "$?" == 0 ]; then
printf "uv ${uv_version} ${GREEN}[OK]${NC}\n"
else
printf "${RED}NOT FOUND${NC}\n"
# Install uv and upgrade pip if necessary
printf "Installing/upgrading pip and uv ... "
pip install uv || exit 1;
fi
# Start installation
printf "Installing FlagGems for ${VENDOR}\n"
printf "Creating virtual environment ... "
uv venv -q -c
if [ "$?" != 0 ]; then
printf "$RED{FAILED]$NC\n"
exit 1
else
printf "$GREEN[OK]$NC\n"
source .venv/bin/activate
fi
# Install FlagGems
export FLAGOS_PYPI="https://resource.flagos.net/repository/flagos-pypi-${VENDOR}/simple"
printf "Install build tools ... "
uv pip install \
"setuptools>=64.0" \
"scikit-build-core==0.12.2" \
"pybind11==3.0.3" \
"cmake>=3.20,<4" \
"ninja==1.13.0"
if [ "$?" != 0 ]; then
printf "$RED[FAILED]$NC\n"
exit 1
else
printf "$GREEN[OK]$NC\n"
fi
# export USE_TRITON=0
## Vendor-specific installation steps
source tools/set-env.sh ${VENDOR}
source tools/setup_vendor.sh ${VENDOR}
[ "$?" == 0 ] || { echo "Failed to setup FlagGems" ; exit 1; }