Skip to content

Commit 3c259e4

Browse files
authored
Merge pull request #31 from pytorch/addDocker
[1/3] step Vllm against pytorch nightly dockerfile
2 parents ef2eb92 + 089d85c commit 3c259e4

File tree

4 files changed

+620
-0
lines changed

4 files changed

+620
-0
lines changed
Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
# The vLLM Dockerfile is used to construct vLLM image that can be directly used for testing
2+
3+
# for torch nightly, cuda >=12.6 is required,
4+
# use 12.8 due to FlashAttention issue with cuda 12.6 (https://github.com/vllm-project/vllm/issues/15435#issuecomment-2775924628)
5+
ARG CUDA_VERSION=12.8.0
6+
#
7+
#################### BASE BUILD IMAGE ####################
8+
# prepare basic build environment
9+
FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu20.04 AS base
10+
ARG CUDA_VERSION=12.8.0
11+
ARG PYTHON_VERSION=3.12
12+
ARG TARGETPLATFORM
13+
ENV DEBIAN_FRONTEND=noninteractive
14+
# Install Python and other dependencies
15+
RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \
16+
&& echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \
17+
&& apt-get update -y \
18+
&& apt-get install -y ccache software-properties-common git curl sudo \
19+
&& add-apt-repository ppa:deadsnakes/ppa \
20+
&& apt-get update -y \
21+
&& apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python${PYTHON_VERSION}-venv \
22+
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 \
23+
&& update-alternatives --set python3 /usr/bin/python${PYTHON_VERSION} \
24+
&& ln -sf /usr/bin/python${PYTHON_VERSION}-config /usr/bin/python3-config \
25+
&& curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} \
26+
&& python3 --version \
27+
&& python3 -m pip --version
28+
# Install uv for faster pip installs
29+
RUN --mount=type=cache,target=/root/.cache/uv \
30+
python3 -m pip install uv
31+
32+
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
33+
# Reference: https://github.com/astral-sh/uv/pull/1694
34+
ENV UV_HTTP_TIMEOUT=500
35+
36+
# Upgrade to GCC 10 to avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92519
37+
# as it was causing spam when compiling the CUTLASS kernels
38+
RUN apt-get install -y gcc-10 g++-10
39+
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 110 --slave /usr/bin/g++ g++ /usr/bin/g++-10
40+
RUN <<EOF
41+
gcc --version
42+
EOF
43+
44+
# Workaround for https://github.com/openai/triton/issues/2507 and
45+
# https://github.com/pytorch/pytorch/issues/107960 -- hopefully
46+
# this won't be needed for future versions of this docker image
47+
# or future versions of triton.
48+
RUN ldconfig /usr/local/cuda-$(echo $CUDA_VERSION | cut -d. -f1,2)/compat/
49+
50+
WORKDIR /workspace
51+
52+
# install build and runtime dependencies
53+
COPY requirements/common.txt requirements/common.txt
54+
COPY use_existing_torch.py use_existing_torch.py
55+
COPY pyproject.toml pyproject.toml
56+
57+
# install build and runtime dependencies without stable torch version
58+
RUN python3 use_existing_torch.py
59+
60+
# install torch nightly
61+
ARG PINNED_TORCH_VERSION
62+
RUN --mount=type=cache,target=/root/.cache/uv \
63+
if [ -n "$PINNED_TORCH_VERSION" ]; then \
64+
pkgs="$PINNED_TORCH_VERSION"; \
65+
else \
66+
pkgs="torch torchaudio torchvision"; \
67+
fi && \
68+
uv pip install --system $pkgs --index-url https://download.pytorch.org/whl/nightly/cu128
69+
70+
RUN --mount=type=cache,target=/root/.cache/uv \
71+
uv pip install --system numba==0.61.2
72+
73+
RUN --mount=type=cache,target=/root/.cache/uv \
74+
uv pip install --system -r requirements/common.txt
75+
76+
# must put before installing xformers, so it can install the correct version of xfomrers.
77+
ARG torch_cuda_arch_list='8.0;8.6;8.9;9.0'
78+
ENV TORCH_CUDA_ARCH_LIST=${torch_cuda_arch_list}
79+
80+
# Build xformers with cuda and torch nightly
81+
ARG max_jobs=64
82+
ENV MAX_JOBS=${max_jobs}
83+
ARG XFORMERS_COMMIT=f2de641ef670510cadab099ce6954031f52f191c
84+
85+
ENV CCACHE_DIR=/root/.cache/ccache
86+
RUN --mount=type=cache,target=/root/.cache/ccache \
87+
--mount=type=cache,target=/root/.cache/uv \
88+
echo 'git clone xformers...' \
89+
&& git clone https://github.com/facebookresearch/xformers.git --recursive \
90+
&& cd xformers \
91+
&& git checkout ${XFORMERS_COMMIT} \
92+
&& git submodule update --init --recursive \
93+
&& echo 'finish git clone xformers...' \
94+
&& rm -rf build \
95+
&& python3 setup.py bdist_wheel --dist-dir=../xformers-dist --verbose \
96+
&& cd .. \
97+
&& rm -rf xformers
98+
99+
RUN --mount=type=cache,target=/root/.cache/uv \
100+
uv pip install --system xformers-dist/*.whl --verbose
101+
102+
# build can take a long time, and the torch nightly version fetched from url can be different in next docker stage.
103+
# track the nightly torch version used in the build, when we set up runtime environment we can make sure the version is the same
104+
RUN uv pip freeze | grep -i '^torch\|^torchvision\|^torchaudio' > torch_build_versions.txt
105+
RUN cat torch_build_versions.txt
106+
107+
# cuda arch list used by torch
108+
# can be useful for `test`
109+
# explicitly set the list to avoid issues with torch 2.2
110+
# see https://github.com/pytorch/pytorch/pull/123243
111+
112+
# Override the arch list for flash-attn to reduce the binary size
113+
ARG vllm_fa_cmake_gpu_arches='80-real;90-real'
114+
ENV VLLM_FA_CMAKE_GPU_ARCHES=${vllm_fa_cmake_gpu_arches}
115+
#################### BASE BUILD IMAGE ####################
116+
117+
#################### WHEEL BUILD IMAGE ####################
118+
FROM base AS build
119+
ARG TARGETPLATFORM
120+
121+
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
122+
# Reference: https://github.com/astral-sh/uv/pull/1694
123+
ENV UV_HTTP_TIMEOUT=500
124+
125+
COPY . .
126+
127+
RUN python3 use_existing_torch.py
128+
129+
RUN --mount=type=cache,target=/root/.cache/uv \
130+
uv pip install --system -r requirements/build.txt
131+
132+
ARG GIT_REPO_CHECK=0
133+
RUN --mount=type=bind,source=.git,target=.git \
134+
if [ "$GIT_REPO_CHECK" != "0" ]; then bash tools/check_repo.sh ; fi
135+
136+
# Max jobs used by Ninja to build extensions
137+
ARG max_jobs=64
138+
ENV MAX_JOBS=${max_jobs}
139+
ARG nvcc_threads=2
140+
ENV NVCC_THREADS=$nvcc_threads
141+
142+
ARG USE_SCCACHE
143+
ARG SCCACHE_BUCKET_NAME=vllm-build-sccache
144+
ARG SCCACHE_REGION_NAME=us-west-2
145+
ARG SCCACHE_S3_NO_CREDENTIALS=0
146+
147+
# if USE_SCCACHE is set, use sccache to speed up compilation
148+
RUN --mount=type=cache,target=/root/.cache/uv \
149+
--mount=type=bind,source=.git,target=.git \
150+
if [ "$USE_SCCACHE" = "1" ]; then \
151+
echo "Installing sccache..." \
152+
&& curl -L -o sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v0.8.1/sccache-v0.8.1-x86_64-unknown-linux-musl.tar.gz \
153+
&& tar -xzf sccache.tar.gz \
154+
&& sudo mv sccache-v0.8.1-x86_64-unknown-linux-musl/sccache /usr/bin/sccache \
155+
&& rm -rf sccache.tar.gz sccache-v0.8.1-x86_64-unknown-linux-musl \
156+
&& export SCCACHE_BUCKET=${SCCACHE_BUCKET_NAME} \
157+
&& export SCCACHE_REGION=${SCCACHE_REGION_NAME} \
158+
&& export SCCACHE_S3_NO_CREDENTIALS=${SCCACHE_S3_NO_CREDENTIALS} \
159+
&& export SCCACHE_IDLE_TIMEOUT=0 \
160+
&& export CMAKE_BUILD_TYPE=Release \
161+
&& sccache --show-stats \
162+
&& python3 setup.py bdist_wheel --dist-dir=dist --py-limited-api=cp38 \
163+
&& sccache --show-stats; \
164+
fi
165+
166+
ENV CCACHE_DIR=/root/.cache/ccache
167+
RUN --mount=type=cache,target=/root/.cache/ccache \
168+
--mount=type=cache,target=/root/.cache/uv \
169+
--mount=type=bind,source=.git,target=.git \
170+
if [ "$USE_SCCACHE" != "1" ]; then \
171+
# Clean any existing CMake artifacts
172+
rm -rf .deps && \
173+
mkdir -p .deps && \
174+
python3 setup.py bdist_wheel --dist-dir=dist --py-limited-api=cp38; \
175+
fi
176+
177+
#################### WHEEL BUILD IMAGE ####################
178+
179+
################### VLLM INSTALLED IMAGE ####################
180+
# Setup clean environment for vLLM and its dependencies for test and api server using ubuntu22.04 with AOT flashinfer
181+
FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu22.04 AS vllm-base
182+
# prepare for environment starts
183+
ARG CUDA_VERSION=12.4.1
184+
ARG PYTHON_VERSION=3.12
185+
WORKDIR /vllm-workspace
186+
ENV DEBIAN_FRONTEND=noninteractive
187+
ARG TARGETPLATFORM
188+
189+
RUN PYTHON_VERSION_STR=$(echo ${PYTHON_VERSION} | sed 's/\.//g') && \
190+
echo "export PYTHON_VERSION_STR=${PYTHON_VERSION_STR}" >> /etc/environment
191+
192+
# Install Python and other dependencies
193+
RUN echo 'tzdata tzdata/Areas select America' | debconf-set-selections \
194+
&& echo 'tzdata tzdata/Zones/America select Los_Angeles' | debconf-set-selections \
195+
&& apt-get update -y \
196+
&& apt-get install -y ccache software-properties-common git curl wget sudo vim python3-pip \
197+
&& apt-get install -y ffmpeg libsm6 libxext6 libgl1 \
198+
&& add-apt-repository ppa:deadsnakes/ppa \
199+
&& apt-get update -y \
200+
&& apt-get install -y python${PYTHON_VERSION} python${PYTHON_VERSION}-dev python${PYTHON_VERSION}-venv libibverbs-dev \
201+
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 \
202+
&& update-alternatives --set python3 /usr/bin/python${PYTHON_VERSION} \
203+
&& ln -sf /usr/bin/python${PYTHON_VERSION}-config /usr/bin/python3-config \
204+
&& curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} \
205+
&& python3 --version && python3 -m pip --version
206+
207+
RUN --mount=type=cache,target=/root/.cache/uv \
208+
python3 -m pip install uv
209+
210+
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
211+
# Reference: https://github.com/astral-sh/uv/pull/1694
212+
ENV UV_HTTP_TIMEOUT=500
213+
214+
# Workaround for https://github.com/openai/triton/issues/2507 and
215+
# https://github.com/pytorch/pytorch/issues/107960 -- hopefully
216+
# this won't be needed for future versions of this docker image
217+
# or future versions of triton.
218+
RUN ldconfig /usr/local/cuda-$(echo $CUDA_VERSION | cut -d. -f1,2)/compat/
219+
220+
# get the nightly torch version used in the build to make sure the version is the same
221+
COPY --from=base /workspace/torch_build_versions.txt ./torch_build_versions.txt
222+
223+
RUN --mount=type=cache,target=/root/.cache/uv \
224+
uv pip install --system $(cat torch_build_versions.txt | xargs) --index-url https://download.pytorch.org/whl/nightly/cu128
225+
226+
# install the vllm wheel
227+
RUN --mount=type=bind,from=build,src=/workspace/dist,target=/vllm-workspace/vllm-dist \
228+
--mount=type=cache,target=/root/.cache/uv \
229+
uv pip install --system vllm-dist/*.whl --verbose
230+
231+
# install xformers again for the new environment
232+
RUN --mount=type=bind,from=base,src=/workspace/xformers-dist,target=/vllm-workspace/xformers-dist \
233+
--mount=type=cache,target=/root/.cache/uv \
234+
uv pip install --system /vllm-workspace/xformers-dist/*.whl --verbose
235+
236+
ARG torch_cuda_arch_list='8.0;8.6;8.9;9.0'
237+
238+
# install package for build flashinfer
239+
# see issue: https://github.com/flashinfer-ai/flashinfer/issues/738
240+
RUN pip install setuptools==75.6.0 packaging==23.2 ninja==1.11.1.3 build==1.2.2.post1
241+
242+
# build flashinfer for torch nightly from source around 10 mins
243+
# release version: v0.2.2.post1
244+
RUN --mount=type=cache,target=/root/.cache/ccache \
245+
--mount=type=cache,target=/root/.cache/uv \
246+
echo "git clone flashinfer..." \
247+
&& git clone --recursive https://github.com/flashinfer-ai/flashinfer.git \
248+
&& cd flashinfer \
249+
&& git checkout v0.2.2.post1 \
250+
&& git submodule update --init --recursive \
251+
&& echo "finish git clone flashinfer..." \
252+
&& rm -rf build \
253+
&& export TORCH_CUDA_ARCH_LIST=${torch_cuda_arch_list} \
254+
&& FLASHINFER_ENABLE_AOT=1 python3 setup.py bdist_wheel --dist-dir=../flashinfer-dist --verbose \
255+
&& cd .. \
256+
&& rm -rf flashinfer
257+
258+
# install flashinfer
259+
RUN --mount=type=cache,target=/root/.cache/uv \
260+
uv pip install --system flashinfer-dist/*.whl --verbose
261+
262+
# install common packages
263+
COPY requirements/common.txt requirements/common.txt
264+
COPY use_existing_torch.py use_existing_torch.py
265+
COPY pyproject.toml pyproject.toml
266+
267+
COPY examples examples
268+
COPY benchmarks benchmarks
269+
COPY ./vllm/collect_env.py .
270+
271+
RUN python3 use_existing_torch.py
272+
RUN --mount=type=cache,target=/root/.cache/uv \
273+
uv pip install --system -r requirements/common.txt
274+
275+
################### VLLM INSTALLED IMAGE ####################
276+
277+
278+
#################### UNITTEST IMAGE #############################
279+
FROM vllm-base as test
280+
COPY tests/ tests/
281+
282+
# install build and runtime dependencies without stable torch version
283+
COPY requirements/nightly_torch_test.txt requirements/nightly_torch_test.txt
284+
285+
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
286+
# Reference: https://github.com/astral-sh/uv/pull/1694
287+
ENV UV_HTTP_TIMEOUT=500
288+
289+
# install development dependencies (for testing)
290+
RUN --mount=type=cache,target=/root/.cache/uv \
291+
uv pip install --system -e tests/vllm_test_utils
292+
293+
# enable fast downloads from hf (for testing)
294+
RUN --mount=type=cache,target=/root/.cache/uv \
295+
uv pip install --system hf_transfer
296+
ENV HF_HUB_ENABLE_HF_TRANSFER 1
297+
298+
RUN --mount=type=cache,target=/root/.cache/uv \
299+
uv pip install --system -r requirements/nightly_torch_test.txt
300+
301+
#################### UNITTEST IMAGE #############################
302+
303+
#################### UNITTEST IMAGE #############################
304+
FROM vllm-base as test-hard
305+
306+
ADD . /vllm-workspace/
307+
308+
# This timeout (in seconds) is necessary when installing some dependencies via uv since it's likely to time out
309+
# Reference: https://github.com/astral-sh/uv/pull/1694
310+
ENV UV_HTTP_TIMEOUT=500
311+
312+
# install development dependencies (for testing)
313+
RUN --mount=type=cache,target=/root/.cache/uv \
314+
uv pip install --system -r requirements/dev.txt
315+
316+
# install development dependencies (for testing)
317+
RUN --mount=type=cache,target=/root/.cache/uv \
318+
uv pip install --system -e tests/vllm_test_utils
319+
320+
# enable fast downloads from hf (for testing)
321+
RUN --mount=type=cache,target=/root/.cache/uv \
322+
uv pip install --system hf_transfer
323+
ENV HF_HUB_ENABLE_HF_TRANSFER 1
324+
325+
# Copy in the v1 package for testing (it isn't distributed yet)
326+
COPY vllm/v1 /usr/local/lib/python3.12/dist-packages/vllm/v1
327+
328+
# doc requires source code
329+
# we hide them inside `test_docs/` , so that this source code
330+
# will not be imported by other tests
331+
RUN mkdir test_docs
332+
RUN mv docs test_docs/
333+
RUN mv vllm test_docs/
334+
335+
#################### UNITTEST IMAGE #############################

0 commit comments

Comments
 (0)