diff --git a/vllm/entrypoints/cli/__init__.py b/vllm/entrypoints/cli/__init__.py index e69de29bb2d1..41671b5b98ab 100644 --- a/vllm/entrypoints/cli/__init__.py +++ b/vllm/entrypoints/cli/__init__.py @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project +from vllm.entrypoints.cli.benchmark.latency import BenchmarkLatencySubcommand +from vllm.entrypoints.cli.benchmark.serve import BenchmarkServingSubcommand +from vllm.entrypoints.cli.benchmark.throughput import ( + BenchmarkThroughputSubcommand) + +__all__: list[str] = [ + "BenchmarkLatencySubcommand", + "BenchmarkServingSubcommand", + "BenchmarkThroughputSubcommand", +] \ No newline at end of file diff --git a/vllm/entrypoints/cli/benchmark/base.py b/vllm/entrypoints/cli/benchmark/base.py index 30a884410800..0c22bc75105e 100644 --- a/vllm/entrypoints/cli/benchmark/base.py +++ b/vllm/entrypoints/cli/benchmark/base.py @@ -3,18 +3,15 @@ import argparse from vllm.entrypoints.cli.types import CLISubcommand -from vllm.utils import FlexibleArgumentParser class BenchmarkSubcommandBase(CLISubcommand): """ The base class of subcommands for vllm bench. """ - @property - def help(self) -> str: - """The help message of the subcommand.""" - raise NotImplementedError + help: str - def add_cli_args(self, parser: argparse.ArgumentParser) -> None: + @classmethod + def add_cli_args(cls, parser: argparse.ArgumentParser) -> None: """Add the CLI arguments to the parser.""" raise NotImplementedError @@ -26,14 +23,3 @@ class BenchmarkSubcommandBase(CLISubcommand): args: The arguments to the command. """ raise NotImplementedError - - def subparser_init( - self, - subparsers: argparse._SubParsersAction) -> FlexibleArgumentParser: - parser = subparsers.add_parser( - self.name, - help=self.help, - description=self.help, - usage=f"vllm bench {self.name} [options]") - self.add_cli_args(parser) - return parser diff --git a/vllm/entrypoints/cli/benchmark/latency.py b/vllm/entrypoints/cli/benchmark/latency.py index e0358a262dcd..3e68963cfd44 100644 --- a/vllm/entrypoints/cli/benchmark/latency.py +++ b/vllm/entrypoints/cli/benchmark/latency.py @@ -4,27 +4,18 @@ import argparse from vllm.benchmarks.latency import add_cli_args, main from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase -from vllm.entrypoints.cli.types import CLISubcommand class BenchmarkLatencySubcommand(BenchmarkSubcommandBase): """ The `latency` subcommand for vllm bench. """ - def __init__(self): - self.name = "latency" - super().__init__() + name = "latency" + help = "Benchmark the latency of a single batch of requests." - @property - def help(self) -> str: - return "Benchmark the latency of a single batch of requests." - - def add_cli_args(self, parser: argparse.ArgumentParser) -> None: + @classmethod + def add_cli_args(cls, parser: argparse.ArgumentParser) -> None: add_cli_args(parser) @staticmethod def cmd(args: argparse.Namespace) -> None: main(args) - - -def cmd_init() -> list[CLISubcommand]: - return [BenchmarkLatencySubcommand()] diff --git a/vllm/entrypoints/cli/benchmark/main.py b/vllm/entrypoints/cli/benchmark/main.py index 717da630ab4f..fdc5a047f692 100644 --- a/vllm/entrypoints/cli/benchmark/main.py +++ b/vllm/entrypoints/cli/benchmark/main.py @@ -2,51 +2,44 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import argparse -import vllm.entrypoints.cli.benchmark.latency -import vllm.entrypoints.cli.benchmark.serve -import vllm.entrypoints.cli.benchmark.throughput +from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase from vllm.entrypoints.cli.types import CLISubcommand from vllm.utils import FlexibleArgumentParser -BENCHMARK_CMD_MODULES = [ - vllm.entrypoints.cli.benchmark.latency, - vllm.entrypoints.cli.benchmark.serve, - vllm.entrypoints.cli.benchmark.throughput, -] - class BenchmarkSubcommand(CLISubcommand): """ The `bench` subcommand for the vLLM CLI. """ - def __init__(self): - self.name = "bench" - super().__init__() + name = "bench" + help = "vLLM bench subcommand." @staticmethod def cmd(args: argparse.Namespace) -> None: args.dispatch_function(args) def validate(self, args: argparse.Namespace) -> None: - if args.bench_type in self.cmds: - self.cmds[args.bench_type].validate(args) + pass def subparser_init( self, subparsers: argparse._SubParsersAction) -> FlexibleArgumentParser: + bench_parser = subparsers.add_parser( - "bench", - help="vLLM bench subcommand.", - description="vLLM bench subcommand.", + self.name, + help=self.help, + description=self.help, usage="vllm bench [options]") bench_subparsers = bench_parser.add_subparsers(required=True, dest="bench_type") - self.cmds = {} - for cmd_module in BENCHMARK_CMD_MODULES: - new_cmds = cmd_module.cmd_init() - for cmd in new_cmds: - cmd.subparser_init(bench_subparsers).set_defaults( - dispatch_function=cmd.cmd) - self.cmds[cmd.name] = cmd + + for cmd_cls in BenchmarkSubcommandBase.__subclasses__(): + cmd_subparser = bench_subparsers.add_parser( + cmd_cls.name, + help=cmd_cls.help, + description=cmd_cls.help, + ) + cmd_subparser.set_defaults(dispatch_function=cmd_cls.cmd) + cmd_cls.add_cli_args(cmd_subparser) return bench_parser diff --git a/vllm/entrypoints/cli/benchmark/serve.py b/vllm/entrypoints/cli/benchmark/serve.py index 304370157023..3dd7a46d6284 100644 --- a/vllm/entrypoints/cli/benchmark/serve.py +++ b/vllm/entrypoints/cli/benchmark/serve.py @@ -4,27 +4,18 @@ import argparse from vllm.benchmarks.serve import add_cli_args, main from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase -from vllm.entrypoints.cli.types import CLISubcommand class BenchmarkServingSubcommand(BenchmarkSubcommandBase): """ The `serve` subcommand for vllm bench. """ - def __init__(self): - self.name = "serve" - super().__init__() + name = "serve" + help = "Benchmark the online serving throughput." - @property - def help(self) -> str: - return "Benchmark the online serving throughput." - - def add_cli_args(self, parser: argparse.ArgumentParser) -> None: + @classmethod + def add_cli_args(cls, parser: argparse.ArgumentParser) -> None: add_cli_args(parser) @staticmethod def cmd(args: argparse.Namespace) -> None: main(args) - - -def cmd_init() -> list[CLISubcommand]: - return [BenchmarkServingSubcommand()] diff --git a/vllm/entrypoints/cli/benchmark/throughput.py b/vllm/entrypoints/cli/benchmark/throughput.py index 20431cd3d870..d5d43ad4a359 100644 --- a/vllm/entrypoints/cli/benchmark/throughput.py +++ b/vllm/entrypoints/cli/benchmark/throughput.py @@ -4,27 +4,18 @@ import argparse from vllm.benchmarks.throughput import add_cli_args, main from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase -from vllm.entrypoints.cli.types import CLISubcommand class BenchmarkThroughputSubcommand(BenchmarkSubcommandBase): """ The `throughput` subcommand for vllm bench. """ - def __init__(self): - self.name = "throughput" - super().__init__() + name = "throughput" + help = "Benchmark offline inference throughput." - @property - def help(self) -> str: - return "Benchmark offline inference throughput." - - def add_cli_args(self, parser: argparse.ArgumentParser) -> None: + @classmethod + def add_cli_args(cls, parser: argparse.ArgumentParser) -> None: add_cli_args(parser) @staticmethod def cmd(args: argparse.Namespace) -> None: main(args) - - -def cmd_init() -> list[CLISubcommand]: - return [BenchmarkThroughputSubcommand()]