Skip to content

Commit 5b43a76

Browse files
nv-tusharmanv-anantsdillon-cullinan
authored
build: OPS-702: Restructure vLLM dockerfile to use dynamo base container and enable s3 sccache to speed up builds (#2503)
Signed-off-by: Anant Sharma <[email protected]> Co-authored-by: Anant Sharma <[email protected]> Co-authored-by: Dillon Cullinan <[email protected]>
1 parent 8f22214 commit 5b43a76

File tree

4 files changed

+362
-386
lines changed

4 files changed

+362
-386
lines changed

.github/workflows/container-validation-backends.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,14 @@ jobs:
5353
- name: Build image
5454
env:
5555
GITHUB_TOKEN: ${{ secrets.CI_TOKEN }}
56+
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
5657
run: |
57-
./container/build.sh --tag ${{ matrix.framework }}:latest --target ${{ matrix.target }} --framework ${{ matrix.framework }}
58+
./container/build.sh --tag ${{ matrix.framework }}:latest \
59+
--target ${{ matrix.target }} \
60+
--framework ${{ matrix.framework }} \
61+
--use-sccache \
62+
--sccache-bucket ai-dynamo-sccache \
63+
--sccache-region "$AWS_DEFAULT_REGION"
5864
- name: Run pytest
5965
run: |
6066
docker run --rm --gpus all -w /workspace \

container/Dockerfile

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ ARG ENABLE_KVBM=false
2323
ARG ARCH=amd64
2424
ARG ARCH_ALT=x86_64
2525

26+
# sccache configuration
27+
ARG USE_SCCACHE
28+
ARG SCCACHE_BUCKET=""
29+
ARG SCCACHE_REGION=""
30+
2631

2732
##################################
2833
########## Base Image ############
@@ -109,13 +114,39 @@ RUN wget --tries=3 --waitretry=5 https://github.com/etcd-io/etcd/releases/downlo
109114
rm /tmp/etcd.tar.gz
110115
ENV PATH=/usr/local/bin/etcd/:$PATH
111116

117+
# Install sccache if requested
118+
ARG USE_SCCACHE
119+
ARG SCCACHE_BUCKET
120+
ARG SCCACHE_REGION
121+
RUN if [ "$USE_SCCACHE" = "true" ]; then \
122+
SCCACHE_VERSION="v0.8.2" && \
123+
wget --tries=3 --waitretry=5 "https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}/sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" && \
124+
tar -xzf "sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" && \
125+
mv "sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache" /usr/local/bin/ && \
126+
rm -rf sccache*; \
127+
fi
128+
129+
# Set sccache environment variables if USE_SCCACHE is set
130+
ENV SCCACHE_BUCKET=${USE_SCCACHE:+${SCCACHE_BUCKET}} \
131+
SCCACHE_REGION=${USE_SCCACHE:+${SCCACHE_REGION}} \
132+
SCCACHE_S3_KEY_PREFIX=${USE_SCCACHE:+${ARCH}} \
133+
RUSTC_WRAPPER=${USE_SCCACHE:+sccache} \
134+
CMAKE_C_COMPILER_LAUNCHER=${USE_SCCACHE:+sccache} \
135+
CMAKE_CXX_COMPILER_LAUNCHER=${USE_SCCACHE:+sccache} \
136+
CMAKE_CUDA_COMPILER_LAUNCHER=${USE_SCCACHE:+sccache}
137+
112138
### UCX EFA Setup ###
139+
# Keep CC and CXX environment variables set to sccache if USE_SCCACHE is set to true for UCX build since this requirement is specific to UCX
113140
RUN rm -rf /opt/hpcx/ucx && \
114141
rm -rf /usr/local/ucx && \
115142
echo "Building UCX with reference $NIXL_UCX_REF" && \
116143
cd /usr/local/src && \
117144
git clone https://github.com/openucx/ucx.git && \
118145
cd ucx && git checkout $NIXL_UCX_REF && \
146+
CC=${USE_SCCACHE:+sccache gcc} && \
147+
CXX=${USE_SCCACHE:+sccache g++} && \
148+
export CC=${CC} && \
149+
export CXX=${CXX} && \
119150
./autogen.sh && \
120151
./configure \
121152
--prefix=/usr/local/ucx \
@@ -133,6 +164,8 @@ RUN rm -rf /opt/hpcx/ucx && \
133164
--enable-mt && \
134165
make -j$(nproc) && \
135166
make -j$(nproc) install-strip && \
167+
echo "=== sccache stats AFTER UCX build ===" && \
168+
sccache --show-stats && \
136169
echo "/usr/local/ucx/lib" > /etc/ld.so.conf.d/ucx.conf && \
137170
echo "/usr/local/ucx/lib/ucx" >> /etc/ld.so.conf.d/ucx.conf && \
138171
ldconfig && \
@@ -155,6 +188,8 @@ RUN git clone --depth 1 --branch ${NIXL_REF} "https://github.com/ai-dynamo/nixl.
155188
fi && \
156189
meson setup build/ --buildtype=release --prefix=$NIXL_PREFIX $nixl_build_args && \
157190
ninja -C build/ -j$(nproc) && \
191+
echo "=== sccache stats AFTER NIXL build ===" && \
192+
sccache --show-stats && \
158193
ninja -C build/ install && \
159194
echo "$NIXL_LIB_DIR" > /etc/ld.so.conf.d/nixl.conf && \
160195
echo "$NIXL_PLUGIN_DIR" >> /etc/ld.so.conf.d/nixl.conf && \
@@ -218,7 +253,11 @@ COPY --from=base $RUSTUP_HOME $RUSTUP_HOME
218253
COPY --from=base $CARGO_HOME $CARGO_HOME
219254
COPY --from=base $NIXL_PREFIX $NIXL_PREFIX
220255
COPY --from=base $VIRTUAL_ENV $VIRTUAL_ENV
221-
ENV PATH=$CARGO_HOME/bin:$VIRTUAL_ENV/bin:$PATH
256+
257+
ENV PATH=$CARGO_HOME/bin:$VIRTUAL_ENV/bin:$PATH:/usr/local/bin/sccache
258+
259+
# Copy sccache from base stage if it was installed
260+
COPY --from=base /usr/local/bin/sccache /usr/local/bin/sccache
222261

223262
# Copy configuration files first for better layer caching
224263
COPY pyproject.toml README.md LICENSE Cargo.toml Cargo.lock rust-toolchain.toml hatch_build.py /opt/dynamo/
@@ -227,10 +266,22 @@ COPY pyproject.toml README.md LICENSE Cargo.toml Cargo.lock rust-toolchain.toml
227266
COPY lib/ /opt/dynamo/lib/
228267
COPY components/ /opt/dynamo/components/
229268

269+
# Redeclare sccache ARGs for wheel_builder stage
270+
ARG USE_SCCACHE
271+
ARG SCCACHE_BUCKET
272+
ARG SCCACHE_REGION
273+
274+
# Set sccache environment variables if USE_SCCACHE is set
275+
ENV SCCACHE_BUCKET=${USE_SCCACHE:+${SCCACHE_BUCKET}} \
276+
SCCACHE_REGION=${USE_SCCACHE:+${SCCACHE_REGION}} \
277+
SCCACHE_S3_KEY_PREFIX=${USE_SCCACHE:+${ARCH}} \
278+
RUSTC_WRAPPER=${USE_SCCACHE:+sccache}
279+
230280
# Build dynamo wheel
231281
RUN uv build --wheel --out-dir /opt/dynamo/dist && \
232282
cd /opt/dynamo/lib/bindings/python && \
233283
uv pip install maturin[patchelf] && \
284+
echo "RUSTC_WRAPPER set to: $RUSTC_WRAPPER" && \
234285
if [ "$ENABLE_KVBM" = "true" ]; then \
235286
maturin build --release --features block-manager --out /opt/dynamo/dist; \
236287
else \
@@ -240,7 +291,9 @@ RUN uv build --wheel --out-dir /opt/dynamo/dist && \
240291
# do not enable KVBM feature, ensure compatibility with lower glibc
241292
uv run --python 3.11 maturin build --release --out /opt/dynamo/dist && \
242293
uv run --python 3.10 maturin build --release --out /opt/dynamo/dist; \
243-
fi
294+
fi && \
295+
echo "=== sccache stats after dynamo build ===" && \
296+
sccache --show-stats
244297

245298
##############################################
246299
########## Dev entrypoint image ##############

0 commit comments

Comments
 (0)