sgl-project--sglang
94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
192 行
6.7 KiB
Python
192 行
6.7 KiB
Python
import json
|
|
import tempfile
|
|
import threading
|
|
import time
|
|
import unittest
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
from pathlib import Path
|
|
|
|
from sglang.benchmark.serving import run_benchmark
|
|
from sglang.benchmark.utils import parse_custom_headers
|
|
from sglang.srt.constants import HEALTH_CHECK_RID_PREFIX
|
|
from sglang.srt.utils import kill_process_tree
|
|
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
|
|
from sglang.test.test_utils import (
|
|
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
|
DEFAULT_URL_FOR_TEST,
|
|
CustomTestCase,
|
|
get_benchmark_args,
|
|
popen_launch_server,
|
|
)
|
|
|
|
register_cuda_ci(est_time=300, suite="nightly-1-gpu", nightly=True)
|
|
register_amd_ci(est_time=300, suite="nightly-amd-1-gpu", nightly=True)
|
|
|
|
MODEL = "Qwen/Qwen3-0.6B"
|
|
NUM_CONVERSATIONS, NUM_TURNS = 4, 3
|
|
|
|
|
|
class TestBenchServingFunctionality(CustomTestCase):
|
|
def test_gsp_multi_turn(self):
|
|
with tempfile.TemporaryDirectory() as temp_dir:
|
|
process = popen_launch_server(
|
|
MODEL,
|
|
DEFAULT_URL_FOR_TEST,
|
|
timeout=DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH,
|
|
other_args=[
|
|
"--mem-fraction-static",
|
|
"0.7",
|
|
"--log-requests",
|
|
"--log-requests-level",
|
|
"3",
|
|
"--log-requests-format",
|
|
"json",
|
|
"--log-requests-target",
|
|
"stdout",
|
|
temp_dir,
|
|
],
|
|
)
|
|
try:
|
|
args = get_benchmark_args(
|
|
base_url=DEFAULT_URL_FOR_TEST,
|
|
backend="sglang-oai-chat",
|
|
tokenizer=MODEL,
|
|
dataset_name="generated-shared-prefix",
|
|
num_prompts=NUM_CONVERSATIONS,
|
|
request_rate=float("inf"),
|
|
gsp_num_groups=2,
|
|
gsp_prompts_per_group=2,
|
|
gsp_system_prompt_len=64,
|
|
gsp_question_len=16,
|
|
gsp_output_len=16,
|
|
gsp_num_turns=NUM_TURNS,
|
|
)
|
|
args.warmup_requests = 0
|
|
res = run_benchmark(args)
|
|
self.assertEqual(res["completed"], NUM_CONVERSATIONS * NUM_TURNS)
|
|
|
|
time.sleep(1)
|
|
logs = "".join(f.read_text() for f in Path(temp_dir).glob("*.log"))
|
|
self._verify_multi_turn_logs(logs)
|
|
finally:
|
|
kill_process_tree(process.pid)
|
|
|
|
def _verify_multi_turn_logs(self, content: str):
|
|
reqs = []
|
|
for line in content.splitlines():
|
|
idx = line.find("{")
|
|
if idx == -1:
|
|
continue
|
|
try:
|
|
obj = json.loads(line[idx:])
|
|
except json.JSONDecodeError:
|
|
continue
|
|
if obj.get("event") != "request.finished":
|
|
continue
|
|
text = obj.get("obj", {}).get("text")
|
|
rid = obj.get("rid", "")
|
|
if text and not rid.startswith(HEALTH_CHECK_RID_PREFIX):
|
|
reqs.append(text)
|
|
|
|
self.assertGreaterEqual(len(reqs), NUM_CONVERSATIONS * NUM_TURNS)
|
|
|
|
# Verify prefix relationships
|
|
reqs_sorted = sorted(reqs, key=len)
|
|
prefix_count = 0
|
|
for i, text in enumerate(reqs_sorted):
|
|
for j in range(i + 1, len(reqs_sorted)):
|
|
if reqs_sorted[j].startswith(text):
|
|
prefix_count += 1
|
|
break
|
|
|
|
expected = NUM_CONVERSATIONS * (NUM_TURNS - 1)
|
|
self.assertGreaterEqual(
|
|
prefix_count, expected, f"Expected at least {expected} prefix pairs"
|
|
)
|
|
|
|
|
|
class TestBenchServingCustomHeaders(CustomTestCase):
|
|
def test_parse_custom_headers(self):
|
|
headers = parse_custom_headers(["MyHeader=MY_VALUE", "Another=value=hello"])
|
|
self.assertEqual(headers, {"MyHeader": "MY_VALUE", "Another": "value=hello"})
|
|
|
|
headers = parse_custom_headers(["InvalidNoEquals"])
|
|
self.assertEqual(headers, {})
|
|
|
|
headers = parse_custom_headers(["=NoKey"])
|
|
self.assertEqual(headers, {})
|
|
|
|
# TODO: Using well-implemented mock server, e.g. the on in sgl-router
|
|
def test_custom_headers_sent_to_server(self):
|
|
import queue
|
|
|
|
received_requests = queue.Queue()
|
|
|
|
class HeaderEchoHandler(BaseHTTPRequestHandler):
|
|
def _handle(self):
|
|
received_requests.put(
|
|
{
|
|
"method": self.command,
|
|
"path": self.path,
|
|
"headers": dict(self.headers),
|
|
}
|
|
)
|
|
self.send_response(200)
|
|
self.send_header("Content-Type", "application/json")
|
|
self.end_headers()
|
|
if self.path == "/v1/models":
|
|
self.wfile.write(json.dumps({"data": [{"id": "gpt2"}]}).encode())
|
|
elif self.path == "/generate":
|
|
self.wfile.write(
|
|
json.dumps(
|
|
{"text": "ok", "meta_info": {"completion_tokens": 1}}
|
|
).encode()
|
|
)
|
|
else:
|
|
self.wfile.write(json.dumps({}).encode())
|
|
|
|
do_GET = do_POST = _handle
|
|
|
|
server = HTTPServer(("127.0.0.1", 0), HeaderEchoHandler)
|
|
port = server.server_address[1]
|
|
server_thread = threading.Thread(target=server.serve_forever)
|
|
server_thread.daemon = True
|
|
server_thread.start()
|
|
|
|
try:
|
|
args = get_benchmark_args(
|
|
base_url=f"http://127.0.0.1:{port}",
|
|
backend="sglang",
|
|
dataset_name="random",
|
|
tokenizer="gpt2",
|
|
num_prompts=1,
|
|
random_input_len=8,
|
|
random_output_len=8,
|
|
header=["X-Custom-Test=TestValue123", "X-Another=AnotherVal"],
|
|
)
|
|
args.warmup_requests = 0
|
|
args.disable_tqdm = True
|
|
run_benchmark(args)
|
|
except Exception:
|
|
pass
|
|
finally:
|
|
server.shutdown()
|
|
|
|
all_reqs = []
|
|
while not received_requests.empty():
|
|
all_reqs.append(received_requests.get_nowait())
|
|
|
|
generate_reqs = [r for r in all_reqs if r["path"] == "/generate"]
|
|
self.assertGreater(
|
|
len(generate_reqs),
|
|
0,
|
|
f"No /generate request. All: {[r['path'] for r in all_reqs]}",
|
|
)
|
|
headers = generate_reqs[0]["headers"]
|
|
self.assertEqual(headers.get("X-Custom-Test"), "TestValue123")
|
|
self.assertEqual(headers.get("X-Another"), "AnotherVal")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|