-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·308 lines (256 loc) · 8.34 KB
/
install.sh
File metadata and controls
executable file
·308 lines (256 loc) · 8.34 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/bin/bash
# Install Parallax from source and build the vLLM Rust frontend binary.
# Usage:
# ./install.sh [--extras EXTRAS] [--python PYTHON_VERSION]
#
# By default, installs mac extras on macOS and gpu extras on Linux, then
# builds vllm-rs in release mode.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
EXTRAS="${PARALLAX_EXTRAS:-}"
PYTHON_VERSION="${PARALLAX_PYTHON_VERSION:-3.12}"
VENV_DIR="$SCRIPT_DIR/.venv"
VLLM_REF="${VLLM_REF:-v0.22.0}"
show_help() {
cat <<'EOF'
Install Parallax from source and build the vLLM Rust frontend binary.
Usage:
./install.sh [--extras EXTRAS] [--python PYTHON_VERSION]
Options:
--extras EXTRAS Python extras to install, for example "mac", "gpu",
or "mac,dev". Defaults to mac on macOS and gpu on Linux.
--python PYTHON_VERSION Python version for uv venv. Defaults to 3.12.
Environment:
PARALLAX_EXTRAS Same as --extras.
PARALLAX_PYTHON_VERSION Same as --python.
VLLM_REF vLLM git branch/tag to clone. Defaults to v0.22.0.
EOF
}
usage_error() {
echo "$1" >&2
show_help >&2
exit 2
}
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--extras)
[[ $# -ge 2 ]] || usage_error "--extras requires a value."
EXTRAS="$2"
shift 2
;;
--extras=*)
EXTRAS="${1#*=}"
shift
;;
--python)
[[ $# -ge 2 ]] || usage_error "--python requires a value."
PYTHON_VERSION="$2"
shift 2
;;
--python=*)
PYTHON_VERSION="${1#*=}"
shift
;;
--help|-h)
show_help
exit 0
;;
*)
usage_error "Unknown argument: $1"
;;
esac
done
}
normalize_config() {
EXTRAS="${EXTRAS//[[:space:]]/}"
if [[ -z "$EXTRAS" ]]; then
case "$(uname -s)" in
Darwin) EXTRAS="mac" ;;
Linux) EXTRAS="gpu" ;;
*) EXTRAS="" ;;
esac
fi
}
run_with_sudo_if_needed() {
if [[ "$(id -u)" -eq 0 ]]; then
"$@"
elif command -v sudo &>/dev/null; then
sudo "$@"
else
echo "Need root privileges to run: $*" >&2
echo "Install the dependency manually, then rerun this script." >&2
exit 1
fi
}
ensure_uv() {
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if command -v uv &>/dev/null; then
return
fi
if ! command -v curl &>/dev/null; then
echo "curl not found; install curl and rerun this script." >&2
exit 1
fi
echo "uv not found, installing..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
if ! command -v uv &>/dev/null; then
echo "uv installation completed, but uv is still not on PATH." >&2
exit 1
fi
}
ensure_venv() {
if [[ -x "$VENV_DIR/bin/python" ]]; then
echo "Using existing virtual environment: $VENV_DIR"
return
fi
echo "Creating virtual environment: $VENV_DIR (Python $PYTHON_VERSION)"
uv venv "$VENV_DIR" --python "$PYTHON_VERSION"
if [[ ! -x "$VENV_DIR/bin/python" ]]; then
echo "Virtual environment was created, but $VENV_DIR/bin/python is missing." >&2
exit 1
fi
}
install_parallax_python() {
local venv_python="$VENV_DIR/bin/python"
local package_spec="."
if [[ -n "$EXTRAS" ]]; then
package_spec=".[${EXTRAS}]"
fi
echo "Installing Parallax Python package: $package_spec"
UV_PRERELEASE=allow uv pip install --python "$venv_python" -e "$package_spec"
}
resolve_venv_bin_dir() {
"$VENV_DIR/bin/python" - <<'PY'
import sysconfig
print(sysconfig.get_path("scripts"))
PY
}
ensure_git() {
if ! command -v git &>/dev/null; then
echo "git not found; install git and rerun this script." >&2
exit 1
fi
}
ensure_protoc() {
if command -v protoc &>/dev/null; then
return
fi
echo "protoc not found, installing protobuf compiler..."
if command -v brew &>/dev/null; then
brew install protobuf
elif command -v apt-get &>/dev/null; then
run_with_sudo_if_needed apt-get update
run_with_sudo_if_needed apt-get install -y protobuf-compiler
elif command -v dnf &>/dev/null; then
run_with_sudo_if_needed dnf install -y protobuf-compiler
elif command -v yum &>/dev/null; then
run_with_sudo_if_needed yum install -y protobuf-compiler
elif command -v apk &>/dev/null; then
run_with_sudo_if_needed apk add --no-cache protobuf
else
echo "Unable to install protoc automatically." >&2
echo "Install protobuf compiler manually, then rerun this script." >&2
exit 1
fi
if ! command -v protoc &>/dev/null; then
echo "protoc installation completed, but protoc is still not on PATH." >&2
exit 1
fi
}
ensure_rust_toolchain() {
local toolchain="$1"
export PATH="$HOME/.cargo/bin:$PATH"
if ! command -v rustup &>/dev/null; then
if ! command -v curl &>/dev/null; then
echo "curl not found; install curl and rerun this script." >&2
exit 1
fi
echo "rustup not found, installing..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |
sh -s -- -y --default-toolchain none
# shellcheck disable=SC1091
source "$HOME/.cargo/env"
fi
if ! rustup run "$toolchain" rustc --version &>/dev/null; then
echo "Installing Rust toolchain: $toolchain"
rustup toolchain install "$toolchain"
fi
}
build_vllm_rust_frontend() {
local vllm_clone_root
local rust_dir
local parallax_scripts_dir
local target_path
local target_version_path
local existing_version
local toolchain
parallax_scripts_dir="$(resolve_venv_bin_dir)"
target_path="$parallax_scripts_dir/vllm-rs"
target_version_path="$target_path.version"
if [[ -f "$target_path" ]]; then
existing_version=""
if [[ -f "$target_version_path" ]]; then
existing_version="$(<"$target_version_path")"
fi
if [[ "$existing_version" != "$VLLM_REF" ]]; then
echo "Existing vllm-rs version (${existing_version:-unknown}) does not match $VLLM_REF, rebuilding."
rm -f "$target_path" "$target_version_path"
else
chmod +x "$target_path"
printf '%s\n' "$VLLM_REF" > "$target_version_path"
echo "vllm-rs already exists at $target_path, skipping Rust build."
return
fi
fi
CLONE_PARENT="$(mktemp -d "${TMPDIR:-/tmp}/parallax-vllm-rs.XXXXXX")"
vllm_clone_root="$CLONE_PARENT/vllm"
trap cleanup_clone EXIT
echo "Cloning vLLM from https://github.com/vllm-project/vllm.git (ref: $VLLM_REF)"
git clone --depth 1 --branch "$VLLM_REF" \
https://github.com/vllm-project/vllm.git \
"$vllm_clone_root"
rust_dir="$vllm_clone_root/rust"
if [[ ! -f "$rust_dir/Cargo.toml" || ! -f "$vllm_clone_root/rust-toolchain.toml" ]]; then
echo "Cloned repository does not contain the expected vLLM Rust frontend sources." >&2
exit 1
fi
toolchain=$(grep -E '^[[:space:]]*channel' "$vllm_clone_root/rust-toolchain.toml" |
sed 's/.*= *"\(.*\)"/\1/')
if [[ -z "$toolchain" ]]; then
echo "Unable to read Rust toolchain from $vllm_clone_root/rust-toolchain.toml" >&2
exit 1
fi
ensure_rust_toolchain "$toolchain"
ensure_protoc
cargo +"$toolchain" build --release \
--manifest-path "$rust_dir/Cargo.toml" \
--bin vllm-rs \
--features native-tls-vendored
mkdir -p "$(dirname "$target_path")"
cp "$rust_dir/target/release/vllm-rs" "$target_path"
chmod +x "$target_path"
printf '%s\n' "$VLLM_REF" > "$target_version_path"
echo "Installed vllm-rs to $target_path"
cleanup_clone
trap - EXIT
}
cleanup_clone() {
if [[ -n "${CLONE_PARENT:-}" ]]; then
rm -rf "$CLONE_PARENT"
fi
}
main() {
parse_args "$@"
normalize_config
cd "$SCRIPT_DIR"
ensure_uv
ensure_venv
install_parallax_python
ensure_git
build_vllm_rust_frontend
echo "Install complete."
echo "Activate the environment with: source .venv/bin/activate"
}
main "$@"