Skip to content

Commit f5fe3af

Browse files
authored
Molly/enable xpu ci (sgl-project#5)
* enable ci * Update pr-test-xpu.yml * Update pr-test-xpu.yml * fix typo * enable ci test and format fix
1 parent d3f063d commit f5fe3af

22 files changed

+245
-22
lines changed

.github/workflows/lint.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Lint
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Set up Python
12+
uses: actions/setup-python@v4
13+
with:
14+
python-version: "3.10"
15+
16+
- name: Install pre-commit hook
17+
run: |
18+
python -m pip install pre-commit
19+
pre-commit install
20+
21+
- name: Linting
22+
run: pre-commit run --all-files --show-diff-on-failure

.github/workflows/pr-test-xpu.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: PR Test (XPU)
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: pr-test-xpu-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
build-and-test:
14+
if: (github.repository == 'sgl-project/sgl-kernel-xpu' || github.event_name == 'pull_request') &&
15+
github.event.pull_request.draft == false
16+
runs-on: sglang-pvc
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v2
25+
26+
- name: Build Docker image
27+
run: |
28+
docker build --no-cache --progress=plain -f Dockerfile.xpu_kernel -t xpu_sglang:pvc .
29+
30+
31+
- name: Run container
32+
run: |
33+
docker run -dt \
34+
--device /dev/dri/ \
35+
--name ci_sglang_xpu \
36+
-e HF_TOKEN=$(cat ~/huggingface_token.txt) \
37+
xpu_sglang:pvc
38+
39+
- name: Install Dependency
40+
timeout-minutes: 20
41+
run: |
42+
docker exec ci_sglang_xpu /miniforge3/envs/py3.10/bin/python3 -m pip install --upgrade pip
43+
docker exec ci_sglang_xpu /miniforge3/envs/py3.10/bin/python3 -m pip install pytest expecttest ray huggingface_hub
44+
docker exec ci_sglang_xpu /bin/bash -c '/miniforge3/envs/py3.10/bin/huggingface-cli login --token ${HF_TOKEN} '
45+
docker exec ci_sglang_xpu /bin/bash -c "ln -sf /miniforge3/envs/py3.10/bin/python3 /usr/bin/python3"
46+
47+
- name: Run Sglang Kernel Cases
48+
timeout-minutes: 20
49+
run: |
50+
docker exec -w /root/sglang ci_sglang_xpu \
51+
/bin/bash -c "cd /root/sglang/sgl-kernel-xpu/tests && python3 -m pytest -v -s test_awq_dequant.py"
52+
53+
- name: Run E2E Bfloat16 tests
54+
timeout-minutes: 20
55+
run: |
56+
echo "[PlaceHolder for E2E Test...]"
57+
58+
- name: Run E2E Qunatization tests
59+
timeout-minutes: 20
60+
run: |
61+
echo "[PlaceHolder for E2E Test...]"
62+
63+
- name: Cleanup container
64+
if: always()
65+
run: |
66+
docker rm -f ci_sglang_xpu || true
67+
68+
finish:
69+
if: always()
70+
needs: [build-and-test]
71+
runs-on: sglang-pvc
72+
steps:
73+
- name: Check job status
74+
run: |
75+
if [ "${{ needs.build-and-test.result }}" != "success" ]; then
76+
echo "Job failed with result: ${{ needs.build-and-test.result }}"
77+
echo "BUILD_LOG=$(cat build.log)" >> $GITHUB_ENV
78+
exit 1
79+
fi
80+
echo "All jobs completed successfully"
81+
exit 0

.pre-commit-config.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
default_stages: [pre-commit, pre-push, manual]
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: check-symlinks
8+
- id: destroyed-symlinks
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-yaml
12+
args: [--allow-multiple-documents]
13+
- id: check-toml
14+
- id: check-ast
15+
- id: check-added-large-files
16+
- id: check-merge-conflict
17+
- id: check-shebang-scripts-are-executable
18+
- id: detect-private-key
19+
- id: debug-statements
20+
- id: no-commit-to-branch
21+
- repo: https://github.com/PyCQA/isort
22+
rev: 5.13.2
23+
hooks:
24+
- id: isort
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
rev: v0.11.7
27+
hooks:
28+
- id: ruff
29+
args: [--select=F401, --fixable=F401]
30+
files: ^(benchmark/|docs/|examples/)
31+
exclude: \.ipynb$
32+
- repo: https://github.com/psf/black
33+
rev: 24.10.0
34+
hooks:
35+
- id: black-jupyter
36+
- repo: https://github.com/codespell-project/codespell
37+
rev: v2.4.1
38+
hooks:
39+
- id: codespell
40+
additional_dependencies: ['tomli']
41+
args: ['--toml', 'python/pyproject.toml', '-L', 'cann']
42+
exclude: |
43+
(?x)^(
44+
test/srt/test_reasoning_parser\.py|
45+
docs/advanced_features/vlm_query\.ipynb
46+
)$
47+
- repo: https://github.com/pre-commit/mirrors-clang-format
48+
rev: v18.1.8
49+
hooks:
50+
- id: clang-format
51+
types_or: [c++, cuda]
52+
args: [--style=file, --verbose]
53+
- repo: https://github.com/kynan/nbstripout
54+
rev: 0.8.1
55+
hooks:
56+
- id: nbstripout
57+
args:
58+
- '--keep-output'
59+
- '--extra-keys=metadata.kernelspec metadata.language_info.version'

Dockerfile.xpu_kernel

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# If the device is Battlemage, we need to set UBUNTU_VERSION to 24.10
2+
3+
# Usage: docker build --build-arg UBUNTU_VERSION=24.04 --build-arg PYTHON_VERSION=3.10 -t sglang:xpu_kernel -f Dockerfile.xpu --no-cache .
4+
5+
6+
# Set default Ubuntu version to 24.04
7+
FROM intel/deep-learning-essentials:2025.1.3-0-devel-ubuntu24.04
8+
9+
ENV DEBIAN_FRONTEND=noninteractive
10+
11+
# Define build arguments
12+
ARG PYTHON_VERSION=3.10
13+
14+
# Set environment variables
15+
16+
ARG SG_LANG_REPO=https://github.com/sgl-project/sglang.git
17+
ARG SG_LANG_BRANCH=main
18+
19+
ARG SG_LANG_KERNEL_REPO=https://github.com/sgl-project/sgl-kernel-xpu.git
20+
ARG SG_LANG_KERNEL_BRANCH=main
21+
22+
# Install Miniforge & PyTorch/Triton & build vllm/SGlang from source
23+
RUN curl -fsSL -v -o miniforge.sh -O https://github.com/conda-forge/miniforge/releases/download/25.1.1-0/Miniforge3-Linux-x86_64.sh && \
24+
bash miniforge.sh -b -p ./miniforge3 && \
25+
rm miniforge.sh && \
26+
. ./miniforge3/bin/activate && \
27+
conda create -y -n py${PYTHON_VERSION} python=${PYTHON_VERSION} && conda activate py${PYTHON_VERSION} && \
28+
conda install pip && \
29+
echo ". /miniforge3/bin/activate; conda activate py${PYTHON_VERSION}; . /opt/intel/oneapi/setvars.sh; cd /root/" >> /root/.bashrc;
30+
31+
# Install Miniforge & PyTorch/Triton & build vllm/SGlang from source
32+
RUN apt-get update && \
33+
apt install -y intel-ocloc
34+
35+
RUN --mount=type=secret,id=github_token \
36+
cd /root && \
37+
. /miniforge3/bin/activate && \
38+
conda activate py${PYTHON_VERSION} && \
39+
# . /opt/intel/oneapi/setvars.sh --force && \
40+
# Install Torch
41+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/xpu
42+
43+
# Install vllm from source
44+
RUN --mount=type=secret,id=github_token \
45+
cd /root && \
46+
. /miniforge3/bin/activate && \
47+
conda activate py${PYTHON_VERSION} && \
48+
echo "Building vllm/sglang from source ..." && \
49+
git clone https://github.com/zhuyuhua-v/vllm.git && \
50+
cd vllm && \
51+
git checkout yuhua/deepseek && \
52+
pip install setuptools_scm --root-user-action=ignore && \
53+
pip install setuptools==75.6.0 packaging==24.2 --root-user-action=ignore && \
54+
VLLM_TARGET_DEVICE=xpu python setup.py install
55+
56+
# Install SGlang from source
57+
RUN --mount=type=secret,id=github_token \
58+
# Install vllm from source
59+
cd /root && \
60+
. /miniforge3/bin/activate && \
61+
conda activate py${PYTHON_VERSION} && \
62+
echo "cloning ${SG_LANG_BRANCH} from ${SG_LANG_REPO}" && \
63+
git clone --branch ${SG_LANG_BRANCH} --single-branch ${SG_LANG_REPO} && \
64+
cd sglang && \
65+
pip install -e "python[all_xpu]" --root-user-action=ignore && \
66+
# Clone sgl-kernel and build sglang-kernel...
67+
echo "cloning ${SG_LANG_KERNEL_REPO} from ${SG_LANG_KERNEL_BRANCH}" && \
68+
git clone --branch ${SG_LANG_KERNEL_BRANCH} --single-branch ${SG_LANG_KERNEL_REPO} && \
69+
cd sgl-kernel-xpu && \
70+
pip install -v . &&\
71+
# Install required packages for sglang workloads
72+
pip install msgspec blake3 py-cpuinfo compressed_tensors gguf partial_json_parser einops --root-user-action=ignore && \
73+
conda install libsqlite=3.48.0 -y && \
74+
echo ". /miniforge3/bin/activate; conda activate py${PYTHON_VERSION}; cd /root/" >> /root/.bashrc;
75+
76+
# Set the default shell to bash
77+
SHELL ["bash", "-c"]
78+
CMD ["bash", "-c", "source /root/.bashrc && exec bash"]

benchmark/bench_fp8_blockwise_gemm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
import triton
88
from deep_gemm import get_col_major_tma_aligned_tensor
99
from sgl_kernel import fp8_blockwise_scaled_mm
10-
from vllm._custom_ops import cutlass_scaled_mm as vllm_scaled_mm
11-
1210
from sglang.srt.layers.quantization.fp8_kernel import (
1311
w8a8_block_fp8_matmul_triton as w8a8_block_fp8_matmul,
1412
)
13+
from vllm._custom_ops import cutlass_scaled_mm as vllm_scaled_mm
1514

1615

1716
def get_weight_shapes(args):

benchmark/bench_moe_ep_post_reorder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import torch
22
import triton
33
from sgl_kernel import ep_moe_post_reorder
4-
54
from sglang.srt.layers.moe.ep_moe.kernels import post_reorder_triton_kernel
65

76
batch_sizes = [64, 128, 256, 512, 640, 768, 1024, 2048, 4096]

benchmark/bench_moe_ep_pre_reorder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import torch
22
import triton
33
from sgl_kernel import ep_moe_pre_reorder
4-
54
from sglang.srt.layers.moe.ep_moe.kernels import pre_reorder_triton_kernel
65

76
batch_sizes = [64, 128, 256, 512, 640, 768, 1024, 2048, 4096]

benchmark/bench_moe_fused_gate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import triton
66
import triton.language as tl
77
from sgl_kernel import moe_fused_gate
8-
98
from sglang.srt.layers.moe.topk import biased_grouped_topk
109

1110

benchmark/bench_moe_silu_and_mul.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import torch
44
import triton
55
from sgl_kernel import ep_moe_silu_and_mul
6-
76
from sglang.srt.layers.moe.ep_moe.kernels import silu_and_mul_triton_kernel
87

98
batch_size_range = [64, 128, 256, 512, 640, 768, 1024, 2048, 4096]

benchmark/bench_per_tensor_quant_fp8.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import triton
88
import triton.testing
99
from sgl_kernel import sgl_per_tensor_quant_fp8
10-
from vllm import _custom_ops as ops
11-
1210
from sglang.srt.utils import is_hip
11+
from vllm import _custom_ops as ops
1312

1413
_is_hip = is_hip()
1514
fp8_type_ = torch.float8_e4m3fnuz if _is_hip else torch.float8_e4m3fn

0 commit comments

Comments
 (0)