|
| 1 | +#! /bin/bash -e |
| 2 | + |
| 3 | +trap "echo -e '\nScript interrupted. Exiting gracefully.'; exit 1" SIGINT |
| 4 | + |
| 5 | +# Copyright (C) 2024-2025 Red Hat, Inc. |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | +# SPDX-License-Identifier: Apache-2.0 |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +WORKSPACE=${WORKSPACE:-${HOME}} |
| 23 | + |
| 24 | +VLLM_REPO=https://github.com/vllm-project/vllm.git |
| 25 | +VLLM_DIR="${WORKSPACE}/vllm" |
| 26 | + |
| 27 | +declare -a PIP_INSTALL_ARGS |
| 28 | +PIP_VLLM_INDEX_URL_BASE=https://wheels.vllm.ai |
| 29 | + |
| 30 | +pip_install() { |
| 31 | + if command -v uv &>/dev/null; then |
| 32 | + uv pip install "$@" |
| 33 | + else |
| 34 | + pip install "$@" |
| 35 | + fi |
| 36 | +} |
| 37 | + |
| 38 | +# Extract the major.minor version from ROCM_VERSION, e.g. 6.4 from 6.4.4 |
| 39 | +get_rocm_version() { |
| 40 | + [[ "$ROCM_VERSION" =~ ^([0-9]+\.[0-9]+) ]] && echo "${BASH_REMATCH[1]}" || |
| 41 | + echo "$ROCM_VERSION" |
| 42 | +} |
| 43 | + |
| 44 | +setup_src() { |
| 45 | + if [ ! -d "${VLLM_DIR}" ]; then |
| 46 | + echo "Cloning the vLLM repo $VLLM_REPO to $VLLM_DIR ..." |
| 47 | + git clone "$VLLM_REPO" "$VLLM_DIR" |
| 48 | + |
| 49 | + if [ ! -d "$VLLM_DIR" ]; then |
| 50 | + echo "$VLLM_DIR not found. ERROR Cloning repository..." |
| 51 | + exit 1 |
| 52 | + else |
| 53 | + pushd "$VLLM_DIR" 1>/dev/null || exit 1 |
| 54 | + git submodule sync |
| 55 | + git submodule update --init --recursive |
| 56 | + |
| 57 | + if [ -n "${VLLM_GITREF:-}" ]; then |
| 58 | + git checkout "$VLLM_GITREF" |
| 59 | + fi |
| 60 | + |
| 61 | + echo "Install pre-commit hooks into your local vLLM git repo (one-time)" |
| 62 | + pip_install pre-commit |
| 63 | + pre-commit install |
| 64 | + popd 1>/dev/null |
| 65 | + fi |
| 66 | + else |
| 67 | + echo "vLLM repo already present, not cloning ..." |
| 68 | + fi |
| 69 | +} |
| 70 | + |
| 71 | +install_build_deps() { |
| 72 | + pushd "$VLLM_DIR" 1>/dev/null || exit 1 |
| 73 | + |
| 74 | + if [ "${INSTALL_TORCH:-}" = "source" ]; then |
| 75 | + echo "Using existing torch source build ..." |
| 76 | + python use_existing_torch.py |
| 77 | + else |
| 78 | + echo "Installing Torch as a vLLM dependency ..." |
| 79 | + "${WORKSPACE}"/setup_torch.sh release |
| 80 | + fi |
| 81 | + |
| 82 | + if [ -n "${CUDA_VERSION:-}" ]; then |
| 83 | + VLLM_TARGET_DEVICE=cuda |
| 84 | + |
| 85 | + if [ -e requirements/cuda.txt ]; then |
| 86 | + echo "Installing vLLM CUDA build dependencies ..." |
| 87 | + pip_install --prerelease=allow -r requirements/cuda.txt |
| 88 | + fi |
| 89 | + elif [ -n "${ROCM_VERSION:-}" ]; then |
| 90 | + VLLM_TARGET_DEVICE=rocm |
| 91 | + |
| 92 | + pip_install --upgrade numba \ |
| 93 | + scipy \ |
| 94 | + "huggingface-hub[cli,hf_transfer]" \ |
| 95 | + setuptools_scm |
| 96 | + |
| 97 | + pip_install "numpy<2" |
| 98 | + |
| 99 | + if [ -e requirements/rocm.txt ]; then |
| 100 | + echo "Installing vLLM ROCm build dependencies ..." |
| 101 | + pip_install --prerelease=allow -r requirements/rocm.txt |
| 102 | + fi |
| 103 | + elif [ "${TRITON_CPU_BACKEND:-0}" -eq 1 ]; then |
| 104 | + VLLM_TARGET_DEVICE=cpu |
| 105 | + |
| 106 | + if [ -e requirements/cpu.txt ]; then |
| 107 | + echo "Installing vLLM CPU build dependencies ..." |
| 108 | + pip_install --prerelease=allow -r requirements/cpu.txt |
| 109 | + fi |
| 110 | + fi |
| 111 | + |
| 112 | + if [ -f requirements/build.txt ]; then |
| 113 | + echo "Installing vLLM build dependencies ..." |
| 114 | + pip_install --prerelease=allow -r requirements/build.txt |
| 115 | + fi |
| 116 | + |
| 117 | + popd 1>/dev/null |
| 118 | + |
| 119 | + echo "Set the target device for vLLM build ..." |
| 120 | + tee -a "${HOME}/.bashrc" <<EOF |
| 121 | +
|
| 122 | +# Target device for vLLM build |
| 123 | +export VLLM_TARGET_DEVICE=$VLLM_TARGET_DEVICE |
| 124 | +EOF |
| 125 | + echo "Run 'source ${HOME}/.bashrc' before building vLLM" |
| 126 | +} |
| 127 | + |
| 128 | +install_whl() { |
| 129 | + echo "Installing vLLM from PyPI ..." |
| 130 | + |
| 131 | + if [ -n "${PIP_VLLM_EXTRA_INDEX_URL:-}" ]; then |
| 132 | + echo "Using the specified index, $PIP_VLLM_EXTRA_INDEX_URL" |
| 133 | + PIP_INSTALL_ARGS+=("--index-url" "$PIP_VLLM_EXTRA_INDEX_URL") |
| 134 | + elif [ -n "${VLLM_COMMIT:-}" ]; then |
| 135 | + echo "Using the build from commit $VLLM_COMMIT ..." |
| 136 | + PIP_VLLM_EXTRA_INDEX_URL="--extra-index-url ${PIP_VLLM_INDEX_URL_BASE}/${VLLM_COMMIT}" |
| 137 | + elif command -v uv &>/dev/null; then |
| 138 | + if [ -n "${UV_TORCH_BACKEND:-}" ]; then |
| 139 | + echo "Using the specified uv backend, $UV_TORCH_BACKEND" |
| 140 | + elif [ -n "${ROCM_VERSION:-}" ]; then |
| 141 | + echo "Using the torch ROCm version $ROCM_VERSION backend" |
| 142 | + UV_TORCH_BACKEND="rocm$(get_rocm_version)" |
| 143 | + elif ((${TRITON_CPU_BACKEND:-0} == 1)); then |
| 144 | + echo "Using the torch CPU backend" |
| 145 | + UV_TORCH_BACKEND=cpu |
| 146 | + elif [ -n "${CUDA_VERSION:-}" ]; then |
| 147 | + echo "Using the torch CUDA version $CUDA_VERSION backend" |
| 148 | + UV_TORCH_BACKEND="cu${CUDA_VERSION/[.-]/}" |
| 149 | + else |
| 150 | + echo "Using the torch auto backend" |
| 151 | + UV_TORCH_BACKEND=auto |
| 152 | + fi |
| 153 | + |
| 154 | + PIP_INSTALL_ARGS+=("--torch-backend" "$UV_TORCH_BACKEND") |
| 155 | + elif ! command -v uv &>/dev/null && [ -n "${UV_TORCH_BACKEND:-}" ]; then |
| 156 | + echo "Error: UV_TORCH_BACKEND is set to $UV_TORCH_BACKEND but uv is not available." |
| 157 | + exit 1 |
| 158 | + fi |
| 159 | + |
| 160 | + if [ -n "${PIP_VLLM_VERSION:-}" ]; then |
| 161 | + echo "Installing specified version $PIP_VLLM_VERSION" |
| 162 | + PIP_VLLM_VERSION="==$PIP_VLLM_VERSION" |
| 163 | + fi |
| 164 | + |
| 165 | + pip_install -U --force-reinstall "${PIP_INSTALL_ARGS[@]}" "vllm${PIP_VLLM_VERSION:-}" \ |
| 166 | + |
| 167 | + # Fix up LD_LIBRARY_PATH for CUDA |
| 168 | + "${WORKSPACE}"/ldpretend.sh |
| 169 | +} |
| 170 | + |
| 171 | +usage() { |
| 172 | + cat >&2 <<EOF |
| 173 | +Usage: $(basename "$0") [COMMAND] |
| 174 | + source Download vLLM's source (if needed) and install the build deps |
| 175 | + release Install vLLM |
| 176 | + nightly Install the vLLM nightly wheel |
| 177 | +EOF |
| 178 | +} |
| 179 | + |
| 180 | +## |
| 181 | +## Main |
| 182 | +## |
| 183 | + |
| 184 | +if [ $# -ne 1 ]; then |
| 185 | + usage |
| 186 | + exit 1 |
| 187 | +fi |
| 188 | + |
| 189 | +COMMAND=${1,,} |
| 190 | + |
| 191 | +case $COMMAND in |
| 192 | +source) |
| 193 | + setup_src |
| 194 | + install_build_deps |
| 195 | + ;; |
| 196 | +release) |
| 197 | + install_whl |
| 198 | + ;; |
| 199 | +nightly) |
| 200 | + PIP_VLLM_EXTRA_INDEX_URL="--extra-index-url ${PIP_VLLM_INDEX_URL_BASE}/nightly" |
| 201 | + install_whl |
| 202 | + ;; |
| 203 | +*) |
| 204 | + usage |
| 205 | + exit 1 |
| 206 | + ;; |
| 207 | +esac |
0 commit comments