diff --git a/docker/Dockerfile b/docker/Dockerfile index 9b222d5f5..c4576606e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -43,15 +43,14 @@ RUN --mount=type=cache,target=/var/cache/apt,id=base-apt \ && apt install -y --no-install-recommends python3.12-full python3.12-dev \ && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2 \ && update-alternatives --set python3 /usr/bin/python3.12 \ - && wget -q https://bootstrap.pypa.io/get-pip.py \ - && python3 get-pip.py --break-system-packages \ - && rm get-pip.py \ - # Allow pip to install packages globally (PEP 668 workaround for Ubuntu 24.04) - && python3 -m pip config set global.break-system-packages true \ # Fix for apt-add-repository && cd /usr/lib/python3/dist-packages/ \ && ln -s apt_pkg.cpython-312-*-linux-gnu.so apt_pkg.so +# create virtual env for sglang to avoid conflict with system python packages +RUN python3 -m venv /opt/sglang +ENV PATH="/opt/sglang/bin:${PATH}" + # Install system dependencies (organized by category for better caching) RUN --mount=type=cache,target=/var/cache/apt,id=base-apt \ apt-get update && apt-get install -y --no-install-recommends \ @@ -313,12 +312,12 @@ RUN --mount=type=cache,target=/root/.cache/pip \ && mkdir -p /flashinfer_jit_output \ # flashinfer-cubin is CUDA-version-agnostic, unlike jit-cache, so its index-url has no cu${CUINDEX} suffix && python3 -m pip install flashinfer-cubin==${FLASHINFER_VERSION} --index-url https://flashinfer.ai/whl \ - && cp -r /usr/local/lib/python3.12/dist-packages/flashinfer_cubin /flashinfer_jit_output/ \ - && cp -r /usr/local/lib/python3.12/dist-packages/flashinfer_cubin-*.dist-info /flashinfer_jit_output/ \ + && cp -r /opt/sglang/lib/python3.12/site-packages/flashinfer_cubin /flashinfer_jit_output/ \ + && cp -r /opt/sglang/lib/python3.12/site-packages/flashinfer_cubin-*.dist-info /flashinfer_jit_output/ \ && if [ "$INSTALL_FLASHINFER_JIT_CACHE" = "1" ]; then \ python3 -m pip install flashinfer-jit-cache==${FLASHINFER_VERSION} --index-url https://flashinfer.ai/whl/cu${CUINDEX} \ - && cp -r /usr/local/lib/python3.12/dist-packages/flashinfer_jit_cache /flashinfer_jit_output/ \ - && cp -r /usr/local/lib/python3.12/dist-packages/flashinfer_jit_cache-*.dist-info /flashinfer_jit_output/ ; \ + && cp -r /opt/sglang/lib/python3.12/site-packages/flashinfer_jit_cache /flashinfer_jit_output/ \ + && cp -r /opt/sglang/lib/python3.12/site-packages/flashinfer_jit_cache-*.dist-info /flashinfer_jit_output/ ; \ fi ######################################################## @@ -432,7 +431,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \ fi && rm -rf /tmp/wheels/hpc-ops # Copy flashinfer cubin (always) and jit-cache (if installed) packages -COPY --from=flashinfer_cache /flashinfer_jit_output/ /usr/local/lib/python3.12/dist-packages/ +COPY --from=flashinfer_cache /flashinfer_jit_output/ /opt/sglang/lib/python3.12/site-packages/ # Copy dev tools COPY --from=devtools_builder /tools/diff-so-fancy /usr/local/bin/ @@ -644,11 +643,11 @@ RUN --mount=type=cache,target=/root/.cache/pip \ [ "$success" = "1" ] ) \ && mkdir -p /root/.cache/huggingface /root/.cache/sglang \ && ( if [ -f python/kernels.lock ]; then mv python/kernels.lock /root/.cache/sglang/; fi ) \ - && ( find /usr/local/lib/python3.12/dist-packages -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true ) + && ( find /opt/sglang/lib/python3.12/site-packages -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true ) # Install pre-built gateway artifacts from parallel builder -COPY --from=gateway_builder /build/sgl-model-gateway-bin /usr/local/bin/sgl-model-gateway +COPY --from=gateway_builder /build/sgl-model-gateway-bin /opt/sglang/bin/sgl-model-gateway COPY --from=gateway_builder /build/gateway_wheels /tmp/gateway_wheels RUN --mount=type=cache,target=/root/.cache/pip \ python3 -m pip install --force-reinstall /tmp/gateway_wheels/*.whl \ @@ -753,14 +752,13 @@ RUN --mount=type=cache,target=/var/cache/apt,id=runtime-apt \ && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 2 \ && update-alternatives --set python3 /usr/bin/python3.12 \ && ln -sf /usr/bin/python3.12 /usr/bin/python \ - && wget -q https://bootstrap.pypa.io/get-pip.py \ - && python3 get-pip.py --break-system-packages \ - && rm get-pip.py \ - # Allow pip to install packages globally (PEP 668 workaround for Ubuntu 24.04) - && python3 -m pip config set global.break-system-packages true \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean +# create virtual env for sglang to avoid conflict with system python packages +RUN python3 -m venv /opt/sglang +ENV PATH="/opt/sglang/bin:${PATH}" + # Set up locale RUN apt-get update && apt-get install -y --no-install-recommends locales \ && locale-gen en_US.UTF-8 \ @@ -782,19 +780,19 @@ RUN --mount=type=cache,target=/var/cache/apt,id=runtime-apt \ && rm -rf /var/lib/apt/lists/* # Copy Python site-packages from framework (already cleaned of __pycache__/tests/pyc files) -COPY --from=framework_final /usr/local/lib/python3.12/dist-packages /usr/local/lib/python3.12/dist-packages +COPY --from=framework_final /opt/sglang/lib/python3.12/site-packages /opt/sglang/lib/python3.12/site-packages # Copy SGLang workspace COPY --from=framework_final /sgl-workspace /sgl-workspace # Copy sgl-model-gateway binary -COPY --from=framework_final /usr/local/bin/sgl-model-gateway /usr/local/bin/sgl-model-gateway +COPY --from=framework_final /opt/sglang/bin/sgl-model-gateway /opt/sglang/bin/sgl-model-gateway # Copy sglang binary -COPY --from=framework_final /usr/local/bin/sglang /usr/local/bin/sglang +COPY --from=framework_final /opt/sglang/bin/sglang /opt/sglang/bin/sglang # Copy py-spy binary -COPY --from=framework_final /usr/local/bin/py-spy /usr/local/bin/py-spy +COPY --from=framework_final /opt/sglang/bin/py-spy /opt/sglang/bin/py-spy # Copy cache for kernels from kernels community COPY --from=framework_final /root/.cache/huggingface /root/.cache/huggingface