Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
hooks:
- id: ruff
args:
- --select=F401,F821,UP037
- --select=F401,F821,F823,UP037
- --fix
files: ^(benchmark/|docs/|examples/|python/sglang/|sgl-model-gateway/py_*|test/)
exclude: |
Expand Down
69 changes: 57 additions & 12 deletions python/sglang/check_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import importlib.metadata
import os
import platform
import resource
import subprocess
import sys
Expand All @@ -10,7 +11,7 @@

import torch

from sglang.srt.utils import is_hip, is_mps, is_musa, is_npu
from sglang.srt.utils import is_hip, is_mps, is_musa, is_npu, is_xpu


def is_cuda_v2():
Expand Down Expand Up @@ -140,6 +141,19 @@ def check_env(self):
print(f"{k}: {v}")


class CPUEnv(BaseEnv):
"""Environment checker for CPU-only systems."""

def get_info(self):
return {
"CPU Architecture": platform.machine(),
"CPU Count": os.cpu_count(),
}

def get_topology(self):
return {}


class GPUEnv(BaseEnv):
"""Environment checker for Nvidia GPU"""

Expand Down Expand Up @@ -296,6 +310,31 @@ def get_topology(self):
return {}


class XPUEnv(BaseEnv):
"""Environment checker for Intel XPU."""

def get_info(self):
xpu_info = {"XPU available": torch.xpu.is_available()}

if xpu_info["XPU available"]:
xpu_info["XPU count"] = torch.xpu.device_count()
xpu_info.update(self.get_device_info())

return xpu_info

def get_device_info(self):
devices = defaultdict(list)
for k in range(torch.xpu.device_count()):
devices[torch.xpu.get_device_name(k)].append(str(k))

return {
f"XPU {','.join(device_ids)}": name for name, device_ids in devices.items()
}

def get_topology(self):
return {}


class NPUEnv(BaseEnv):
"""Environment checker for Ascend NPU"""

Expand Down Expand Up @@ -580,15 +619,21 @@ def get_topology(self):
return {}


if __name__ == "__main__":
def _get_env():
if is_cuda_v2():
env = GPUEnv()
elif is_hip():
env = HIPEnv()
elif is_npu():
env = NPUEnv()
elif is_musa():
env = MUSAEnv()
elif is_mps():
env = MPSEnv()
env.check_env()
return GPUEnv()
if is_hip():
return HIPEnv()
if is_npu():
return NPUEnv()
if is_musa():
return MUSAEnv()
if is_xpu():
return XPUEnv()
if is_mps():
return MPSEnv()
return CPUEnv()


if __name__ == "__main__":
_get_env().check_env()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"_comment": "Consistency thresholds for Intel Arc Pro B60 (XPU). The GT images are CUDA-generated, and XPU seeds its initial latent noise from a different RNG stream, so pixels cannot match: the image is semantically identical (CLIP stays high) while ssim/psnr/mean_abs_diff degrade. Per-case entries below are only tuned where an XPU run has actually been measured; the rest are inherited from h100.json and will need the same treatment as they are triaged.",
"cases": {
"qwen_image_t2i_2_gpus": {
"clip_threshold": 0.98,
"ssim_threshold": 0.79,
"psnr_threshold": 15.7,
"mean_abs_diff_threshold": 17.2
},
"fsdp-inference": {
"clip_threshold": 0.97,
"ssim_threshold": 0.6,
"psnr_threshold": 11.0,
"mean_abs_diff_threshold": 37.0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"metadata": {
"model": "Diffusion Server",
"hardware": "CI Intel Arc Pro B60 (24 GiB) pool: bmg-multigen-models",
"description": "All scenarios re-seeded from XPU multimodal_gen CI run 35563559050 job 106220948594 (PR #39956), with SGLANG_DIFFUSION_SYNC_STAGE_PROFILING=1 so step timings record device time rather than host enqueue. Each value is the max over the 7 attempts of that job. Denoise numbers are stable across attempts (<=2% spread); expected_load_ms is host I/O bound and ranged 21.4-48.0s across attempts, so it is guarded only by the wide e2e tolerance.",
"description": "Core scenarios were re-seeded from XPU multimodal_gen CI run 35563559050 job 106220948594 (PR #39956), with SGLANG_DIFFUSION_SYNC_STAGE_PROFILING=1 so step timings record device time rather than host enqueue. Each core value is the max over the 7 attempts of that job. Denoise numbers are stable across attempts (<=2% spread); expected_load_ms is host I/O bound and ranged 21.4-48.0s across attempts, so it is guarded only by the wide e2e tolerance. The fsdp-inference scenario comes from the dedicated 2x B60 validation in PR #35267.",
"last_updated": "2026-09-21"
},
"tolerances": {
Expand Down Expand Up @@ -155,6 +155,31 @@
"expected_median_denoise_ms": 1068.45,
"estimated_full_test_time_s": 103.3
},
"fsdp-inference": {
"stages_ms": {
"InputValidationStage": 0.04,
"TextEncodingStage": 822.67,
"LatentPreparationStage": 0.21,
"TimestepPreparationStage": 34933.02,
"DenoisingStage": 9091.12,
"DecodingStage": 17.8
},
"denoise_step_ms": {
"0": 285.12,
"1": 1096.41,
"2": 1091.69,
"3": 1098.41,
"4": 1124.7,
"5": 1099.74,
"6": 1100.13,
"7": 1095.65,
"8": 1094.18
},
"expected_e2e_ms": 44870.65,
"expected_avg_denoise_ms": 1009.56,
"expected_median_denoise_ms": 1096.41,
"estimated_full_test_time_s": 157.0
},
"wan2_1_t2v_1.3b": {
"estimated_full_test_time_s": 331.5,
"stages_ms": {
Expand Down
4 changes: 4 additions & 0 deletions python/sglang/multimodal_gen/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"h100": "h100.json",
"b200": "b200.json",
"5090": "5090.json",
"intel_xpu_b60": "intel_xpu_b60.json",
}
CONSISTENCY_PLATFORM_ALIASES = {
"sm90": "h100",
Expand All @@ -91,6 +92,7 @@
"sm120": "5090",
"rtx5090": "5090",
"5090": "5090",
"intelxpub60": "intel_xpu_b60",
}
CLIP_MODEL_NAME = "openai/clip-vit-large-patch14"
DEFAULT_CLIP_THRESHOLD_IMAGE = 0.92
Expand Down Expand Up @@ -904,6 +906,8 @@ def get_consistency_platform() -> str:
return "5090"
if current_platform.is_blackwell():
return "b200"
if current_platform.is_xpu():
return "intel_xpu_b60"
return "h100"


Expand Down
2 changes: 1 addition & 1 deletion python/sglang/srt/arg_groups/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@

GRAMMAR_BACKEND_CHOICES = ["xgrammar", "outlines", "llguidance", "none"]

SAMPLING_BACKEND_CHOICES = {"flashinfer", "pytorch", "ascend"}
SAMPLING_BACKEND_CHOICES = {"flashinfer", "pytorch", "ascend", "intel_xpu"}

MOE_RUNNER_BACKEND_CHOICES = [
"auto",
Expand Down
6 changes: 6 additions & 0 deletions python/sglang/srt/arg_groups/platform_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def handle_symm_mem_device_support(server_args: Any):
def handle_xpu_backends(server_args: Any):
cfg = resolving_view(server_args)
if cfg.device == "xpu":
if cfg.sampling_backend is None:
declare_resolution(
server_args,
"_handle_xpu_backends",
sampling_backend="intel_xpu",
)
# Decode graph is opt-in on XPU: unless the user explicitly set
# --cuda-graph-backend-decode (or --cuda-graph-config), keep it
# disabled so the default startup doesn't require graph capture.
Expand Down
14 changes: 14 additions & 0 deletions python/sglang/srt/arg_groups/validation_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ def check_server_args(server_args: Any):
if cfg.enable_quant_communications and cfg.device != "npu":
raise ValueError("Communications quantization is only supported for NPU device")

validate_device_sampling_backend(cfg.sampling_backend, cfg.device)

# grpc_port is None for HTTP-only launches, so the == comparison is
# already False there; no explicit None check needed.
if not (cfg.smg_grpc_mode or cfg.grpc_mode) and cfg.grpc_port == cfg.port:
Expand Down Expand Up @@ -406,6 +408,18 @@ def check_load_publish_args(server_args: Any):
raise ValueError(reason)


def validate_device_sampling_backend(
sampling_backend: Optional[str], device: str
) -> None:
# sampler.py binds the intel_xpu kernels only under is_xpu(), so on another
# device the backend either aliases to flashinfer's names or NameErrors on
# the first non-greedy decode.
if sampling_backend == "intel_xpu" and device != "xpu":
raise ValueError(
f"--sampling-backend intel_xpu requires --device xpu, got --device {device}"
)


def validate_ib_devices(device_str: Optional[str]) -> Optional[str]:
"""
Validate IB devices before passing to mooncake.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ def __init__(self, runner: ModelRunner):
# that wide. Head split mirrors MiniMaxM3 sparse attention's.
self._idx_group_size = 1
if self.index_cache_enabled:
from sglang.srt.runtime_context import get_parallel

_num_idx_heads = max(
sparse_cfg["sparse_num_index_heads"] // get_parallel().attn_tp_size, 1
)
Expand Down
7 changes: 5 additions & 2 deletions python/sglang/srt/layers/moe/topk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2051,9 +2051,12 @@ def biased_grouped_topk_gpu(
and experts_per_group <= 32
and is_power_of_two(num_experts)
):
from sgl_kernel import moe_fused_gate
# aliased: a plain `import moe_fused_gate` here makes the name local
# to the whole function, and the MUSA branch above, which reads the
# module-level mate import, raised UnboundLocalError (ruff F823)
from sgl_kernel import moe_fused_gate as _sgl_kernel_moe_fused_gate

return moe_fused_gate(
return _sgl_kernel_moe_fused_gate(
gating_output.to(torch.float32),
correction_bias.to(torch.float32),
num_expert_group,
Expand Down
9 changes: 5 additions & 4 deletions python/sglang/srt/layers/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
is_hip,
is_musa,
is_npu,
is_xpu,
)

if is_cuda():
Expand All @@ -42,7 +43,7 @@
top_p_renorm_prob,
)

if is_musa():
if is_musa() or is_xpu():
from sgl_kernel import (
min_p_sampling_from_probs,
top_k_renorm_prob,
Expand Down Expand Up @@ -72,7 +73,7 @@
SYNC_TOKEN_IDS_ACROSS_TP = get_bool_env_var("SYNC_TOKEN_IDS_ACROSS_TP")
SGLANG_RETURN_ORIGINAL_LOGPROB = get_bool_env_var("SGLANG_RETURN_ORIGINAL_LOGPROB")
_CUSTOM_SAMPLER_FACTORIES: Dict[str, Callable[[], "Sampler"]] = {}
_BUILT_IN_SAMPLING_BACKENDS = {"flashinfer", "pytorch", "ascend"}
_BUILT_IN_SAMPLING_BACKENDS = {"flashinfer", "pytorch", "ascend", "intel_xpu"}


def _trace_e2e_sampler(stage: str, **fields) -> None:
Expand Down Expand Up @@ -361,9 +362,9 @@ def _sample_from_probs(
)
else:
backend = get_exec().kernel.sampling_backend
if backend == "flashinfer":
if backend in ("flashinfer", "intel_xpu"):
assert sampling_info.sampling_seed is None, (
"Sampling seed is not supported for flashinfer backend"
f"Sampling seed is not supported for {backend} backend"
)
if sampling_info.need_min_p_sampling:
probs = top_k_renorm_prob(probs, sampling_info.top_ks)
Expand Down
57 changes: 57 additions & 0 deletions test/registered/unit/test_check_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Regression tests for environment checker backend selection."""

import unittest
from unittest.mock import Mock, patch

import sglang.check_env as check_env
from sglang.test.ci.ci_register import register_cpu_ci
from sglang.test.test_utils import CustomTestCase

register_cpu_ci(est_time=1, suite="base-a-test-cpu")


class TestCheckEnvBackendSelection(CustomTestCase):
def _get_env(self, *, xpu_available: bool):
predicates = {
"is_cuda_v2": False,
"is_hip": False,
"is_npu": False,
"is_musa": False,
"is_xpu": xpu_available,
"is_mps": False,
}
with patch.multiple(
check_env,
**{name: Mock(return_value=value) for name, value in predicates.items()},
):
return check_env._get_env()

def test_cpu_fallback_without_accelerator(self):
"""CPU-only environments must still select a checker instead of crashing."""
self.assertIsInstance(
self._get_env(xpu_available=False),
check_env.CPUEnv,
)

def test_xpu_backend_selection(self):
"""An available Intel XPU must select its checker instead of falling through."""
xpu = Mock()
xpu.is_available.return_value = True
xpu.device_count.return_value = 2
xpu.get_device_name.side_effect = ["Intel GPU", "Intel GPU"]

with patch.object(check_env.torch, "xpu", xpu, create=True):
env = self._get_env(xpu_available=True)
self.assertIsInstance(env, check_env.XPUEnv)
self.assertEqual(
env.get_info(),
{
"XPU available": True,
"XPU count": 2,
"XPU 0,1": "Intel GPU",
},
)


if __name__ == "__main__":
unittest.main()
Loading