[XPU] upgrade sglang xpu backend to PyTorch 2.13 (#31751)
Co-authored-by: MingxuZh <109504044+MingxuZh@users.noreply.github.com> Co-authored-by: Ma Mingfei <mingfei.ma@intel.com>
This commit is contained in:
co-authored by
MingxuZh
Ma Mingfei
parent
c82e928fe5
commit
744740dbea
@@ -1,7 +1,7 @@
|
|||||||
# docker build -t sglang:xpu -f xpu.Dockerfile --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} --build-arg no_proxy=${no_proxy} --no-cache .
|
# docker build -t sglang:xpu -f xpu.Dockerfile --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} --build-arg no_proxy=${no_proxy} --no-cache .
|
||||||
|
|
||||||
# Use Intel deep learning essentials base image with Ubuntu 24.04
|
# Use Intel deep learning essentials base image with Ubuntu 24.04
|
||||||
FROM intel/deep-learning-essentials:2025.3.2-0-devel-ubuntu24.04
|
FROM intel/deep-learning-essentials:2026.0.0-devel-ubuntu24.04
|
||||||
|
|
||||||
# Avoid interactive prompts during package install
|
# Avoid interactive prompts during package install
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
@@ -19,9 +19,10 @@ USER root
|
|||||||
|
|
||||||
# Pin Level-Zero UMD + IGC (rolling PPA once faulted libze on B580; see sgl-kernel-xpu#296).
|
# Pin Level-Zero UMD + IGC (rolling PPA once faulted libze on B580; see sgl-kernel-xpu#296).
|
||||||
# Keep in lockstep with the host xe KMD; override via --build-arg.
|
# Keep in lockstep with the host xe KMD; override via --build-arg.
|
||||||
ARG COMPUTE_RUNTIME_VERSION=26.05.37020.3
|
ARG COMPUTE_RUNTIME_VERSION=26.18.38308.1
|
||||||
ARG IGC_VERSION=2.28.4+20760
|
ARG IGC_VERSION=2.34.4+21428
|
||||||
ARG GMM_VERSION=22.9.0
|
ARG GMM_VERSION=22.10.0
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y software-properties-common curl && \
|
RUN apt-get update && apt-get install -y software-properties-common curl && \
|
||||||
add-apt-repository -y ppa:kobuk-team/intel-graphics && \
|
add-apt-repository -y ppa:kobuk-team/intel-graphics && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
@@ -68,14 +69,14 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
|||||||
|
|
||||||
WORKDIR /sgl-workspace
|
WORKDIR /sgl-workspace
|
||||||
|
|
||||||
RUN pip install --no-cache-dir msgspec blake3 py-cpuinfo compressed_tensors gguf partial_json_parser einops tabulate --root-user-action=ignore && \
|
RUN pip install --no-cache-dir torch==2.13.0+xpu torchvision==0.28.0+xpu torchaudio==2.11.0+xpu --index-url https://download.pytorch.org/whl/xpu && \
|
||||||
pip install --no-cache-dir torch==2.12.0+xpu torchvision==0.27.0+xpu torchaudio==2.11.0+xpu --index-url https://download.pytorch.org/whl/xpu
|
pip install --no-cache-dir msgspec blake3 py-cpuinfo compressed_tensors gguf partial_json_parser einops tabulate --root-user-action=ignore
|
||||||
|
|
||||||
RUN echo "Cloning ${SG_LANG_BRANCH} from ${SG_LANG_REPO}" && \
|
RUN echo "Cloning ${SG_LANG_BRANCH} from ${SG_LANG_REPO}" && \
|
||||||
git clone --branch ${SG_LANG_BRANCH} --single-branch ${SG_LANG_REPO} sglang && \
|
git clone --branch ${SG_LANG_BRANCH} --single-branch ${SG_LANG_REPO} sglang && \
|
||||||
cd sglang && cd python && \
|
cd sglang && cd python && \
|
||||||
cp pyproject_xpu.toml pyproject.toml && \
|
cp pyproject_xpu.toml pyproject.toml && \
|
||||||
pip install --no-cache-dir . --extra-index-url https://download.pytorch.org/whl/xpu && \
|
pip install --no-cache-dir ".[dev,diffusion]" --extra-index-url https://download.pytorch.org/whl/xpu && \
|
||||||
pip install --no-cache-dir --no-deps xgrammar==0.1.33
|
pip install --no-cache-dir --no-deps xgrammar==0.1.33
|
||||||
|
|
||||||
CMD ["bash", "-c", "source /opt/intel/oneapi/setvars.sh --force && exec bash"]
|
CMD ["bash", "-c", "source /opt/intel/oneapi/setvars.sh --force && exec bash"]
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ conda create -n sgl-xpu python=3.12 -y
|
|||||||
conda activate sgl-xpu
|
conda activate sgl-xpu
|
||||||
|
|
||||||
# Set PyTorch XPU as primary pip install channel to avoid installing the larger CUDA-enabled version and prevent potential runtime issues.
|
# Set PyTorch XPU as primary pip install channel to avoid installing the larger CUDA-enabled version and prevent potential runtime issues.
|
||||||
pip3 install torch==2.12.0+xpu torchvision==0.27.0+xpu torchaudio==2.11.0+xpu --index-url https://download.pytorch.org/whl/xpu
|
pip3 install torch==2.13.0+xpu torchvision==0.28.0+xpu torchaudio==2.11.0+xpu --index-url https://download.pytorch.org/whl/xpu
|
||||||
pip3 install xgrammar --no-deps # xgrammar will introduce CUDA-enabled triton which might conflict with XPU
|
pip3 install xgrammar --no-deps # xgrammar will introduce CUDA-enabled triton which might conflict with XPU
|
||||||
pip3 install apache-tvm-ffi # xgrammar requires apache-tvm-ffi
|
pip3 install apache-tvm-ffi # xgrammar requires apache-tvm-ffi
|
||||||
|
|
||||||
|
|||||||
@@ -87,11 +87,7 @@ pip install -e "python[all_musa]"
|
|||||||
|
|
||||||
## Platform-Specific: Intel XPU
|
## Platform-Specific: Intel XPU
|
||||||
|
|
||||||
For Intel Data Center GPU Max or Arc GPUs, follow the [XPU installation guide](../hardware-platforms/xpu) to set up the base environment, then install diffusion dependencies:
|
For Intel Data Center GPU Max or Arc GPUs, follow the installation with docker in [XPU installation guide](../hardware-platforms/xpu). The dockerfile already include diffusion dependencies:
|
||||||
|
|
||||||
```bash Command
|
|
||||||
pip install -e "python[diffusion]"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Platform-Specific: Ascend NPU
|
## Platform-Specific: Ascend NPU
|
||||||
|
|
||||||
|
|||||||
@@ -59,10 +59,10 @@ dependencies = [
|
|||||||
"soundfile==0.13.1",
|
"soundfile==0.13.1",
|
||||||
"tiktoken",
|
"tiktoken",
|
||||||
"timm==1.0.16",
|
"timm==1.0.16",
|
||||||
"torch==2.12.0+xpu",
|
"torch==2.13.0+xpu",
|
||||||
"torchaudio==2.11.0+xpu",
|
"torchaudio==2.11.0+xpu",
|
||||||
"torchcodec==0.12.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')", # torch==2.12.0 on XPU uses torchcodec 0.12.0
|
"torchcodec==0.13.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')", # torch==2.13.0 on XPU uses torchcodec 0.13.0
|
||||||
"torchvision==0.27.0+xpu",
|
"torchvision==0.28.0+xpu",
|
||||||
"tqdm",
|
"tqdm",
|
||||||
"transformers==5.12.1",
|
"transformers==5.12.1",
|
||||||
"uvicorn",
|
"uvicorn",
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
|
torch.use_deterministic_algorithms(True)
|
||||||
|
|
||||||
from sglang.srt.layers.moe.topk import (
|
from sglang.srt.layers.moe.topk import (
|
||||||
biased_grouped_topk_gpu,
|
biased_grouped_topk_gpu,
|
||||||
)
|
)
|
||||||
@@ -33,6 +36,39 @@ def _scatter_by_expert(
|
|||||||
return dense
|
return dense
|
||||||
|
|
||||||
|
|
||||||
|
def assert_equal(
|
||||||
|
score: torch.Tensor,
|
||||||
|
indices_ref: torch.Tensor,
|
||||||
|
indices_our: torch.Tensor,
|
||||||
|
bs: int,
|
||||||
|
k: int,
|
||||||
|
seq_len: int,
|
||||||
|
topk_indices_offset: Optional[torch.Tensor] = None,
|
||||||
|
max_permit_error: int = 0,
|
||||||
|
):
|
||||||
|
indices_our_cpu = indices_our.cpu().tolist()
|
||||||
|
indices_ref_cpu = indices_ref.cpu().tolist()
|
||||||
|
|
||||||
|
wrong_values = 0
|
||||||
|
for i in range(bs):
|
||||||
|
indices_ref_set_i = set(indices_ref_cpu[i])
|
||||||
|
indices_our_set_i = set(indices_our_cpu[i])
|
||||||
|
more = indices_our_set_i - indices_ref_set_i
|
||||||
|
less = indices_ref_set_i - indices_our_set_i
|
||||||
|
offset = topk_indices_offset[i].item() if topk_indices_offset is not None else 0
|
||||||
|
if len(more) > 0 or len(less) > 0:
|
||||||
|
# check whether more values are the same with less values
|
||||||
|
# if so, either one is acceptable, since their values are the same
|
||||||
|
more_values = sorted(score[i, idx - offset].item() for idx in more)
|
||||||
|
less_values = sorted(score[i, idx - offset].item() for idx in less)
|
||||||
|
if more_values != less_values:
|
||||||
|
wrong_values += len(more)
|
||||||
|
print(
|
||||||
|
f"{bs=}, {k=}, {seq_len=}, {i=}, {more=}, {less=} failed, with {more_values=}, {less_values=}"
|
||||||
|
)
|
||||||
|
assert wrong_values <= max_permit_error, f"{wrong_values=}, {max_permit_error=}"
|
||||||
|
|
||||||
|
|
||||||
# Nemotron-3 uses biased_grouped_topk
|
# Nemotron-3 uses biased_grouped_topk
|
||||||
class TestBiasedGroupedTopK(CustomTestCase):
|
class TestBiasedGroupedTopK(CustomTestCase):
|
||||||
def _run_single_test(
|
def _run_single_test(
|
||||||
@@ -226,15 +262,13 @@ class TestBiasedGroupedTopK(CustomTestCase):
|
|||||||
routed_scaling_factor,
|
routed_scaling_factor,
|
||||||
)
|
)
|
||||||
|
|
||||||
torch.testing.assert_close(
|
assert_equal(
|
||||||
_scatter_by_expert(
|
gating_output,
|
||||||
topk_weights[:, :topk_routed], topk_ids[:, :topk_routed], E_num
|
ref_topk_ids[:, :topk_routed],
|
||||||
),
|
topk_ids[:, :topk_routed],
|
||||||
_scatter_by_expert(
|
bs=len(bs),
|
||||||
ref_topk_weights[:, :topk_routed],
|
k=topk_value,
|
||||||
ref_topk_ids[:, :topk_routed],
|
seq_len=seq_len,
|
||||||
E_num,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user