Skip to content

Commit 6cdda03

Browse files
authored
build: Add support for sglang runtime image (#1770)
1 parent 30e5c35 commit 6cdda03

File tree

1 file changed

+65
-15
lines changed

1 file changed

+65
-15
lines changed

container/Dockerfile.sglang

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,32 @@ RUN apt-get update -y && \
7474

7575
WORKDIR /workspace
7676

77-
### TODO: Bring back UCX EFA setup once we are confident it works with IB devices
77+
### UCX EFA Setup ###
78+
RUN rm -rf /opt/hpcx/ucx
79+
RUN rm -rf /usr/local/ucx
80+
RUN cd /usr/local/src && \
81+
git clone https://github.com/openucx/ucx.git && \
82+
cd ucx && \
83+
git checkout v1.19.x && \
84+
./autogen.sh && ./configure \
85+
--prefix=/usr/local/ucx \
86+
--enable-shared \
87+
--disable-static \
88+
--disable-doxygen-doc \
89+
--enable-optimizations \
90+
--enable-cma \
91+
--enable-devel-headers \
92+
--with-cuda=/usr/local/cuda \
93+
--with-verbs \
94+
--with-efa \
95+
--with-dm \
96+
--with-gdrcopy=/usr/local \
97+
--enable-mt && \
98+
make -j && \
99+
make -j install-strip && \
100+
ldconfig
101+
102+
ENV LD_LIBRARY_PATH=/usr/lib:/usr/local/ucx/lib:$LD_LIBRARY_PATH
78103
ENV CPATH=/usr/include:$CPATH
79104
ENV PATH=/usr/bin:$PATH
80105
ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH
@@ -127,21 +152,22 @@ ENV VIRTUAL_ENV=/opt/dynamo/venv
127152
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
128153

129154
# Install NIXL Python module
130-
# TODO: Move gds_path selection based on arch into NIXL build
131-
RUN if [ "$ARCH" = "arm64" ]; then \
132-
cd /opt/nixl && uv pip install . --config-settings=setup-args="-Dgds_path=/usr/local/cuda/targets/sbsa-linux"; \
133-
else \
134-
cd /opt/nixl && uv pip install . ; \
135-
fi
155+
RUN cd /opt/nixl && uv build . --out-dir /workspace/wheels/nixl
156+
157+
# Install the wheel
158+
# TODO: Move NIXL wheel install to the wheel_builder stage
159+
RUN uv pip install /workspace/wheels/nixl/*.whl
136160

137161
# Install sglang
138-
# This commit references a NIXL fix that was releasted after the 0.4.8.post1 release https://github.com/sgl-project/sglang/pull/7330
162+
# This commit references a NIXL fix that was released after the 0.4.8.post1 release https://github.com/sgl-project/sglang/pull/7330
163+
#TODO: Built wheel should become an artifact which can be cached and reused in subsequent builds
139164
ARG SGLANG_COMMIT="bb9b608c86ebad7d9d01e29fe058bc184dc7285f"
140165
RUN --mount=type=cache,target=/root/.cache/uv \
141166
cd /opt && \
142167
git clone https://github.com/sgl-project/sglang.git && \
143168
cd sglang && \
144169
git checkout ${SGLANG_COMMIT} && \
170+
# Install in editable mode for development
145171
uv pip install -e "python[all]"
146172

147173
# Set env var that allows for forceful shutdown of inflight requests in SGL's TokenizerManager
@@ -380,20 +406,43 @@ ENV DYNAMO_HOME=/workspace
380406
ENV VIRTUAL_ENV=/opt/dynamo/venv
381407
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
382408

409+
### COPY NATS & ETCD ###
410+
# Copy nats and etcd from base image
411+
COPY --from=base /usr/bin/nats-server /usr/bin/nats-server
412+
COPY --from=base /usr/local/bin/etcd/ /usr/local/bin/etcd/
413+
ENV PATH=/usr/local/bin/etcd/:$PATH
414+
415+
# Copy UCX from base image as plugin for NIXL
416+
# Copy NIXL source from base image (required for NIXL plugins)
417+
COPY --from=base /usr/local/ucx /usr/local/ucx
418+
COPY --from=base /usr/local/nixl /usr/local/nixl
419+
ARG ARCH_ALT
420+
ENV NIXL_PLUGIN_DIR=/usr/local/nixl/lib/${ARCH_ALT}-linux-gnu/plugins
421+
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
422+
383423
# Setup the python environment
384424
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
385425
RUN apt-get update && \
386-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends python3-dev && \
426+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends build-essential python3-dev libnuma-dev && \
387427
rm -rf /var/lib/apt/lists/* && \
388428
uv venv $VIRTUAL_ENV --python 3.12 && \
389429
echo "source $VIRTUAL_ENV/bin/activate" >> ~/.bashrc
390430

431+
# Install SGLang and related packages (sgl-kernel, einops, sentencepiece) since they are not included in the runtime wheel
432+
# https://github.com/sgl-project/sglang/blob/v0.4.9.post1/python/pyproject.toml#L18-51
433+
RUN uv pip install "sglang[runtime_common]>=0.4.9.post1" && \
434+
uv pip install einops && \
435+
uv pip install sgl-kernel==0.2.4 && \
436+
uv pip install sentencepiece
437+
391438
# Install the wheels and symlink executables to /usr/local/bin so dynamo components can use them
392439
# Dynamo components currently do not have the VIRTUAL_ENV in their PATH, so we need to symlink the executables
393440
COPY --from=wheel_builder /workspace/dist/*.whl wheelhouse/
394-
RUN uv pip install ai-dynamo[vllm] --find-links wheelhouse && \
395-
ln -sf $VIRTUAL_ENV/bin/* /usr/local/bin/ && \
396-
rm -r wheelhouse
441+
COPY --from=base /workspace/wheels/nixl/*.whl wheelhouse/
442+
RUN uv pip install ai-dynamo --find-links wheelhouse && \
443+
uv pip install ai-dynamo-runtime --find-links wheelhouse && \
444+
uv pip install nixl --find-links wheelhouse && \
445+
ln -sf $VIRTUAL_ENV/bin/* /usr/local/bin/
397446

398447
# Tell vllm to use the Dynamo LLM C API for KV Cache Routing
399448
ENV VLLM_KV_CAPI_PATH="/opt/dynamo/bindings/lib/libdynamo_llm_capi.so"
@@ -403,8 +452,9 @@ RUN --mount=type=bind,source=./container/launch_message.txt,target=/workspace/la
403452
sed '/^#\s/d' /workspace/launch_message.txt > ~/.launch_screen && \
404453
echo "cat ~/.launch_screen" >> ~/.bashrc
405454

406-
# Copy examples
407-
COPY ./examples examples/
455+
# Copy examples and set up Python path
456+
COPY . /workspace
457+
ENV PYTHONPATH=/workspace/examples/sglang/utils:$PYTHONPATH
408458

409-
ENTRYPOINT [ "/usr/bin/bash" ]
459+
ENTRYPOINT ["/opt/nvidia/nvidia_entrypoint.sh"]
410460
CMD []

0 commit comments

Comments
 (0)