Dockerfile.cpu 4.81 KB
Newer Older
1
# This vLLM Dockerfile is used to construct image that can build and run vLLM on x86 CPU platform.
2
3
4
5
6
7
8
9
10
11
12
13
14
#
# Build targets:
#   vllm-openai (default): used for serving deployment
#   vllm-test: used for CI tests
#   vllm-dev: used for development
#
# Build arguments:
#   PYTHON_VERSION=3.12 (default)|3.11|3.10|3.9
#   VLLM_CPU_DISABLE_AVX512=false (default)|true
#

######################### BASE IMAGE #########################
FROM ubuntu:22.04 AS base
15

16
WORKDIR /workspace/
17

18
19
ARG PYTHON_VERSION=3.12
ARG PIP_EXTRA_INDEX_URL="https://download.pytorch.org/whl/cpu"
20

21
22
ENV LD_PRELOAD=""

23
24
25
26
27
28
29
30
31
32
# 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 \
    && apt-get install -y --no-install-recommends ccache git curl wget ca-certificates \
        gcc-12 g++-12 libtcmalloc-minimal4 libnuma-dev ffmpeg libsm6 libxext6 libgl1 \
    && 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

ENV CCACHE_DIR=/root/.cache/ccache
33
34
ENV CMAKE_CXX_COMPILER_LAUNCHER=ccache

35
36
ENV PATH="/root/.local/bin:$PATH"
ENV VIRTUAL_ENV="/opt/venv"
37
ENV UV_PYTHON_INSTALL_DIR=/opt/uv/python
38
39
RUN uv venv --python ${PYTHON_VERSION} --seed ${VIRTUAL_ENV}
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
40

41
ENV UV_HTTP_TIMEOUT=500
42

43
44
45
46
47
48
49
50
51
52
# Install Python dependencies 
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"
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,src=requirements/common.txt,target=requirements/common.txt \
    --mount=type=bind,src=requirements/cpu.txt,target=requirements/cpu.txt \
    uv pip install --upgrade pip && \
    uv pip install -r requirements/cpu.txt
53

54
55
RUN --mount=type=cache,target=/root/.cache/uv \
    uv pip install intel-openmp==2024.2.1 intel_extension_for_pytorch==2.6.0
56

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

59
RUN echo 'ulimit -c 0' >> ~/.bashrc
60

61
62
######################### BUILD IMAGE #########################
FROM base AS vllm-build
63

64
65
66
67
ARG GIT_REPO_CHECK=0
# Support for building with non-AVX512 vLLM: docker build --build-arg VLLM_CPU_DISABLE_AVX512="true" ...
ARG VLLM_CPU_DISABLE_AVX512
ENV VLLM_CPU_DISABLE_AVX512=${VLLM_CPU_DISABLE_AVX512}
68

69
70
WORKDIR /workspace/vllm

71
72
73
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,src=requirements/build.txt,target=requirements/build.txt \
    uv pip install -r requirements/build.txt
74

75
76
77
COPY . .
RUN --mount=type=bind,source=.git,target=.git \
    if [ "$GIT_REPO_CHECK" != 0 ]; then bash tools/check_repo.sh ; fi
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=cache,target=/root/.cache/ccache \
    --mount=type=bind,source=.git,target=.git \
    VLLM_TARGET_DEVICE=cpu python3 setup.py bdist_wheel 

######################### DEV IMAGE #########################
FROM vllm-build AS vllm-dev

WORKDIR /workspace/vllm

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

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

97
RUN --mount=type=cache,target=/root/.cache/uv \
98
    --mount=type=cache,target=/root/.cache/ccache \
99
    --mount=type=bind,source=.git,target=.git \
100
101
102
103
104
105
106
107
108
109
    VLLM_TARGET_DEVICE=cpu python3 setup.py develop 

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 #########################
FROM base AS vllm-test
110

111
112
WORKDIR /workspace/

113
114
115
116
117
118
119
120
121
122
123
RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,src=requirements/test.txt,target=requirements/test.txt \
    uv pip install -r requirements/test.txt

RUN --mount=type=cache,target=/root/.cache/uv \
    --mount=type=bind,from=vllm-build,src=/workspace/vllm/dist,target=dist \
    uv pip install dist/*.whl

ADD ./tests/ ./tests/
ADD ./examples/ ./examples/
ADD ./benchmarks/ ./benchmarks/
124
ADD ./vllm/collect_env.py .
125

youkaichao's avatar
youkaichao committed
126
# install development dependencies (for testing)
127
128
129
130
131
132
133
134
135
136
137
138
139
140
RUN --mount=type=cache,target=/root/.cache/uv \
    uv pip install -e tests/vllm_test_utils 

ENTRYPOINT ["bash"]

######################### RELEASE IMAGE #########################
FROM base AS vllm-openai

WORKDIR /workspace/

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

142
ENTRYPOINT ["python3", "-m", "vllm.entrypoints.openai.api_server"]