[misc] Unify benchmark deprecation shims and one_batch_server CLI entrypoint (#29108)

This commit is contained in:
Liangsheng Yin
2026-06-23 21:10:25 -07:00
committed by GitHub
parent 52b89c4948
commit e3f1fa9d8e
9 changed files with 41 additions and 37 deletions
+8 -6
View File
@@ -1,13 +1,15 @@
"""Back-compat shim. The implementation now lives in """Deprecated import path for ``sglang.benchmark.one_batch_server``.
``sglang.benchmark.one_batch_server``; this module preserves the
``python -m sglang.bench_one_batch_server`` entry point and the ``python -m sglang.bench_one_batch_server`` and
``from sglang.bench_one_batch_server import ...`` imports. ``from sglang.bench_one_batch_server import ...`` still work, but the
implementation now lives in ``sglang.benchmark.one_batch_server``.
Update references to the new path.
""" """
import warnings import warnings
from sglang.benchmark.one_batch_server import * # noqa: F401,F403 from sglang.benchmark.one_batch_server import * # noqa: F401,F403
from sglang.benchmark.one_batch_server import main from sglang.benchmark.one_batch_server import cli_main
warnings.warn( warnings.warn(
"`sglang.bench_one_batch_server` is deprecated and will be removed in a " "`sglang.bench_one_batch_server` is deprecated and will be removed in a "
@@ -18,4 +20,4 @@ warnings.warn(
) )
if __name__ == "__main__": if __name__ == "__main__":
main() cli_main()
+11 -9
View File
@@ -1,20 +1,22 @@
# SPDX-License-Identifier: Apache-2.0 """Deprecated import path for ``sglang.benchmark.serving``.
"""Compatibility shim for the relocated serving benchmark entrypoint."""
``python -m sglang.bench_serving`` and ``from sglang.bench_serving import ...``
still work, but the implementation now lives in ``sglang.benchmark.serving``.
Update references to the new path.
"""
import warnings import warnings
from sglang.benchmark.serving import * # noqa: F403 from sglang.benchmark.serving import * # noqa: F401,F403
from sglang.benchmark.serving import ( # noqa: F401 from sglang.benchmark.serving import cli_main
_create_bench_client_session,
cli_main,
)
warnings.warn( warnings.warn(
"sglang.bench_serving is deprecated; use sglang.benchmark.serving instead.", "`sglang.bench_serving` is deprecated and will be removed in a future "
"release; use `sglang.benchmark.serving` instead "
"(e.g. `python -m sglang.benchmark.serving`).",
FutureWarning, FutureWarning,
stacklevel=1, stacklevel=1,
) )
if __name__ == "__main__": if __name__ == "__main__":
cli_main() cli_main()
@@ -173,7 +173,7 @@ def _estimate_prompt_lens(
prompt_len = len(prompt) prompt_len = len(prompt)
return prompt_len, prompt_len, 0 return prompt_len, prompt_len, 0
# Multi-turn prompt lists are handled specially by bench_serving and do not # Multi-turn prompt lists are handled specially by the serving benchmark and do not
# contribute reliable static prompt lengths. # contribute reliable static prompt lengths.
return 0, 0, 0 return 0, 0, 0
@@ -60,7 +60,7 @@ class GeneratedSharedPrefixDataset(BaseDataset):
# Defensive validation for in-process callers that construct a # Defensive validation for in-process callers that construct a
# Namespace by hand and bypass the argparse boundary in # Namespace by hand and bypass the argparse boundary in
# bench_serving.py. The CLI hook enforces the same rules first. # serving.py. The CLI hook enforces the same rules first.
if group_distribution not in ("uniform", "zipf"): if group_distribution not in ("uniform", "zipf"):
raise ValueError( raise ValueError(
f"--gsp-group-distribution must be 'uniform' or 'zipf', " f"--gsp-group-distribution must be 'uniform' or 'zipf', "
@@ -97,7 +97,7 @@ def sample_openai_requests(
tools_tokens = len(tokenizer.encode(tools_str)) tools_tokens = len(tokenizer.encode(tools_str))
prompt_len += tools_tokens prompt_len += tools_tokens
# Pass messages list directly - bench_serving handles List[Dict] prompts # Pass messages list directly - the serving benchmark handles List[Dict] prompts
filtered_dataset.append( filtered_dataset.append(
DatasetRow( DatasetRow(
prompt=messages, prompt=messages,
@@ -1,4 +1,4 @@
"""SPEED-Bench (nvidia/SPEED-Bench) dataset for SGLang bench_serving. """SPEED-Bench (nvidia/SPEED-Bench) dataset for the SGLang serving benchmark.
Reads the pre-downloaded throughput_1k JSONL produced by prepare_speed_bench.sh Reads the pre-downloaded throughput_1k JSONL produced by prepare_speed_bench.sh
(or equivalent), optionally filtering by category (low_entropy / mixed / (or equivalent), optionally filtering by category (low_entropy / mixed /
@@ -1,13 +1,13 @@
""" """
Benchmark the throughput in the offline mode. Benchmark the throughput in the offline mode.
It accepts server arguments (the same as launch_server.py) and benchmark arguments (the same as bench_serving.py). It accepts server arguments (the same as launch_server.py) and benchmark arguments (the same as serving.py).
# Usage # Usage
## Sharegpt dataset with default args ## Sharegpt dataset with default args
python -m sglang.bench_offline_throughput --model-path meta-llama/Meta-Llama-3.1-8B-Instruct --num-prompts 10 python -m sglang.benchmark.offline_throughput --model-path meta-llama/Meta-Llama-3.1-8B-Instruct --num-prompts 10
## Random dataset with default args ## Random dataset with default args
python -m sglang.bench_offline_throughput --model-path meta-llama/Meta-Llama-3.1-8B-Instruct --dataset-name random --random-input 1024 --random-output 1024 python -m sglang.benchmark.offline_throughput --model-path meta-llama/Meta-Llama-3.1-8B-Instruct --dataset-name random --random-input 1024 --random-output 1024
""" """
import argparse import argparse
+6 -6
View File
@@ -6,18 +6,18 @@ It accepts server arguments (the same as launch_server.py) and benchmark argumen
# Usage (latency test) # Usage (latency test)
## with dummy weights: ## with dummy weights:
python -m sglang.bench_one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --load-format dummy python -m sglang.benchmark.one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --load-format dummy
## sweep through multiple data points and store (append) the results in a jsonl file: ## sweep through multiple data points and store (append) the results in a jsonl file:
python -m sglang.bench_one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 12 14 --input-len 256 512 --output-len 32 256 --run-name test_run python -m sglang.benchmark.one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 12 14 --input-len 256 512 --output-len 32 256 --run-name test_run
## run with profiling: ## run with profiling:
python -m sglang.bench_one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 12 14 --input-len 256 512 --profile python -m sglang.benchmark.one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 12 14 --input-len 256 512 --profile
## run with profiling to custom directory: ## run with profiling to custom directory:
export SGLANG_TORCH_PROFILER_DIR=/root/sglang/profile_log export SGLANG_TORCH_PROFILER_DIR=/root/sglang/profile_log
python -m sglang.bench_one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 --input-len 256 --profile python -m sglang.benchmark.one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 --input-len 256 --profile
## run with CUDA profiler (nsys): ## run with CUDA profiler (nsys):
nsys profile --force-overwrite=true -o bench_one_batch python -m sglang.bench_one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 --input-len 256 --profile --profile-activities CUDA_PROFILER nsys profile --force-overwrite=true -o bench_one_batch python -m sglang.benchmark.one_batch --model-path meta-llama/Meta-Llama-3-8B-Instruct --batch-size 1 --input-len 256 --profile --profile-activities CUDA_PROFILER
# Usage (correctness test): # Usage (correctness test):
python -m sglang.bench_one_batch --model-path TinyLlama/TinyLlama-1.1B-Chat-v0.4 --correct python -m sglang.benchmark.one_batch --model-path TinyLlama/TinyLlama-1.1B-Chat-v0.4 --correct
## Reference output (of the correctness test above, can be gpu dependent): ## Reference output (of the correctness test above, can be gpu dependent):
input_ids=[[1, 450, 7483, 310, 3444, 338], [1, 450, 7483, 310, 278, 3303, 13187, 290, 338], [1, 20628, 338, 263, 6575, 1460, 2462, 322, 306, 763]] input_ids=[[1, 450, 7483, 310, 3444, 338], [1, 450, 7483, 310, 278, 3303, 13187, 290, 338], [1, 20628, 338, 263, 6575, 1460, 2462, 322, 306, 763]]
+9 -9
View File
@@ -5,11 +5,11 @@ This script launches a server and uses the HTTP interface.
It accepts server arguments (the same as launch_server.py) and benchmark arguments (e.g., batch size, input lengths). It accepts server arguments (the same as launch_server.py) and benchmark arguments (e.g., batch size, input lengths).
Usage: Usage:
python3 -m sglang.bench_one_batch_server --model meta-llama/Meta-Llama-3.1-8B --batch-size 1 16 64 --input-len 1024 --output-len 8 python3 -m sglang.benchmark.one_batch_server --model meta-llama/Meta-Llama-3.1-8B --batch-size 1 16 64 --input-len 1024 --output-len 8
python3 -m sglang.bench_one_batch_server --model None --base-url http://localhost:30000 --batch-size 16 --input-len 1024 --output-len 8 python3 -m sglang.benchmark.one_batch_server --model None --base-url http://localhost:30000 --batch-size 16 --input-len 1024 --output-len 8
python3 -m sglang.bench_one_batch_server --model None --base-url http://localhost:30000 --batch-size 16 --input-len 1024 --output-len 8 --show-report --profile --profile-by-stage python3 -m sglang.benchmark.one_batch_server --model None --base-url http://localhost:30000 --batch-size 16 --input-len 1024 --output-len 8 --show-report --profile --profile-by-stage
python3 -m sglang.bench_one_batch_server --model None --base-url http://localhost:30000 --batch-size 16 --input-len 1024 --output-len 8 --result-filename results.jsonl --profile python3 -m sglang.benchmark.one_batch_server --model None --base-url http://localhost:30000 --batch-size 16 --input-len 1024 --output-len 8 --result-filename results.jsonl --profile
""" """
import argparse import argparse
@@ -309,7 +309,7 @@ class BenchArgs:
default=BenchArgs.lora_request_distribution, default=BenchArgs.lora_request_distribution,
choices=["uniform", "distinct", "skewed"], choices=["uniform", "distinct", "skewed"],
help="How to sample a LoRA adapter per prompt when more than one " help="How to sample a LoRA adapter per prompt when more than one "
"is listed in --lora-name. Mirrors bench_serving.py. " "is listed in --lora-name. Mirrors serving.py. "
"'uniform' picks uniformly at random, 'distinct' round-robins so " "'uniform' picks uniformly at random, 'distinct' round-robins so "
"consecutive prompts get different adapters, 'skewed' samples " "consecutive prompts get different adapters, 'skewed' samples "
"from a Zipf distribution over --lora-name (alpha controls the " "from a Zipf distribution over --lora-name (alpha controls the "
@@ -507,7 +507,7 @@ def run_one_case(
else: else:
_flush_cache_with_retry(url, "/flush_cache") _flush_cache_with_retry(url, "/flush_cache")
# Load input token ids via bench_serving.get_dataset # Load input token ids via benchmark.datasets.get_dataset
supported_datasets = ("random", "random-ids", "mmmu", "generated-shared-prefix") supported_datasets = ("random", "random-ids", "mmmu", "generated-shared-prefix")
if dataset_name not in supported_datasets: if dataset_name not in supported_datasets:
raise ValueError( raise ValueError(
@@ -968,7 +968,7 @@ def run_benchmark_internal(
f"to actually exercise multi-batch." f"to actually exercise multi-batch."
) )
# LoRA distribution args: mirror bench_serving.py semantics so multi-LoRA # LoRA distribution args: mirror serving.py semantics so multi-LoRA
# benchmarks behave consistently across harnesses. # benchmarks behave consistently across harnesses.
if bench_args.lora_request_distribution in ("distinct", "skewed"): if bench_args.lora_request_distribution in ("distinct", "skewed"):
assert bench_args.lora_name is not None and len(bench_args.lora_name) > 1, ( assert bench_args.lora_name is not None and len(bench_args.lora_name) > 1, (
@@ -1152,7 +1152,7 @@ def run_benchmark(server_args: ServerArgs, bench_args: BenchArgs):
return results, server_info return results, server_info
def main(): def cli_main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
ServerArgs.add_cli_args(parser) ServerArgs.add_cli_args(parser)
BenchArgs.add_cli_args(parser) BenchArgs.add_cli_args(parser)
@@ -1165,4 +1165,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() cli_main()