Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit ab445b1

Browse files
mgoinjoerunde
authored andcommitted
[Bugfix] Allow "None" or "" to be passed to CLI for string args that default to None (vllm-project#4586)
1 parent a5d0d0e commit ab445b1

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

vllm/engine/arg_utils.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
from vllm.utils import str_to_int_tuple
1212

1313

14+
def nullable_str(val: str):
15+
if not val or val == "None":
16+
return None
17+
return val
18+
19+
1420
@dataclass
1521
class EngineArgs:
1622
"""Arguments for vLLM engine."""
@@ -96,7 +102,7 @@ def add_cli_args(
96102
help='Name or path of the huggingface model to use.')
97103
parser.add_argument(
98104
'--tokenizer',
99-
type=str,
105+
type=nullable_str,
100106
default=EngineArgs.tokenizer,
101107
help='Name or path of the huggingface tokenizer to use.')
102108
parser.add_argument(
@@ -105,21 +111,21 @@ def add_cli_args(
105111
help='Skip initialization of tokenizer and detokenizer')
106112
parser.add_argument(
107113
'--revision',
108-
type=str,
114+
type=nullable_str,
109115
default=None,
110116
help='The specific model version to use. It can be a branch '
111117
'name, a tag name, or a commit id. If unspecified, will use '
112118
'the default version.')
113119
parser.add_argument(
114120
'--code-revision',
115-
type=str,
121+
type=nullable_str,
116122
default=None,
117123
help='The specific revision to use for the model code on '
118124
'Hugging Face Hub. It can be a branch name, a tag name, or a '
119125
'commit id. If unspecified, will use the default version.')
120126
parser.add_argument(
121127
'--tokenizer-revision',
122-
type=str,
128+
type=nullable_str,
123129
default=None,
124130
help='The specific tokenizer version to use. It can be a branch '
125131
'name, a tag name, or a commit id. If unspecified, will use '
@@ -136,7 +142,7 @@ def add_cli_args(
136142
action='store_true',
137143
help='Trust remote code from huggingface.')
138144
parser.add_argument('--download-dir',
139-
type=str,
145+
type=nullable_str,
140146
default=EngineArgs.download_dir,
141147
help='Directory to download and load the weights, '
142148
'default to the default cache dir of '
@@ -187,7 +193,7 @@ def add_cli_args(
187193
'supported for common inference criteria.')
188194
parser.add_argument(
189195
'--quantization-param-path',
190-
type=str,
196+
type=nullable_str,
191197
default=None,
192198
help='Path to the JSON file containing the KV cache '
193199
'scaling factors. This should generally be supplied, when '
@@ -304,7 +310,7 @@ def add_cli_args(
304310
# Quantization settings.
305311
parser.add_argument('--quantization',
306312
'-q',
307-
type=str,
313+
type=nullable_str,
308314
choices=[*QUANTIZATION_METHODS, None],
309315
default=EngineArgs.quantization,
310316
help='Method used to quantize the weights. If '
@@ -349,7 +355,7 @@ def add_cli_args(
349355
'asynchronous tokenization. Ignored '
350356
'if tokenizer_pool_size is 0.')
351357
parser.add_argument('--tokenizer-pool-extra-config',
352-
type=str,
358+
type=nullable_str,
353359
default=EngineArgs.tokenizer_pool_extra_config,
354360
help='Extra config for tokenizer pool. '
355361
'This should be a JSON string that will be '
@@ -404,7 +410,7 @@ def add_cli_args(
404410
# Related to Vision-language models such as llava
405411
parser.add_argument(
406412
'--image-input-type',
407-
type=str,
413+
type=nullable_str,
408414
default=None,
409415
choices=[
410416
t.name.lower() for t in VisionLanguageConfig.ImageInputType
@@ -417,7 +423,7 @@ def add_cli_args(
417423
help=('Input id for image token.'))
418424
parser.add_argument(
419425
'--image-input-shape',
420-
type=str,
426+
type=nullable_str,
421427
default=None,
422428
help=('The biggest image input shape (worst for memory footprint) '
423429
'given an input type. Only used for vLLM\'s profile_run.'))
@@ -440,7 +446,7 @@ def add_cli_args(
440446

441447
parser.add_argument(
442448
'--speculative-model',
443-
type=str,
449+
type=nullable_str,
444450
default=EngineArgs.speculative_model,
445451
help=
446452
'The name of the draft model to be used in speculative decoding.')
@@ -454,7 +460,7 @@ def add_cli_args(
454460

455461
parser.add_argument(
456462
'--speculative-max-model-len',
457-
type=str,
463+
type=int,
458464
default=EngineArgs.speculative_max_model_len,
459465
help='The maximum sequence length supported by the '
460466
'draft model. Sequences over this length will skip '
@@ -475,7 +481,7 @@ def add_cli_args(
475481
'decoding.')
476482

477483
parser.add_argument('--model-loader-extra-config',
478-
type=str,
484+
type=nullable_str,
479485
default=EngineArgs.model_loader_extra_config,
480486
help='Extra config for model loader. '
481487
'This will be passed to the model loader '

vllm/entrypoints/openai/cli_args.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99
import ssl
1010

11-
from vllm.engine.arg_utils import AsyncEngineArgs
11+
from vllm.engine.arg_utils import AsyncEngineArgs, nullable_str
1212
from vllm.entrypoints.openai.serving_engine import LoRAModulePath
1313
from vllm.tgis_utils.args import EnvVarArgumentParser
1414

@@ -26,7 +26,10 @@ def __call__(self, parser, namespace, values, option_string=None):
2626
def make_arg_parser():
2727
parser = EnvVarArgumentParser(
2828
description="vLLM OpenAI-Compatible RESTful API server.")
29-
parser.add_argument("--host", type=str, default=None, help="host name")
29+
parser.add_argument("--host",
30+
type=nullable_str,
31+
default=None,
32+
help="host name")
3033
parser.add_argument("--port", type=int, default=8000, help="port number")
3134
parser.add_argument(
3235
"--uvicorn-log-level",
@@ -50,13 +53,13 @@ def make_arg_parser():
5053
default=["*"],
5154
help="allowed headers")
5255
parser.add_argument("--api-key",
53-
type=str,
56+
type=nullable_str,
5457
default=None,
5558
help="If provided, the server will require this key "
5659
"to be presented in the header.")
5760
parser.add_argument("--served-model-name",
5861
nargs="+",
59-
type=str,
62+
type=nullable_str,
6063
default=None,
6164
help="The model name(s) used in the API. If multiple "
6265
"names are provided, the server will respond to any "
@@ -66,33 +69,33 @@ def make_arg_parser():
6669
"same as the `--model` argument.")
6770
parser.add_argument(
6871
"--lora-modules",
69-
type=str,
72+
type=nullable_str,
7073
default=None,
7174
nargs='+',
7275
action=LoRAParserAction,
7376
help="LoRA module configurations in the format name=path. "
7477
"Multiple modules can be specified.")
7578
parser.add_argument("--chat-template",
76-
type=str,
79+
type=nullable_str,
7780
default=None,
7881
help="The file path to the chat template, "
7982
"or the template in single-line form "
8083
"for the specified model")
8184
parser.add_argument("--response-role",
82-
type=str,
85+
type=nullable_str,
8386
default="assistant",
8487
help="The role name to return if "
8588
"`request.add_generation_prompt=true`.")
8689
parser.add_argument("--ssl-keyfile",
87-
type=str,
90+
type=nullable_str,
8891
default=None,
8992
help="The file path to the SSL key file")
9093
parser.add_argument("--ssl-certfile",
91-
type=str,
94+
type=nullable_str,
9295
default=None,
9396
help="The file path to the SSL cert file")
9497
parser.add_argument("--ssl-ca-certs",
95-
type=str,
98+
type=nullable_str,
9699
default=None,
97100
help="The CA certificates file")
98101
parser.add_argument(
@@ -103,12 +106,12 @@ def make_arg_parser():
103106
)
104107
parser.add_argument(
105108
"--root-path",
106-
type=str,
109+
type=nullable_str,
107110
default=None,
108111
help="FastAPI root_path when app is behind a path based routing proxy")
109112
parser.add_argument(
110113
"--middleware",
111-
type=str,
114+
type=nullable_str,
112115
action="append",
113116
default=[],
114117
help="Additional ASGI middleware to apply to the app. "

0 commit comments

Comments
 (0)