From 0b0b2607ca5c7d470cd08ff982a844f12faddeb4 Mon Sep 17 00:00:00 2001 From: Zaili Wang <109502517+ZailiWang@users.noreply.github.com> Date: Sat, 29 Nov 2025 02:36:53 +0800 Subject: [PATCH] [CPU] Apply uv as package manager (#14106) --- .github/CI_PERMISSIONS.json | 4 +-- .github/workflows/pr-test-xeon.yml | 4 +-- docker/xeon.Dockerfile | 44 ++++++++++++++++-------------- sgl-kernel/csrc/cpu/CMakeLists.txt | 16 +++++++++++ 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/.github/CI_PERMISSIONS.json b/.github/CI_PERMISSIONS.json index 88e60d547..90f995d34 100644 --- a/.github/CI_PERMISSIONS.json +++ b/.github/CI_PERMISSIONS.json @@ -207,7 +207,7 @@ "can_tag_run_ci_label": true, "can_rerun_failed_ci": true, "cooldown_interval_minutes": 0, - "reason": "top contributor" + "reason": "custom override" }, "ZhengdQin": { "can_tag_run_ci_label": true, @@ -230,7 +230,7 @@ "airMeng": { "can_tag_run_ci_label": true, "can_rerun_failed_ci": true, - "cooldown_interval_minutes": 60, + "cooldown_interval_minutes": 0, "reason": "custom override" }, "alisonshao": { diff --git a/.github/workflows/pr-test-xeon.yml b/.github/workflows/pr-test-xeon.yml index 58e16c9a7..4eb335a2f 100644 --- a/.github/workflows/pr-test-xeon.yml +++ b/.github/workflows/pr-test-xeon.yml @@ -80,13 +80,13 @@ jobs: timeout-minutes: 5 run: | docker exec -w /sglang-checkout/ ci_sglang_xeon \ - bash -c "python3 -c 'import torch; import sgl_kernel; assert torch._C._cpu._is_amx_tile_supported(); assert hasattr(torch.ops.sgl_kernel, \"convert_weight_packed\"); '" + bash -c "source /opt/.venv/bin/activate && python3 -c 'import torch; import sgl_kernel; assert torch._C._cpu._is_amx_tile_supported(); assert hasattr(torch.ops.sgl_kernel, \"convert_weight_packed\"); '" - name: Run unit tests timeout-minutes: 36 run: | docker exec -w /sglang-checkout/ ci_sglang_xeon \ - bash -c "cd ./test/srt && python3 run_suite.py --suite per-commit-cpu --timeout-per-file 1500" + bash -c "source /opt/.venv/bin/activate && cd ./test/srt && python3 run_suite.py --suite per-commit-cpu --timeout-per-file 1500" - name: Change permission timeout-minutes: 2 diff --git a/docker/xeon.Dockerfile b/docker/xeon.Dockerfile index c0d82ffb9..da2f4a0f0 100644 --- a/docker/xeon.Dockerfile +++ b/docker/xeon.Dockerfile @@ -18,35 +18,39 @@ RUN apt-get update && \ vim \ gcc \ g++ \ - make + make \ + libsqlite3-dev \ + google-perftools \ + libtbb-dev \ + libnuma-dev \ + numactl + +WORKDIR /opt + +RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \ + source $HOME/.local/bin/env && \ + uv venv --python 3.12 + +RUN echo -e '[[index]]\nname = "torch"\nurl = "https://download.pytorch.org/whl/cpu"\n\n[[index]]\nname = "torchvision"\nurl = "https://download.pytorch.org/whl/cpu"\n\n[[index]]\nname = "triton"\nurl = "https://download.pytorch.org/whl/cpu"' > .venv/uv.toml + +ENV UV_CONFIG_FILE=/opt/.venv/uv.toml WORKDIR /sgl-workspace - -RUN curl -fsSL -o miniforge.sh -O https://github.com/conda-forge/miniforge/releases/download/25.3.1-0/Miniforge3-25.3.1-0-Linux-x86_64.sh && \ - bash miniforge.sh -b -p ./miniforge3 && \ - rm -f miniforge.sh && \ - . miniforge3/bin/activate && \ - conda install -y libsqlite==3.48.0 gperftools tbb libnuma numactl - -ENV PATH=/sgl-workspace/miniforge3/bin:/sgl-workspace/miniforge3/condabin:${PATH} -ENV PIP_ROOT_USER_ACTION=ignore -ENV CONDA_PREFIX=/sgl-workspace/miniforge3 - -RUN pip config set global.index-url https://download.pytorch.org/whl/cpu && \ - pip config set global.extra-index-url https://pypi.org/simple - -RUN git clone ${SGLANG_REPO} sglang && \ +RUN source $HOME/.local/bin/env && \ + source /opt/.venv/bin/activate && \ + git clone ${SGLANG_REPO} sglang && \ cd sglang && \ git checkout ${VER_SGLANG} && \ cd python && \ cp pyproject_cpu.toml pyproject.toml && \ - pip install . && \ - pip install torch==${VER_TORCH} torchvision==${VER_TORCHVISION} triton==${VER_TRITON} --force-reinstall && \ + uv pip install . && \ + uv pip install torch==${VER_TORCH} torchvision==${VER_TORCHVISION} triton==${VER_TRITON} --force-reinstall && \ cd ../sgl-kernel && \ cp pyproject_cpu.toml pyproject.toml && \ - pip install . + uv pip install . ENV SGLANG_USE_CPU_ENGINE=1 -ENV LD_PRELOAD=/sgl-workspace/miniforge3/lib/libiomp5.so:/sgl-workspace/miniforge3/lib/libtcmalloc.so:/sgl-workspace/miniforge3/lib/libtbbmalloc.so.2 +ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4:/usr/lib/x86_64-linux-gnu/libtbbmalloc.so:/opt/.venv/lib/libiomp5.so +RUN echo 'source /opt/.venv/bin/activate' >> /root/.bashrc WORKDIR /sgl-workspace/sglang diff --git a/sgl-kernel/csrc/cpu/CMakeLists.txt b/sgl-kernel/csrc/cpu/CMakeLists.txt index 421fbedab..220ed3e26 100755 --- a/sgl-kernel/csrc/cpu/CMakeLists.txt +++ b/sgl-kernel/csrc/cpu/CMakeLists.txt @@ -54,6 +54,22 @@ if(DEFINED ENV{CONDA_PREFIX}) message(FATAL_ERROR "libnuma not found in Conda environment at ${CONDA_LIB_DIR}\n" "Please install it using: conda install libnuma numactl\n") endif() +else() + if(DEFINED ENV{VIRTUAL_ENV}) + set(VENV_LIB_DIR "$ENV{VIRTUAL_ENV}/lib") + message(STATUS "Using venv lib dir: ${VENV_LIB_DIR}") + link_directories(${VENV_LIB_DIR}) + set(VENV_INCLUDE_DIR "$ENV{VIRTUAL_ENV}/include") + include_directories(${VENV_INCLUDE_DIR}) + endif() + # Look for libnuma in system env paths + find_library(NUMA_LIB numa) + if(NUMA_LIB) + message(STATUS "Found libnuma: ${NUMA_LIB}") + else() + message(FATAL_ERROR "libnuma not found in system environment\n" + "Please install it using: apt-get install libnuma numactl\n") + endif() endif() file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")