Dockerfile.cpu 8.34 KB
Newer Older
1
2
3
4
5
6
7
8
# This vLLM Dockerfile is used to build images that can run vLLM on both x86_64 and arm64 CPU platforms.
#
# Supported platforms:
#   - linux/amd64 (x86_64)
#   - linux/arm64 (aarch64)
#
# Use the `--platform` option with `docker buildx build` to specify the target architecture, e.g.:
#   docker buildx build --platform=linux/arm64 -f docker/Dockerfile.cpu .
9
10
11
#
# Build targets:
#   vllm-openai (default): used for serving deployment
12
#   vllm-openai-zen: vLLM from source + zentorch from PyPI via vllm[zen]
13
14
15
16
#   vllm-test: used for CI tests
#   vllm-dev: used for development
#
# Build arguments:
17
#   PYTHON_VERSION=3.13|3.12 (default)|3.11|3.10
18
#   VLLM_CPU_X86=false (default)|true (for cross-compilation)
19
#   VLLM_CPU_ARM_BF16=false (default)|true (for cross-compilation)
20
21
#

22
23
######################### COMMON BASE IMAGE #########################
FROM ubuntu:22.04 AS base-common
24

25
WORKDIR /workspace
26

27
28
ARG PYTHON_VERSION=3.12
ARG PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu"
29

30
31
32
33
# Install minimal dependencies and uv
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    apt-get update -y \
34
    && apt-get install -y --no-install-recommends sudo ccache git curl wget ca-certificates \
35
    gcc-12 g++-12 libtcmalloc-minimal4 libnuma-dev ffmpeg libsm6 libxext6 libgl1 jq lsof make xz-utils \
36
37
38
    && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10 --slave /usr/bin/g++ g++ /usr/bin/g++-12 \
    && curl -LsSf https://astral.sh/uv/install.sh | sh

39
ENV CC=/usr/bin/gcc-12 CXX=/usr/bin/g++-12
40
ENV CCACHE_DIR=/root/.cache/ccache
41
42
ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache

43
44
ENV PATH="/root/.local/bin:$PATH"
ENV VIRTUAL_ENV="/opt/venv"
45
ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python
46
47
RUN uv venv --python ${PYTHON_VERSION} --seed ${VIRTUAL_ENV}
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
48

49
ENV UV_HTTP_TIMEOUT=500
50

51
# Install Python dependencies
52
53
54
55
ENV PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL}
ENV UV_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL}
ENV UV_INDEX_STRATEGY="unsafe-best-match"
ENV UV_LINK_MODE="copy"
56
57
58
59
60

# Copy requirements files for installation
COPY requirements/common.txt requirements/common.txt
COPY requirements/cpu.txt requirements/cpu.txt

61
62
63
RUN --mount=type=cache,target=/root/.cache/uv \
    uv pip install --upgrade pip && \
    uv pip install -r requirements/cpu.txt
64

65
66
67
ARG TARGETARCH
ENV TARGETARCH=${TARGETARCH}

68
69
70
71
######################### x86_64 BASE IMAGE #########################
FROM base-common AS base-amd64

ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4:/opt/venv/lib/libiomp5.so"
72

73
74
######################### arm64 BASE IMAGE #########################
FROM base-common AS base-arm64
75

76
77
78
79
ENV LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libtcmalloc_minimal.so.4"

######################### BASE IMAGE #########################
FROM base-${TARGETARCH} AS base
80

81
RUN echo 'ulimit -c 0' >> ~/.bashrc
82

83
84
######################### BUILD IMAGE #########################
FROM base AS vllm-build
85

86
ARG max_jobs=32
87
88
ENV MAX_JOBS=${max_jobs}

89
ARG GIT_REPO_CHECK=0
90
91
92
# Support for cross-compilation with x86 ISA including AVX2 and AVX512: docker build --build-arg VLLM_CPU_X86="true" ...
ARG VLLM_CPU_X86=0
ENV VLLM_CPU_X86=${VLLM_CPU_X86}
93
94
95
# Support for cross-compilation with ARM BF16 ISA: docker build --build-arg VLLM_CPU_ARM_BF16="true" ...
ARG VLLM_CPU_ARM_BF16=0
ENV VLLM_CPU_ARM_BF16=${VLLM_CPU_ARM_BF16}
96

97
WORKDIR /vllm-workspace
98

99
# Validate build arguments - prevent mixing incompatible ISA flags
100
RUN if [ "$TARGETARCH" = "arm64" ] && [ "$VLLM_CPU_X86" != "0" ]; then \
101
102
103
104
105
106
107
108
        echo "ERROR: Cannot use x86-specific ISA flags (AVX2, AVX512, etc.) when building for ARM64 (--platform=linux/arm64)"; \
        exit 1; \
    fi && \
    if [ "$TARGETARCH" = "amd64" ] && [ "$VLLM_CPU_ARM_BF16" != "0" ]; then \
        echo "ERROR: Cannot use ARM-specific ISA flags (ARM_BF16) when building for x86_64 (--platform=linux/amd64)"; \
        exit 1; \
    fi

109
110
111
# Copy build requirements
COPY requirements/cpu-build.txt requirements/build.txt

112
113
RUN --mount=type=cache,target=/root/.cache/uv \
    uv pip install -r requirements/build.txt
114

115
COPY . .
116
117

RUN if [ "$GIT_REPO_CHECK" != 0 ]; then bash tools/check_repo.sh ; fi
118

119
120
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=cache,target=/root/.cache/ccache \
121
    --mount=type=cache,target=/vllm-workspace/.deps,sharing=locked \
122
    VLLM_TARGET_DEVICE=cpu python3 setup.py bdist_wheel --dist-dir=dist --py-limited-api=cp38
123

124
125
126
######################### TEST DEPS #########################
FROM base AS vllm-test-deps

127
WORKDIR /vllm-workspace
128

129
130
131
132
# Copy test requirements
COPY requirements/test.in requirements/cpu-test.in

RUN \
133
    sed -i '/mamba_ssm/d' requirements/cpu-test.in && \
134
    remove_packages_not_supported_on_aarch64() { \
135
136
137
138
139
140
    case "$(uname -m)" in \
    aarch64|arm64) \
    sed -i '/decord/d' requirements/cpu-test.in; \
    sed -i '/terratorch/d' requirements/cpu-test.in; \
    ;; \
    esac; \
141
142
    }; \
    remove_packages_not_supported_on_aarch64 && \
143
    sed -i 's/^torch==.*/torch==2.10.0/g' requirements/cpu-test.in && \
144
145
    sed -i 's/torchaudio.*/torchaudio/g' requirements/cpu-test.in && \
    sed -i 's/torchvision.*/torchvision/g' requirements/cpu-test.in && \
146
147
148
    uv pip compile requirements/cpu-test.in -o requirements/cpu-test.txt --index-strategy unsafe-best-match --torch-backend cpu

RUN --mount=type=cache,target=/root/.cache/uv \
149
    uv pip install -r requirements/cpu-test.txt
150

151
152
153
######################### DEV IMAGE #########################
FROM vllm-build AS vllm-dev

154
WORKDIR /vllm-workspace
155
156
157

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
158
    apt-get install -y --no-install-recommends vim numactl clangd-14
159
160

RUN ln -s /usr/bin/clangd-14 /usr/bin/clangd
161
162
163

# install development dependencies (for testing)
RUN --mount=type=cache,target=/root/.cache/uv \
164
    uv pip install --no-build-isolation -e tests/vllm_test_utils
165

166
RUN --mount=type=cache,target=/root/.cache/uv \
167
    --mount=type=cache,target=/root/.cache/ccache \
168
    --mount=type=bind,source=.git,target=.git \
169
    VLLM_TARGET_DEVICE=cpu python3 setup.py develop
170

171
COPY --from=vllm-test-deps /vllm-workspace/requirements/cpu-test.txt requirements/test.txt
172

173
174
175
176
177
178
179
RUN --mount=type=cache,target=/root/.cache/uv \
    uv pip install -r requirements/dev.txt && \
    pre-commit install --hook-type pre-commit --hook-type commit-msg

ENTRYPOINT ["bash"]

######################### TEST IMAGE #########################
180
FROM vllm-test-deps AS vllm-test
181

182
WORKDIR /vllm-workspace
183

184
RUN --mount=type=cache,target=/root/.cache/uv \
185
    --mount=type=bind,from=vllm-build,src=/vllm-workspace/dist,target=dist \
186
187
188
189
190
    uv pip install dist/*.whl

ADD ./tests/ ./tests/
ADD ./examples/ ./examples/
ADD ./benchmarks/ ./benchmarks/
191
ADD ./vllm/collect_env.py .
192
ADD ./.buildkite/ ./.buildkite/
193

youkaichao's avatar
youkaichao committed
194
# install development dependencies (for testing)
195
RUN --mount=type=cache,target=/root/.cache/uv \
196
    uv pip install -e tests/vllm_test_utils
197

198
199
200
201
202
203
# enable fast downloads from hf (for testing)
ENV HF_XET_HIGH_PERFORMANCE 1

# increase timeout for hf downloads (for testing)
ENV HF_HUB_DOWNLOAD_TIMEOUT 60

204
205
206
######################### RELEASE IMAGE #########################
FROM base AS vllm-openai

207
WORKDIR /vllm-workspace
208
209
210

RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=cache,target=/root/.cache/ccache \
211
    --mount=type=bind,from=vllm-build,src=/vllm-workspace/dist,target=dist \
212
    uv pip install dist/*.whl
youkaichao's avatar
youkaichao committed
213

214
215
216
217
218
219
220
221
# Add labels to document build configuration
LABEL org.opencontainers.image.title="vLLM CPU"
LABEL org.opencontainers.image.description="vLLM inference engine for CPU platforms"
LABEL org.opencontainers.image.vendor="vLLM Project"
LABEL org.opencontainers.image.source="https://github.com/vllm-project/vllm"

# Build configuration labels
ARG TARGETARCH
222
ARG VLLM_CPU_X86
223
ARG VLLM_CPU_ARM_BF16
224
225
226
ARG PYTHON_VERSION

LABEL ai.vllm.build.target-arch="${TARGETARCH}"
227
LABEL ai.vllm.build.cpu-x86="${VLLM_CPU_X86:-false}"
228
LABEL ai.vllm.build.cpu-arm-bf16="${VLLM_CPU_ARM_BF16:-false}"
229
230
LABEL ai.vllm.build.python-version="${PYTHON_VERSION:-3.12}"

231
ENTRYPOINT ["vllm", "serve"]
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247


######################### ZEN CPU PYPI IMAGE #########################
FROM vllm-openai AS vllm-openai-zen

ARG TARGETARCH

RUN if [ "$TARGETARCH" != "amd64" ]; then \
        echo "ERROR: vllm-openai-amd only supports --platform=linux/amd64"; \
        exit 1; \
    fi

RUN --mount=type=cache,target=/root/.cache/uv \
    uv pip install "vllm[zen]"

ENTRYPOINT ["vllm", "serve"]