main.py 1.58 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5

from __future__ import annotations

6
import argparse
7
import typing
8

9
from vllm.entrypoints.cli.benchmark.base import BenchmarkSubcommandBase
10
from vllm.entrypoints.cli.types import CLISubcommand
11
12
13

if typing.TYPE_CHECKING:
    from vllm.utils import FlexibleArgumentParser
14
15
16
17
18


class BenchmarkSubcommand(CLISubcommand):
    """ The `bench` subcommand for the vLLM CLI. """

19
20
    name = "bench"
    help = "vLLM bench subcommand."
21
22
23
24
25
26

    @staticmethod
    def cmd(args: argparse.Namespace) -> None:
        args.dispatch_function(args)

    def validate(self, args: argparse.Namespace) -> None:
27
        pass
28
29
30
31
32

    def subparser_init(
            self,
            subparsers: argparse._SubParsersAction) -> FlexibleArgumentParser:
        bench_parser = subparsers.add_parser(
33
34
35
            self.name,
            help=self.help,
            description=self.help,
36
37
38
            usage="vllm bench <bench_type> [options]")
        bench_subparsers = bench_parser.add_subparsers(required=True,
                                                       dest="bench_type")
39
40
41
42
43
44
45
46
47

        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)
48
49
50
51
52
        return bench_parser


def cmd_init() -> list[CLISubcommand]:
    return [BenchmarkSubcommand()]