Support Qwen3 MoE context parallel (#18233)

Co-authored-by: Shunkang <182541032+Shunkangz@users.noreply.github.co>
Co-authored-by: Jiying Dong <87510204+dongjiyingdjy@users.noreply.github.com>
This commit is contained in:
Shunkangz
2026-03-22 01:27:20 -07:00
committed by GitHub
co-authored by Shunkang Jiying Dong
parent 6d160b42bb
commit bb737d7a82
19 changed files with 968 additions and 73 deletions
@@ -0,0 +1,77 @@
import unittest
from types import SimpleNamespace
from sglang.test.ci.ci_register import register_cuda_ci
from sglang.test.run_eval import run_eval
from sglang.test.test_utils import (
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
DEFAULT_URL_FOR_TEST,
CustomTestCase,
kill_process_tree,
popen_launch_server,
)
register_cuda_ci(est_time=300, suite="stage-c-test-4-gpu-h100")
QWEN3_30B_MODEL_PATH = "Qwen/Qwen3-30B-A3B-FP8"
GSM8K_BASELINE_ACCURACY = 0.85
class TestQwen330B(CustomTestCase):
@classmethod
def setUpClass(cls):
cls.model = QWEN3_30B_MODEL_PATH
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",
"4",
"--moe-dp-size",
"2",
"--ep-size",
"2",
"--attn-cp-size",
"2",
"--enable-prefill-context-parallel",
"--cuda-graph-max-bs",
"32",
"--max-running-requests",
"32",
"--trust-remote-code",
"--disable-piecewise-cuda-graph",
"--model-loader-extra-config",
'{"enable_multithread_load": true, "num_threads": 64}',
],
)
@classmethod
def tearDownClass(cls):
kill_process_tree(cls.process.pid)
def test_gsm8k(self):
args = SimpleNamespace(
model=self.model,
eval_name="gsm8k",
num_shots=5,
num_examples=200,
max_tokens=16000,
num_threads=128,
repeat=1,
temperature=0.6,
top_p=0.95,
top_k=20,
base_url=self.base_url,
host="http://127.0.0.1",
port=int(self.base_url.split(":")[-1]),
)
metrics = run_eval(args)
print(f"{metrics=}")
self.assertGreaterEqual(metrics["score"], GSM8K_BASELINE_ACCURACY)
if __name__ == "__main__":
unittest.main()
@@ -18,9 +18,10 @@ QWEN3_235B_EAGLE3_MODEL_PATH = (
class TestQwen3235BFP8(unittest.TestCase):
"""Test class for Qwen3-235B-FP8 performance and accuracy.
Two variants:
Three variants:
- basic: TP=8
- eagle3: TP=8 + EP=2 + EAGLE3 speculative decoding
- TP8+CP2+EP2: TP=8 + CP=2 + EP=2 context parallel
Each variant runs BOTH:
- Performance test (using NightlyBenchmarkRunner)
@@ -69,6 +70,42 @@ class TestQwen3235BFP8(unittest.TestCase):
),
)
def test_qwen3_235b_fp8_cp(self):
"""Run performance and accuracy for Qwen3-235B-FP8 with context parallelism."""
BASE_ARGS = [
"--trust-remote-code",
"--model-loader-extra-config",
'{"enable_multithread_load": true, "num_threads": 64}',
]
DP_ARGS = [
"--tp=8",
"--moe-dp-size=2",
"--attn-cp-size=2",
"--ep-size=4",
"--enable-prefill-context-parallel",
]
MTP_ARGS = [
"--cuda-graph-max-bs=32",
"--max-running-requests=32",
]
variants = [
ModelLaunchSettings(
QWEN3_235B_FP8_MODEL_PATH,
tp_size=8,
extra_args=BASE_ARGS + DP_ARGS + MTP_ARGS,
variant="TP8+CP2+EP2",
),
]
run_combined_tests(
models=variants,
test_name="Qwen3-235B-FP8 Context Parallel",
accuracy_params=AccuracyTestParams(dataset="gsm8k", baseline_accuracy=0.88),
)
if __name__ == "__main__":
unittest.main()
@@ -1,6 +1,6 @@
import unittest
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock
from sglang.srt.managers.schedule_batch import Req
from sglang.srt.managers.schedule_policy import AddReqResult, PrefillAdder
@@ -8,6 +8,7 @@ from sglang.srt.mem_cache.base_prefix_cache import (
DecLockRefResult,
IncLockRefResult,
)
from sglang.srt.server_args import ServerArgs, set_global_server_args_for_scheduler
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
from sglang.test.test_utils import CustomTestCase
@@ -17,14 +18,9 @@ register_amd_ci(est_time=2, suite="stage-b-test-small-1-gpu-amd")
class TestPrefillAdder(CustomTestCase):
def setUp(self):
set_global_server_args_for_scheduler(ServerArgs(model_path="dummy"))
self.mock_tree_cache = self.create_tree_cache()
self.mock_token_allocator = self.create_token_allocator()
patcher = patch(
"sglang.srt.managers.schedule_policy.is_nsa_prefill_cp_in_seq_split",
return_value=False,
)
self.mock_is_nsa = patcher.start()
self.addCleanup(patcher.stop)
def create_tree_cache(
self,