"vscode:/vscode.git/clone" did not exist on "b4e4eda92e1d3a013fc4007db64b69d8604264ff"
cli_args.py 6.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
"""
This file contains the command line arguments for the vLLM's
OpenAI-compatible server. It is kept in a separate file for documentation
purposes.
"""

import argparse
import json
import ssl
10
from typing import List, Optional, Sequence, Union
11

12
from vllm.engine.arg_utils import AsyncEngineArgs, nullable_str
13
14
from vllm.entrypoints.openai.serving_engine import (LoRAModulePath,
                                                    PromptAdapterPath)
15
from vllm.utils import FlexibleArgumentParser
16
17
18
19


class LoRAParserAction(argparse.Action):

20
21
22
23
24
25
26
27
28
29
30
31
32
    def __call__(
        self,
        parser: argparse.ArgumentParser,
        namespace: argparse.Namespace,
        values: Optional[Union[str, Sequence[str]]],
        option_string: Optional[str] = None,
    ):
        if values is None:
            values = []
        if isinstance(values, str):
            raise TypeError("Expected values to be a list")

        lora_list: List[LoRAModulePath] = []
33
34
        for item in values:
            name, path = item.split('=')
35
            lora_list.append(LoRAModulePath(name, path))
36
37
38
        setattr(namespace, self.dest, lora_list)


39
40
class PromptAdapterParserAction(argparse.Action):

41
42
43
44
45
46
47
48
49
50
51
52
53
    def __call__(
        self,
        parser: argparse.ArgumentParser,
        namespace: argparse.Namespace,
        values: Optional[Union[str, Sequence[str]]],
        option_string: Optional[str] = None,
    ):
        if values is None:
            values = []
        if isinstance(values, str):
            raise TypeError("Expected values to be a list")

        adapter_list: List[PromptAdapterPath] = []
54
55
56
57
58
59
        for item in values:
            name, path = item.split('=')
            adapter_list.append(PromptAdapterPath(name, path))
        setattr(namespace, self.dest, adapter_list)


Ethan Xu's avatar
Ethan Xu committed
60
def make_arg_parser(parser: FlexibleArgumentParser) -> FlexibleArgumentParser:
61
62
63
64
    parser.add_argument("--host",
                        type=nullable_str,
                        default=None,
                        help="host name")
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    parser.add_argument("--port", type=int, default=8000, help="port number")
    parser.add_argument(
        "--uvicorn-log-level",
        type=str,
        default="info",
        choices=['debug', 'info', 'warning', 'error', 'critical', 'trace'],
        help="log level for uvicorn")
    parser.add_argument("--allow-credentials",
                        action="store_true",
                        help="allow credentials")
    parser.add_argument("--allowed-origins",
                        type=json.loads,
                        default=["*"],
                        help="allowed origins")
    parser.add_argument("--allowed-methods",
                        type=json.loads,
                        default=["*"],
                        help="allowed methods")
    parser.add_argument("--allowed-headers",
                        type=json.loads,
                        default=["*"],
                        help="allowed headers")
    parser.add_argument("--api-key",
88
                        type=nullable_str,
89
90
91
92
93
                        default=None,
                        help="If provided, the server will require this key "
                        "to be presented in the header.")
    parser.add_argument(
        "--lora-modules",
94
        type=nullable_str,
95
96
97
98
99
        default=None,
        nargs='+',
        action=LoRAParserAction,
        help="LoRA module configurations in the format name=path. "
        "Multiple modules can be specified.")
100
101
102
103
104
105
106
107
    parser.add_argument(
        "--prompt-adapters",
        type=nullable_str,
        default=None,
        nargs='+',
        action=PromptAdapterParserAction,
        help="Prompt adapter configurations in the format name=path. "
        "Multiple adapters can be specified.")
108
    parser.add_argument("--chat-template",
109
                        type=nullable_str,
110
111
112
113
114
                        default=None,
                        help="The file path to the chat template, "
                        "or the template in single-line form "
                        "for the specified model")
    parser.add_argument("--response-role",
115
                        type=nullable_str,
116
117
118
119
                        default="assistant",
                        help="The role name to return if "
                        "`request.add_generation_prompt=true`.")
    parser.add_argument("--ssl-keyfile",
120
                        type=nullable_str,
121
122
123
                        default=None,
                        help="The file path to the SSL key file")
    parser.add_argument("--ssl-certfile",
124
                        type=nullable_str,
125
126
127
                        default=None,
                        help="The file path to the SSL cert file")
    parser.add_argument("--ssl-ca-certs",
128
                        type=nullable_str,
129
130
131
132
133
134
135
136
137
138
                        default=None,
                        help="The CA certificates file")
    parser.add_argument(
        "--ssl-cert-reqs",
        type=int,
        default=int(ssl.CERT_NONE),
        help="Whether client certificate is required (see stdlib ssl module's)"
    )
    parser.add_argument(
        "--root-path",
139
        type=nullable_str,
140
141
142
143
        default=None,
        help="FastAPI root_path when app is behind a path based routing proxy")
    parser.add_argument(
        "--middleware",
144
        type=nullable_str,
145
146
147
148
149
150
151
152
153
        action="append",
        default=[],
        help="Additional ASGI middleware to apply to the app. "
        "We accept multiple --middleware arguments. "
        "The value should be an import path. "
        "If a function is provided, vLLM will add it to the server "
        "using @app.middleware('http'). "
        "If a class is provided, vLLM will add it to the server "
        "using app.add_middleware(). ")
154
155
156
    parser.add_argument(
        "--return-tokens-as-token-ids",
        action="store_true",
157
158
        help="When --max-logprobs is specified, represents single tokens as "
        "strings of the form 'token_id:{token_id}' so that tokens that "
159
        "are not JSON-encodable can be identified.")
160
161
162
163
164
    parser.add_argument(
        "--disable-frontend-multiprocessing",
        action="store_true",
        help="If specified, will run the OpenAI frontend server in the same "
        "process as the model serving engine.")
165
166

    parser = AsyncEngineArgs.add_cli_args(parser)
167
168
169
170
171
172
173
174

    parser.add_argument('--max-log-len',
                        type=int,
                        default=None,
                        help='Max number of prompt characters or prompt '
                        'ID numbers being printed in log.'
                        '\n\nDefault: Unlimited')

175
    return parser
Ethan Xu's avatar
Ethan Xu committed
176
177
178
179
180
181


def create_parser_for_docs() -> FlexibleArgumentParser:
    parser_for_docs = FlexibleArgumentParser(
        prog="-m vllm.entrypoints.openai.api_server")
    return make_arg_parser(parser_for_docs)