|
1 | 1 | # This vLLM Dockerfile is used to construct image that can build and run vLLM on x86 CPU platform. |
| 2 | +# |
| 3 | +# Build targets: |
| 4 | +# vllm-openai (default): used for serving deployment |
| 5 | +# vllm-test: used for CI tests |
| 6 | +# vllm-dev: used for development |
| 7 | +# |
| 8 | +# Build arguments: |
| 9 | +# PYTHON_VERSION=3.12 (default)|3.11|3.10|3.9 |
| 10 | +# VLLM_CPU_DISABLE_AVX512=false (default)|true |
| 11 | +# |
| 12 | + |
| 13 | +######################### BASE IMAGE ######################### |
| 14 | +FROM ubuntu:22.04 AS base |
2 | 15 |
|
3 | | -FROM ubuntu:22.04 AS cpu-test-1 |
| 16 | +WORKDIR /workspace/ |
4 | 17 |
|
5 | | -ENV CCACHE_DIR=/root/.cache/ccache |
| 18 | +ARG PYTHON_VERSION=3.12 |
| 19 | +ARG PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu" |
6 | 20 |
|
| 21 | +# Install minimal dependencies and uv |
| 22 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 23 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 24 | + apt-get update -y \ |
| 25 | + && apt-get install -y --no-install-recommends ccache git curl wget ca-certificates \ |
| 26 | + gcc-12 g++-12 libtcmalloc-minimal4 libnuma-dev ffmpeg libsm6 libxext6 libgl1 \ |
| 27 | + && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10 --slave /usr/bin/g++ g++ /usr/bin/g++-12 \ |
| 28 | + && curl -LsSf https://astral.sh/uv/install.sh | sh |
| 29 | + |
| 30 | +ENV CCACHE_DIR=/root/.cache/ccache |
7 | 31 | ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache |
8 | 32 |
|
9 | | -RUN --mount=type=cache,target=/var/cache/apt \ |
10 | | - apt-get update -y \ |
11 | | - && apt-get install -y curl ccache git wget vim numactl gcc-12 g++-12 python3 python3-pip libtcmalloc-minimal4 libnuma-dev \ |
12 | | - && apt-get install -y ffmpeg libsm6 libxext6 libgl1 \ |
13 | | - && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10 --slave /usr/bin/g++ g++ /usr/bin/g++-12 |
| 33 | +ENV PATH="/root/.local/bin:$PATH" |
| 34 | +ENV VIRTUAL_ENV="/opt/venv" |
| 35 | +RUN uv venv --python ${PYTHON_VERSION} --seed ${VIRTUAL_ENV} |
| 36 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
14 | 37 |
|
15 | | -# https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/performance_tuning/tuning_guide.html |
16 | | -# intel-openmp provides additional performance improvement vs. openmp |
17 | | -# tcmalloc provides better memory allocation efficiency, e.g, holding memory in caches to speed up access of commonly-used objects. |
18 | | -RUN --mount=type=cache,target=/root/.cache/pip \ |
19 | | - pip install intel-openmp==2025.0.1 |
| 38 | +ENV UV_HTTP_TIMEOUT=500 |
20 | 39 |
|
21 | | -ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4:/usr/local/lib/libiomp5.so" |
| 40 | +# Install Python dependencies |
| 41 | +ENV PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL} |
| 42 | +ENV UV_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL} |
| 43 | +ENV UV_INDEX_STRATEGY="unsafe-best-match" |
| 44 | +ENV UV_LINK_MODE="copy" |
| 45 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 46 | + --mount=type=bind,src=requirements/common.txt,target=requirements/common.txt \ |
| 47 | + --mount=type=bind,src=requirements/cpu.txt,target=requirements/cpu.txt \ |
| 48 | + uv pip install --upgrade pip && \ |
| 49 | + uv pip install -r requirements/cpu.txt |
22 | 50 |
|
23 | | -RUN echo 'ulimit -c 0' >> ~/.bashrc |
| 51 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 52 | + uv pip install intel-openmp==2024.2.1 intel_extension_for_pytorch==2.6.0 |
24 | 53 |
|
25 | | -RUN pip install intel_extension_for_pytorch==2.6.0 |
| 54 | +ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4:/opt/venv/lib/libiomp5.so:$LD_PRELOAD" |
26 | 55 |
|
27 | | -WORKDIR /workspace |
| 56 | +RUN echo 'ulimit -c 0' >> ~/.bashrc |
28 | 57 |
|
29 | | -ARG PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu" |
30 | | -ENV PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL} |
31 | | -RUN --mount=type=cache,target=/root/.cache/pip \ |
32 | | - --mount=type=bind,src=requirements/build.txt,target=requirements/build.txt \ |
33 | | - pip install --upgrade pip && \ |
34 | | - pip install -r requirements/build.txt |
| 58 | +######################### BUILD IMAGE ######################### |
| 59 | +FROM base AS vllm-build |
35 | 60 |
|
36 | | -FROM cpu-test-1 AS build |
| 61 | +ARG GIT_REPO_CHECK=0 |
| 62 | +# Support for building with non-AVX512 vLLM: docker build --build-arg VLLM_CPU_DISABLE_AVX512="true" ... |
| 63 | +ARG VLLM_CPU_DISABLE_AVX512 |
| 64 | +ENV VLLM_CPU_DISABLE_AVX512=${VLLM_CPU_DISABLE_AVX512} |
37 | 65 |
|
38 | 66 | WORKDIR /workspace/vllm |
39 | 67 |
|
40 | | -RUN --mount=type=cache,target=/root/.cache/pip \ |
41 | | - --mount=type=bind,src=requirements/common.txt,target=requirements/common.txt \ |
42 | | - --mount=type=bind,src=requirements/cpu.txt,target=requirements/cpu.txt \ |
43 | | - pip install -v -r requirements/cpu.txt |
| 68 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 69 | + --mount=type=bind,src=requirements/build.txt,target=requirements/build.txt \ |
| 70 | + uv pip install -r requirements/build.txt |
44 | 71 |
|
45 | 72 | COPY . . |
46 | | -ARG GIT_REPO_CHECK=0 |
47 | 73 | RUN --mount=type=bind,source=.git,target=.git \ |
48 | 74 | if [ "$GIT_REPO_CHECK" != 0 ]; then bash tools/check_repo.sh ; fi |
49 | 75 |
|
50 | | -# Support for building with non-AVX512 vLLM: docker build --build-arg VLLM_CPU_DISABLE_AVX512="true" ... |
51 | | -ARG VLLM_CPU_DISABLE_AVX512 |
52 | | -ENV VLLM_CPU_DISABLE_AVX512=${VLLM_CPU_DISABLE_AVX512} |
| 76 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 77 | + --mount=type=cache,target=/root/.cache/ccache \ |
| 78 | + --mount=type=bind,source=.git,target=.git \ |
| 79 | + VLLM_TARGET_DEVICE=cpu python3 setup.py bdist_wheel |
| 80 | + |
| 81 | +######################### DEV IMAGE ######################### |
| 82 | +FROM vllm-build AS vllm-dev |
| 83 | + |
| 84 | +WORKDIR /workspace/vllm |
| 85 | + |
| 86 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 87 | + --mount=type=cache,target=/var/lib/apt,sharing=locked \ |
| 88 | + apt-get install -y --no-install-recommends vim numactl |
| 89 | + |
| 90 | +# install development dependencies (for testing) |
| 91 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 92 | + uv pip install -e tests/vllm_test_utils |
53 | 93 |
|
54 | | -RUN --mount=type=cache,target=/root/.cache/pip \ |
| 94 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
55 | 95 | --mount=type=cache,target=/root/.cache/ccache \ |
56 | 96 | --mount=type=bind,source=.git,target=.git \ |
57 | | - VLLM_TARGET_DEVICE=cpu python3 setup.py bdist_wheel && \ |
58 | | - pip install dist/*.whl && \ |
59 | | - rm -rf dist |
| 97 | + VLLM_TARGET_DEVICE=cpu python3 setup.py develop |
| 98 | + |
| 99 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 100 | + uv pip install -r requirements/dev.txt && \ |
| 101 | + pre-commit install --hook-type pre-commit --hook-type commit-msg |
| 102 | + |
| 103 | +ENTRYPOINT ["bash"] |
| 104 | + |
| 105 | +######################### TEST IMAGE ######################### |
| 106 | +FROM base AS vllm-test |
60 | 107 |
|
61 | 108 | WORKDIR /workspace/ |
62 | 109 |
|
63 | | -RUN ln -s /workspace/vllm/tests && ln -s /workspace/vllm/examples && ln -s /workspace/vllm/benchmarks |
| 110 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 111 | + --mount=type=bind,src=requirements/test.txt,target=requirements/test.txt \ |
| 112 | + uv pip install -r requirements/test.txt |
| 113 | + |
| 114 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 115 | + --mount=type=bind,from=vllm-build,src=/workspace/vllm/dist,target=dist \ |
| 116 | + uv pip install dist/*.whl |
| 117 | + |
| 118 | +ADD ./tests/ ./tests/ |
| 119 | +ADD ./examples/ ./examples/ |
| 120 | +ADD ./benchmarks/ ./benchmarks/ |
64 | 121 |
|
65 | 122 | # install development dependencies (for testing) |
66 | | -RUN --mount=type=cache,target=/root/.cache/pip \ |
67 | | - pip install -e tests/vllm_test_utils |
| 123 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 124 | + uv pip install -e tests/vllm_test_utils |
| 125 | + |
| 126 | +ENTRYPOINT ["bash"] |
| 127 | + |
| 128 | +######################### RELEASE IMAGE ######################### |
| 129 | +FROM base AS vllm-openai |
| 130 | + |
| 131 | +WORKDIR /workspace/ |
| 132 | + |
| 133 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 134 | + --mount=type=cache,target=/root/.cache/ccache \ |
| 135 | + --mount=type=bind,from=vllm-build,src=/workspace/vllm/dist,target=dist \ |
| 136 | + uv pip install dist/*.whl |
68 | 137 |
|
69 | 138 | ENTRYPOINT ["python3", "-m", "vllm.entrypoints.openai.api_server"] |
0 commit comments