forked from fauxpilot/fauxpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·125 lines (111 loc) · 3.8 KB
/
setup.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
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
#!/usr/bin/env bash
if [ -f .env ]; then
read -rp ".env already exists, do you want to delete .env and recreate it? [y/n] " DELETE
if [[ ${DELETE:-y} =~ ^[Yy]$ ]]
then
echo "Deleting .env"
rm .env
else
echo "Exiting"
exit 0
fi;
fi
function check_dep(){
echo "Checking for $1 ..."
which "$1" 2>/dev/null || {
echo "Please install $1."
exit 1
}
}
check_dep curl
check_dep zstd
check_dep docker
echo "Models available:"
echo "[1] codegen-350M-mono (2GB total VRAM required; Python-only)"
echo "[2] codegen-350M-multi (2GB total VRAM required; multi-language)"
echo "[3] codegen-2B-mono (7GB total VRAM required; Python-only)"
echo "[4] codegen-2B-multi (7GB total VRAM required; multi-language)"
echo "[5] codegen-6B-mono (13GB total VRAM required; Python-only)"
echo "[6] codegen-6B-multi (13GB total VRAM required; multi-language)"
echo "[7] codegen-16B-mono (32GB total VRAM required; Python-only)"
echo "[8] codegen-16B-multi (32GB total VRAM required; multi-language)"
# Read their choice
read -rp "Enter your choice [6]: " MODEL_NUM
# Convert model number to model name
case $MODEL_NUM in
1) MODEL="codegen-350M-mono" ;;
2) MODEL="codegen-350M-multi" ;;
3) MODEL="codegen-2B-mono" ;;
4) MODEL="codegen-2B-multi" ;;
5) MODEL="codegen-6B-mono" ;;
6) MODEL="codegen-6B-multi" ;;
7) MODEL="codegen-16B-mono" ;;
8) MODEL="codegen-16B-multi" ;;
*) MODEL="codegen-6B-multi" ;;
esac
# Read number of GPUs
read -rp "Enter number of GPUs [1]: " NUM_GPUS
NUM_GPUS=${NUM_GPUS:-1}
read -rp "External port for the API [5000]: " API_EXTERNAL_PORT
API_EXTERNAL_PORT=${API_EXTERNAL_PORT:-5000}
read -rp "Address for Triton [triton]: " TRITON_HOST
TRITON_HOST=${TRITON_HOST:-triton}
read -rp "Port of Triton host [8001]: " TRITON_PORT
TRITON_PORT=${TRITON_PORT:-8001}
# Read model directory
read -rp "Where do you want to save the model [$(pwd)/models]? " MODEL_DIR
if [ -z "$MODEL_DIR" ]; then
MODEL_DIR="$(pwd)/models"
else
MODEL_DIR="$(readlink -m "${MODEL_DIR}")"
fi
# Write .env
echo "MODEL=${MODEL}" > .env
echo "NUM_GPUS=${NUM_GPUS}" >> .env
echo "MODEL_DIR=${MODEL_DIR}/${MODEL}-${NUM_GPUS}gpu" >> .env
echo "API_EXTERNAL_PORT=${API_EXTERNAL_PORT}" >> .env
echo "TRITON_HOST=${TRITON_HOST}" >> .env
echo "TRITON_PORT=${TRITON_PORT}" >> .env
echo "GPUS=$(seq 0 $(( NUM_GPUS - 1)) | paste -s -d ',' -)" >> .env
if (test -d "$MODEL_DIR"/"${MODEL}"-"${NUM_GPUS}"gpu ); then
echo "$MODEL_DIR"/"${MODEL}"-"${NUM_GPUS}"gpu
echo "Converted model for ${MODEL}-${NUM_GPUS}gpu already exists."
read -rp "Do you want to re-use it? y/n: " REUSE_CHOICE
if [[ ${REUSE_CHOICE:-y} =~ ^[Yy]$ ]]
then
DOWNLOAD_MODEL=n
echo "Re-using model"
else
DOWNLOAD_MODEL=y
rm -rf "$MODEL_DIR"/"${MODEL}"-"${NUM_GPUS}"gpu
fi
else
DOWNLOAD_MODEL=y
fi
if [[ ${DOWNLOAD_MODEL:-y} =~ ^[Yy]$ ]]
then
# Create model directory
mkdir -p "${MODEL_DIR}"
if [ "$NUM_GPUS" -le 2 ]; then
echo "Downloading the model from HuggingFace, this will take a while..."
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
DEST="${MODEL}-${NUM_GPUS}gpu"
ARCHIVE="${MODEL_DIR}/${DEST}.tar.zst"
cp -r "$SCRIPT_DIR"/converter/models/"$DEST" "${MODEL_DIR}"
curl -L "https://huggingface.co/moyix/${MODEL}-gptj/resolve/main/${MODEL}-${NUM_GPUS}gpu.tar.zst" \
-o "$ARCHIVE"
zstd -dc "$ARCHIVE" | tar -xf - -C "${MODEL_DIR}"
rm -f "$ARCHIVE"
else
echo "Downloading and converting the model, this will take a while..."
docker run --rm -v "${MODEL_DIR}":/models -e MODEL=${MODEL} -e NUM_GPUS="${NUM_GPUS}" moyix/model_converter:latest
fi
fi
read -rp "Config complete, do you want to run FauxPilot? [y/n] " RUN
if [[ ${RUN:-y} =~ ^[Yy]$ ]]
then
bash ./launch.sh
else
echo "You can run ./launch.sh to start the FauxPilot server."
exit 0
fi;