[Test] Stage-a sanity kits; consolidate core/ + models_e2e/ tests (#25831)
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
"""Basic sanity: small-but-broad server smoke that downstream stages
|
||||
depend on. Three sanity kits, one shared server, covering protocol
|
||||
contract, decode correctness, and scheduler stress paths."""
|
||||
|
||||
import unittest
|
||||
|
||||
from sglang.srt.utils import kill_process_tree
|
||||
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
|
||||
from sglang.test.kits.basic_api_contract_kit import BasicAPIContractMixin
|
||||
from sglang.test.kits.basic_decode_correctness_kit import BasicDecodeCorrectnessMixin
|
||||
from sglang.test.kits.basic_scheduler_stress_kit import BasicSchedulerStressMixin
|
||||
from sglang.test.test_utils import (
|
||||
DEFAULT_MODEL_NAME_FOR_TEST,
|
||||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
DEFAULT_URL_FOR_TEST,
|
||||
CustomTestCase,
|
||||
popen_launch_server,
|
||||
)
|
||||
|
||||
register_cuda_ci(est_time=120, stage="base-a", runner_config="1-gpu-small")
|
||||
register_amd_ci(est_time=120, suite="stage-a-test-1-gpu-small-amd")
|
||||
|
||||
|
||||
class TestBasicSanity(
|
||||
BasicAPIContractMixin,
|
||||
BasicDecodeCorrectnessMixin,
|
||||
BasicSchedulerStressMixin,
|
||||
CustomTestCase,
|
||||
):
|
||||
served_model_name = DEFAULT_MODEL_NAME_FOR_TEST
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.base_url = DEFAULT_URL_FOR_TEST
|
||||
cls.process = popen_launch_server(
|
||||
DEFAULT_MODEL_NAME_FOR_TEST,
|
||||
cls.base_url,
|
||||
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
other_args=[
|
||||
"--cuda-graph-max-bs",
|
||||
"4",
|
||||
"--mem-fraction-static",
|
||||
"0.7",
|
||||
"--enable-metrics",
|
||||
],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
kill_process_tree(cls.process.pid)
|
||||
|
||||
def test_accuracy_floor(self):
|
||||
# Stage-a-private accuracy guard: hellaswag via the frontend DSL
|
||||
# bound to this server. Catches systematic regressions that pass
|
||||
# every cheap probe in the mixed-in kits but tank multi-choice
|
||||
# reasoning. Not part of any reusable mixin -- accuracy gating
|
||||
# is the gate test's own responsibility.
|
||||
import sglang as sgl
|
||||
from sglang.test.test_programs import test_hellaswag_select
|
||||
|
||||
sgl.set_default_backend(sgl.RuntimeEndpoint(self.base_url))
|
||||
try:
|
||||
accuracy, _ = test_hellaswag_select()
|
||||
finally:
|
||||
sgl.set_default_backend(None)
|
||||
self.assertGreater(
|
||||
accuracy,
|
||||
0.60,
|
||||
f"hellaswag accuracy floor breached: {accuracy:.3f}",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,41 +0,0 @@
|
||||
import unittest
|
||||
|
||||
from sglang.srt.environ import envs
|
||||
from sglang.srt.utils import kill_process_tree
|
||||
from sglang.test.ci.ci_register import register_cuda_ci
|
||||
from sglang.test.kits.eval_accuracy_kit import MMLUMixin
|
||||
from sglang.test.test_utils import (
|
||||
DEFAULT_MODEL_NAME_FOR_TEST,
|
||||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
DEFAULT_URL_FOR_TEST,
|
||||
CustomTestCase,
|
||||
popen_launch_server,
|
||||
)
|
||||
|
||||
# Note: AMD registration removed - test_cpp_radix_cache fails on AMD due to C++ radix tree issues
|
||||
register_cuda_ci(est_time=60, suite="nightly-1-gpu", nightly=True)
|
||||
|
||||
|
||||
class TestCppRadixCache(CustomTestCase, MMLUMixin):
|
||||
mmlu_score_threshold = 0.65
|
||||
mmlu_num_examples = 64
|
||||
mmlu_num_threads = 32
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
envs.SGLANG_EXPERIMENTAL_CPP_RADIX_TREE.set(True)
|
||||
cls.model = DEFAULT_MODEL_NAME_FOR_TEST
|
||||
cls.base_url = DEFAULT_URL_FOR_TEST
|
||||
cls.process = popen_launch_server(
|
||||
cls.model,
|
||||
cls.base_url,
|
||||
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
kill_process_tree(cls.process.pid)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,57 +0,0 @@
|
||||
"""
|
||||
Usage:
|
||||
cd test/srt
|
||||
python3 -m unittest test_deepseek_v3_deterministic.TestFa3Deterministic
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from sglang.test.ci.ci_register import register_cuda_ci
|
||||
from sglang.test.test_deterministic_utils import (
|
||||
COMMON_SERVER_ARGS,
|
||||
TestDeterministicBase,
|
||||
)
|
||||
|
||||
register_cuda_ci(est_time=240, suite="nightly-1-gpu", nightly=True)
|
||||
|
||||
DEEPSEEK_MODEL = "lmsys/sglang-ci-dsv3-test"
|
||||
|
||||
|
||||
class TestFa3Deterministic(TestDeterministicBase):
|
||||
@classmethod
|
||||
def get_model(cls):
|
||||
return DEEPSEEK_MODEL
|
||||
|
||||
# Test with fa3 attention backend
|
||||
@classmethod
|
||||
def get_server_args(cls):
|
||||
args = COMMON_SERVER_ARGS
|
||||
args.extend(
|
||||
[
|
||||
"--attention-backend",
|
||||
"fa3",
|
||||
]
|
||||
)
|
||||
return args
|
||||
|
||||
|
||||
class TestTritonDeterministic(TestDeterministicBase):
|
||||
@classmethod
|
||||
def get_model(cls):
|
||||
return DEEPSEEK_MODEL
|
||||
|
||||
# Test with triton attention backend
|
||||
@classmethod
|
||||
def get_server_args(cls):
|
||||
args = COMMON_SERVER_ARGS
|
||||
args.extend(
|
||||
[
|
||||
"--attention-backend",
|
||||
"triton",
|
||||
]
|
||||
)
|
||||
return args
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,68 +0,0 @@
|
||||
"""
|
||||
Usage:
|
||||
cd test/srt
|
||||
python3 -m unittest test_deterministic.TestDeterministic.TESTCASE
|
||||
|
||||
Note that there is also `python/sglang/test/test_deterministic.py` as an interactive test. We are converting that
|
||||
test into unit tests so that's easily reproducible in CI.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
|
||||
from sglang.test.test_deterministic_utils import (
|
||||
COMMON_SERVER_ARGS,
|
||||
TestDeterministicBase,
|
||||
)
|
||||
from sglang.test.test_utils import is_in_amd_ci
|
||||
|
||||
register_cuda_ci(est_time=207, stage="base-b", runner_config="1-gpu-large")
|
||||
register_amd_ci(est_time=278, suite="stage-b-test-1-gpu-small-amd")
|
||||
|
||||
|
||||
@unittest.skipIf(is_in_amd_ci(), "Skip for AMD CI.")
|
||||
class TestFlashinferDeterministic(TestDeterministicBase):
|
||||
# Test with flashinfer attention backend
|
||||
@classmethod
|
||||
def get_server_args(cls):
|
||||
args = COMMON_SERVER_ARGS
|
||||
args.extend(
|
||||
[
|
||||
"--attention-backend",
|
||||
"flashinfer",
|
||||
]
|
||||
)
|
||||
return args
|
||||
|
||||
|
||||
@unittest.skipIf(is_in_amd_ci(), "Skip for AMD CI.")
|
||||
class TestFa3Deterministic(TestDeterministicBase):
|
||||
# Test with fa3 attention backend
|
||||
@classmethod
|
||||
def get_server_args(cls):
|
||||
args = COMMON_SERVER_ARGS
|
||||
args.extend(
|
||||
[
|
||||
"--attention-backend",
|
||||
"fa3",
|
||||
]
|
||||
)
|
||||
return args
|
||||
|
||||
|
||||
class TestTritonDeterministic(TestDeterministicBase):
|
||||
# Test with triton attention backend
|
||||
@classmethod
|
||||
def get_server_args(cls):
|
||||
args = COMMON_SERVER_ARGS
|
||||
args.extend(
|
||||
[
|
||||
"--attention-backend",
|
||||
"triton",
|
||||
]
|
||||
)
|
||||
return args
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -25,66 +25,55 @@ register_amd_ci(est_time=77, suite="stage-b-test-1-gpu-small-amd")
|
||||
|
||||
|
||||
class TestEngineChildPids(CustomTestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.engine = sgl.Engine(
|
||||
model_path=DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
random_seed=42,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.engine.shutdown()
|
||||
|
||||
def test_get_all_child_pids_returns_live_pids(self):
|
||||
engine = sgl.Engine(
|
||||
model_path=DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
random_seed=42,
|
||||
)
|
||||
try:
|
||||
pids = engine.get_all_child_pids()
|
||||
pids = self.engine.get_all_child_pids()
|
||||
|
||||
self.assertIsInstance(pids, list)
|
||||
self.assertGreater(len(pids), 0, "Expected at least one child PID")
|
||||
self.assertIsInstance(pids, list)
|
||||
self.assertGreater(len(pids), 0, "Expected at least one child PID")
|
||||
|
||||
for pid in pids:
|
||||
self.assertIsInstance(pid, int)
|
||||
self.assertTrue(
|
||||
psutil.pid_exists(pid),
|
||||
f"PID {pid} does not correspond to a running process",
|
||||
)
|
||||
for pid in pids:
|
||||
self.assertIsInstance(pid, int)
|
||||
self.assertTrue(
|
||||
psutil.pid_exists(pid),
|
||||
f"PID {pid} does not correspond to a running process",
|
||||
)
|
||||
|
||||
current_proc = psutil.Process(os.getpid())
|
||||
child_pids = {c.pid for c in current_proc.children(recursive=True)}
|
||||
for pid in pids:
|
||||
self.assertIn(
|
||||
pid,
|
||||
child_pids,
|
||||
f"PID {pid} is not a child of the current process",
|
||||
)
|
||||
finally:
|
||||
engine.shutdown()
|
||||
current_proc = psutil.Process(os.getpid())
|
||||
child_pids = {c.pid for c in current_proc.children(recursive=True)}
|
||||
for pid in pids:
|
||||
self.assertIn(
|
||||
pid,
|
||||
child_pids,
|
||||
f"PID {pid} is not a child of the current process",
|
||||
)
|
||||
|
||||
def test_child_pids_include_scheduler_and_detokenizer(self):
|
||||
engine = sgl.Engine(
|
||||
model_path=DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
random_seed=42,
|
||||
pids = self.engine.get_all_child_pids()
|
||||
# dp_size=1 gives one scheduler + one detokenizer = at least 2 PIDs
|
||||
self.assertGreaterEqual(
|
||||
len(pids),
|
||||
2,
|
||||
"Expected at least 2 child PIDs (scheduler + detokenizer)",
|
||||
)
|
||||
try:
|
||||
pids = engine.get_all_child_pids()
|
||||
# dp_size=1 gives one scheduler + one detokenizer = at least 2 PIDs
|
||||
self.assertGreaterEqual(
|
||||
len(pids),
|
||||
2,
|
||||
"Expected at least 2 child PIDs (scheduler + detokenizer)",
|
||||
)
|
||||
finally:
|
||||
engine.shutdown()
|
||||
|
||||
def test_child_pids_no_duplicates(self):
|
||||
engine = sgl.Engine(
|
||||
model_path=DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
random_seed=42,
|
||||
pids = self.engine.get_all_child_pids()
|
||||
self.assertEqual(
|
||||
len(pids),
|
||||
len(set(pids)),
|
||||
f"Duplicate PIDs found: {pids}",
|
||||
)
|
||||
try:
|
||||
pids = engine.get_all_child_pids()
|
||||
self.assertEqual(
|
||||
len(pids),
|
||||
len(set(pids)),
|
||||
f"Duplicate PIDs found: {pids}",
|
||||
)
|
||||
finally:
|
||||
engine.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
"""Regression test for issue #24394.
|
||||
|
||||
`--enable-deterministic-inference` with `--attention-backend triton` on a
|
||||
hybrid `SWAKVPool` model (Gemma4 family) used to crash with
|
||||
`CUDA error: an illegal memory access` inside `_fwd_kernel_unified`: the
|
||||
unified extend kernel read the new tokens at `out_cache_loc` (full-pool
|
||||
index space) while `SWAKVPool.set_kv_buffer` had written them at the
|
||||
SWA-translated indices. With diverse prompts the OOB never materialises;
|
||||
the repro is same-prompt × high-concurrency, which is what this test fires.
|
||||
"""
|
||||
|
||||
import concurrent.futures
|
||||
import unittest
|
||||
|
||||
import requests
|
||||
|
||||
from sglang.srt.utils import kill_process_tree
|
||||
from sglang.test.ci.ci_register import register_cuda_ci
|
||||
from sglang.test.test_utils import (
|
||||
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
DEFAULT_URL_FOR_TEST,
|
||||
CustomTestCase,
|
||||
popen_launch_server,
|
||||
)
|
||||
|
||||
register_cuda_ci(est_time=107, stage="base-b", runner_config="2-gpu-large")
|
||||
|
||||
|
||||
PROMPT = (
|
||||
"Question: Janet's ducks lay 16 eggs per day. She eats three for breakfast "
|
||||
"every morning and bakes muffins for her friends every day with four. She "
|
||||
"sells the remainder at the farmers' market daily for $2 per fresh duck "
|
||||
"egg. How much in dollars does she make every day at the farmers' market?\n"
|
||||
"Answer:"
|
||||
)
|
||||
NUM_REQUESTS = 180
|
||||
CONCURRENCY = 128
|
||||
MAX_TOKENS = 256
|
||||
|
||||
|
||||
class TestGemma4MoeDeterministic(CustomTestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.model = "google/gemma-4-26B-A4B-it"
|
||||
cls.base_url = DEFAULT_URL_FOR_TEST
|
||||
cls.process = popen_launch_server(
|
||||
cls.model,
|
||||
cls.base_url,
|
||||
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
||||
other_args=[
|
||||
"--tp-size",
|
||||
"2",
|
||||
"--attention-backend",
|
||||
"triton",
|
||||
"--enable-deterministic-inference",
|
||||
"--dtype",
|
||||
"bfloat16",
|
||||
"--mem-fraction-static",
|
||||
"0.55",
|
||||
"--max-running-requests",
|
||||
"16",
|
||||
"--context-length",
|
||||
"2048",
|
||||
"--max-total-tokens",
|
||||
"32768",
|
||||
"--skip-server-warmup",
|
||||
"--random-seed",
|
||||
"0",
|
||||
],
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
if hasattr(cls, "process") and cls.process:
|
||||
kill_process_tree(cls.process.pid)
|
||||
|
||||
def _fire_one(self):
|
||||
try:
|
||||
r = requests.post(
|
||||
self.base_url + "/v1/completions",
|
||||
json={
|
||||
"model": self.model,
|
||||
"prompt": PROMPT,
|
||||
"max_tokens": MAX_TOKENS,
|
||||
"temperature": 0.0,
|
||||
"top_k": 1,
|
||||
},
|
||||
timeout=300,
|
||||
)
|
||||
r.raise_for_status()
|
||||
return True, ""
|
||||
except Exception as e:
|
||||
return False, repr(e)
|
||||
|
||||
def test_no_ima_under_concurrent_load(self):
|
||||
try:
|
||||
requests.get(self.base_url + "/flush_cache", timeout=30)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
n_ok = n_fail = 0
|
||||
first_fail = ""
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=CONCURRENCY) as ex:
|
||||
futs = [ex.submit(self._fire_one) for _ in range(NUM_REQUESTS)]
|
||||
for f in concurrent.futures.as_completed(futs):
|
||||
ok, msg = f.result()
|
||||
if ok:
|
||||
n_ok += 1
|
||||
else:
|
||||
if n_fail == 0:
|
||||
first_fail = msg
|
||||
n_fail += 1
|
||||
|
||||
print(f"n_ok={n_ok} n_fail={n_fail} first_fail={first_fail!r}")
|
||||
self.assertEqual(
|
||||
n_fail,
|
||||
0,
|
||||
f"{n_fail}/{NUM_REQUESTS} requests failed; first error: {first_fail}",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,34 +0,0 @@
|
||||
import unittest
|
||||
|
||||
import torch
|
||||
|
||||
from sglang.test.ci.ci_register import register_cuda_ci
|
||||
from sglang.test.gpt_oss_common import BaseTestGptOss
|
||||
|
||||
register_cuda_ci(est_time=345, stage="extra-a", runner_config="1-gpu-small")
|
||||
|
||||
|
||||
@unittest.skipIf(not torch.cuda.is_available(), "CUDA is not available")
|
||||
class TestGptOssSm120(BaseTestGptOss):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
compute_capability = torch.cuda.get_device_capability()
|
||||
if compute_capability != (12, 0):
|
||||
raise unittest.SkipTest(
|
||||
f"GPT-OSS SM120 test requires SM 12.0, but found {compute_capability[0]}.{compute_capability[1]}"
|
||||
)
|
||||
|
||||
def test_mxfp4_20b(self):
|
||||
self.run_test(
|
||||
model_variant="20b",
|
||||
quantization="mxfp4",
|
||||
expected_score_of_reasoning_effort={
|
||||
"low": 0.34,
|
||||
"medium": 0.34,
|
||||
"high": 0.27,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -19,29 +19,39 @@ if _is_hip:
|
||||
|
||||
|
||||
class TestHiddenState(CustomTestCase):
|
||||
def test_return_hidden_states(self):
|
||||
prompts = ["Today is", "Today is a sunny day and I like"]
|
||||
model_path = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
||||
input_ids = tokenizer(prompts).input_ids
|
||||
|
||||
sampling_params = {
|
||||
"temperature": 0,
|
||||
"max_new_tokens": 8,
|
||||
}
|
||||
|
||||
engine = sgl.Engine(
|
||||
model_path=model_path,
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.model_path = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
|
||||
cls.tokenizer = AutoTokenizer.from_pretrained(cls.model_path)
|
||||
cls.prompts = ["Today is", "Today is a sunny day and I like"]
|
||||
cls.input_ids = cls.tokenizer(cls.prompts).input_ids
|
||||
cls.sampling_params = {"temperature": 0, "max_new_tokens": 8}
|
||||
# mem_fraction_static=0.7 leaves headroom for the HF reference
|
||||
# model that test_return_hidden_states loads on the same GPU.
|
||||
cls.engine = sgl.Engine(
|
||||
model_path=cls.model_path,
|
||||
random_seed=42,
|
||||
skip_tokenizer_init=True,
|
||||
enable_return_hidden_states=True,
|
||||
mem_fraction_static=0.7,
|
||||
)
|
||||
outputs = engine.generate(
|
||||
input_ids=input_ids,
|
||||
sampling_params=sampling_params,
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.engine.shutdown()
|
||||
|
||||
def setUp(self):
|
||||
# Tests share one Engine; flush radix cache so each test sees a
|
||||
# cold prefill (test_return_hidden_states asserts on the prefill
|
||||
# hidden-state shape, which collapses to 0 on a full cache hit).
|
||||
self.engine.flush_cache()
|
||||
|
||||
def test_return_hidden_states(self):
|
||||
outputs = self.engine.generate(
|
||||
input_ids=self.input_ids,
|
||||
sampling_params=self.sampling_params,
|
||||
return_hidden_states=True,
|
||||
)
|
||||
engine.shutdown()
|
||||
|
||||
for output in outputs:
|
||||
self.assertEqual(len(output["meta_info"]["hidden_states"]), 8)
|
||||
@@ -57,10 +67,10 @@ class TestHiddenState(CustomTestCase):
|
||||
)
|
||||
|
||||
model = AutoModelForCausalLM.from_pretrained(
|
||||
model_path, torch_dtype=torch.bfloat16, device_map=get_device()
|
||||
self.model_path, torch_dtype=torch.bfloat16, device_map=get_device()
|
||||
)
|
||||
|
||||
for input_id, output in zip(input_ids, outputs):
|
||||
for input_id, output in zip(self.input_ids, outputs):
|
||||
with torch.inference_mode():
|
||||
hf_out = model(
|
||||
torch.tensor(
|
||||
@@ -94,39 +104,22 @@ class TestHiddenState(CustomTestCase):
|
||||
)
|
||||
|
||||
def test_repeatedly_changes_hidden_states(self):
|
||||
prompts = ["Today is", "Today is a sunny day and I like"]
|
||||
model_path = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
||||
input_ids = tokenizer(prompts).input_ids
|
||||
|
||||
sampling_params = {
|
||||
"temperature": 0,
|
||||
"max_new_tokens": 8,
|
||||
}
|
||||
|
||||
engine = sgl.Engine(
|
||||
model_path=model_path,
|
||||
random_seed=42,
|
||||
skip_tokenizer_init=True,
|
||||
enable_return_hidden_states=True,
|
||||
)
|
||||
outputs_completion_first_round = engine.generate(
|
||||
input_ids=input_ids,
|
||||
sampling_params=sampling_params,
|
||||
outputs_completion_first_round = self.engine.generate(
|
||||
input_ids=self.input_ids,
|
||||
sampling_params=self.sampling_params,
|
||||
return_hidden_states=True,
|
||||
)
|
||||
outputs_hidden_state = engine.generate(
|
||||
input_ids=input_ids,
|
||||
sampling_params=sampling_params,
|
||||
outputs_hidden_state = self.engine.generate(
|
||||
input_ids=self.input_ids,
|
||||
sampling_params=self.sampling_params,
|
||||
return_hidden_states=False,
|
||||
)
|
||||
|
||||
outputs_completion_last_round = engine.generate(
|
||||
input_ids=input_ids,
|
||||
sampling_params=sampling_params,
|
||||
outputs_completion_last_round = self.engine.generate(
|
||||
input_ids=self.input_ids,
|
||||
sampling_params=self.sampling_params,
|
||||
return_hidden_states=True,
|
||||
)
|
||||
engine.shutdown()
|
||||
|
||||
for (
|
||||
output_completion_first_round,
|
||||
|
||||
@@ -1,290 +0,0 @@
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from sglang.srt.server_args import ServerArgs
|
||||
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
|
||||
|
||||
register_cuda_ci(est_time=9, stage="base-b", runner_config="1-gpu-small")
|
||||
register_amd_ci(est_time=1, suite="stage-b-test-1-gpu-small-amd")
|
||||
|
||||
|
||||
class TestMmProcessConfigValidation(unittest.TestCase):
|
||||
"""Server-args validation for mm_process_config."""
|
||||
|
||||
def test_valid_config_accepted(self):
|
||||
args = ServerArgs(
|
||||
model_path="dummy",
|
||||
mm_process_config={"image": {"max_pixels": 5000000}},
|
||||
)
|
||||
self.assertEqual(args.mm_process_config, {"image": {"max_pixels": 5000000}})
|
||||
|
||||
def test_empty_config_accepted(self):
|
||||
args = ServerArgs(model_path="dummy", mm_process_config={})
|
||||
self.assertEqual(args.mm_process_config, {})
|
||||
|
||||
def test_none_config_defaults_to_empty_dict(self):
|
||||
args = ServerArgs(model_path="dummy", mm_process_config=None)
|
||||
# None is kept as-is for dummy models (default happens after early return)
|
||||
# but for real models it would be set to {}
|
||||
self.assertIsNone(args.mm_process_config)
|
||||
|
||||
def test_top_level_non_dict_rejected(self):
|
||||
with self.assertRaises(TypeError) as ctx:
|
||||
ServerArgs(model_path="dummy", mm_process_config="bad")
|
||||
self.assertIn("mm_process_config must be a dict", str(ctx.exception))
|
||||
|
||||
def test_modality_non_dict_rejected_image(self):
|
||||
with self.assertRaises(TypeError) as ctx:
|
||||
ServerArgs(model_path="dummy", mm_process_config={"image": "bad"})
|
||||
self.assertIn("mm_process_config['image'] must be a dict", str(ctx.exception))
|
||||
|
||||
def test_modality_non_dict_rejected_video(self):
|
||||
with self.assertRaises(TypeError) as ctx:
|
||||
ServerArgs(model_path="dummy", mm_process_config={"video": 123})
|
||||
self.assertIn("mm_process_config['video'] must be a dict", str(ctx.exception))
|
||||
|
||||
def test_modality_non_dict_rejected_audio(self):
|
||||
with self.assertRaises(TypeError) as ctx:
|
||||
ServerArgs(model_path="dummy", mm_process_config={"audio": [1, 2]})
|
||||
self.assertIn("mm_process_config['audio'] must be a dict", str(ctx.exception))
|
||||
|
||||
def test_multi_modality_config_accepted(self):
|
||||
config = {
|
||||
"image": {"max_pixels": 1048576},
|
||||
"video": {"max_pixels": 602112},
|
||||
"audio": {"sample_rate": 16000},
|
||||
}
|
||||
args = ServerArgs(model_path="dummy", mm_process_config=config)
|
||||
self.assertEqual(args.mm_process_config, config)
|
||||
|
||||
|
||||
class TestBaseProcessorConfigExtraction(unittest.TestCase):
|
||||
"""Verify BaseMultimodalProcessor.__init__ extracts configs from server_args."""
|
||||
|
||||
def _make_processor(self, mm_process_config):
|
||||
"""Create a BaseMultimodalProcessor via the real __init__ with mocked deps."""
|
||||
from sglang.srt.multimodal.processors.base_processor import (
|
||||
BaseMultimodalProcessor,
|
||||
)
|
||||
|
||||
server_args = MagicMock()
|
||||
server_args.mm_process_config = mm_process_config
|
||||
|
||||
hf_config = MagicMock()
|
||||
mock_hf_processor = MagicMock()
|
||||
|
||||
# Call real __init__ so we test actual config extraction
|
||||
with patch.object(BaseMultimodalProcessor, "__abstractmethods__", set()):
|
||||
proc = BaseMultimodalProcessor(
|
||||
hf_config=hf_config,
|
||||
server_args=server_args,
|
||||
_processor=mock_hf_processor,
|
||||
transport_mode=None,
|
||||
)
|
||||
return proc
|
||||
|
||||
def test_configs_extracted(self):
|
||||
config = {
|
||||
"image": {"max_pixels": 5000000},
|
||||
"video": {"fps": 3},
|
||||
"audio": {"sample_rate": 16000},
|
||||
}
|
||||
proc = self._make_processor(config)
|
||||
self.assertEqual(proc.image_config, {"max_pixels": 5000000})
|
||||
self.assertEqual(proc.video_config, {"fps": 3})
|
||||
self.assertEqual(proc.audio_config, {"sample_rate": 16000})
|
||||
|
||||
def test_empty_config_yields_empty_dicts(self):
|
||||
proc = self._make_processor({})
|
||||
self.assertEqual(proc.image_config, {})
|
||||
self.assertEqual(proc.video_config, {})
|
||||
self.assertEqual(proc.audio_config, {})
|
||||
|
||||
|
||||
class TestProcessMmDataKwargs(unittest.TestCase):
|
||||
"""Verify process_mm_data injects per-modality kwargs correctly."""
|
||||
|
||||
def _make_base_processor(self, mm_process_config):
|
||||
"""Create a BaseMultimodalProcessor with process_mm_data testable."""
|
||||
from sglang.srt.multimodal.processors.base_processor import (
|
||||
BaseMultimodalProcessor,
|
||||
)
|
||||
|
||||
server_args = MagicMock()
|
||||
server_args.mm_process_config = mm_process_config
|
||||
server_args.disable_fast_image_processor = True
|
||||
server_args.keep_mm_feature_on_device = True
|
||||
|
||||
mock_processor = MagicMock()
|
||||
mock_processor.__class__.__name__ = "TestProcessor"
|
||||
# Capture kwargs passed to __call__
|
||||
captured_kwargs = {}
|
||||
|
||||
def capture_call(**kwargs):
|
||||
captured_kwargs.update(kwargs)
|
||||
return {}
|
||||
|
||||
mock_processor.__call__ = MagicMock(side_effect=capture_call)
|
||||
|
||||
with patch.object(BaseMultimodalProcessor, "__abstractmethods__", set()):
|
||||
with patch.object(BaseMultimodalProcessor, "__init__", lambda self: None):
|
||||
proc = BaseMultimodalProcessor()
|
||||
|
||||
proc.server_args = server_args
|
||||
proc._processor = mock_processor
|
||||
proc.image_config = mm_process_config.get("image", {})
|
||||
proc.video_config = mm_process_config.get("video", {})
|
||||
proc.audio_config = mm_process_config.get("audio", {})
|
||||
proc.FEATURE_NAMES = []
|
||||
|
||||
return proc, mock_processor, captured_kwargs
|
||||
|
||||
def test_images_kwargs_injected(self):
|
||||
config = {"image": {"max_pixels": 5000000}}
|
||||
proc, mock_proc, _ = self._make_base_processor(config)
|
||||
|
||||
proc.process_mm_data("test", images=["img1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
self.assertEqual(
|
||||
call_kwargs.kwargs.get("images_kwargs"), {"max_pixels": 5000000}
|
||||
)
|
||||
|
||||
def test_videos_kwargs_injected(self):
|
||||
config = {"video": {"fps": 3, "max_frames": 60}}
|
||||
proc, mock_proc, _ = self._make_base_processor(config)
|
||||
|
||||
proc.process_mm_data("test", videos=["vid1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
self.assertEqual(
|
||||
call_kwargs.kwargs.get("videos_kwargs"), {"fps": 3, "max_frames": 60}
|
||||
)
|
||||
|
||||
def test_no_collision_with_overlapping_keys(self):
|
||||
"""Core test: image and video both have max_pixels but stay separate."""
|
||||
config = {
|
||||
"image": {"max_pixels": 1048576},
|
||||
"video": {"max_pixels": 602112},
|
||||
}
|
||||
proc, mock_proc, _ = self._make_base_processor(config)
|
||||
|
||||
proc.process_mm_data("test", images=["img1"], videos=["vid1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
self.assertEqual(
|
||||
call_kwargs.kwargs.get("images_kwargs"), {"max_pixels": 1048576}
|
||||
)
|
||||
self.assertEqual(
|
||||
call_kwargs.kwargs.get("videos_kwargs"), {"max_pixels": 602112}
|
||||
)
|
||||
|
||||
def test_empty_config_no_kwargs_injected(self):
|
||||
proc, mock_proc, _ = self._make_base_processor({})
|
||||
|
||||
proc.process_mm_data("test", images=["img1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
self.assertNotIn("images_kwargs", call_kwargs.kwargs)
|
||||
|
||||
def test_audio_kwargs_preserved_with_config(self):
|
||||
"""audio_config merges with existing truncation=False."""
|
||||
config = {"audio": {"sample_rate": 16000}}
|
||||
proc, mock_proc, _ = self._make_base_processor(config)
|
||||
# Simulate a processor that uses singular "audio" key
|
||||
mock_proc.__class__.__name__ = "Gemma3nProcessor"
|
||||
|
||||
proc.process_mm_data("test", audios=["aud1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
audio_kw = call_kwargs.kwargs.get("audio_kwargs", {})
|
||||
self.assertFalse(audio_kw.get("truncation", True))
|
||||
self.assertEqual(audio_kw.get("sample_rate"), 16000)
|
||||
|
||||
|
||||
class TestOverrideProcessorsConfigInjection(unittest.TestCase):
|
||||
"""Regression tests for processors that override process_mm_data."""
|
||||
|
||||
def _make_override_processor(self, processor_cls, mm_process_config):
|
||||
"""Create an override processor with mocked dependencies."""
|
||||
server_args = MagicMock()
|
||||
server_args.mm_process_config = mm_process_config
|
||||
server_args.disable_fast_image_processor = True
|
||||
server_args.keep_mm_feature_on_device = False
|
||||
|
||||
mock_hf_processor = MagicMock()
|
||||
mock_hf_processor.__class__.__name__ = "TestProcessor"
|
||||
# Ernie processor accesses result["images"] after __call__,
|
||||
# so return {"images": None} to pass the None-guard safely.
|
||||
mock_hf_processor.__call__ = MagicMock(return_value={"images": None})
|
||||
|
||||
with patch.object(processor_cls, "__init__", lambda self: None):
|
||||
proc = processor_cls()
|
||||
|
||||
proc.server_args = server_args
|
||||
proc._processor = mock_hf_processor
|
||||
proc.image_config = mm_process_config.get("image", {})
|
||||
proc.video_config = mm_process_config.get("video", {})
|
||||
proc.audio_config = mm_process_config.get("audio", {})
|
||||
proc.FEATURE_NAMES = []
|
||||
|
||||
return proc, mock_hf_processor
|
||||
|
||||
def test_ernie45_vl_injects_images_kwargs(self):
|
||||
from sglang.srt.multimodal.processors.ernie45_vl import (
|
||||
Ernie4_5_VLImageProcessor,
|
||||
)
|
||||
|
||||
config = {"image": {"max_pixels": 2000000}, "video": {"max_pixels": 500000}}
|
||||
proc, mock_proc = self._make_override_processor(
|
||||
Ernie4_5_VLImageProcessor, config
|
||||
)
|
||||
|
||||
proc.process_mm_data("test", images=["img1"], videos=["vid1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
self.assertEqual(
|
||||
call_kwargs.kwargs.get("images_kwargs"), {"max_pixels": 2000000}
|
||||
)
|
||||
self.assertEqual(
|
||||
call_kwargs.kwargs.get("videos_kwargs"), {"max_pixels": 500000}
|
||||
)
|
||||
|
||||
def test_midashenglm_injects_audio_kwargs(self):
|
||||
from sglang.srt.multimodal.processors.midashenglm import (
|
||||
MiDashengLMMultimodalProcessor,
|
||||
)
|
||||
|
||||
config = {"audio": {"sample_rate": 16000}}
|
||||
proc, mock_proc = self._make_override_processor(
|
||||
MiDashengLMMultimodalProcessor, config
|
||||
)
|
||||
|
||||
proc.process_mm_data("test", audios=["aud1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
audio_kw = call_kwargs.kwargs.get("audio_kwargs", {})
|
||||
self.assertFalse(audio_kw.get("truncation", True))
|
||||
self.assertEqual(audio_kw.get("sample_rate"), 16000)
|
||||
|
||||
def test_midashenglm_user_config_overrides_truncation(self):
|
||||
"""User config can override the default truncation=False."""
|
||||
from sglang.srt.multimodal.processors.midashenglm import (
|
||||
MiDashengLMMultimodalProcessor,
|
||||
)
|
||||
|
||||
config = {"audio": {"truncation": True}}
|
||||
proc, mock_proc = self._make_override_processor(
|
||||
MiDashengLMMultimodalProcessor, config
|
||||
)
|
||||
|
||||
proc.process_mm_data("test", audios=["aud1"])
|
||||
|
||||
call_kwargs = mock_proc.__call__.call_args
|
||||
audio_kw = call_kwargs.kwargs.get("audio_kwargs", {})
|
||||
# User config can override truncation if they explicitly set it
|
||||
self.assertTrue(audio_kw.get("truncation"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,47 +0,0 @@
|
||||
"""
|
||||
Usage:
|
||||
cd test/srt
|
||||
python3 -m unittest test_qwen3_next_deterministic.TestFlashInferDeterministic
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from sglang.test.ci.ci_register import register_cuda_ci
|
||||
from sglang.test.test_deterministic_utils import (
|
||||
COMMON_SERVER_ARGS,
|
||||
TestDeterministicBase,
|
||||
)
|
||||
|
||||
register_cuda_ci(est_time=200, suite="nightly-4-gpu", nightly=True)
|
||||
|
||||
QWEN3_NEXT = "Qwen/Qwen3-Next-80B-A3B-Instruct"
|
||||
|
||||
|
||||
class TestFlashInferDeterministic(TestDeterministicBase):
|
||||
@classmethod
|
||||
def get_model(cls):
|
||||
return QWEN3_NEXT
|
||||
|
||||
# Test with flashinfer attention backend
|
||||
@classmethod
|
||||
def get_server_args(cls):
|
||||
args = COMMON_SERVER_ARGS
|
||||
args.extend(["--attention-backend", "flashinfer", "--tp", "4"])
|
||||
return args
|
||||
|
||||
|
||||
class TestTritonDeterministic(TestDeterministicBase):
|
||||
@classmethod
|
||||
def get_model(cls):
|
||||
return QWEN3_NEXT
|
||||
|
||||
# Test with triton attention backend
|
||||
@classmethod
|
||||
def get_server_args(cls):
|
||||
args = COMMON_SERVER_ARGS
|
||||
args.extend(["--attention-backend", "triton", "--tp", "4"])
|
||||
return args
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -95,18 +95,6 @@ class TestSRTEndpoint(CustomTestCase):
|
||||
print(json.dumps(response_json, indent=2))
|
||||
print("=" * 100)
|
||||
|
||||
def test_simple_decode(self):
|
||||
self.run_decode()
|
||||
|
||||
def test_simple_decode_batch(self):
|
||||
self.run_decode(batch=True)
|
||||
|
||||
def test_parallel_sample(self):
|
||||
self.run_decode(n=3)
|
||||
|
||||
def test_parallel_sample_stream(self):
|
||||
self.run_decode(n=3, stream=True)
|
||||
|
||||
def test_logprob(self):
|
||||
self.run_decode(
|
||||
return_logprob=True,
|
||||
|
||||
@@ -6,7 +6,6 @@ python3 -m unittest test_srt_engine.TestSRTEngine.test_4_sync_async_stream_combi
|
||||
import asyncio
|
||||
import json
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
import torch
|
||||
|
||||
@@ -15,7 +14,6 @@ from sglang.bench_offline_throughput import BenchArgs, throughput_test
|
||||
from sglang.srt.server_args import ServerArgs
|
||||
from sglang.srt.utils.hf_transformers_utils import get_tokenizer
|
||||
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
|
||||
from sglang.test.few_shot_gsm8k_engine import run_eval
|
||||
from sglang.test.test_utils import (
|
||||
DEFAULT_SMALL_EMBEDDING_MODEL_NAME_FOR_TEST,
|
||||
DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
@@ -89,68 +87,6 @@ class TestSRTEngine(CustomTestCase):
|
||||
print(out2)
|
||||
self.assertEqual(out1, out2)
|
||||
|
||||
def test_4_sync_async_stream_combination(self):
|
||||
prompt = "AI safety is"
|
||||
sampling_params = {"temperature": 0.8, "top_p": 0.95}
|
||||
|
||||
# Create an LLM.
|
||||
llm = sgl.Engine(
|
||||
model_path=DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
)
|
||||
|
||||
if True:
|
||||
# 1. sync + non streaming
|
||||
print("\n\n==== 1. sync + non streaming ====")
|
||||
output = llm.generate(prompt, sampling_params)
|
||||
print(output["text"])
|
||||
|
||||
# 2. sync + streaming
|
||||
print("\n\n==== 2. sync + streaming ====")
|
||||
output_generator = llm.generate(prompt, sampling_params, stream=True)
|
||||
offset = 0
|
||||
for output in output_generator:
|
||||
print(output["text"][offset:], end="", flush=True)
|
||||
offset = len(output["text"])
|
||||
print()
|
||||
|
||||
if True:
|
||||
loop = asyncio.get_event_loop()
|
||||
# 3. async + non_streaming
|
||||
print("\n\n==== 3. async + non streaming ====")
|
||||
output = loop.run_until_complete(
|
||||
llm.async_generate(prompt, sampling_params)
|
||||
)
|
||||
print(output["text"])
|
||||
|
||||
# 4. async + streaming
|
||||
async def async_streaming(engine):
|
||||
generator = await engine.async_generate(
|
||||
prompt, sampling_params, stream=True
|
||||
)
|
||||
|
||||
offset = 0
|
||||
async for output in generator:
|
||||
print(output["text"][offset:], end="", flush=True)
|
||||
offset = len(output["text"])
|
||||
print()
|
||||
|
||||
print("\n\n==== 4. async + streaming ====")
|
||||
loop.run_until_complete(async_streaming(llm))
|
||||
|
||||
llm.shutdown()
|
||||
|
||||
def test_5_gsm8k(self):
|
||||
|
||||
args = SimpleNamespace(
|
||||
model_path=DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
|
||||
local_data_path=None,
|
||||
num_shots=5,
|
||||
num_questions=1400,
|
||||
)
|
||||
|
||||
metrics = run_eval(args)
|
||||
self.assertGreater(metrics["accuracy"], 0.33)
|
||||
|
||||
def test_6_engine_cpu_offload(self):
|
||||
prompt = "Today is a sunny day and I like"
|
||||
model_path = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
|
||||
|
||||
Reference in New Issue
Block a user