From fc6057868696418c53854662eb1ea439efd7994f Mon Sep 17 00:00:00 2001 From: Amrutha M Date: Mon, 21 Sep 2026 09:11:20 -0700 Subject: [PATCH 1/4] [XPU Weekly] Add Intel XPU diffusion test baselines (#35267) Source: https://github.com/sgl-project/sglang/pull/35267 --- .../consistency_thresholds/intel_xpu_b60.json | 17 ++++++++++++ .../test/server/perf_baselines/xpu_b60.json | 27 ++++++++++++++++++- .../sglang/multimodal_gen/test/test_utils.py | 4 +++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 python/sglang/multimodal_gen/test/server/consistency_thresholds/intel_xpu_b60.json diff --git a/python/sglang/multimodal_gen/test/server/consistency_thresholds/intel_xpu_b60.json b/python/sglang/multimodal_gen/test/server/consistency_thresholds/intel_xpu_b60.json new file mode 100644 index 000000000000..3df93e9682a5 --- /dev/null +++ b/python/sglang/multimodal_gen/test/server/consistency_thresholds/intel_xpu_b60.json @@ -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 + } + } +} diff --git a/python/sglang/multimodal_gen/test/server/perf_baselines/xpu_b60.json b/python/sglang/multimodal_gen/test/server/perf_baselines/xpu_b60.json index 422eadcc509c..f8b7d240eb67 100644 --- a/python/sglang/multimodal_gen/test/server/perf_baselines/xpu_b60.json +++ b/python/sglang/multimodal_gen/test/server/perf_baselines/xpu_b60.json @@ -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": { @@ -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": { diff --git a/python/sglang/multimodal_gen/test/test_utils.py b/python/sglang/multimodal_gen/test/test_utils.py index b400b771c10c..038ef4de7f87 100644 --- a/python/sglang/multimodal_gen/test/test_utils.py +++ b/python/sglang/multimodal_gen/test/test_utils.py @@ -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", @@ -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 @@ -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" From 1ba46799ae27b8ea36e47efda1d501e4dccc73cb Mon Sep 17 00:00:00 2001 From: charlesxu91 Date: Mon, 21 Sep 2026 09:11:20 -0700 Subject: [PATCH 2/4] [XPU Weekly] Handle CPU and XPU in check_env (#37037) Source: https://github.com/sgl-project/sglang/pull/37037 --- python/sglang/check_env.py | 69 +++++++++++++++++++++----- test/registered/unit/test_check_env.py | 57 +++++++++++++++++++++ 2 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 test/registered/unit/test_check_env.py diff --git a/python/sglang/check_env.py b/python/sglang/check_env.py index 225048560fd8..ecae09afa94f 100644 --- a/python/sglang/check_env.py +++ b/python/sglang/check_env.py @@ -2,6 +2,7 @@ import importlib.metadata import os +import platform import resource import subprocess import sys @@ -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(): @@ -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""" @@ -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""" @@ -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() diff --git a/test/registered/unit/test_check_env.py b/test/registered/unit/test_check_env.py new file mode 100644 index 000000000000..28b2c2ced5f4 --- /dev/null +++ b/test/registered/unit/test_check_env.py @@ -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() From 80cd401b663c42a744ac0452373c1992e19b6ef5 Mon Sep 17 00:00:00 2001 From: KMS07 Date: Mon, 21 Sep 2026 09:11:20 -0700 Subject: [PATCH 3/4] [XPU Weekly] Enable fused sampling kernels on XPU (#38510) Source: https://github.com/sgl-project/sglang/pull/38510 --- python/sglang/srt/arg_groups/choices.py | 2 +- python/sglang/srt/arg_groups/platform_hook.py | 6 ++++++ python/sglang/srt/arg_groups/validation_hook.py | 14 ++++++++++++++ python/sglang/srt/layers/sampler.py | 9 +++++---- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/python/sglang/srt/arg_groups/choices.py b/python/sglang/srt/arg_groups/choices.py index 558cc8ab52a0..809e33ff193b 100644 --- a/python/sglang/srt/arg_groups/choices.py +++ b/python/sglang/srt/arg_groups/choices.py @@ -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", diff --git a/python/sglang/srt/arg_groups/platform_hook.py b/python/sglang/srt/arg_groups/platform_hook.py index 67007b73427f..7fdffb6c2aef 100644 --- a/python/sglang/srt/arg_groups/platform_hook.py +++ b/python/sglang/srt/arg_groups/platform_hook.py @@ -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. diff --git a/python/sglang/srt/arg_groups/validation_hook.py b/python/sglang/srt/arg_groups/validation_hook.py index 57cd08d73499..c49ba30b41ae 100644 --- a/python/sglang/srt/arg_groups/validation_hook.py +++ b/python/sglang/srt/arg_groups/validation_hook.py @@ -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: @@ -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. diff --git a/python/sglang/srt/layers/sampler.py b/python/sglang/srt/layers/sampler.py index acd35db2cff2..b2622e7a2c67 100644 --- a/python/sglang/srt/layers/sampler.py +++ b/python/sglang/srt/layers/sampler.py @@ -30,6 +30,7 @@ is_hip, is_musa, is_npu, + is_xpu, ) if is_cuda(): @@ -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, @@ -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: @@ -355,9 +356,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) From bb41bd5c4da45c08c66d6d434f687c190bd8f7f8 Mon Sep 17 00:00:00 2001 From: Avi Fenesh Date: Mon, 21 Sep 2026 09:11:20 -0700 Subject: [PATCH 4/4] [XPU Weekly] Fix function-local import scoping (#39484) Source: https://github.com/sgl-project/sglang/pull/39484 --- .pre-commit-config.yaml | 2 +- .../sglang/srt/layers/attention/minimax_sparse_backend.py | 2 -- python/sglang/srt/layers/moe/topk.py | 7 +++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5584fd5dd295..03d827b63236 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: | diff --git a/python/sglang/srt/layers/attention/minimax_sparse_backend.py b/python/sglang/srt/layers/attention/minimax_sparse_backend.py index c3745ab17adb..69eee1c7851b 100644 --- a/python/sglang/srt/layers/attention/minimax_sparse_backend.py +++ b/python/sglang/srt/layers/attention/minimax_sparse_backend.py @@ -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 ) diff --git a/python/sglang/srt/layers/moe/topk.py b/python/sglang/srt/layers/moe/topk.py index 3175d230dacc..ae29c7473272 100644 --- a/python/sglang/srt/layers/moe/topk.py +++ b/python/sglang/srt/layers/moe/topk.py @@ -2050,9 +2050,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,