Dockerfile.vllm 16.8 KB
Newer Older
1
2
3
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

4
ARG BASE_IMAGE="nvcr.io/nvidia/cuda-dl-base"
5
6
7
8
9
# FIXME: NCCL will hang with 25.03, so use 25.01 for now
# Please check https://github.com/ai-dynamo/dynamo/pull/1065
# for details and reproducer to manually test if the image
# can be updated to later versions.
ARG BASE_IMAGE_TAG="25.01-cuda12.8-devel-ubuntu24.04"
10
ARG RELEASE_BUILD
11
12
ARG RUNTIME_IMAGE="nvcr.io/nvidia/cuda"
ARG RUNTIME_IMAGE_TAG="12.8.1-runtime-ubuntu24.04"
13

14
# Make sure to update the dependency version in pyproject.toml when updating this
15
16
17
18
19
20
21
ARG VLLM_REF="v0.10.0"
ARG TORCH_BACKEND="cu128"

# Match 0.10.0 vLLM release
# https://github.com/vllm-project/vllm/releases/tag/v0.10.0
ARG DEEPGEMM_REF="1876566"
ARG FLASHINF_REF="v0.2.8rc1"
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Define general architecture ARGs for supporting both x86 and aarch64 builds.
#   ARCH: Used for package suffixes (e.g., amd64, arm64)
#   ARCH_ALT: Used for Rust targets, manylinux suffix (e.g., x86_64, aarch64)
#
# Default values are for x86/amd64:
#   --build-arg ARCH=amd64 --build-arg ARCH_ALT=x86_64
#
# For arm64/aarch64, build with:
#   --build-arg ARCH=arm64 --build-arg ARCH_ALT=aarch64
#
# NOTE: There isn't an easy way to define one of these values based on the other value
# without adding if statements everywhere, so just define both as ARGs for now.
ARG ARCH=amd64
ARG ARCH_ALT=x86_64

38
##################################
39
########## Base Image ############
40
41
##################################

42
FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG} AS base
43

44
# Redeclare ARCH, ARCH_ALT, TORCH_BACKEND so they're available in this stage
45
46
ARG ARCH
ARG ARCH_ALT
47
ARG TORCH_BACKEND
48

49
USER root
50
ARG PYTHON_VERSION=3.12
51
52

RUN apt-get update -y && \
53
    apt-get install -y --no-install-recommends  \
54
    # NIXL build dependencies
55
    cmake \
56
57
    meson \
    ninja-build \
58
    pybind11-dev \
59
    # Rust build dependencies
60
	clang \
61
    libclang-dev \
62
	git \
63
64
65
66
    build-essential \
    protobuf-compiler \
    libssl-dev \
    pkg-config \
67
68
    # Install utilities
    nvtop \
69
    tmux \
70
71
    vim \
    autoconf \
72
    automake \
73
    libtool \
74
75
76
77
78
79
80
81
    net-tools \
    # These headers are missing with the hpcx installer, required
    # by UCX to find RDMA devices
    libibverbs-dev rdma-core ibverbs-utils libibumad-dev \
    libnuma-dev librdmacm-dev ibverbs-providers \
    # For Prometheus
    curl tar ca-certificates && \
    rm -rf /var/lib/apt/lists/*
82
83

ARG NIXL_UCX_REF=v1.19.x
84
ARG NIXL_REF=3c47a48955e6f96bd5d4fb43a9d80bb64722f8e4
85

86
87
88
89
90
91
92
ENV NIXL_SRC_DIR=/opt/nixl
ENV NIXL_PREFIX=/opt/nvidia/nvda_nixl
ARG ARCH_ALT
ENV NIXL_LIB_DIR=$NIXL_PREFIX/lib/${ARCH_ALT}-linux-gnu
ENV NIXL_PLUGIN_DIR=$NIXL_LIB_DIR/plugins
ENV LD_LIBRARY_PATH=$NIXL_LIB_DIR:$NIXL_PLUGIN_DIR:$LD_LIBRARY_PATH

93
94
95
WORKDIR /workspace

### UCX EFA Setup ###
96
97
98
99
RUN rm -rf /opt/hpcx/ucx && \
    rm -rf /usr/local/ucx && \
    echo "Building UCX with reference $NIXL_UCX_REF" && \
    cd /usr/local/src &&                            \
100
    git clone https://github.com/openucx/ucx.git && \
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    cd ucx &&                                       \
    git checkout $NIXL_UCX_REF &&                   \
    ./autogen.sh && ./configure                     \
    --prefix=/usr/local/ucx                         \
    --enable-shared                                 \
    --disable-static                                \
    --disable-doxygen-doc                           \
    --enable-optimizations                          \
    --enable-cma                                    \
    --enable-devel-headers                          \
    --with-cuda=/usr/local/cuda                     \
    --with-verbs                                    \
    --with-efa                                      \
    --with-dm                                       \
    --with-gdrcopy=/usr/local                       \
    --enable-mt &&                                  \
    make -j &&                                      \
    make -j install-strip &&                        \
119
120
    ldconfig

121
122
123
124
ENV LD_LIBRARY_PATH=\
/usr/lib:/usr/local/ucx/lib:\
/usr/local/ucx/lib/ucx:\
$LD_LIBRARY_PATH
125
ENV CPATH=/usr/include
126
ENV PATH=/usr/bin:$PATH
127
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig
128
SHELL ["/bin/bash", "-c"]
129
130
131

WORKDIR /workspace

132
### NIXL SETUP ###
133
# Clone nixl source
134
# TEMP: disable gds backend for arm64
135
136
RUN git clone "https://github.com/ai-dynamo/nixl.git" ${NIXL_SRC_DIR} && \
    cd ${NIXL_SRC_DIR} && \
137
138
    git checkout ${NIXL_REF} && \
    if [ "$ARCH" = "arm64" ]; then \
139
        nixl_build_args="-Ddisable_gds_backend=true"; \
140
    else \
141
142
143
144
145
146
147
        nixl_build_args=""; \
    fi && \
    mkdir build && \
    meson setup build/ --buildtype=release --prefix=$NIXL_PREFIX $nixl_build_args && \
    cd build/ && \
    ninja && \
    ninja install;
148

149
### NATS & ETCD SETUP ###
150
ENV ETCD_VERSION="v3.5.21"
151
152
153
RUN wget --tries=3 --waitretry=5 https://github.com/nats-io/nats-server/releases/download/v2.10.28/nats-server-v2.10.28-${ARCH}.deb && \
    dpkg -i nats-server-v2.10.28-${ARCH}.deb && rm nats-server-v2.10.28-${ARCH}.deb && \
    wget --tries=3 --waitretry=5 https://github.com/etcd-io/etcd/releases/download/$ETCD_VERSION/etcd-$ETCD_VERSION-linux-${ARCH}.tar.gz -O /tmp/etcd.tar.gz && \
154
155
156
    mkdir -p /usr/local/bin/etcd && \
    tar -xvf /tmp/etcd.tar.gz -C /usr/local/bin/etcd --strip-components=1 && \
    rm /tmp/etcd.tar.gz
157
158
159
160
ENV PATH=/usr/local/bin/etcd/:$PATH


### VIRTUAL ENVIRONMENT SETUP ###
161
162

# Install uv and create virtualenv
163
ENV VIRTUAL_ENV=/opt/dynamo/venv
164
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
Neelay Shah's avatar
Neelay Shah committed
165
RUN mkdir /opt/dynamo && \
166
    uv venv ${VIRTUAL_ENV} --python 3.12
167
168
169
170

# Activate virtual environment
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"

171
# Install NIXL Python module
172
# TODO: Move gds_path selection based on arch into NIXL build
173
# TEMP: disable gds backend for arm64
174
RUN if [ "$ARCH" = "arm64" ]; then \
175
        cd ${NIXL_SRC_DIR} && uv build . --out-dir /workspace/wheels/nixl \
176
        --config-settings=setup-args="-Ddisable_gds_backend=true"; \
177
    else \
178
        cd ${NIXL_SRC_DIR} && uv build . --out-dir /workspace/wheels/nixl; \
179
180
181
182
    fi && \
    # Install the wheel
    # TODO: Move NIXL wheel install to the wheel_builder stage
    uv pip install /workspace/wheels/nixl/*.whl
183

184
# Install vllm - keep this early in Dockerfile to avoid
185
# rebuilds from unrelated source code changes
186
187
188
189
ARG VLLM_REF
ARG DEEPGEMM_REF
ARG FLASHINF_REF

190
191
ARG MAX_JOBS=16
ENV MAX_JOBS=$MAX_JOBS
192
ENV CUDA_HOME=/usr/local/cuda
193

194
RUN --mount=type=bind,source=./container/deps/,target=/tmp/deps \
195
    --mount=type=cache,target=/root/.cache/uv \
196
197
198
199
        # TODO - split vllm, DeepEP, DeepGeMM, PPLX installs
        # Should be able to select how you want your build to go
        cp /tmp/deps/vllm/install_vllm.sh /tmp/install_vllm.sh && \
        chmod +x /tmp/install_vllm.sh && \
200
        /tmp/install_vllm.sh --editable --vllm-ref $VLLM_REF --max-jobs $MAX_JOBS --arch $ARCH --installation-dir /opt --deepgemm-ref $DEEPGEMM_REF --flashinf-ref $FLASHINF_REF --torch-backend $TORCH_BACKEND;
201
202
203
204

ENV LD_LIBRARY_PATH=\
/opt/vllm/tools/ep_kernels/ep_kernels_workspace/nvshmem_install/lib:\
$LD_LIBRARY_PATH
205

206
207
208
209
# Common dependencies
RUN --mount=type=bind,source=./container/deps/requirements.txt,target=/tmp/requirements.txt \
    uv pip install --requirement /tmp/requirements.txt

210
211
### MISC UTILITY SETUP ###

212
213
# Install test dependencies
RUN --mount=type=bind,source=./container/deps/requirements.test.txt,target=/tmp/requirements.txt \
214
215
216
    uv pip install --requirement /tmp/requirements.txt && \
    pyright --help > /dev/null 2>&1 && \
    printf "[safe]\n      directory=/workspace\n" > /root/.gitconfig
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Install prometheus
ARG PROM_VERSION=3.4.1
RUN ARCH=$(dpkg --print-architecture) && \
    case "$ARCH" in \
        amd64) PLATFORM=linux-amd64 ;; \
        arm64) PLATFORM=linux-arm64 ;; \
        *) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
    esac && \
    curl -fsSL https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.${PLATFORM}.tar.gz \
    | tar -xz -C /tmp && \
    mv /tmp/prometheus-${PROM_VERSION}.${PLATFORM}/prometheus /usr/local/bin/ && \
    chmod +x /usr/local/bin/prometheus && \
    rm -rf /tmp/prometheus-${PROM_VERSION}.${PLATFORM}

232
233
### BUILDS ###

234
235
236
ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
    PATH=/usr/local/cargo/bin:$PATH \
237
    RUST_VERSION=1.87.0
238

239
240
241
242
# Define Rust target based on ARCH_ALT ARG
ARG RUSTARCH=${ARCH_ALT}-unknown-linux-gnu

# Install Rust using RUSTARCH derived from ARCH_ALT
243
RUN wget --tries=3 --waitretry=5 "https://static.rust-lang.org/rustup/archive/1.28.1/${RUSTARCH}/rustup-init" && \
244
    # TODO: Add SHA check back based on RUSTARCH
245
    chmod +x rustup-init && \
246
    ./rustup-init -y --no-modify-path --profile default --default-toolchain $RUST_VERSION --default-host ${RUSTARCH} && \
247
248
    rm rustup-init && \
    chmod -R a+w $RUSTUP_HOME $CARGO_HOME
249

250
251
252
253
254
255
ARG CARGO_BUILD_JOBS
# Set CARGO_BUILD_JOBS to 16 if not provided
# This is to prevent cargo from building $(nproc) jobs in parallel,
# which might exceed the number of opened files limit.
ENV CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS:-16}

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#######################################
########## Local Development ##########
#######################################

FROM base AS local-dev

# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
# Will use the default ubuntu user, but give sudo access
# Needed so files permissions aren't set to root ownership when writing from inside container

# Don't want ubuntu to be editable, just change uid and gid. User ubuntu is hardcoded in .devcontainer
ENV USERNAME=ubuntu
ARG USER_UID=1000
ARG USER_GID=1000

RUN apt-get update && apt-get install -y sudo gnupg2 gnupg1 \
    && echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    && mkdir -p /home/$USERNAME \
    && chown -R $USERNAME:$USERNAME /home/$USERNAME \
    && rm -rf /var/lib/apt/lists/* \
    && chsh -s /bin/bash $USERNAME

# This is a slow operation (~40s on my cpu)
# Much better than chown -R $USERNAME:$USERNAME /opt/dynamo/venv (~10min on my cpu)
281
282
COPY --from=base --chown=$USER_UID:$USER_GID ${VIRTUAL_ENV} ${VIRTUAL_ENV}
RUN chown $USERNAME:$USERNAME ${VIRTUAL_ENV}
283
284
COPY --from=base --chown=$USERNAME:$USERNAME /usr/local/bin /usr/local/bin

285
# so we can use maturin develop
286
RUN uv pip install maturin[patchelf]
287

288
289
USER $USERNAME
ENV HOME=/home/$USERNAME
290
ENV PYTHONPATH=$HOME/dynamo/deploy/sdk/src:$PYTHONPATH:$HOME/dynamo/components/planner/src:$PYTHONPATH
291
ENV CARGO_TARGET_DIR=$HOME/dynamo/.build/target
292
293
294
295
296
297
298
299
300
301
302
303
304
WORKDIR $HOME

# https://code.visualstudio.com/remote/advancedcontainers/persist-bash-history
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=$HOME/.commandhistory/.bash_history" \
    && mkdir -p $HOME/.commandhistory \
    && touch $HOME/.commandhistory/.bash_history \
    && echo "$SNIPPET" >> "$HOME/.bashrc"

RUN mkdir -p /home/$USERNAME/.cache/

ENTRYPOINT ["/opt/nvidia/nvidia_entrypoint.sh"]

##################################
305
##### Wheel Build Image ##########
306
307
##################################

308
309
310
311
# Redeclare ARCH_ALT ARG so it's available for interpolation in the FROM instruction
ARG ARCH_ALT

FROM quay.io/pypa/manylinux_2_28_${ARCH_ALT} AS wheel_builder
312

313
314
315
316
317
318
319
ARG CARGO_BUILD_JOBS
# Set CARGO_BUILD_JOBS to 16 if not provided
# This is to prevent cargo from building $(nproc) jobs in parallel,
# which might exceed the number of opened files limit.
ENV CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS:-16}
# Use build arg RELEASE_BUILD = true to generate wheels for Python 3.10, 3.11 and 3.12.
ARG RELEASE_BUILD
320

321
322
323
# Keep in sync with the base image.
ENV NIXL_PREFIX=/opt/nvidia/nvda_nixl

324
325
WORKDIR /workspace

326
RUN yum update -y \
Ryan Olson's avatar
Ryan Olson committed
327
    && yum install -y llvm-toolset \
328
    && yum install -y python3.12-devel \
329
330
331
    && yum install -y protobuf-compiler \
    && yum clean all \
    && rm -rf /var/cache/yum
332
333
334

ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
335
336
    CARGO_TARGET_DIR=/workspace/target \
    VIRTUAL_ENV=/opt/dynamo/venv
337

338
339
COPY --from=base $RUSTUP_HOME $RUSTUP_HOME
COPY --from=base $CARGO_HOME $CARGO_HOME
340
COPY --from=base $NIXL_PREFIX $NIXL_PREFIX
341
342
343
COPY --from=base /workspace /workspace
COPY --from=base $VIRTUAL_ENV $VIRTUAL_ENV
ENV PATH=$CARGO_HOME/bin:$VIRTUAL_ENV/bin:$PATH
344

345
346
347
348
349
350
351
# Copy configuration files
COPY pyproject.toml /workspace/
COPY README.md /workspace/
COPY LICENSE /workspace/
COPY Cargo.toml /workspace/
COPY Cargo.lock /workspace/
COPY rust-toolchain.toml /workspace/
352

353
354
355
356
# Copy source code
COPY lib/ /workspace/lib/
COPY components /workspace/components
COPY launch /workspace/launch
357
COPY deploy/sdk /workspace/deploy/sdk
358

359
360
361
362
363
RUN cargo build \
	--release \
	--locked \
	--features dynamo-llm/block-manager \
	--workspace
364
365

# Build dynamo wheel
366
RUN uv build --wheel --out-dir /workspace/dist && \
367
    cd /workspace/lib/bindings/python && \
368
369
    uv pip install maturin[patchelf] && \
    maturin build --release --features block-manager --out /workspace/dist && \
370
    if [ "$RELEASE_BUILD" = "true" ]; then \
371
372
373
        # do not enable KVBM feature, ensure compatibility with lower glibc
        uv run --python 3.11 maturin build --release --out /workspace/dist && \
        uv run --python 3.10 maturin build --release --out /workspace/dist; \
374
    fi
375

376
377
378
#######################################
########## CI Minimum Image ###########
#######################################
379
FROM base AS ci_minimum
380

381
ENV DYNAMO_HOME=/workspace
382
383
384
ENV CARGO_TARGET_DIR=/workspace/target

WORKDIR /workspace
385

386
COPY --from=wheel_builder /workspace /workspace
387
COPY --from=wheel_builder $NIXL_PREFIX $NIXL_PREFIX
388

389
390
391
# Copy Cargo cache to avoid re-downloading dependencies
COPY --from=wheel_builder $CARGO_HOME $CARGO_HOME

392
393
394
# Copy rest of the code
COPY . /workspace

395
396
397
398
# Package the bindings
RUN mkdir -p /opt/dynamo/bindings/wheels && \
    mkdir /opt/dynamo/bindings/lib && \
    cp dist/ai_dynamo*cp312*.whl /opt/dynamo/bindings/wheels/. && \
399
    cp target/release/metrics /usr/local/bin
400
401

RUN uv pip install /workspace/dist/ai_dynamo_runtime*cp312*.whl && \
402
    uv pip install /workspace/dist/ai_dynamo*any.whl
403

404
405
RUN uv pip install /workspace/benchmarks

406
407
408
409
410
# Copy launch banner
RUN --mount=type=bind,source=./container/launch_message.txt,target=/workspace/launch_message.txt \
    sed '/^#\s/d' /workspace/launch_message.txt > ~/.launch_screen && \
    echo "cat ~/.launch_screen" >> ~/.bashrc

411
########################################
412
########## Development Image ###########
413
########################################
414
FROM ci_minimum AS dev
415
416
417
418
419
420
421
422

ENTRYPOINT ["/opt/nvidia/nvidia_entrypoint.sh"]

CMD []

####################################
########## Runtime Image ###########
####################################
423
424
425
426

FROM ${RUNTIME_IMAGE}:${RUNTIME_IMAGE_TAG} AS runtime

WORKDIR /workspace
427
ENV DYNAMO_HOME=/workspace
428
ENV VIRTUAL_ENV=/opt/dynamo/venv
429
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
430

431
432
433
434
435
ARG ARCH_ALT
ENV NIXL_PREFIX=/opt/nvidia/nvda_nixl
ENV NIXL_LIB_DIR=$NIXL_PREFIX/lib/${ARCH_ALT}-linux-gnu
ENV NIXL_PLUGIN_DIR=$NIXL_LIB_DIR/plugins

436
437
438
439
# Install build-essential and python3-dev as apt dependencies
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        build-essential \
440
441
442
443
444
        python3-dev \
        # JIT Kernel Compilation, flashinfer
        ninja-build \
        g++ \
        cuda-toolkit-12-8 && \
445
446
447
448
449
450
    rm -rf /var/lib/apt/lists/*

### COPY NATS & ETCD ###
# Copy nats and etcd from base image
COPY --from=base /usr/bin/nats-server /usr/bin/nats-server
COPY --from=base /usr/local/bin/etcd/ /usr/local/bin/etcd/
451
ENV PATH=/usr/local/bin/etcd/:$PATH
452
453

# Copy UCX from base image as plugin for NIXL
454
# Copy NIXL source from wheel_builder image
455
# Copy dynamo wheels for gitlab artifacts
456
COPY --from=base /usr/local/ucx /usr/local/ucx
457
COPY --from=wheel_builder $NIXL_PREFIX $NIXL_PREFIX
458
COPY --from=wheel_builder /workspace/dist/*.whl wheelhouse/
459

460
# Copies vllm, DeepEP, DeepGEMM, PPLX repos (all editable installs) and nvshmem binaries
461
COPY --from=base /opt/vllm /opt/vllm
462

463
464
ENV LD_LIBRARY_PATH=\
/opt/vllm/tools/ep_kernels/ep_kernels_workspace/nvshmem_install/lib:\
465
466
$NIXL_LIB_DIR:\
$NIXL_PLUGIN_DIR:\
467
468
469
470
471
/usr/local/ucx/lib:\
/usr/local/ucx/lib/ucx:\
$LD_LIBRARY_PATH

# Copy entire venv
472
473
474
475
# Theres a lot of stuff we'd have to re-compile (for arm64)
# TODO: use pip ai-dynamo[vllm] in venv to replicate end user environment
# Copy metrics binary from wheel_builder image, not part of ai-dynamo wheel
COPY --from=ci_minimum /workspace/target/release/metrics /usr/local/bin/metrics
476
477
COPY --from=ci_minimum ${VIRTUAL_ENV} ${VIRTUAL_ENV}

478
479
480
# Keep everything from ci_minimum for mypy and other pre-merge tests
# TODO: Remove this once we have a functional CI image built on top of the runtime image
COPY --from=ci_minimum /workspace/ /workspace/
481

482
483
484
# Copy launch banner
RUN --mount=type=bind,source=./container/launch_message.txt,target=/workspace/launch_message.txt \
    sed '/^#\s/d' /workspace/launch_message.txt > ~/.launch_screen && \
485
486
    echo "cat ~/.launch_screen" >> ~/.bashrc && \
    echo "source $VIRTUAL_ENV/bin/activate" >> ~/.bashrc
487

488
ENTRYPOINT ["/opt/nvidia/nvidia_entrypoint.sh"]
489
CMD []