[XPU] Add registry mechanism for XPU CI tests (#25405)

Co-authored-by: Ma Mingfei <mingfei.ma@intel.com>
This commit is contained in:
vikram singh shekhawat
2026-05-27 08:56:59 +08:00
committed by GitHub
co-authored by Ma Mingfei
parent 87c3171aaa
commit 737c6cd6d1
9 changed files with 156 additions and 22 deletions
@@ -10,7 +10,7 @@ from sglang.srt.utils import get_device
from sglang.test.ci.ci_register import register_cuda_ci, register_xpu_ci
register_cuda_ci(est_time=11, stage="base-b", runner_config="1-gpu-large")
register_xpu_ci(est_time=30, suite="xpu")
register_xpu_ci(est_time=900, suite="stage-b-test-1-gpu-xpu")
@unittest.skipIf(
+113
View File
@@ -0,0 +1,113 @@
"""
python3 -m unittest test_deepseek_ocr.py
"""
import json
import os
import unittest
from pathlib import Path
import requests
from sglang.srt.utils import kill_process_tree
from sglang.srt.utils.hf_transformers import get_tokenizer
from sglang.test.ci.ci_register import register_xpu_ci
from sglang.test.test_utils import (
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
DEFAULT_URL_FOR_TEST,
CustomTestCase,
popen_launch_server,
)
register_xpu_ci(est_time=360, suite="stage-b-test-1-gpu-xpu")
class TestDeepSeekOCR(CustomTestCase):
@classmethod
def setUpClass(cls):
cls.model = "deepseek-ai/DeepSeek-OCR"
cls.tokenizer = get_tokenizer(cls.model)
cls.base_url = DEFAULT_URL_FOR_TEST
cls.image_path = str(
(Path(__file__).resolve().parents[3] / "examples/assets/example_image.png")
)
if not os.path.exists(cls.image_path):
raise FileNotFoundError(f"Image not found: {cls.image_path}")
cls.common_args = [
"--device",
"xpu",
"--attention-backend",
"intel_xpu",
]
os.environ["SGLANG_USE_SGL_XPU"] = "1"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
other_args=[
*cls.common_args,
],
)
@classmethod
def tearDownClass(cls):
"""Fixture that is run once after all tests in the class."""
if hasattr(cls, "process") and cls.process:
cls.process.terminate()
try:
cls.process.wait(timeout=30)
except Exception:
# Force kill if it didn't exit cleanly in time
kill_process_tree(cls.process.pid)
def get_request_json(self, max_new_tokens=32, n=1):
response = requests.post(
self.base_url + "/generate",
json={
"text": "<image>\n<|grounding|>Convert the document to pure text.",
"image_data": self.image_path,
"sampling_params": {
"temperature": 0 if n == 1 else 0.5,
"max_new_tokens": max_new_tokens,
},
},
)
return response.json()
def run_decode(
self,
max_new_tokens=128,
n=1,
):
ret = self.get_request_json(max_new_tokens=max_new_tokens, n=n)
print(json.dumps(ret, indent=2))
def assert_one_item(item):
if item["meta_info"]["finish_reason"]["type"] == "stop":
self.assertEqual(
item["meta_info"]["finish_reason"]["matched"],
self.tokenizer.eos_token_id,
)
elif item["meta_info"]["finish_reason"]["type"] == "length":
self.assertEqual(
len(item["output_ids"]), item["meta_info"]["completion_tokens"]
)
self.assertEqual(len(item["output_ids"]), max_new_tokens)
# Determine whether to assert a single item or multiple items based on n
if n == 1:
assert_one_item(ret)
else:
self.assertEqual(len(ret), n)
for i in range(n):
assert_one_item(ret[i])
print("=" * 100)
def test_moe(self):
self.run_decode()
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,60 @@
"""
python3 -m unittest test_deepseek_ocr_triton.py
"""
import os
import unittest
from pathlib import Path
from test_deepseek_ocr import TestDeepSeekOCR
from sglang.srt.utils.hf_transformers import get_tokenizer
from sglang.test.ci.ci_register import register_xpu_ci
from sglang.test.test_utils import (
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
DEFAULT_URL_FOR_TEST,
popen_launch_server,
)
register_xpu_ci(
est_time=360,
suite="stage-b-test-1-gpu-xpu",
disabled="Temporarily disabled until Triton-XPU upgrade",
)
# TODO: Temporarily disable this test and re-enable it after Triton-XPU is upgraded.
@unittest.skip("Temporarily disabled until Triton-XPU upgrade")
class TestDeepSeekOCRTriton(TestDeepSeekOCR):
@classmethod
def setUpClass(cls):
cls.model = "deepseek-ai/DeepSeek-OCR"
cls.tokenizer = get_tokenizer(cls.model)
cls.base_url = DEFAULT_URL_FOR_TEST
cls.image_path = str(
(Path(__file__).resolve().parents[3] / "examples/assets/example_image.png")
)
if not os.path.exists(cls.image_path):
raise FileNotFoundError(f"Image not found: {cls.image_path}")
cls.common_args = [
"--device",
"xpu",
"--attention-backend",
"intel_xpu",
]
os.environ["SGLANG_USE_SGL_XPU"] = "0"
cls.process = popen_launch_server(
cls.model,
cls.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
other_args=[
*cls.common_args,
],
)
# Prevent pytest from collecting the imported base test class here.
del TestDeepSeekOCR
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,86 @@
"""
Usage:
python3 -m unittest test_intel_xpu_backend.TestIntelXPUBackend.test_latency_qwen_model
"""
import unittest
from functools import wraps
from sglang.test.ci.ci_register import register_xpu_ci
from sglang.test.test_utils import (
DEFAULT_MODEL_NAME_FOR_TEST_FP8_WITH_MOE,
DEFAULT_SMALL_MODEL_NAME_FOR_TEST_BASE,
DEFAULT_SMALL_MODEL_NAME_FOR_TEST_QWEN,
CustomTestCase,
is_in_ci,
run_bench_one_batch,
)
register_xpu_ci(est_time=600, suite="stage-b-test-1-gpu-xpu")
def intel_xpu_benchmark(
extra_args=None, min_throughput=None, mem_fraction_static="0.4"
):
def decorator(test_func):
@wraps(test_func)
def wrapper(self):
common_args = [
"--disable-radix-cache",
"--trust-remote-code",
"--mem-fraction-static",
str(mem_fraction_static),
"--batch-size",
"1",
"--device",
"xpu",
]
ci_args = ["--input", "64", "--output", "4"] if is_in_ci() else []
full_args = common_args + ci_args + (extra_args or [])
model = test_func(self)
prefill_latency, decode_throughput, decode_latency = run_bench_one_batch(
model, full_args
)
print(f"{model=}")
print(f"{prefill_latency=}")
print(f"{decode_throughput=}")
print(f"{decode_latency=}")
if is_in_ci() and min_throughput is not None:
self.assertGreater(decode_throughput, min_throughput)
return wrapper
return decorator
class TestIntelXPUBackend(CustomTestCase):
@intel_xpu_benchmark(min_throughput=10, mem_fraction_static="0.3")
def test_latency_qwen_model(self):
return DEFAULT_SMALL_MODEL_NAME_FOR_TEST_QWEN
@intel_xpu_benchmark(
["--attention-backend", "intel_xpu", "--page-size", "128"],
mem_fraction_static="0.5",
)
def test_attention_backend(self):
return DEFAULT_SMALL_MODEL_NAME_FOR_TEST_BASE
@intel_xpu_benchmark(
[
"--json-model-override-args",
'{"num_hidden_layers": 4}',
"--decode-attention-backend",
"intel_xpu",
],
min_throughput=32,
)
def test_mla_decode_attention_backend(self):
return DEFAULT_MODEL_NAME_FOR_TEST_FP8_WITH_MOE
if __name__ == "__main__":
unittest.main()
+47
View File
@@ -0,0 +1,47 @@
"""
Basic XPU test: verifies the server starts and produces a non-empty
response on Intel XPU with the default attention backend.
Assigned to stage-a so it gates stage-b before the heavier tests run.
Usage:
python3 -m unittest test_xpu_basic.TestXPUBasic.test_basic_generation
"""
import unittest
from sglang.test.ci.ci_register import register_xpu_ci
from sglang.test.test_utils import (
DEFAULT_SMALL_MODEL_NAME_FOR_TEST_QWEN,
CustomTestCase,
is_in_ci,
run_bench_one_batch,
)
register_xpu_ci(est_time=300, suite="stage-a-test-1-gpu-xpu")
class TestXPUBasic(CustomTestCase):
def test_basic_generation(self):
"""Server starts on XPU and completes at least one decode step."""
args = [
"--device",
"xpu",
"--disable-radix-cache",
"--mem-fraction-static",
"0.6",
"--batch-size",
"1",
]
if is_in_ci():
args += ["--input", "64", "--output", "4"]
_, decode_throughput, _ = run_bench_one_batch(
DEFAULT_SMALL_MODEL_NAME_FOR_TEST_QWEN, args
)
self.assertGreater(decode_throughput, 0, "XPU decode throughput must be > 0")
if __name__ == "__main__":
unittest.main()