"vllm/attention/utils/__init__.py" did not exist on "0b98ba15c744f1dfb0ea4f2135e85ca23d572ae1"
Dockerfile.vllm 20.6 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
19
20
21
22
23
24
25
26
27
28
# 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

29
FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG} AS nixl_base
30
31
32
33
34

# Redeclare ARCH and ARCH_ALT so they're available in this stage
ARG ARCH
ARG ARCH_ALT

35
36
37
38
39
40
41
42
WORKDIR /opt/nixl
# Add a cache hint that only changes when the nixl commit changes
ARG NIXL_COMMIT
# This line acts as a cache key - it only changes when NIXL_COMMIT changes
RUN echo "NIXL commit: ${NIXL_COMMIT}" > /opt/nixl/commit.txt
# Copy the nixl source
COPY --from=nixl . .

43
##################################
44
########## Base Image ############
45
46
##################################

47
FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG} AS base
48

49
50
51
# Redeclare ARCH and ARCH_ALT so they're available in this stage
ARG ARCH
ARG ARCH_ALT
52

53
USER root
54
ARG PYTHON_VERSION=3.12
55
56
57
58

RUN apt-get update -y && \
    apt-get install -y \
    # NIXL build dependencies
59
    cmake \
60
61
    meson \
    ninja-build \
62
    pybind11-dev \
63
    # Rust build dependencies
64
	clang \
65
    libclang-dev \
66
	git \
67
68
    # Install utilities
    nvtop \
69
    tmux \
70
71
72
73
    vim \
    autoconf \
    libtool

74
75
76
77
78
79
80
81
82
# These headers are missing with the hpcx installer, required
# by UCX to find RDMA devices
RUN apt-get update -y && \
    apt-get install -y --no-install-recommends \
    --reinstall libibverbs-dev rdma-core ibverbs-utils libibumad-dev \
    libnuma-dev librdmacm-dev ibverbs-providers

ARG NIXL_UCX_REF=v1.19.x

83
84
85
86
87
WORKDIR /workspace

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

Alec's avatar
Alec committed
111
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/ucx/lib:$LD_LIBRARY_PATH
112
ENV CPATH=/usr/include
113
ENV PATH=/usr/bin:$PATH
114
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig
115
SHELL ["/bin/bash", "-c"]
116
117
118

WORKDIR /workspace

119
### NIXL SETUP ###
120
121
122
# Copy nixl source, and use commit hash as cache hint
COPY --from=nixl_base /opt/nixl /opt/nixl
COPY --from=nixl_base /opt/nixl/commit.txt /opt/nixl/commit.txt
123
124
125
126
127
128
RUN cd /opt/nixl && \
    mkdir build && \
    meson setup build/ --buildtype=release --prefix=/usr/local/nixl && \
    cd build/ && \
    ninja && \
    ninja install
129

130
### NATS & ETCD SETUP ###
131
# nats
132
133
RUN wget --tries=3 --waitretry=5 https://github.com/nats-io/nats-server/releases/download/v2.10.24/nats-server-v2.10.24-${ARCH}.deb && \
    dpkg -i nats-server-v2.10.24-${ARCH}.deb && rm nats-server-v2.10.24-${ARCH}.deb
134
135
# etcd
ENV ETCD_VERSION="v3.5.18"
136
RUN 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 && \
137
138
139
    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
140
141
142
143
ENV PATH=/usr/local/bin/etcd/:$PATH


### VIRTUAL ENVIRONMENT SETUP ###
144
145
146

# Install uv and create virtualenv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
Neelay Shah's avatar
Neelay Shah committed
147
148
RUN mkdir /opt/dynamo && \
    uv venv /opt/dynamo/venv --python 3.12
149
150

# Activate virtual environment
Neelay Shah's avatar
Neelay Shah committed
151
ENV VIRTUAL_ENV=/opt/dynamo/venv
152
153
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"

154
# Install NIXL Python module
155
RUN cd /opt/nixl && uv build . --out-dir /workspace/wheels/nixl
156

157
158
159
160
# Install the wheel
# TODO: Move NIXL wheel install to the wheel_builder stage
RUN uv pip install /workspace/wheels/nixl/*.whl

161
162
# Install patched vllm - keep this early in Dockerfile to avoid
# rebuilds from unrelated source code changes
163
ARG VLLM_REF="0.8.4"
164
ARG VLLM_PATCH="vllm_v${VLLM_REF}-dynamo-kv-disagg-patch.patch"
165
ARG VLLM_PATCHED_PACKAGE_NAME="ai_dynamo_vllm"
166
ARG VLLM_PATCHED_PACKAGE_VERSION="0.8.4.post3"
167
ARG VLLM_MAX_JOBS=4
168
RUN --mount=type=bind,source=./container/deps/,target=/tmp/deps \
169
    --mount=type=cache,target=/root/.cache/uv \
170
171
    mkdir /tmp/vllm && \
    uv pip install pip wheel && \
172
173
174
    # NOTE: vLLM build from source on ARM can take several hours, see VLLM_MAX_JOBS details.
    if [ "$ARCH" = "arm64" ]; then \
        # PyTorch 2.7 supports CUDA 12.8 and aarch64 installs
175
176
        # NIXL has a torch dependency, so need to force-reinstall to install the correct version
        uv pip install torch==2.7.0 torchvision torchaudio --force-reinstall --index-url https://download.pytorch.org/whl/cu128 && \
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
        # Download vLLM source with version matching patch
        git clone --branch v${VLLM_REF} --depth 1 https://github.com/vllm-project/vllm.git /tmp/vllm/vllm-${VLLM_REF} && \
        cd /tmp/vllm/vllm-${VLLM_REF}/ && \
        # Patch vLLM source with dynamo additions
        patch -p1 < /tmp/deps/vllm/${VLLM_PATCH} && \
        # WAR: Set package version check to 'vllm' instead of 'ai_dynamo_vllm' to avoid
        # platform detection issues on ARM install.
        # TODO: Rename package from vllm to ai_dynamo_vllm like x86 path below to remove this WAR.
        sed -i 's/version("ai_dynamo_vllm")/version("vllm")/g' vllm/platforms/__init__.py && \
        # Remove pytorch from vllm install dependencies
        python use_existing_torch.py && \
        # Build/install vllm from source
        uv pip install -r requirements/build.txt && \
        # MAX_JOBS set to avoid running OOM on vllm-flash-attn build, this can
        # significantly impact the overall build time. Each job can take up
        # to -16GB RAM each, so tune according to available system memory.
193
        MAX_JOBS=${VLLM_MAX_JOBS} uv pip install -vv . --no-build-isolation ; \
194
195
196
197
198
199
200
201
202
203
204
205
206
    # Handle x86_64: Download wheel, unpack, setup for later steps
    else \
        python -m pip download --only-binary=:all: --no-deps --dest /tmp/vllm vllm==v${VLLM_REF} && \
        # Patch vLLM pre-built download with dynamo additions
        cd /tmp/vllm && \
        wheel unpack *.whl && \
        cd vllm-${VLLM_REF}/ && \
        patch -p1 < /tmp/deps/vllm/${VLLM_PATCH} && \
        # Rename the package from vllm to ai_dynamo_vllm
        mv vllm-${VLLM_REF}.dist-info ${VLLM_PATCHED_PACKAGE_NAME}-${VLLM_PATCHED_PACKAGE_VERSION}.dist-info && \
        sed -i "s/^Name: vllm/Name: ${VLLM_PATCHED_PACKAGE_NAME}/g" ${VLLM_PATCHED_PACKAGE_NAME}-${VLLM_PATCHED_PACKAGE_VERSION}.dist-info/METADATA && \
        sed -i "s/^Version: ${VLLM_REF}/Version: ${VLLM_PATCHED_PACKAGE_VERSION}/g" ${VLLM_PATCHED_PACKAGE_NAME}-${VLLM_PATCHED_PACKAGE_VERSION}.dist-info/METADATA && \
        # Update wheel tag from linux_${ARCH_ALT} to manylinux1_${ARCH_ALT} in WHEEL file
207
        sed -i "s/Tag: cp38-abi3-linux_${ARCH_ALT}/Tag: cp38-abi3-manylinux1_${ARCH_ALT}/g" ${VLLM_PATCHED_PACKAGE_NAME}-${VLLM_PATCHED_PACKAGE_VERSION}.dist-info/WHEEL && \
208
209
210
211
212
213
        # Also update the tag in RECORD file to match
        sed -i "s/-cp38-abi3-linux_${ARCH_ALT}.whl/-cp38-abi3-manylinux1_${ARCH_ALT}.whl/g" ${VLLM_PATCHED_PACKAGE_NAME}-${VLLM_PATCHED_PACKAGE_VERSION}.dist-info/RECORD && \
        mkdir -p /workspace/dist && \
        wheel pack . --dest-dir /workspace/dist && \
        uv pip install /workspace/dist/${VLLM_PATCHED_PACKAGE_NAME}-*.whl ; \
    fi
214

215
216
217
218
# Common dependencies
RUN --mount=type=bind,source=./container/deps/requirements.txt,target=/tmp/requirements.txt \
    uv pip install --requirement /tmp/requirements.txt

219
220
221
# Install test dependencies
RUN --mount=type=bind,source=./container/deps/requirements.test.txt,target=/tmp/requirements.txt \
    uv pip install --requirement /tmp/requirements.txt
222

223
# ### MISC UTILITY SETUP ###
224
225
226

# Finish pyright install
RUN pyright --help > /dev/null 2>&1
227

228
229
230
231
232
# Enable Git operations in the /workspace directory
RUN printf "[safe]\n      directory=/workspace\n" > /root/.gitconfig

RUN ln -sf /bin/bash /bin/sh

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Install prometheus
ARG PROM_VERSION=3.4.1
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl tar ca-certificates && \
    rm -rf /var/lib/apt/lists/*
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}

250
251
252
253
### BUILDS ###

# Rust build/dev dependencies
RUN apt update -y && \
254
    apt install --no-install-recommends -y \
255
    build-essential \
Biswa Panda's avatar
Biswa Panda committed
256
    protobuf-compiler \
Neelay Shah's avatar
Neelay Shah committed
257
258
    cmake \
    libssl-dev \
259
260
261
262
263
    pkg-config

ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
    PATH=/usr/local/cargo/bin:$PATH \
264
    RUST_VERSION=1.87.0
265

266
267
268
269
# Define Rust target based on ARCH_ALT ARG
ARG RUSTARCH=${ARCH_ALT}-unknown-linux-gnu

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

277
278
279
280
281
282
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}

283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#######################################
########## 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)
COPY --from=base --chown=$USER_UID:$USER_GID /opt/dynamo/venv/ /opt/dynamo/venv/
309
RUN chown $USERNAME:$USERNAME /opt/dynamo/venv
310
311
COPY --from=base --chown=$USERNAME:$USERNAME /usr/local/bin /usr/local/bin

312
# so we can use maturin develop
313
RUN uv pip install maturin[patchelf]
314

315
316
USER $USERNAME
ENV HOME=/home/$USERNAME
317
ENV PYTHONPATH=$HOME/dynamo/deploy/sdk/src:$PYTHONPATH:$HOME/dynamo/components/planner/src:$PYTHONPATH
318
ENV CARGO_TARGET_DIR=$HOME/dynamo/.build/target
319
320
321
322
323
324
325
326
327
328
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/

329
ENV VLLM_KV_CAPI_PATH=$HOME/dynamo/.build/target/debug/libdynamo_llm_capi.so
330
331
332
333

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

##################################
334
##### Wheel Build Image ##########
335
336
##################################

337
338
339
340
# 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
341

342
343
344
345
346
347
348
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
349

350
351
WORKDIR /workspace

352
RUN yum update -y \
Ryan Olson's avatar
Ryan Olson committed
353
    && yum install -y llvm-toolset \
354
    && yum install -y python3.12-devel \
355
356
357
    && yum install -y protobuf-compiler \
    && yum clean all \
    && rm -rf /var/cache/yum
358
359
360

ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
361
362
    CARGO_TARGET_DIR=/workspace/target \
    VIRTUAL_ENV=/opt/dynamo/venv
363

364
365
COPY --from=base $RUSTUP_HOME $RUSTUP_HOME
COPY --from=base $CARGO_HOME $CARGO_HOME
Ryan Olson's avatar
Ryan Olson committed
366
COPY --from=base /usr/local/nixl /opt/nvidia/nvda_nixl
367
368
369
COPY --from=base /workspace /workspace
COPY --from=base $VIRTUAL_ENV $VIRTUAL_ENV
ENV PATH=$CARGO_HOME/bin:$VIRTUAL_ENV/bin:$PATH
370

371
372
373
374
375
376
377
378
# 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/
379

380
381
382
383
# Copy source code
COPY lib/ /workspace/lib/
COPY components /workspace/components
COPY launch /workspace/launch
384
COPY deploy/sdk /workspace/deploy/sdk
385

386
387
388
389
390
RUN cargo build \
	--release \
	--locked \
	--features dynamo-llm/block-manager \
	--workspace
391
392

# Build dynamo wheel
393
RUN uv build --wheel --out-dir /workspace/dist && \
394
    cd /workspace/lib/bindings/python && \
395
396
    uv pip install maturin[patchelf] && \
    maturin build --release --features block-manager --out /workspace/dist && \
397
    if [ "$RELEASE_BUILD" = "true" ]; then \
398
399
400
        # 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; \
401
    fi
402

403
404
405
#######################################
########## CI Minimum Image ###########
#######################################
406
FROM base AS ci_minimum
407

408
ENV DYNAMO_HOME=/workspace
409
410
411
ENV CARGO_TARGET_DIR=/workspace/target

WORKDIR /workspace
412

413
COPY --from=wheel_builder /workspace /workspace
Ryan Olson's avatar
Ryan Olson committed
414
COPY --from=wheel_builder /opt/nvidia/nvda_nixl /opt/nvidia/nvda_nixl
415
416
417
# Copy Cargo cache to avoid re-downloading dependencies
COPY --from=wheel_builder $CARGO_HOME $CARGO_HOME

418
419
420
# Copy rest of the code
COPY . /workspace

421
422
423
424
425
426
# 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
427
428
429
430
431
432

# 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/. && \
433
434
435
436
437
438
    cp -r lib/bindings/c/include /opt/dynamo/bindings/.  && \
    cp target/release/dynamo-run /usr/local/bin && \
    cp target/release/http /usr/local/bin && \
    cp target/release/llmctl /usr/local/bin && \
    cp target/release/metrics /usr/local/bin && \
    cp target/release/mock_worker /usr/local/bin
439
440

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

443
444
RUN uv pip install /workspace/benchmarks

445
446
447
448
449
# 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

450
# Tell vllm to use the Dynamo LLM C API for KV Cache Routing
451
ENV VLLM_KV_CAPI_PATH=/opt/dynamo/bindings/lib/libdynamo_llm_capi.so
452
453
454
455

ARG ARCH_ALT
ENV NIXL_PLUGIN_DIR=/usr/local/nixl/lib/${ARCH_ALT}-linux-gnu/plugins
ENV LD_LIBRARY_PATH=/usr/local/nixl/lib/${ARCH_ALT}-linux-gnu:/usr/local/nixl/lib/${ARCH_ALT}-linux-gnu/plugins:/usr/local/ucx/lib:$LD_LIBRARY_PATH
456

457
########################################
458
########## Development Image ###########
459
########################################
460
FROM ci_minimum AS dev
461
462
463
464
465
466
467
468

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

CMD []

####################################
########## Runtime Image ###########
####################################
469
470
471
472

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

WORKDIR /workspace
473
ENV DYNAMO_HOME=/workspace
474
ENV VIRTUAL_ENV=/opt/dynamo/venv
475
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
476

477
478
479
480
481
482
483
484
485
486
487
488
489
490
# 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 \
        python3-dev && \
    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/
491
ENV PATH=/usr/local/bin/etcd/:$PATH
492
493
494
495
496
497
498
499
500

# Copy UCX from base image as plugin for NIXL
# Copy NIXL source from base image (required for NIXL plugins)
COPY --from=base /usr/local/ucx /usr/local/ucx
COPY --from=base /usr/local/nixl /usr/local/nixl
ARG ARCH_ALT
ENV NIXL_PLUGIN_DIR=/usr/local/nixl/lib/${ARCH_ALT}-linux-gnu/plugins
ENV LD_LIBRARY_PATH=/usr/local/nixl/lib/${ARCH_ALT}-linux-gnu:/usr/local/nixl/lib/${ARCH_ALT}-linux-gnu/plugins:/usr/local/ucx/lib:$LD_LIBRARY_PATH

501
502
# Setup the python environment
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
503
RUN uv venv $VIRTUAL_ENV --python 3.12 && \
504
505
    echo "source $VIRTUAL_ENV/bin/activate" >> ~/.bashrc

506
507
508
509
# Common dependencies
RUN --mount=type=bind,source=./container/deps/requirements.txt,target=/tmp/requirements.txt \
    uv pip install --requirement /tmp/requirements.txt

510
511
512
513
514
515
516
517
518
# Install test dependencies
#TODO: Remove this once we have a functional ci_minimum image built on top of the runtime image
RUN --mount=type=bind,source=./container/deps/requirements.test.txt,target=/tmp/requirements.txt \
    uv pip install --requirement /tmp/requirements.txt

#TODO: Remove this once we have a functional ci_minimum image built on top of the runtime image
COPY . /workspace
RUN uv pip install /workspace/benchmarks

519
520
# Install the wheels and symlink executables to /usr/local/bin so dynamo components can use them
# Dynamo components currently do not have the VIRTUAL_ENV in their PATH, so we need to symlink the executables
521
522
#Copy NIXL and Dynamo wheels into wheelhouse
COPY --from=base /workspace/wheels/nixl/*.whl wheelhouse/
523
COPY --from=wheel_builder /workspace/dist/*.whl wheelhouse/
524
RUN uv pip install ai-dynamo[vllm] --find-links wheelhouse && \
525
    uv pip install nixl --find-links wheelhouse && \
526
    ln -sf $VIRTUAL_ENV/bin/* /usr/local/bin/
527
528
529

# Tell vllm to use the Dynamo LLM C API for KV Cache Routing
ENV VLLM_KV_CAPI_PATH="/opt/dynamo/bindings/lib/libdynamo_llm_capi.so"
530

531
532
533
534
535
536
# 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


537
ENTRYPOINT ["/opt/nvidia/nvidia_entrypoint.sh"]
538
CMD []