Add pr tests (#31952)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: sglang-npu-bot <sglangnpu@163.com>
Co-authored-by: Cherry_ming <136634645@qq.com>
This commit is contained in:
Sugar920
2026-08-01 15:03:21 +08:00
committed by GitHub
co-authored by Claude sglang-npu-bot Cherry_ming
parent fd96a35fb0
commit 33ecf4bcd8
170 changed files with 1968 additions and 329 deletions
@@ -0,0 +1,84 @@
import os
import unittest
from types import SimpleNamespace
from urllib.parse import urlparse
from sglang.srt.utils import kill_process_tree
from sglang.test.ci.ci_register import register_npu_ci
from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
from sglang.test.test_utils import (
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
DEFAULT_URL_FOR_TEST,
CustomTestCase,
popen_launch_server,
)
register_npu_ci(est_time=400, suite="stage-b-test-1-npu-a2", nightly=False)
register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
TEST_MODEL_MATRIX = {
"/root/.cache/modelscope/hub/models/Qwen/Qwen2.5-7B-Instruct": {
"accuracy": 0.84,
"latency": 150,
"output_throughput": 30,
},
}
os.environ["ASCEND_USE_FIA"] = "true"
class TestAscendTp1Bf16(CustomTestCase):
@classmethod
def setUpClass(cls):
cls.models = TEST_MODEL_MATRIX.keys()
cls.base_url = DEFAULT_URL_FOR_TEST
cls.url = urlparse(DEFAULT_URL_FOR_TEST)
cls.common_args = [
"--trust-remote-code",
"--mem-fraction-static",
0.6,
"--attention-backend",
"ascend",
"--disable-radix-cache",
"--enable-torch-compile",
"--watchdog-timeout",
30000,
]
def test_a_gsm8k(self):
for model in self.models:
with self.subTest(model=model):
print(f"##=== Testing accuracy: {model} ===##")
process = popen_launch_server(
model,
self.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
other_args=[
*self.common_args,
],
)
try:
args = SimpleNamespace(
num_shots=5,
data_path=None,
num_questions=1319,
max_new_tokens=512,
parallel=32,
host=f"http://{self.url.hostname}",
port=int(self.url.port),
)
metrics = run_eval_few_shot_gsm8k(args)
self.assertGreaterEqual(
metrics["accuracy"],
TEST_MODEL_MATRIX[model]["accuracy"],
)
finally:
kill_process_tree(process.pid)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,76 @@
import unittest
from types import SimpleNamespace
from urllib.parse import urlparse
from sglang.srt.utils import kill_process_tree
from sglang.test.ci.ci_register import register_npu_ci
from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
from sglang.test.test_utils import (
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
DEFAULT_URL_FOR_TEST,
CustomTestCase,
popen_launch_server,
)
register_npu_ci(est_time=400, suite="full-1-npu-a3", nightly=True)
TEST_MODEL_MATRIX = {
"/root/.cache/modelscope/hub/models/Qwen/Qwen2.5-7B-Instruct": {
"accuracy": 0.85,
"latency": 150,
"output_throughput": 30,
},
}
class TestAscendGraphTp1Bf16(CustomTestCase):
@classmethod
def setUpClass(cls):
cls.models = TEST_MODEL_MATRIX.keys()
cls.base_url = DEFAULT_URL_FOR_TEST
cls.url = urlparse(DEFAULT_URL_FOR_TEST)
cls.common_args = [
"--trust-remote-code",
"--mem-fraction-static",
0.8,
"--attention-backend",
"ascend",
]
def test_a_gsm8k(self):
for model in self.models:
with self.subTest(model=model):
print(f"##=== Testing accuracy: {model} ===##")
process = popen_launch_server(
model,
self.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
other_args=[
*self.common_args,
],
)
try:
args = SimpleNamespace(
num_shots=5,
data_path=None,
num_questions=1319,
max_new_tokens=512,
parallel=128,
host=f"http://{self.url.hostname}",
port=int(self.url.port),
)
metrics = run_eval_few_shot_gsm8k(args)
self.assertGreaterEqual(
metrics["accuracy"],
TEST_MODEL_MATRIX[model]["accuracy"],
)
finally:
kill_process_tree(process.pid)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,78 @@
import unittest
from types import SimpleNamespace
from urllib.parse import urlparse
from sglang.srt.utils import kill_process_tree
from sglang.test.ci.ci_register import register_npu_ci
from sglang.test.few_shot_gsm8k import run_eval as run_eval_few_shot_gsm8k
from sglang.test.test_utils import (
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
DEFAULT_URL_FOR_TEST,
CustomTestCase,
popen_launch_server,
)
register_npu_ci(est_time=400, suite="full-2-npu-a3", nightly=True)
TEST_MODEL_MATRIX = {
"/root/.cache/modelscope/hub/models/Qwen/Qwen2.5-7B-Instruct": {
"accuracy": 0.85,
"latency": 180,
"output_throughput": 20,
},
}
class TestAscendGraphTp2Bf16(CustomTestCase):
@classmethod
def setUpClass(cls):
cls.models = TEST_MODEL_MATRIX.keys()
cls.base_url = DEFAULT_URL_FOR_TEST
cls.url = urlparse(DEFAULT_URL_FOR_TEST)
cls.common_args = [
"--trust-remote-code",
"--mem-fraction-static",
0.8,
"--attention-backend",
"ascend",
"--tp-size",
2,
]
def test_a_gsm8k(self):
for model in self.models:
with self.subTest(model=model):
print(f"##=== Testing accuracy: {model} ===##")
process = popen_launch_server(
model,
self.base_url,
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
other_args=[
*self.common_args,
],
)
try:
args = SimpleNamespace(
num_shots=5,
data_path=None,
num_questions=1319,
max_new_tokens=512,
parallel=128,
host=f"http://{self.url.hostname}",
port=int(self.url.port),
)
metrics = run_eval_few_shot_gsm8k(args)
self.assertGreaterEqual(
metrics["accuracy"],
TEST_MODEL_MATRIX[model]["accuracy"],
)
finally:
kill_process_tree(process.pid)
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,77 @@
import subprocess
import unittest
from sglang.test.ascend.gsm8k_ascend_mixin import GSM8KAscendMixin
from sglang.test.ascend.test_ascend_utils import (
QWEN2_5_7B_INSTRUCT_WEIGHTS_PATH,
write_results_to_github_step_summary,
)
from sglang.test.ci.ci_register import register_npu_ci
from sglang.test.test_utils import (
CustomTestCase,
run_bench_one_batch,
)
register_npu_ci(est_time=400, suite="stage-b-test-1-npu-a2", nightly=False)
register_npu_ci(est_time=400, suite="nightly-1-npu-a3", nightly=True)
TOKENS_TO_CAPTURE = [i for i in range(128, 4096, 128)]
class TestPiecewiseGraphPrefillCorrectness(GSM8KAscendMixin, CustomTestCase):
model = QWEN2_5_7B_INSTRUCT_WEIGHTS_PATH
other_args = [
"--trust-remote-code",
"--mem-fraction-static",
0.8,
"--attention-backend",
"ascend",
"--cuda-graph-bs",
128,
"--cuda-graph-backend-prefill=tc_piecewise",
"--cuda-graph-bs-prefill",
*TOKENS_TO_CAPTURE,
]
accuracy = 0.84
num_questions = 1319
class TestPiecewiseGraphPrefillBenchmark(CustomTestCase):
model = QWEN2_5_7B_INSTRUCT_WEIGHTS_PATH
other_args = [
"--trust-remote-code",
"--mem-fraction-static",
0.8,
"--attention-backend",
"ascend",
"--cuda-graph-backend-prefill=tc_piecewise",
"--cuda-graph-bs-prefill",
] + TOKENS_TO_CAPTURE
latency = 0.045
def test_latency(self):
print(f"##=== Testing prefill latency: {self.model} ===##")
model_metrics = {
"server": subprocess.list2cmdline(map(str, self.other_args)),
"client": "bench_one_batch",
"latency_threshold": self.latency,
}
try:
prefill_latency, _, _ = run_bench_one_batch(
self.model,
other_args=self.other_args,
)
model_metrics["latency"] = float(prefill_latency)
self.assertLess(prefill_latency, self.latency)
except Exception as e:
model_metrics["error"] = e
print(f"Error testing {self.model}: {e}")
self.fail(f"Test failed for {self.model}: {e}")
finally:
write_results_to_github_step_summary({self.model: model_metrics})
if __name__ == "__main__":
unittest.main()