Dockerfile.vllm 17.2 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
15
16
17
18
ARG VLLM_REF="059d4cd"

# After this commit deepgemm API changed
# 1.0.0 -> 2.0.0
ARG DEEPGEMM_REF="03d0be3"
ARG FLASHINF_REF="1d72ed4"
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

35
##################################
36
########## Base Image ############
37
38
##################################

39
FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG} AS base
40

41
42
43
# Redeclare ARCH and ARCH_ALT so they're available in this stage
ARG ARCH
ARG ARCH_ALT
44

45
USER root
46
ARG PYTHON_VERSION=3.12
47
48

RUN apt-get update -y && \
49
    apt-get install -y --no-install-recommends  \
50
    # NIXL build dependencies
51
    cmake \
52
53
    meson \
    ninja-build \
54
    pybind11-dev \
55
    # Rust build dependencies
56
	clang \
57
    libclang-dev \
58
	git \
59
60
61
62
    build-essential \
    protobuf-compiler \
    libssl-dev \
    pkg-config \
63
64
    # Install utilities
    nvtop \
65
    tmux \
66
67
    vim \
    autoconf \
68
    automake \
69
    libtool \
70
71
72
73
74
75
76
77
    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/*
78
79

ARG NIXL_UCX_REF=v1.19.x
80
ARG NIXL_REF=3c47a48955e6f96bd5d4fb43a9d80bb64722f8e4
81

82
83
84
WORKDIR /workspace

### UCX EFA Setup ###
85
86
87
88
RUN rm -rf /opt/hpcx/ucx && \
    rm -rf /usr/local/ucx && \
    echo "Building UCX with reference $NIXL_UCX_REF" && \
    cd /usr/local/src &&                            \
89
    git clone https://github.com/openucx/ucx.git && \
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    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 &&                        \
108
109
    ldconfig

110
111
112
113
ENV LD_LIBRARY_PATH=\
/usr/lib:/usr/local/ucx/lib:\
/usr/local/ucx/lib/ucx:\
$LD_LIBRARY_PATH
114
ENV CPATH=/usr/include
115
ENV PATH=/usr/bin:$PATH
116
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig
117
SHELL ["/bin/bash", "-c"]
118
119
120

WORKDIR /workspace

121
### NIXL SETUP ###
122
# Clone nixl source
123
# TEMP: disable gds backend for arm64
124
125
RUN git clone "https://github.com/ai-dynamo/nixl.git" /opt/nixl && \
    cd /opt/nixl && \
126
127
    git checkout ${NIXL_REF} && \
    if [ "$ARCH" = "arm64" ]; then \
128
129
        cd /opt/nixl && \
        mkdir build && \
130
        meson setup build/ --buildtype=release --prefix=/usr/local/nixl -Ddisable_gds_backend=true -Dgds_path=/usr/local/cuda/targets/sbsa-linux && \
131
132
133
134
135
136
137
138
139
140
141
        cd build/ && \
        ninja && \
        ninja install; \
    else \
        cd /opt/nixl && \
        mkdir build && \
        meson setup build/ --buildtype=release --prefix=/usr/local/nixl && \
        cd build/ && \
        ninja && \
        ninja install; \
    fi
142

143
### NATS & ETCD SETUP ###
144
ENV ETCD_VERSION="v3.5.21"
145
146
147
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 && \
148
149
150
    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
151
152
153
154
ENV PATH=/usr/local/bin/etcd/:$PATH


### VIRTUAL ENVIRONMENT SETUP ###
155
156

# Install uv and create virtualenv
157
ENV VIRTUAL_ENV=/opt/dynamo/venv
158
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
Neelay Shah's avatar
Neelay Shah committed
159
RUN mkdir /opt/dynamo && \
160
    uv venv ${VIRTUAL_ENV} --python 3.12
161
162
163
164

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

165
# Install NIXL Python module
166
# TODO: Move gds_path selection based on arch into NIXL build
167
# TEMP: disable gds backend for arm64
168
169
RUN if [ "$ARCH" = "arm64" ]; then \
        cd /opt/nixl && uv build . --out-dir /workspace/wheels/nixl \
170
        --config-settings=setup-args="-Ddisable_gds_backend=true" \
171
172
173
        --config-settings=setup-args="-Dgds_path=/usr/local/cuda/targets/sbsa-linux"; \
    else \
        cd /opt/nixl && uv build . --out-dir /workspace/wheels/nixl; \
174
175
176
177
    fi && \
    # Install the wheel
    # TODO: Move NIXL wheel install to the wheel_builder stage
    uv pip install /workspace/wheels/nixl/*.whl
178

179
# Install vllm - keep this early in Dockerfile to avoid
180
# rebuilds from unrelated source code changes
181
182
183
184
ARG VLLM_REF
ARG DEEPGEMM_REF
ARG FLASHINF_REF

185
186
ARG MAX_JOBS=16
ENV MAX_JOBS=$MAX_JOBS
187
ENV CUDA_HOME=/usr/local/cuda
188
189
190

# TODO - split vllm, DeepEP, DeepGeMM, PPLX installs
# Should be able to select how you want your build to go
191
RUN --mount=type=bind,source=./container/deps/,target=/tmp/deps \
192
    --mount=type=cache,target=/root/.cache/uv \
193
194
195
196
197
198
199
    cp /tmp/deps/vllm/install_vllm.sh /tmp/install_vllm.sh && \
    chmod +x /tmp/install_vllm.sh && \
    /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

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

201
202
203
204
# Common dependencies
RUN --mount=type=bind,source=./container/deps/requirements.txt,target=/tmp/requirements.txt \
    uv pip install --requirement /tmp/requirements.txt

205
206
### MISC UTILITY SETUP ###

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

213
214
215
216
217
218
219
220
221
222
223
224
225
226
# 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}

227
228
### BUILDS ###

229
230
231
ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
    PATH=/usr/local/cargo/bin:$PATH \
232
    RUST_VERSION=1.87.0
233

234
235
236
237
# Define Rust target based on ARCH_ALT ARG
ARG RUSTARCH=${ARCH_ALT}-unknown-linux-gnu

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

245
246
247
248
249
250
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}

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#######################################
########## 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)
276
277
COPY --from=base --chown=$USER_UID:$USER_GID ${VIRTUAL_ENV} ${VIRTUAL_ENV}
RUN chown $USERNAME:$USERNAME ${VIRTUAL_ENV}
278
279
COPY --from=base --chown=$USERNAME:$USERNAME /usr/local/bin /usr/local/bin

280
# so we can use maturin develop
281
RUN uv pip install maturin[patchelf]
282

283
284
USER $USERNAME
ENV HOME=/home/$USERNAME
285
ENV PYTHONPATH=$HOME/dynamo/deploy/sdk/src:$PYTHONPATH:$HOME/dynamo/components/planner/src:$PYTHONPATH
286
ENV CARGO_TARGET_DIR=$HOME/dynamo/.build/target
287
288
289
290
291
292
293
294
295
296
297
298
299
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"]

##################################
300
##### Wheel Build Image ##########
301
302
##################################

303
304
305
306
# 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
307

308
309
310
311
312
313
314
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
315

316
317
WORKDIR /workspace

318
RUN yum update -y \
Ryan Olson's avatar
Ryan Olson committed
319
    && yum install -y llvm-toolset \
320
    && yum install -y python3.12-devel \
321
322
323
    && yum install -y protobuf-compiler \
    && yum clean all \
    && rm -rf /var/cache/yum
324
325
326

ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
327
328
    CARGO_TARGET_DIR=/workspace/target \
    VIRTUAL_ENV=/opt/dynamo/venv
329

330
331
COPY --from=base $RUSTUP_HOME $RUSTUP_HOME
COPY --from=base $CARGO_HOME $CARGO_HOME
332
# NIXL path default is NIXL_PREFIX=/opt/nvidia/nvda_nixl
Ryan Olson's avatar
Ryan Olson committed
333
COPY --from=base /usr/local/nixl /opt/nvidia/nvda_nixl
334
335
336
COPY --from=base /workspace /workspace
COPY --from=base $VIRTUAL_ENV $VIRTUAL_ENV
ENV PATH=$CARGO_HOME/bin:$VIRTUAL_ENV/bin:$PATH
337

338
339
340
341
342
343
344
345
# 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/
COPY hatch_build.py /workspace/
346

347
348
349
350
# Copy source code
COPY lib/ /workspace/lib/
COPY components /workspace/components
COPY launch /workspace/launch
351
COPY deploy/sdk /workspace/deploy/sdk
352

353
354
355
356
357
RUN cargo build \
	--release \
	--locked \
	--features dynamo-llm/block-manager \
	--workspace
358
359

# Build dynamo wheel
360
RUN uv build --wheel --out-dir /workspace/dist && \
361
    cd /workspace/lib/bindings/python && \
362
363
    uv pip install maturin[patchelf] && \
    maturin build --release --features block-manager --out /workspace/dist && \
364
    if [ "$RELEASE_BUILD" = "true" ]; then \
365
366
367
        # 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; \
368
    fi
369

370
371
372
#######################################
########## CI Minimum Image ###########
#######################################
373
FROM base AS ci_minimum
374

375
ENV DYNAMO_HOME=/workspace
376
377
378
ENV CARGO_TARGET_DIR=/workspace/target

WORKDIR /workspace
379

380
COPY --from=wheel_builder /workspace /workspace
Ryan Olson's avatar
Ryan Olson committed
381
COPY --from=wheel_builder /opt/nvidia/nvda_nixl /opt/nvidia/nvda_nixl
382
383
384
385
386
ARG ARCH_ALT
ENV LD_LIBRARY_PATH=/opt/nvidia/nvda_nixl/lib/${ARCH_ALT}-linux-gnu:\
/opt/nvidia/nvda_nixl/lib/${ARCH_ALT}-linux-gnu/plugin:\
$LD_LIBRARY_PATH

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

390
391
392
# Copy rest of the code
COPY . /workspace

393
394
395
396
397
398
# Build C bindings, creates lib/bindings/c/include
#
# TODO: In theory the 'cargo build' in earlier stage covers this, we "just" need to copy the
# `lib/bindings/c/include` folder that build.rs generated across.
# I couldn't get that to work, hence TODO.
RUN cd /workspace/lib/bindings/c && cargo build --release --locked
399
400
401
402
403
404

# 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/. && \
    cp target/release/libdynamo_llm_capi.so /opt/dynamo/bindings/lib/. && \
405
406
407
408
    cp -r lib/bindings/c/include /opt/dynamo/bindings/.  && \
    cp target/release/dynamo-run /usr/local/bin && \
    cp target/release/metrics /usr/local/bin && \
    cp target/release/mock_worker /usr/local/bin
409
410

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

413
414
RUN uv pip install /workspace/benchmarks

415
416
417
418
419
# 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

420
########################################
421
########## Development Image ###########
422
########################################
423
FROM ci_minimum AS dev
424
425
426
427
428
429
430
431

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

CMD []

####################################
########## Runtime Image ###########
####################################
432
433
434
435

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

WORKDIR /workspace
436
ENV DYNAMO_HOME=/workspace
437
ENV VIRTUAL_ENV=/opt/dynamo/venv
438
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
439

440
441
442
443
# 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 \
444
445
446
447
448
        python3-dev \
        # JIT Kernel Compilation, flashinfer
        ninja-build \
        g++ \
        cuda-toolkit-12-8 && \
449
450
451
452
453
454
455
456
457
    rm -rf /var/lib/apt/lists/*

### COPY BINDINGS ###
# Copy all bindings (wheels, lib, include) from ci_minimum
COPY --from=ci_minimum /opt/dynamo/bindings /opt/dynamo/bindings
### 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/
458
ENV PATH=/usr/local/bin/etcd/:$PATH
459
460

# Copy UCX from base image as plugin for NIXL
461
# Copy NIXL source from wheel_builder image
462
COPY --from=base /usr/local/ucx /usr/local/ucx
463
COPY --from=wheel_builder /opt/nvidia/nvda_nixl /opt/nvidia/nvda_nixl
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# Copies vllm, DeepEP, DeepGEMM, PPLX repos (all editable installs) and nvshmem binaries
COPY --from=base /opt/vllm /opt/vllm
ARG ARCH_ALT
ENV LD_LIBRARY_PATH=\
/opt/vllm/tools/ep_kernels/ep_kernels_workspace/nvshmem_install/lib:\
/opt/nvidia/nvda_nixl/lib/${ARCH_ALT}-linux-gnu:\
/opt/nvidia/nvda_nixl/lib/${ARCH_ALT}-linux-gnu/plugin:\
/usr/local/ucx/lib:\
/usr/local/ucx/lib/ucx:\
$LD_LIBRARY_PATH


# Copy entire venv
# Theres a lot of stuff we'd have to re-compile
# Think its better to just copy
COPY --from=ci_minimum ${VIRTUAL_ENV} ${VIRTUAL_ENV}

# Once UX refactor is merged
# Python components will have been pip installed and packaged in wheel
# Can remove these files
COPY components/ /workspace/components/
COPY tests/ /workspace/tests/
COPY examples/ /workspace/examples/
COPY deploy/ /workspace/deploy/
COPY benchmarks/ /workspace/benchmarks/
490

491
492
493
# 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 && \
494
495
    echo "cat ~/.launch_screen" >> ~/.bashrc && \
    echo "source $VIRTUAL_ENV/bin/activate" >> ~/.bashrc
496

497
ENTRYPOINT ["/opt/nvidia/nvidia_entrypoint.sh"]
498
CMD []