Skip to content

Commit 6e8f38b

Browse files
hmellorYuqi Zhang
authored andcommitted
Automatically tell users that dict args must be valid JSON in CLI (vllm-project#17577)
Signed-off-by: Harry Mellor <[email protected]> Signed-off-by: Yuqi Zhang <[email protected]>
1 parent 1524dad commit 6e8f38b

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

tests/engine/test_arg_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class DummyConfigClass:
106106
"""List with literal choices"""
107107
literal_literal: Literal[Literal[1], Literal[2]] = 1
108108
"""Literal of literals with default 1"""
109+
json_tip: dict = field(default_factory=dict)
110+
"""Dict which will be JSON in CLI"""
109111

110112

111113
@pytest.mark.parametrize(("type_hint", "expected"), [
@@ -137,6 +139,9 @@ def test_get_kwargs():
137139
assert kwargs["list_literal"]["choices"] == [1, 2]
138140
# literals of literals should have merged choices
139141
assert kwargs["literal_literal"]["choices"] == [1, 2]
142+
# dict should have json tip in help
143+
json_tip = "\n\nShould be a valid JSON string."
144+
assert kwargs["json_tip"]["help"].endswith(json_tip)
140145

141146

142147
@pytest.mark.parametrize(("arg", "expected"), [

vllm/config.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class ModelConfig:
268268
It can be a branch name, a tag name, or a commit id. If unspecified, will
269269
use the default version."""
270270
rope_scaling: dict[str, Any] = field(default_factory=dict)
271-
"""RoPE scaling configuration in JSON format. For example,
271+
"""RoPE scaling configuration. For example,
272272
`{"rope_type":"dynamic","factor":2.0}`."""
273273
rope_theta: Optional[float] = None
274274
"""RoPE theta. Use with `rope_scaling`. In some cases, changing the RoPE
@@ -346,30 +346,28 @@ class ModelConfig:
346346
(stored in `~/.huggingface`)."""
347347
hf_overrides: HfOverrides = field(default_factory=dict)
348348
"""If a dictionary, contains arguments to be forwarded to the Hugging Face
349-
config. If a callable, it is called to update the HuggingFace config. When
350-
specified via CLI, the argument must be a valid JSON string."""
349+
config. If a callable, it is called to update the HuggingFace config."""
351350
mm_processor_kwargs: Optional[dict[str, Any]] = None
352351
"""Arguments to be forwarded to the model's processor for multi-modal data,
353352
e.g., image processor. Overrides for the multi-modal processor obtained
354353
from `AutoProcessor.from_pretrained`. The available overrides depend on the
355354
model that is being run. For example, for Phi-3-Vision: `{"num_crops": 4}`.
356-
When specified via CLI, the argument must be a valid JSON string."""
355+
"""
357356
disable_mm_preprocessor_cache: bool = False
358357
"""If `True`, disable caching of the multi-modal preprocessor/mapper (not
359358
recommended)."""
360359
override_neuron_config: dict[str, Any] = field(default_factory=dict)
361360
"""Initialize non-default neuron config or override default neuron config
362361
that are specific to Neuron devices, this argument will be used to
363362
configure the neuron config that can not be gathered from the vllm
364-
arguments. e.g. `{"cast_logits_dtype": "bloat16"}`. When specified via CLI,
365-
the argument must be a valid JSON string."""
363+
arguments. e.g. `{"cast_logits_dtype": "bloat16"}`."""
366364
pooler_config: Optional["PoolerConfig"] = field(init=False)
367365
"""Pooler config which controls the behaviour of output pooling in pooling
368366
models."""
369367
override_pooler_config: Optional[Union[dict, "PoolerConfig"]] = None
370368
"""Initialize non-default pooling config or override default pooling config
371369
for the pooling model. e.g. `{"pooling_type": "mean", "normalize": false}`.
372-
When specified via CLI, the argument must be a valid JSON string."""
370+
"""
373371
logits_processor_pattern: Optional[str] = None
374372
"""Optional regex pattern specifying valid logits processor qualified names
375373
that can be passed with the `logits_processors` extra completion argument.
@@ -385,8 +383,7 @@ class ModelConfig:
385383
"""Overrides or sets generation config. e.g. `{"temperature": 0.5}`. If
386384
used with `--generation-config auto`, the override parameters will be
387385
merged with the default config from the model. If used with
388-
`--generation-config vllm`, only the override parameters are used.
389-
When specified via CLI, the argument must be a valid JSON string."""
386+
`--generation-config vllm`, only the override parameters are used."""
390387
enable_sleep_mode: bool = False
391388
"""Enable sleep mode for the engine (only cuda platform is supported)."""
392389
model_impl: Union[str, ModelImpl] = ModelImpl.AUTO.value
@@ -1556,8 +1553,7 @@ class LoadConfig:
15561553
cache directory of Hugging Face."""
15571554
model_loader_extra_config: dict = field(default_factory=dict)
15581555
"""Extra config for model loader. This will be passed to the model loader
1559-
corresponding to the chosen load_format. This should be a JSON string that
1560-
will be parsed into a dictionary."""
1556+
corresponding to the chosen load_format."""
15611557
ignore_patterns: Optional[Union[list[str], str]] = None
15621558
"""The list of patterns to ignore when loading the model. Default to
15631559
"original/**/*" to avoid repeated loading of llama's checkpoints."""
@@ -2826,7 +2822,6 @@ class MultiModalConfig:
28262822
"limit_mm_per_prompt")
28272823
"""
28282824
The maximum number of input items allowed per prompt for each modality.
2829-
This should be a JSON string that will be parsed into a dictionary.
28302825
Defaults to 1 (V0) or 999 (V1) for each modality.
28312826
28322827
For example, to allow up to 16 images and 2 videos per prompt:

vllm/engine/arg_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def get_kwargs(cls: ConfigType) -> dict[str, Any]:
150150

151151
# Get the help text for the field
152152
name = field.name
153-
help = cls_docs[name]
153+
help = cls_docs[name].strip()
154154
# Escape % for argparse
155155
help = help.replace("%", "%%")
156156

@@ -165,6 +165,7 @@ def get_kwargs(cls: ConfigType) -> dict[str, Any]:
165165
type_hints.add(field.type)
166166

167167
# Set other kwargs based on the type hints
168+
json_tip = "\n\nShould be a valid JSON string."
168169
if contains_type(type_hints, bool):
169170
# Creates --no-<name> and --<name> flags
170171
kwargs[name]["action"] = argparse.BooleanOptionalAction
@@ -201,6 +202,7 @@ def get_kwargs(cls: ConfigType) -> dict[str, Any]:
201202
elif contains_type(type_hints, dict):
202203
# Dict arguments will always be optional
203204
kwargs[name]["type"] = optional_type(json.loads)
205+
kwargs[name]["help"] += json_tip
204206
elif (contains_type(type_hints, str)
205207
or any(is_not_builtin(th) for th in type_hints)):
206208
kwargs[name]["type"] = str

0 commit comments

Comments
 (0)