diff --git a/v/vllm-rocm/vllm_v0.31.0_rocm_ubi_10.sh b/v/vllm-rocm/vllm_v0.31.0_rocm_ubi_10.sh new file mode 100644 index 0000000000..4105747107 --- /dev/null +++ b/v/vllm-rocm/vllm_v0.31.0_rocm_ubi_10.sh @@ -0,0 +1,549 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# +# Package : vllm +# Version : v0.31.0 +# Source repo : https://github.com/vllm-project/vllm +# Tested on : UBI 10 (ppc64le) +# Language : Python, C++, CUDA/HIP +# Ci-Check : True +# Script License: Apache License, Version 2 or later +# Maintainer : Daniel Schenker +# +# Disclaimer: This script has been tested in root mode on given +# ========== platform using the mentioned version of the package. +# It may not work as expected with newer versions of the +# package and/or distribution. In such case, please +# contact "Maintainer" of this script. +# +# ---------------------------------------------------------------------------- +# +# ROCm installation mode (ROCM_INSTALL_MODE env var): +# rpms (default) - Install ROCm RPMs from a provided repo URL +# path - Assume ROCm is already present; use ROCM_PATH as-is +# +# PyTorch, torchvision, and torchaudio are installed from the IBM ROCm devpi +# wheel index (DEVPI_ROCM_INDEX) rather than built from source. +# +# Runtime dependencies that are only available on the IBM devpi index +# (xgrammar, sentencepiece, etc.) are installed from DEVPI_INDEX before the +# wheel build so they are present in the environment at test time. +# +# Usage: +# ./vllm_v0.31.0_rocm_ubi_10.sh [v0.31.0] +# +# Environment variables honoured (can be set before running): +# PACKAGE_VERSION - vLLM tag to build (default: v0.31.0) +# ROCM_INSTALL_MODE - rpms (default) or path +# ROCM_PATH - Path to ROCm installation (default: /opt/rocm) +# ROCM_REPO_URL - RPM repo baseurl for ROCm +# MOONCAKE_WHEEL - Path to a local mooncake-transfer-engine-rocm wheel. +# Required until the wheel is published to DEVPI_ROCM_INDEX. +# DEVPI_INDEX - IBM ppc64le devpi wheel index URL +# (default: https://wheels.developerfirst.ibm.com/ppc64le/linux/+simple) +# DEVPI_ROCM_INDEX - IBM ppc64le ROCm-specific devpi wheel index URL +# (default: https://wheels.developerfirst.ibm.com/ppc64le/rocm/+simple) +# +# --------------------------------------------------------------------------- + +set -e + +PACKAGE_NAME=vllm +PACKAGE_VERSION=${1:-v0.31.0} +PACKAGE_URL=https://github.com/vllm-project/vllm.git +CURRENT_DIR=$(pwd) +OS_NAME=$(grep ^PRETTY_NAME /etc/os-release | cut -d= -f2) + +ROCM_INSTALL_MODE=${ROCM_INSTALL_MODE:-"rpms"} # rpms | path +ROCM_REPO_URL=${ROCM_REPO_URL:-"https://public.dhe.ibm.com/software/server/POWER/Linux/AMD/ROCm/RHEL/10/ppc64le"} +ROCM_PATH=${ROCM_PATH:-/opt/rocm} + +DEVPI_INDEX=${DEVPI_INDEX:-"https://wheels.developerfirst.ibm.com/ppc64le/linux/+simple"} +DEVPI_ROCM_INDEX=${DEVPI_ROCM_INDEX:-"https://wheels.developerfirst.ibm.com/ppc64le/rocm/+simple"} +MOONCAKE_WHEEL=${MOONCAKE_WHEEL:-""} + +if [[ "$ROCM_INSTALL_MODE" != "rpms" && "$ROCM_INSTALL_MODE" != "path" ]]; then + echo "ERROR: ROCM_INSTALL_MODE must be one of: rpms, path" + exit 1 +fi + +echo "=== vLLM ROCm Build ===" +echo " PACKAGE_VERSION : $PACKAGE_VERSION" +echo " ROCM_INSTALL_MODE: $ROCM_INSTALL_MODE" +echo " ROCM_PATH : $ROCM_PATH" +echo " MOONCAKE_WHEEL : ${MOONCAKE_WHEEL:-"(not set — will install from DEVPI_ROCM_INDEX)"}" +echo " DEVPI_INDEX : $DEVPI_INDEX" +echo " DEVPI_ROCM_INDEX : $DEVPI_ROCM_INDEX" +echo "=======================" + +# --------------------------------------------------------------------------- +# Install system build dependencies +# --------------------------------------------------------------------------- + +# Python packages must appear first (wrapper script requirement). +# Note: libdrm is not available in the UBI 10 repo — it is built from source below. +yum install -y python3.12 python3.12-devel python3.12-pip \ + gcc-toolset-15 gcc-toolset-15-gcc gcc-toolset-15-gcc-c++ \ + git make wget patch cmake ninja-build \ + zlib-devel curl \ + meson pkgconf-pkg-config + +# Configure GCC Toolset 15 +if [[ -f /opt/rh/gcc-toolset-15/enable ]]; then + source /opt/rh/gcc-toolset-15/enable +elif [[ -d /opt/rh/gcc-toolset-15/root/usr/bin ]]; then + export PATH="/opt/rh/gcc-toolset-15/root/usr/bin:$PATH" + export LD_LIBRARY_PATH="/opt/rh/gcc-toolset-15/root/usr/lib64:${LD_LIBRARY_PATH:-}" +else + echo "ERROR: gcc-toolset-15 not found" + exit 1 +fi + +echo "Using gcc: $(gcc --version | head -1)" + +# Use Python 3.12 for the build so all produced wheels are cp312 +PYTHON=python3.12 + +# --------------------------------------------------------------------------- +# Build libdrm from source +# libdrm is not available in the UBI 10 package repository. We clone the +# upstream freedesktop.org release, build it with meson, and install it into +# /usr/local so every subsequent build step can find it via pkg-config. +# --------------------------------------------------------------------------- +LIBDRM_VERSION=${LIBDRM_VERSION:-"libdrm-2.4.124"} +LIBDRM_URL="https://gitlab.freedesktop.org/mesa/drm.git" + +echo "Building libdrm ${LIBDRM_VERSION} from source" +if [ -d "${CURRENT_DIR}/drm" ]; then + echo "drm directory already exists, reusing." + cd "${CURRENT_DIR}/drm" + git checkout "$LIBDRM_VERSION" +else + if ! git clone --branch "$LIBDRM_VERSION" --depth 1 "$LIBDRM_URL" "${CURRENT_DIR}/drm"; then + echo "ERROR: Failed to clone libdrm ${LIBDRM_VERSION}" + exit 1 + fi + cd "${CURRENT_DIR}/drm" +fi + +meson setup build \ + --prefix=/usr/local \ + --buildtype=release \ + -Damdgpu=enabled \ + -Dradeon=enabled \ + -Dintel=disabled \ + -Dnouveau=disabled \ + -Dvmwgfx=disabled \ + -Dtests=false + +ninja -C build +ninja -C build install + +# Make the freshly installed libdrm visible to pkg-config and the linker +export PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH:-}" +export LD_LIBRARY_PATH="/usr/local/lib64:/usr/local/lib:${LD_LIBRARY_PATH:-}" +echo "libdrm installed: $(pkg-config --modversion libdrm)" + +cd "${CURRENT_DIR}" + +# --------------------------------------------------------------------------- +# Install Rust (required by vLLM build) +# --------------------------------------------------------------------------- +if command -v cargo &>/dev/null; then + echo "Rust already installed: $(cargo --version)" +else + echo "Installing Rust via rustup" + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rust-install.sh + sh /tmp/rust-install.sh --no-modify-path --default-toolchain stable --profile minimal -y + rm /tmp/rust-install.sh + export PATH="$PATH:$HOME/.cargo/bin" + echo "Rust installed: $(cargo --version)" +fi + +# --------------------------------------------------------------------------- +# MODE: rpms — install ROCm from a provided RPM repository +# --------------------------------------------------------------------------- +if [[ "$ROCM_INSTALL_MODE" == "rpms" ]]; then + if [[ ! "$ROCM_REPO_URL" =~ ^(https?|file):// ]]; then + echo "ERROR: ROCM_REPO_URL does not look like a valid URL (got: ${ROCM_REPO_URL})" + exit 1 + fi + echo "Installing ROCm from ${ROCM_REPO_URL}" + + ROCM_GPG_URL="https://public.dhe.ibm.com/software/server/POWER/Linux/AMD/RPM-GPG-KEY-PAMD" + ROCM_GPG_PATH="/etc/pki/rpm-gpg/RPM-GPG-KEY-PAMD" + echo "Importing ROCm GPG key from ${ROCM_GPG_URL}" + wget -q -O "${ROCM_GPG_PATH}" "${ROCM_GPG_URL}" + rpm --import "${ROCM_GPG_PATH}" + + cat > /etc/yum.repos.d/rocm.repo </dev/null; then + echo "ERROR: hipcc not found under ROCM_PATH=${ROCM_PATH}. Check your ROCm installation." + exit 1 +fi +echo "ROCm hipcc: $(hipcc --version | head -1)" + +# --------------------------------------------------------------------------- +# Install PyTorch, torchvision, and torchaudio from IBM ROCm devpi index +# --------------------------------------------------------------------------- + +$PYTHON -m pip install --upgrade pip setuptools wheel + +echo "Installing torch, torchvision, and torchaudio from ROCm devpi index" +$PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_ROCM_INDEX}" \ + --extra-index-url "${DEVPI_INDEX}" \ + torch torchvision torchaudio + +# Verify torch is importable and ROCm is visible through it +echo "Verifying torch install" +export ROCPROFILER_LOG_LEVEL=0 +$PYTHON -c "import torch; print('torch version :', torch.__version__); print('ROCm available:', torch.cuda.is_available())" +$PYTHON -c "import torchvision; print('torchvision version:', torchvision.__version__)" +$PYTHON -c "import torchaudio; print('torchaudio version:', torchaudio.__version__)" + +# --------------------------------------------------------------------------- +# Clone vLLM +# --------------------------------------------------------------------------- +echo "Cloning vLLM ${PACKAGE_VERSION}" +if [ -d "${CURRENT_DIR}/vllm/.git" ]; then + echo "vllm directory already exists, reusing." + cd "${CURRENT_DIR}/vllm" + git fetch --tags origin + git checkout "$PACKAGE_VERSION" +else + if ! git clone "$PACKAGE_URL" "${CURRENT_DIR}/vllm"; then + echo "------------------$PACKAGE_NAME:clone_fails---------------------------------------" + echo "$PACKAGE_URL $PACKAGE_NAME" + echo "$PACKAGE_NAME | $PACKAGE_URL | $PACKAGE_VERSION | GitHub | Fail | Clone_Fails" + exit 1 + fi + cd "${CURRENT_DIR}/vllm" + git checkout "$PACKAGE_VERSION" +fi + +echo "Current vLLM commit:" +git --no-pager log -1 --oneline + +# --------------------------------------------------------------------------- +# Apply vLLM patches +# --------------------------------------------------------------------------- + +# use_existing_torch.py — removes vLLM's bundled torch build in favour of +# the torch wheel already installed above +echo "Running vLLM use_existing_torch.py patch" +[[ -f "tools/use_existing_torch.py" ]] || { echo "ERROR: use_existing_torch.py not found"; exit 1; } +$PYTHON tools/use_existing_torch.py + +# Patch requirements/build/rocm.txt: +# 1. Relax triton pin (==3.6.0 → >=3.6.0) for ppc64le wheel compatibility +# 2. Remove amdsmi PyPI pin — installed from system ROCm below +# 3. Pin apache-tvm-ffi to 0.1.10 — required by tilelang +REQ_FILE="requirements/build/rocm.txt" +[[ -f "$REQ_FILE" ]] || { echo "ERROR: $REQ_FILE not found"; exit 1; } + +if grep -q '^triton==3\.[0-9].*$' "$REQ_FILE"; then + sed -i 's/^triton==3\.[0-9].*$/triton>=3.6.0/' "$REQ_FILE" + echo "Patched $REQ_FILE: triton==3.x.y -> triton>=3.6.0" +elif grep -q '^triton>=3\.6\.0$' "$REQ_FILE"; then + echo "$REQ_FILE already patched for triton>=3.6.0" +else + echo "ERROR: Could not find expected triton==3.x line in $REQ_FILE" + exit 1 +fi + +if grep -q '^amdsmi' "$REQ_FILE"; then + sed -i '/^amdsmi/d' "$REQ_FILE" + echo "Patched $REQ_FILE: removed amdsmi line (installed from system ROCm instead)" +fi + +# Pin apache-tvm-ffi to 0.1.10 — required by tilelang; +# https://github.com/tile-ai/tilelang/issues/2367 +if grep -q '^apache-tvm-ffi' "$REQ_FILE"; then + sed -i 's|^apache-tvm-ffi.*$|apache-tvm-ffi==0.1.10|' "$REQ_FILE" + echo "Patched $REQ_FILE: apache-tvm-ffi pinned to 0.1.10" +else + echo "apache-tvm-ffi==0.1.10" >> "$REQ_FILE" + echo "Patched $REQ_FILE: appended apache-tvm-ffi==0.1.10" +fi + +# Inject ROCm bitcode path into CMAKE_HIP_FLAGS in setup.py +ROCM_BITCODE_DIR="$ROCM_PATH/lib/llvm/amdgcn/bitcode" +[[ -d "$ROCM_BITCODE_DIR" ]] || { echo "ERROR: ROCm bitcode directory not found: $ROCM_BITCODE_DIR"; exit 1; } + +echo "Patching setup.py CMAKE_HIP_FLAGS with ROCm bitcode path" +$PYTHON - <=3.6.0" + +echo "Installing runai-model-streamer wheels from devpi index" +$PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + "runai-model-streamer" \ + "runai-model-streamer[s3]" + +echo "Installing z3-solver from devpi index" +$PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + z3-solver==4.15.4.0 +# tilelang has moved to the ROCm-specific index; install with --no-build-isolation +# so the already-installed torch is reused rather than a fresh copy downloaded. +$PYTHON -m pip install cmake ninja \ + "scikit-build-core[pyproject]>=0.10.0" \ + "cython>=3.2.8" \ + setuptools-scm +echo "Installing tilelang from ROCm devpi index" +$PYTHON -m pip install --prefer-binary --no-build-isolation \ + --extra-index-url "${DEVPI_ROCM_INDEX}" \ + tilelang + +echo "Installing opencv-python-headless and grpcio from devpi index" +$PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + "opencv-python-headless==4.13.0.92" \ + grpcio + +echo "Installing xgrammar and sentencepiece from devpi index" +$PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + xgrammar \ + sentencepiece \ + tiktoken \ + ijson \ + llguidance \ + msgspec \ + cbor2 \ + grpcio \ + numba \ + llvmlite \ + onnx \ + pandas \ + scipy + +# Install pyarrow and datasets with explicit version caps: +# - datasets>=5.1.0 requires pyarrow>=24.0.0 which has no ppc64le binary on +# PyPI and is not yet on the IBM devpi index (highest available: 23.0.1). +# Pin datasets<5.1.0 so pip never needs pyarrow>=24. +# - Pre-install pyarrow from devpi so it is already present and resolved +# before the vLLM wheel install triggers datasets' dependency. +echo "Installing pyarrow and datasets from devpi index" +$PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + "pyarrow>=21.0.0" \ + "datasets<5.1.0" +echo "Devpi runtime deps installed" + +# --------------------------------------------------------------------------- +# Install mooncake-transfer-engine-rocm +# +# vLLM v0.31.0 requires mooncake-transfer-engine-rocm >= 0.3.13 in +# requirements/rocm.txt. The wheel is not yet on the IBM devpi index so it +# is installed from a local path supplied via MOONCAKE_WHEEL. +# +# TODO: once the wheel is published to DEVPI_ROCM_INDEX, remove the +# MOONCAKE_WHEEL local-path branch and the env var. +# --------------------------------------------------------------------------- +if [[ -n "$MOONCAKE_WHEEL" ]]; then + [[ -f "$MOONCAKE_WHEEL" ]] || { echo "ERROR: MOONCAKE_WHEEL file not found: ${MOONCAKE_WHEEL}"; exit 1; } + echo "Installing mooncake-transfer-engine-rocm from local wheel: ${MOONCAKE_WHEEL}" + $PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + "${MOONCAKE_WHEEL}" +else + echo "Installing mooncake-transfer-engine-rocm from ROCm devpi index" + $PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_ROCM_INDEX}" \ + "mooncake-transfer-engine-rocm>=0.3.13" +fi + +# --------------------------------------------------------------------------- +# Build vLLM wheel +# --------------------------------------------------------------------------- +cd "${CURRENT_DIR}/vllm" + +# Seed CMAKE_PREFIX_PATH with the installed torch cmake config so that vLLM's +# CMake can find TorchConfig.cmake without a from-source build tree. +TORCH_CMAKE_PREFIX=$($PYTHON -c 'import torch; print(torch.utils.cmake_prefix_path)') +export CMAKE_PREFIX_PATH="${TORCH_CMAKE_PREFIX}:${ROCM_PATH}:${CMAKE_PREFIX_PATH:-}" + +# Must be exported (not just inline) so that vLLM's get_runtime_environment() +# in setup.py sees VLLM_TARGET_DEVICE=rocm when it calls os.environ.get(). +# An inline-only assignment on the build command is not sufficient because +# get_vllm_version() is invoked at module-scope before the env is propagated. +export VLLM_TARGET_DEVICE="rocm" + +echo "Installing vLLM ROCm build requirements" +[[ -f "requirements/build/rocm.txt" ]] || { echo "ERROR: requirements/build/rocm.txt not found"; exit 1; } +$PYTHON -m pip install --prefer-binary -r requirements/build/rocm.txt --extra-index-url "${DEVPI_INDEX}" + +# Install matching AMDSMI Python bindings from system ROCm (not PyPI) +AMDSMI_SRC="$ROCM_PATH/share/amd_smi" +[[ -d "$AMDSMI_SRC" ]] || { echo "ERROR: AMDSMI source not found: $AMDSMI_SRC"; exit 1; } +AMDSMI_TMP=$(mktemp -d) +cp -a "$AMDSMI_SRC/." "$AMDSMI_TMP/" +$PYTHON -m pip install --force-reinstall --no-deps "$AMDSMI_TMP" +rm -rf "$AMDSMI_TMP" +echo "Installed AMDSMI from system ROCm" + +echo "Building vLLM ROCm wheel (this will take a while)" +# VLLM_VERSION_OVERRIDE bypasses get_vllm_version()'s own ROCm suffix logic +# (which would append .rocm714 on top of +rocm7.14 and produce a double suffix). +# The override is used as-is — producing e.g. vllm-0.28.0+rocm7.14-cp312-... +unset BUILD_VERSION SETUPTOOLS_SCM_PRETEND_VERSION +export VLLM_VERSION_OVERRIDE="${PACKAGE_VERSION#v}+rocm7.14" +if ! $PYTHON setup.py bdist_wheel --universal --dist-dir "${CURRENT_DIR}"; then + echo "------------------$PACKAGE_NAME:install_fails---------------------------------------" + echo "$PACKAGE_URL $PACKAGE_NAME" + echo "$PACKAGE_NAME | $PACKAGE_URL | $PACKAGE_VERSION | $OS_NAME | GitHub | Fail | Install_Fails" + exit 1 +fi + +echo "Built vLLM wheel(s):" +ls -lh "${CURRENT_DIR}"/vllm-*.whl + +$PYTHON -m pip install "${CURRENT_DIR}"/vllm-*.whl \ + --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + --extra-index-url "${DEVPI_ROCM_INDEX}" + +# --------------------------------------------------------------------------- +# Import test +# --------------------------------------------------------------------------- +echo "Installing test-stage dependencies from devpi index" +$PYTHON -m pip install --prefer-binary \ + --extra-index-url "${DEVPI_INDEX}" \ + "apache-tvm-ffi==0.1.10" \ + fastsafetensors + +echo "Running import test" +cd "${CURRENT_DIR}" + +if ! $PYTHON -c "import vllm; print('vllm version:', vllm.__version__)"; then + echo "------------------$PACKAGE_NAME:Install_success_but_test_fails---------------------" + echo "$PACKAGE_URL $PACKAGE_NAME" + echo "$PACKAGE_NAME | $PACKAGE_URL | $PACKAGE_VERSION | $OS_NAME | GitHub | Fail | Install_success_but_test_Fails" + exit 2 +else + echo "------------------$PACKAGE_NAME:Install_&_test_both_success-------------------------" + echo "$PACKAGE_URL $PACKAGE_NAME" + echo "$PACKAGE_NAME | $PACKAGE_URL | $PACKAGE_VERSION | $OS_NAME | GitHub | Pass | Both_Install_and_Test_Success" + exit 0 +fi