A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 04:45 UTC
[Misc] Simplify vllm bench cli subcommand implementation (#19948)
Ye (Charlotte) Qi committed
Jun 22, 2025 at 09:34 UTC
2c11a29f0b474d3607227bbc895867bff9d8f8f4
6 files changed
+44
-80
vllm/entrypoints/cli/__init__.py
+12
@@ -0,0 +1,12 @@
1
+# SPDX-License-Identifier: Apache-2.0
2
+# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+from vllm.entrypoints.cli.benchmark.latency import BenchmarkLatencySubcommand
4
+from vllm.entrypoints.cli.benchmark.serve import BenchmarkServingSubcommand
5
+from vllm.entrypoints.cli.benchmark.throughput import (
6
+ BenchmarkThroughputSubcommand)
7
+
8
+__all__: list[str] = [
9
+ "BenchmarkLatencySubcommand",
10
+ "BenchmarkServingSubcommand",
11
+ "BenchmarkThroughputSubcommand",
12
+]
\ No newline at end of file
vllm/entrypoints/cli/benchmark/base.py
+3
-17
@@ -3,18 +3,15 @@
3
import argparse
4
5
from vllm.entrypoints.cli.types import CLISubcommand
6
-from vllm.utils import FlexibleArgumentParser
6
7
8
class BenchmarkSubcommandBase(CLISubcommand):
9
""" The base class of subcommands for vllm bench. """
10
12
- @property
13
- def help(self) -> str:
14
- """The help message of the subcommand."""
15
- raise NotImplementedError
11
+ help: str
12
17
- def add_cli_args(self, parser: argparse.ArgumentParser) -> None:
13
+ @classmethod
14
+ def add_cli_args(cls, parser: argparse.ArgumentParser) -> None:
15
"""Add the CLI arguments to the parser."""
16
raise NotImplementedError
17
@@ -26,14 +23,3 @@ class BenchmarkSubcommandBase(CLISubcommand):
23
args: The arguments to the command.
24
"""
25
raise NotImplementedError
29
-
30
- def subparser_init(
31
- self,
32
- subparsers: argparse._SubParsersAction) -> FlexibleArgumentParser:
33
- parser = subparsers.add_parser(
34
- self.name,
35
- help=self.help,
36
- description=self.help,
37
- usage=f"vllm bench {self.name} [options]")
38
- self.add_cli_args(parser)
39
- return parser
vllm/entrypoints/cli/benchmark/latency.py
+4
-13
@@ -4,27 +4,18 @@ import argparse
4
5
from vllm.benchmarks.latency import add_cli_args, main
6
from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase
7
-from vllm.entrypoints.cli.types import CLISubcommand
7
8
9
class BenchmarkLatencySubcommand(BenchmarkSubcommandBase):
10
""" The `latency` subcommand for vllm bench. """
11
13
- def __init__(self):
14
- self.name = "latency"
15
- super().__init__()
12
+ name = "latency"
13
+ help = "Benchmark the latency of a single batch of requests."
14
17
- @property
18
- def help(self) -> str:
19
- return "Benchmark the latency of a single batch of requests."
20
-
21
- def add_cli_args(self, parser: argparse.ArgumentParser) -> None:
15
+ @classmethod
16
+ def add_cli_args(cls, parser: argparse.ArgumentParser) -> None:
17
add_cli_args(parser)
18
19
@staticmethod
20
def cmd(args: argparse.Namespace) -> None:
21
main(args)
27
-
28
-
29
-def cmd_init() -> list[CLISubcommand]:
30
- return [BenchmarkLatencySubcommand()]
vllm/entrypoints/cli/benchmark/main.py
+17
-24
@@ -2,51 +2,44 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
import argparse
4
5
-import vllm.entrypoints.cli.benchmark.latency
6
-import vllm.entrypoints.cli.benchmark.serve
7
-import vllm.entrypoints.cli.benchmark.throughput
5
+from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase
6
from vllm.entrypoints.cli.types import CLISubcommand
7
from vllm.utils import FlexibleArgumentParser
8
11
-BENCHMARK_CMD_MODULES = [
12
- vllm.entrypoints.cli.benchmark.latency,
13
- vllm.entrypoints.cli.benchmark.serve,
14
- vllm.entrypoints.cli.benchmark.throughput,
15
-]
16
-
9
10
class BenchmarkSubcommand(CLISubcommand):
11
""" The `bench` subcommand for the vLLM CLI. """
12
21
- def __init__(self):
22
- self.name = "bench"
23
- super().__init__()
13
+ name = "bench"
14
+ help = "vLLM bench subcommand."
15
16
@staticmethod
17
def cmd(args: argparse.Namespace) -> None:
18
args.dispatch_function(args)
19
20
def validate(self, args: argparse.Namespace) -> None:
30
- if args.bench_type in self.cmds:
31
- self.cmds[args.bench_type].validate(args)
21
+ pass
22
23
def subparser_init(
24
self,
25
subparsers: argparse._SubParsersAction) -> FlexibleArgumentParser:
26
+
27
bench_parser = subparsers.add_parser(
37
- "bench",
38
- help="vLLM bench subcommand.",
39
- description="vLLM bench subcommand.",
28
+ self.name,
29
+ help=self.help,
30
+ description=self.help,
31
usage="vllm bench <bench_type> [options]")
32
bench_subparsers = bench_parser.add_subparsers(required=True,
33
dest="bench_type")
43
- self.cmds = {}
44
- for cmd_module in BENCHMARK_CMD_MODULES:
45
- new_cmds = cmd_module.cmd_init()
46
- for cmd in new_cmds:
47
- cmd.subparser_init(bench_subparsers).set_defaults(
48
- dispatch_function=cmd.cmd)
49
- self.cmds[cmd.name] = cmd
34
+
35
+ for cmd_cls in BenchmarkSubcommandBase.__subclasses__():
36
+ cmd_subparser = bench_subparsers.add_parser(
37
+ cmd_cls.name,
38
+ help=cmd_cls.help,
39
+ description=cmd_cls.help,
40
+ )
41
+ cmd_subparser.set_defaults(dispatch_function=cmd_cls.cmd)
42
+ cmd_cls.add_cli_args(cmd_subparser)
43
return bench_parser
44
45
vllm/entrypoints/cli/benchmark/serve.py
+4
-13
@@ -4,27 +4,18 @@ import argparse
4
5
from vllm.benchmarks.serve import add_cli_args, main
6
from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase
7
-from vllm.entrypoints.cli.types import CLISubcommand
7
8
9
class BenchmarkServingSubcommand(BenchmarkSubcommandBase):
10
""" The `serve` subcommand for vllm bench. """
11
13
- def __init__(self):
14
- self.name = "serve"
15
- super().__init__()
12
+ name = "serve"
13
+ help = "Benchmark the online serving throughput."
14
17
- @property
18
- def help(self) -> str:
19
- return "Benchmark the online serving throughput."
20
-
21
- def add_cli_args(self, parser: argparse.ArgumentParser) -> None:
15
+ @classmethod
16
+ def add_cli_args(cls, parser: argparse.ArgumentParser) -> None:
17
add_cli_args(parser)
18
19
@staticmethod
20
def cmd(args: argparse.Namespace) -> None:
21
main(args)
27
-
28
-
29
-def cmd_init() -> list[CLISubcommand]:
30
- return [BenchmarkServingSubcommand()]
vllm/entrypoints/cli/benchmark/throughput.py
+4
-13
@@ -4,27 +4,18 @@ import argparse
4
5
from vllm.benchmarks.throughput import add_cli_args, main
6
from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase
7
-from vllm.entrypoints.cli.types import CLISubcommand
7
8
9
class BenchmarkThroughputSubcommand(BenchmarkSubcommandBase):
10
""" The `throughput` subcommand for vllm bench. """
11
13
- def __init__(self):
14
- self.name = "throughput"
15
- super().__init__()
12
+ name = "throughput"
13
+ help = "Benchmark offline inference throughput."
14
17
- @property
18
- def help(self) -> str:
19
- return "Benchmark offline inference throughput."
20
-
21
- def add_cli_args(self, parser: argparse.ArgumentParser) -> None:
15
+ @classmethod
16
+ def add_cli_args(cls, parser: argparse.ArgumentParser) -> None:
17
add_cli_args(parser)
18
19
@staticmethod
20
def cmd(args: argparse.Namespace) -> None:
21
main(args)
27
-
28
-
29
-def cmd_init() -> list[CLISubcommand]:
30
- return [BenchmarkThroughputSubcommand()]