XPU: remove SGLANG_USE_SGL_XPU flag (#34492)

This commit is contained in:
Xia Weiwen
2026-08-27 02:38:02 -07:00
committed by GitHub
parent 78d36f5f62
commit 56fdfc3b26
19 changed files with 96 additions and 46 deletions
@@ -23,7 +23,6 @@ class TestGemma4_26BA4BXPU(SimpleEvalGSM8KXPUMixin, CustomTestCase):
tp_size = 4
accuracy = 0.90
timeout_for_server_launch = 3600
env = {"SGLANG_USE_SGL_XPU": "1"}
# Gemma-4 hybrid-attention kernels crash under chunked prefill on XPU.
other_args = SimpleEvalGSM8KXPUMixin.other_args + [
@@ -27,7 +27,6 @@ class TestNemotron3Nano30BA3BXPU(SimpleEvalGSM8KXPUMixin, CustomTestCase):
max_tokens = 8192
# Client-side eval concurrency (mixin default is 1).
num_threads = 4
env = {"SGLANG_USE_SGL_XPU": "1"}
# Hybrid-mamba layout needs --model-impl sglang, a fixed page size, and
# the nemotron_3 reasoning / qwen3_coder tool-call parsers.
@@ -23,8 +23,6 @@ class TestQwen3_30BA3BXPU(SimpleEvalGSM8KXPUMixin, CustomTestCase):
tp_size = 4
accuracy = 0.90
timeout_for_server_launch = 3600
# SGL XPU MoE kernels gate on this env var.
env = {"SGLANG_USE_SGL_XPU": "1"}
num_examples = 50
num_threads = 4
max_tokens = 8192
@@ -23,8 +23,6 @@ class TestQwen3_5_35BA3BXPU(SimpleEvalGSM8KXPUMixin, CustomTestCase):
tp_size = 4
accuracy = 0.90
timeout_for_server_launch = 3600
# SGL XPU MoE kernels gate on this env var.
env = {"SGLANG_USE_SGL_XPU": "1"}
num_examples = 50
num_threads = 4
max_tokens = 8192
-1
View File
@@ -43,7 +43,6 @@ class TestDeepSeekOCR(CustomTestCase):
"--attention-backend",
"intel_xpu",
]
os.environ["SGLANG_USE_SGL_XPU"] = "1"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
@@ -67,7 +67,7 @@ class TestDeepSeekOCR2OlmBenchXPU(CustomTestCase):
"8192",
"--disable-cuda-graph",
]
env = {"SGLANG_USE_SGL_XPU": "1"}
env = {}
@classmethod
def setUpClass(cls):
@@ -41,8 +41,9 @@ class TestDeepSeekOCRTriton(TestDeepSeekOCR):
"xpu",
"--attention-backend",
"intel_xpu",
"--moe-runner-backend",
"triton",
]
os.environ["SGLANG_USE_SGL_XPU"] = "0"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
@@ -40,7 +40,6 @@ class TestEncoderAttention(CustomTestCase):
"--mm-attention-backend",
"xpu_attn",
]
os.environ["SGLANG_USE_SGL_XPU"] = "1"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
@@ -128,7 +127,6 @@ class TestEncoderAttention_Triton(TestEncoderAttention):
"--mm-attention-backend",
"triton_attn",
]
os.environ["SGLANG_USE_SGL_XPU"] = "0"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
-2
View File
@@ -19,7 +19,6 @@ Server is started with ``sglang serve`` (``--model-impl sglang``).
from __future__ import annotations
import os
import unittest
import openai
@@ -83,7 +82,6 @@ class TestGemma4E2BXPU(CustomTestCase):
cls.model = MODEL
cls.base_url = DEFAULT_URL_FOR_TEST
cls.api_key = "sk-123456"
os.environ["SGLANG_USE_SGL_XPU"] = "1"
_empty_xpu_cache()
cls.process = popen_launch_server(
@@ -75,6 +75,8 @@ class TestIntelXPUBackend(CustomTestCase):
'{"num_hidden_layers": 4}',
"--decode-attention-backend",
"intel_xpu",
"--moe-runner-backend",
"triton", # FP8 is not yet supported in sgl-kernel
],
min_throughput=32,
)
+12 -7
View File
@@ -9,6 +9,7 @@ import torch
from sglang.srt.layers.moe.utils import (
XPU_MOE_LD_PADDING_BYTES,
MoeRunnerBackend,
xpu_moe_ld_padding_elems,
)
from sglang.srt.layers.quantization.unquant import _empty_xpu_moe_expert_weight
@@ -60,7 +61,7 @@ class TestXpuMoeLdPadding(CustomTestCase):
self.assertTrue(unpadded.is_contiguous())
def test_only_pads_weights_that_land_on_xpu(self):
# SGLANG_USE_SGL_XPU only says an XPU exists on the machine; the weights
# is_xpu() only says an XPU exists on the machine; the weights
# can still be built for CPU/CUDA. create_weights takes no device
# argument, so the gate reads the ambient device context. Padding a
# non-XPU weight would make it non-contiguous for no benefit.
@@ -88,10 +89,12 @@ class TestXpuMoeLdPadding(CustomTestCase):
return layer.w13_weight, layer.w2_weight
with unittest.mock.patch(
"sglang.srt.layers.quantization.unquant.use_intel_xpu_backend",
return_value=True,
"sglang.srt.layers.quantization.unquant.is_xpu", return_value=True
), unittest.mock.patch(
"sglang.srt.layers.quantization.unquant.get_moe_runner_backend",
return_value=MoeRunnerBackend.AUTO,
):
# Env var on but building for CPU -> must stay contiguous.
# Backend on but building for CPU -> must stay contiguous.
w13_cpu, w2_cpu = build("cpu")
self.assertTrue(w13_cpu.is_contiguous())
self.assertTrue(w2_cpu.is_contiguous())
@@ -103,10 +106,12 @@ class TestXpuMoeLdPadding(CustomTestCase):
w13_triton, _ = build("xpu", use_triton_kernels=True)
self.assertTrue(w13_triton.is_contiguous())
# Backend off entirely -> never padded, even on XPU.
# Backend forced to Triton -> never padded, even on XPU.
with unittest.mock.patch(
"sglang.srt.layers.quantization.unquant.use_intel_xpu_backend",
return_value=False,
"sglang.srt.layers.quantization.unquant.is_xpu", return_value=True
), unittest.mock.patch(
"sglang.srt.layers.quantization.unquant.get_moe_runner_backend",
return_value=MoeRunnerBackend.TRITON,
):
device = "xpu" if torch.xpu.is_available() else "cpu"
w13, w2 = build(device)
@@ -0,0 +1,55 @@
import sys
from types import SimpleNamespace
import pytest
from sglang.srt.layers.attention import vision
from sglang.test.ci.ci_register import register_xpu_ci
register_xpu_ci(est_time=300, suite="stage-a-test-1-gpu-xpu")
@pytest.mark.parametrize(
("server_backend", "passed_backend", "expected"),
[
(
None,
None,
"xpu_attn",
), # server backend is not set, expected to use xpu_attn as default
(
"xpu_attn",
None,
"xpu_attn",
), # server backend is set to xpu_attn, expected to use xpu_attn
(
"xpu_attn",
"triton_attn",
"xpu_attn",
), # server backend is set to xpu_attn, passed backend is triton_attn
(
"triton_attn",
None,
"triton_attn",
), # server backend is set to triton_attn, expected to use triton_attn
],
)
def test_xpu_backend_selection_priority(
monkeypatch,
server_backend, # specified by the server argument
passed_backend, # specified by the layer argument
expected,
):
monkeypatch.setattr(
vision,
"get_mm",
lambda: SimpleNamespace(mm_attention_backend=server_backend),
)
backend = vision.VisionAttention._determine_attention_backend(None, passed_backend)
assert backend == expected
if __name__ == "__main__":
sys.exit(pytest.main([__file__]))