mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2025-12-10 06:45:01 +08:00
[Misc] Simplify vllm bench cli subcommand implementation (#19948)
This commit is contained in:
parent
c76a506bd6
commit
2c11a29f0b
@ -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",
|
||||
]
|
||||
@ -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
|
||||
|
||||
@ -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()]
|
||||
|
||||
@ -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 <bench_type> [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
|
||||
|
||||
|
||||
|
||||
@ -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()]
|
||||
|
||||
@ -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()]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user