main
py 115 lines 3.54 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import argparse
5 import inspect
6
7 import uvloop
8
9 from vllm.entrypoints.cli.types import CLISubcommand
10 from vllm.entrypoints.launchers.cli_args import (
11 make_arg_parser,
12 validate_parsed_serve_args,
13 )
14 from vllm.entrypoints.launchers.render.entry import run_launch_fastapi
15 from vllm.entrypoints.serve.utils.api_utils import VLLM_SUBCMD_PARSER_EPILOG
16 from vllm.logger import init_logger
17 from vllm.utils.argparse_utils import FlexibleArgumentParser
18
19 logger = init_logger(__name__)
20
21 DESCRIPTION = "Launch individual vLLM components."
22
23
24 class LaunchSubcommandBase(CLISubcommand):
25 """The base class of subcommands for `vllm launch`."""
26
27 help: str
28
29 @classmethod
30 def add_cli_args(cls, parser: FlexibleArgumentParser) -> None:
31 """Add the CLI arguments to the parser.
32
33 By default, uses the subcommand's docstring as the description and adds
34 the standard vLLM serving arguments.
35 Subclasses can override to add component-specific arguments.
36 """
37 if cls.__doc__:
38 parser.description = inspect.cleandoc(cls.__doc__)
39 make_arg_parser(parser)
40
41 @staticmethod
42 def cmd(args: argparse.Namespace) -> None:
43 raise NotImplementedError
44
45
46 class RenderSubcommand(LaunchSubcommandBase):
47 """`vllm launch render` starts a GPU-less rendering server for preprocessing
48 and postprocessing only.
49
50 ```bash
51 vllm launch render meta-llama/Llama-3.2-1B-Instruct --port 8100
52 ```
53
54 This command reuses the standard serving parser, so model, frontend,
55 networking, and related CLI options follow the same conventions as
56 [`vllm serve`](https://docs.vllm.ai/en/latest/cli/serve/).
57 """
58
59 name = "render"
60 help = "Launch a GPU-less rendering server (preprocessing and postprocessing only)."
61
62 @staticmethod
63 def cmd(args: argparse.Namespace) -> None:
64 uvloop.run(run_launch_fastapi(args))
65
66
67 class LaunchSubcommand(CLISubcommand):
68 """The `launch` subcommand for the vLLM CLI.
69
70 Uses nested sub-subcommands so each component can define its own
71 arguments independently (e.g. ``vllm launch render``).
72 """
73
74 name = "launch"
75
76 @staticmethod
77 def cmd(args: argparse.Namespace) -> None:
78 if hasattr(args, "model_tag") and args.model_tag is not None:
79 args.model = args.model_tag
80
81 args.launch_command(args)
82
83 def validate(self, args: argparse.Namespace) -> None:
84 validate_parsed_serve_args(args)
85
86 def subparser_init(
87 self, subparsers: argparse._SubParsersAction
88 ) -> FlexibleArgumentParser:
89 launch_parser = subparsers.add_parser(
90 self.name,
91 help=DESCRIPTION,
92 description=DESCRIPTION,
93 usage=f"vllm {self.name} <component> [options]",
94 )
95 launch_subparsers = launch_parser.add_subparsers(
96 required=True, dest="launch_component"
97 )
98
99 for cmd_cls in LaunchSubcommandBase.__subclasses__():
100 cmd_subparser = launch_subparsers.add_parser(
101 cmd_cls.name,
102 help=cmd_cls.help,
103 usage=f"vllm {self.name} {cmd_cls.name} [options]",
104 )
105 cmd_subparser.set_defaults(launch_command=cmd_cls.cmd)
106 cmd_cls.add_cli_args(cmd_subparser)
107 cmd_subparser.epilog = VLLM_SUBCMD_PARSER_EPILOG.format(
108 subcmd=f"{self.name} {cmd_cls.name}"
109 )
110
111 return launch_parser
112
113
114 def cmd_init() -> list[CLISubcommand]:
115 return [LaunchSubcommand()]