|
| 1 | +ARG BASE_UBI_IMAGE_TAG=9.5-1741599792 |
| 2 | +############################################################### |
| 3 | +# base stage with basic dependencies |
| 4 | +############################################################### |
| 5 | +FROM registry.access.redhat.com/ubi9/ubi-minimal:${BASE_UBI_IMAGE_TAG} AS base-builder |
| 6 | +ARG PYTHON_VERSION=3.12 |
| 7 | +ARG OPENBLAS_VERSION=0.3.29 |
| 8 | +# Set Environment Variables for venv, cargo & openblas |
| 9 | +ENV VIRTUAL_ENV=/opt/vllm |
| 10 | +ENV PATH=${VIRTUAL_ENV}/bin:/root/.cargo/bin:$PATH |
| 11 | +ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ |
| 12 | +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib |
| 13 | +# install gcc-13, python, rust, openblas |
| 14 | +# Note: A symlink for libatomic.so is created for gcc-13 (linker fails to find to find libatomic otherwise - reqd. for sentencepiece) |
| 15 | +# Note: A dummy file 'control' is created in /tmp/ to artifically create dependencies between stages when building stages in parallel |
| 16 | +# when `--jobs=<N>` is passed with podman build command |
| 17 | +RUN microdnf install -y dnf \ |
| 18 | + && dnf install -y https://mirror.stream.centos.org/9-stream/BaseOS/`arch`/os/Packages/centos-gpg-keys-9.0-24.el9.noarch.rpm \ |
| 19 | + https://mirror.stream.centos.org/9-stream/BaseOS/`arch`/os/Packages/centos-stream-repos-9.0-24.el9.noarch.rpm \ |
| 20 | + https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \ |
| 21 | + && dnf config-manager --add-repo https://mirror.stream.centos.org/9-stream/BaseOS/`arch`/os \ |
| 22 | + && dnf config-manager --add-repo https://mirror.stream.centos.org/9-stream/AppStream/`arch`/os \ |
| 23 | + && dnf config-manager --set-enabled crb \ |
| 24 | + && dnf install -y \ |
| 25 | + git tar gcc-toolset-13 numactl-devel lapack-devel \ |
| 26 | + pkgconfig openssl-devel xsimd zeromq-devel kmod \ |
| 27 | + libtiff-devel libjpeg-devel openjpeg2-devel zlib-devel \ |
| 28 | + freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel \ |
| 29 | + harfbuzz-devel fribidi-devel libraqm-devel libimagequant-devel libxcb-devel \ |
| 30 | + python${PYTHON_VERSION}-devel python${PYTHON_VERSION}-pip \ |
| 31 | + && dnf clean all \ |
| 32 | + && ln -sf /usr/lib64/libatomic.so.1 /usr/lib64/libatomic.so \ |
| 33 | + && python${PYTHON_VERSION} -m venv ${VIRTUAL_ENV} \ |
| 34 | + && python -m pip install -U pip uv \ |
| 35 | + && uv pip install wheel build setuptools setuptools_scm setuptools_rust meson-python cmake ninja cython scikit_build_core scikit_build \ |
| 36 | + && curl -sL https://ftp2.osuosl.org/pub/ppc64el/openblas/latest/Openblas_${OPENBLAS_VERSION}_ppc64le.tar.gz | tar xvf - -C /usr/local \ |
| 37 | + && curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ |
| 38 | + && cd /tmp && touch control |
| 39 | +############################################################### |
| 40 | +# Stage to build torch family |
| 41 | +############################################################### |
| 42 | +FROM base-builder AS torch-builder |
| 43 | +# buld cache without torch dependent packages |
| 44 | +# sentencepiece has linker issues otherwise |
| 45 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 46 | + --mount=type=bind,src=requirements-common.txt,dst=/requirements-common.txt,ro \ |
| 47 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 48 | + sed -e 's/.*opencv.*//g; s/.*outlines.*//g; s/.*tensors.*//g' requirements-common.txt | uv pip install -r /dev/stdin && \ |
| 49 | + uv pip list |
| 50 | +ARG MAX_JOBS |
| 51 | +ARG TORCH_VERSION=2.5.1 |
| 52 | +ARG _GLIBCXX_USE_CXX11_ABI=1 |
| 53 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 54 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 55 | + git clone --recursive https://github.com/pytorch/pytorch.git -b v${TORCH_VERSION} && \ |
| 56 | + cd pytorch && \ |
| 57 | + uv pip install -r requirements.txt && \ |
| 58 | + python setup.py develop && \ |
| 59 | + rm -f dist/torch*+git*whl && \ |
| 60 | + MAX_JOBS=${MAX_JOBS:-$(nproc)} \ |
| 61 | + PYTORCH_BUILD_VERSION=${TORCH_VERSION} PYTORCH_BUILD_NUMBER=1 uv build --wheel --out-dir /torchwheels/ |
| 62 | +ARG TORCHVISION_VERSION=0.20.1 |
| 63 | +ARG TORCHVISION_USE_NVJPEG=0 |
| 64 | +ARG TORCHVISION_USE_FFMPEG=0 |
| 65 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 66 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 67 | + git clone --recursive https://github.com/pytorch/vision.git -b v${TORCHVISION_VERSION} && \ |
| 68 | + cd vision && \ |
| 69 | + MAX_JOBS=${MAX_JOBS:-$(nproc)} \ |
| 70 | + BUILD_VERSION=${TORCHVISION_VERSION} \ |
| 71 | + uv build --wheel --out-dir /torchwheels/ --no-build-isolation |
| 72 | +ARG TORCHAUDIO_VERSION=2.5.1 |
| 73 | +ARG BUILD_SOX=1 |
| 74 | +ARG BUILD_KALDI=1 |
| 75 | +ARG BUILD_RNNT=1 |
| 76 | +ARG USE_FFMPEG=0 |
| 77 | +ARG USE_ROCM=0 |
| 78 | +ARG USE_CUDA=0 |
| 79 | +ARG TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_FFMPEG=1 |
| 80 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 81 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 82 | + git clone --recursive https://github.com/pytorch/audio.git -b v${TORCHAUDIO_VERSION} && \ |
| 83 | + cd audio && \ |
| 84 | + MAX_JOBS=${MAX_JOBS:-$(nproc)} \ |
| 85 | + BUILD_VERSION=${TORCHAUDIO_VERSION} \ |
| 86 | + uv build --wheel --out-dir /torchwheels/ --no-build-isolation |
| 87 | +# build cache with torch dependent packages |
| 88 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 89 | + --mount=type=bind,src=requirements-common.txt,dst=/requirements-common.txt,ro \ |
| 90 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 91 | + grep "outlines" requirements-common.txt | uv pip install -r /dev/stdin && \ |
| 92 | + grep "tensors" requirements-common.txt | uv pip install -r /dev/stdin && \ |
| 93 | + uv pip list |
| 94 | +############################################################### |
| 95 | +# Stage to build pyarrow |
| 96 | +############################################################### |
| 97 | +FROM base-builder AS arrow-builder |
| 98 | +ARG MAX_JOBS |
| 99 | +ARG PYARROW_PARALLEL |
| 100 | +ARG PYARROW_VERSION=19.0.1 |
| 101 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 102 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 103 | + git clone --recursive https://github.com/apache/arrow.git -b apache-arrow-${PYARROW_VERSION} && \ |
| 104 | + cd arrow/cpp && \ |
| 105 | + mkdir build && cd build && \ |
| 106 | + cmake -DCMAKE_BUILD_TYPE=release \ |
| 107 | + -DCMAKE_INSTALL_PREFIX=/usr/local \ |
| 108 | + -DARROW_PYTHON=ON \ |
| 109 | + -DARROW_BUILD_TESTS=OFF \ |
| 110 | + -DARROW_JEMALLOC=ON \ |
| 111 | + -DARROW_BUILD_STATIC="OFF" \ |
| 112 | + -DARROW_PARQUET=ON \ |
| 113 | + .. && \ |
| 114 | + make install -j ${MAX_JOBS:-$(nproc)} && \ |
| 115 | + cd ../../python/ && \ |
| 116 | + uv pip install -v -r requirements-wheel-build.txt && \ |
| 117 | + PYARROW_PARALLEL=${PYARROW_PARALLEL:-$(nproc)} \ |
| 118 | + python setup.py build_ext \ |
| 119 | + --build-type=release --bundle-arrow-cpp \ |
| 120 | + bdist_wheel --dist-dir /arrowwheels/ |
| 121 | +############################################################### |
| 122 | +# Stage to build opencv |
| 123 | +############################################################### |
| 124 | +FROM base-builder AS cv-builder |
| 125 | +ARG MAX_JOBS |
| 126 | +ARG OPENCV_VERSION=84 |
| 127 | +ARG ENABLE_HEADLESS=1 |
| 128 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 129 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 130 | + git clone --recursive https://github.com/opencv/opencv-python.git -b ${OPENCV_VERSION} && \ |
| 131 | + cd opencv-python && \ |
| 132 | + sed -i 's/"setuptools==59.2.0",/"setuptools<70.0",/g' pyproject.toml && \ |
| 133 | + python -m build --wheel --installer=uv --outdir /opencvwheels/ |
| 134 | +# build opencv dependent packages |
| 135 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 136 | + --mount=type=bind,src=requirements-common.txt,dst=/requirements-common.txt,ro \ |
| 137 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 138 | + uv pip install /opencvwheels/*.whl && \ |
| 139 | + uv pip list | grep opencv && \ |
| 140 | + grep "opencv" requirements-common.txt | uv pip install -r /dev/stdin --no-build-isolation && \ |
| 141 | + uv pip list |
| 142 | +############################################################### |
| 143 | +# Stage to build vllm - this stage builds and installs |
| 144 | +# vllm, tensorizer and vllm-tgis-adapter and builds uv cache |
| 145 | +# for transitive dependencies - eg. grpcio |
| 146 | +############################################################### |
| 147 | +FROM base-builder AS vllmcache-builder |
| 148 | +COPY --from=torch-builder /tmp/control /dev/null |
| 149 | +COPY --from=arrow-builder /tmp/control /dev/null |
| 150 | +COPY --from=cv-builder /tmp/control /dev/null |
| 151 | +ARG VLLM_TGIS_ADAPTER_VERSION=0.6.3 |
| 152 | +ARG VLLM_TARGET_DEVICE=cpu |
| 153 | +ARG GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 |
| 154 | +# this step installs vllm & tgis adapter and populates uv cache |
| 155 | +# with all the transitive dependencies |
| 156 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 157 | + --mount=type=bind,from=torch-builder,source=/torchwheels/,target=/torchwheels/,ro \ |
| 158 | + --mount=type=bind,from=arrow-builder,source=/arrowwheels/,target=/arrowwheels/,ro \ |
| 159 | + --mount=type=bind,from=cv-builder,source=/opencvwheels/,target=/opencvwheels/,ro \ |
| 160 | + --mount=type=bind,src=.,dst=/src/,rw \ |
| 161 | + source /opt/rh/gcc-toolset-13/enable && \ |
| 162 | + uv pip install /opencvwheels/*.whl /arrowwheels/*.whl /torchwheels/*.whl && \ |
| 163 | + sed -i -e 's/.*torch.*//g' /src/pyproject.toml /src/requirements-*.txt && \ |
| 164 | + uv pip install pandas && \ |
| 165 | + uv pip install -r /src/requirements-common.txt -r /src/requirements-cpu.txt -r /src/requirements-build.txt --no-build-isolation && \ |
| 166 | + cd /src/ && \ |
| 167 | + uv build --wheel --out-dir /vllmwheel/ --no-build-isolation && \ |
| 168 | + uv pip install "$(echo /vllmwheel/*.whl)[tensorizer]" vllm-tgis-adapter==${VLLM_TGIS_ADAPTER_VERSION} |
| 169 | +############################################################### |
| 170 | +# FINAL VLLM IMAGE STAGE # |
| 171 | +############################################################### |
| 172 | +FROM registry.access.redhat.com/ubi9/ubi-minimal:${BASE_UBI_IMAGE_TAG} AS vllm-openai |
| 173 | +ARG PYTHON_VERSION=3.12 |
| 174 | +ARG OPENBLAS_VERSION=0.3.29 |
| 175 | +# Set Environment Variables for venv & openblas |
| 176 | +ENV VIRTUAL_ENV=/opt/vllm |
| 177 | +ENV PATH=${VIRTUAL_ENV}/bin:$PATH |
| 178 | +ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ |
| 179 | +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib |
| 180 | +# install gcc-13, python, openblas |
| 181 | +RUN rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \ |
| 182 | + microdnf install --nodocs -y \ |
| 183 | + tar findutils openssl numactl lapack \ |
| 184 | + pkgconfig xsimd g++ libsndfile \ |
| 185 | + libtiff libjpeg openjpeg2 zlib zeromq \ |
| 186 | + freetype lcms2 libwebp tcl tk utf8proc \ |
| 187 | + harfbuzz fribidi libraqm libimagequant libxcb \ |
| 188 | + python${PYTHON_VERSION}-devel python${PYTHON_VERSION}-pip \ |
| 189 | + && microdnf clean all \ |
| 190 | + && python${PYTHON_VERSION} -m venv ${VIRTUAL_ENV} \ |
| 191 | + && python -m pip install -U pip uv --no-cache \ |
| 192 | + && curl -sL https://ftp2.osuosl.org/pub/ppc64el/openblas/latest/Openblas_${OPENBLAS_VERSION}_ppc64le.tar.gz | tar xvf - -C /usr/local |
| 193 | +# create artificial dependencies between stages for independent stages to build in parallel |
| 194 | +COPY --from=torch-builder /tmp/control /dev/null |
| 195 | +COPY --from=arrow-builder /tmp/control /dev/null |
| 196 | +COPY --from=cv-builder /tmp/control /dev/null |
| 197 | +COPY --from=vllmcache-builder /tmp/control /dev/null |
| 198 | +# consume previously built wheels |
| 199 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 200 | + --mount=type=bind,from=torch-builder,source=/torchwheels/,target=/torchwheels/,ro \ |
| 201 | + --mount=type=bind,from=arrow-builder,source=/arrowwheels/,target=/arrowwheels/,ro \ |
| 202 | + --mount=type=bind,from=cv-builder,source=/opencvwheels/,target=/opencvwheels/,ro \ |
| 203 | + --mount=type=bind,from=vllmcache-builder,source=/vllmwheel/,target=/vllmwheel/,ro \ |
| 204 | + HOME=/root uv pip install /opencvwheels/*.whl /arrowwheels/*.whl /torchwheels/*.whl /vllmwheel/*.whl |
| 205 | +WORKDIR /home/vllm |
| 206 | +# setup non-root user for OpenShift |
| 207 | +RUN umask 002 && \ |
| 208 | + useradd --uid 2000 --gid 0 vllm && \ |
| 209 | + mkdir -p /home/vllm && \ |
| 210 | + chmod g+rwx /home/vllm |
| 211 | +ENV HF_HUB_OFFLINE=0 \ |
| 212 | + HOME=/home/vllm \ |
| 213 | + # Allow requested max length to exceed what is extracted from the |
| 214 | + # config.json |
| 215 | + # see: https://github.com/vllm-project/vllm/pull/7080 |
| 216 | + VLLM_ALLOW_LONG_MAX_MODEL_LEN=1 \ |
| 217 | + VLLM_USAGE_SOURCE=production-docker-image \ |
| 218 | + VLLM_WORKER_MULTIPROC_METHOD=fork \ |
| 219 | + VLLM_NO_USAGE_STATS=1 \ |
| 220 | + OUTLINES_CACHE_DIR=/tmp/outlines |
| 221 | +COPY LICENSE /licenses/vllm.md |
| 222 | +COPY examples/*.jinja /app/data/template/ |
| 223 | +USER 2000 |
| 224 | +ENTRYPOINT ["python", "-m", "vllm.entrypoints.openai.api_server"] |
| 225 | +FROM vllm-openai as vllm-grpc-adapter |
| 226 | +USER root |
| 227 | +ARG VLLM_TGIS_ADAPTER_VERSION=0.6.3 |
| 228 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 229 | + --mount=type=bind,from=vllmcache-builder,source=/vllmwheel/,target=/vllmwheel/,ro \ |
| 230 | + HOME=/root uv pip install "$(echo /vllmwheel/*.whl)[tensorizer]" vllm-tgis-adapter==${VLLM_TGIS_ADAPTER_VERSION} |
| 231 | +ENV GRPC_PORT=8033 \ |
| 232 | + PORT=8000 \ |
| 233 | + # As an optimization, vLLM disables logprobs when using spec decoding by |
| 234 | + # default, but this would be unexpected to users of a hosted model that |
| 235 | + # happens to have spec decoding |
| 236 | + # see: https://github.com/vllm-project/vllm/pull/6485 |
| 237 | + DISABLE_LOGPROBS_DURING_SPEC_DECODING=false |
| 238 | +USER 2000 |
| 239 | +ENTRYPOINT ["python", "-m", "vllm_tgis_adapter", "--uvicorn-log-level=warning"] |
0 commit comments