-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.sh
executable file
·153 lines (125 loc) · 4.6 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
################################################################################
# Script: setup.sh <DEVICE>
# Description: Automates the setup of a virtual environment and installs project
# requirements.
################################################################################
set -euo pipefail
CURRENT_DIR="$(pwd)"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Set default folder paths for AWQ weights
LLAMA2_AWQ_WEIGHTS_FOLDER="$CURRENT_DIR/models/llama-2-7b-chat-autoawq"
MISTRAL_AWQ_WEIGHTS_FOLDER="$CURRENT_DIR/models/mistral-7b-v0.1-instruct-autoawq"
check_python() {
if command -v python &> /dev/null; then
PYTHON_CMD="python"
elif command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
else
echo "Python is not installed."
exit 1
fi
}
check_python
install_vllm_cuda() {
CUDA_VERSION=$(nvcc --version | grep "release" | sed -n 's/.*release \(.*\),.*/\1/p')
if [ -z "$CUDA_VERSION" ]; then
echo "CUDA is not installed or not found."
exit 1
fi
CUDA_MAJOR=$(echo "$CUDA_VERSION" | cut -d. -f1)
CUDA_MINOR=$(echo "$CUDA_VERSION" | cut -d. -f2)
if [ "$CUDA_MAJOR" -ge 12 ] || { [ "$CUDA_MAJOR" -eq 12 ] && [ "$CUDA_MINOR" -ge 0 ]; }; then
echo "Detected CUDA version >= 12.2"
"$PYTHON_CMD" -m pip install vllm==0.4.0 transformers==4.39.2
else
echo "Detected CUDA version < 12.2"
PY_VERSION=$(get_python_version)
if [ -z "$PY_VERSION" ]; then
echo "Python version not found."
exit 1
fi
echo "Installing vllm for CUDA 11.8 with Python version: $PY_VERSION"
# Download vllm for CUDA 11.8 and specified Python version
"$PYTHON_CMD" -m pip install https://github.com/vllm-project/vllm/releases/download/v0.2.2/vllm-0.2.2+cu118-"$PY_VERSION"-"$PY_VERSION"-manylinux1_x86_64.whl
"$PYTHON_CMD" -m pip install torch --upgrade --index-url https://download.pytorch.org/whl/cu118
"$PYTHON_CMD" -m pip install huggingface-cli==0.1 transformers==4.39.2
fi
}
get_python_version() {
# Fetch Python version
PY_VER=$("$PYTHON_CMD" -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
case $PY_VER in
3.10) echo "cp310";;
3.8) echo "cp38";;
3.9) echo "cp39";;
3.11) echo "cp311";;
*) echo "Unknown Python version"; exit 1;;
esac
}
install_device_specific_vllm() {
local DEVICE="$1"
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <DEVICE>"
exit 1
fi
case "$DEVICE" in
cuda)
echo "Installing VLLM for CUDA."
install_vllm_cuda
;;
metal)
echo "VLLM for metal is not supported yet."
echo "For more information, checkout this issue: https://github.com/vllm-project/vllm/issues/1441"
return 1
;;
cpu)
echo "VLLM for CPU is not supported yet."
echo "For more information, checkout this issue: https://github.com/vllm-project/vllm/issues/176"
;;
*)
echo "Unsupported DEVICE: $DEVICE"
return 1
;;
esac
}
download_awq_weights() {
local MODEL_NAME="$1"
# Set download directory based on MODEL_NAME
if [ "$MODEL_NAME" = "llama" ]; then
DOWNLOAD_DIR="$LLAMA2_AWQ_WEIGHTS_FOLDER"
MODEL_IDENTIFIER="TheBloke/Llama-2-7B-Chat-AWQ"
elif [ "$MODEL_NAME" = "mistral" ]; then
DOWNLOAD_DIR="$MISTRAL_AWQ_WEIGHTS_FOLDER"
MODEL_IDENTIFIER="TheBloke/Mistral-7B-Instruct-v0.1-AWQ"
else
echo "Invalid MODEL_NAME. Supported values: 'llama', 'mistral'"
exit 1
fi
# Check if weights folder exists
echo "$DOWNLOAD_DIR"
if [ ! -d "$DOWNLOAD_DIR" ]; then
# Download weights using huggingface-cli
echo "Downloading weights to $DOWNLOAD_DIR..."
huggingface-cli download "$MODEL_IDENTIFIER" --local-dir "$DOWNLOAD_DIR" --exclude "*.git*" "*.md" "Notice" "LICENSE"
else
echo "Weights already downloaded"
fi
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$SCRIPT_DIR/venv"
DEVICE="$1"
MODEL_NAME="$2"
# Build and activate the virtual environment.
if [ ! -d "$VENV_DIR" ]; then
"$PYTHON_CMD" -m venv "$VENV_DIR"
echo "Virtual environment '$VENV_DIR' created."
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
"$PYTHON_CMD" -m pip install --upgrade pip > /dev/null
install_device_specific_vllm "$DEVICE"
else
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
fi
download_awq_weights "$MODEL_NAME"