@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 28c5e69ba0
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 7, 21:30 UTC

Enforce that `model` is the first positional arg when `--served-model-name` is used (#34973)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Harry Mellor committed Feb 23, 2026 at 16:38 UTC 28c5e69ba0c4ccc9b33e05bfb757052b68af4282
2 files changed +67 -6
tests/entrypoints/openai/test_cli_args.py
+52 -2
@@ -20,10 +20,22 @@ CHATML_JINJA_PATH = VLLM_PATH / "examples/template_chatml.jinja"
20 assert CHATML_JINJA_PATH.exists()
21
22
23 +def _build_vllm_parsers():
24 + vllm_parser = FlexibleArgumentParser()
25 + subparsers = vllm_parser.add_subparsers()
26 + serve_parser = subparsers.add_parser("serve")
27 + make_arg_parser(serve_parser)
28 + return {"vllm": vllm_parser, "vllm serve": serve_parser}
29 +
30 +
31 +@pytest.fixture
32 +def vllm_parser():
33 + return _build_vllm_parsers()["vllm"]
34 +
35 +
36 @pytest.fixture
37 def serve_parser():
25 - parser = FlexibleArgumentParser(description="vLLM's remote OpenAI server.")
26 - return make_arg_parser(parser)
38 + return _build_vllm_parsers()["vllm serve"]
39
40
41 ### Test config parsing
@@ -241,3 +253,41 @@ def test_default_chat_template_kwargs_invalid_json(serve_parser):
253 serve_parser.parse_args(
254 args=["--default-chat-template-kwargs", "not valid json"]
255 )
256 +
257 +
258 +@pytest.mark.parametrize(
259 + "args, raises",
260 + [
261 + (["user/model"], None),
262 + (["user/model", "--served-model-name", "model"], None),
263 + (["--served-model-name", "model", "user/model"], ValueError),
264 + (["--served-model-name", "model", "--config", "config.yaml"], None),
265 + (["--served-model-name", "model", "--config", "config.yaml"], ValueError),
266 + ],
267 + ids=[
268 + "model_tag_only",
269 + "model_tag_with_served_model_name",
270 + "served_model_name_before_model_tag",
271 + "served_model_name_with_model_in_config",
272 + "served_model_name_with_no_model_in_config",
273 + ],
274 +)
275 +def test_served_model_name_parsing(tmp_path, vllm_parser, args, raises):
276 + """Ensure that users don't misuse --served-model-name and end up with the default
277 + model tag instead of the one they intended to serve."""
278 + # Call the serve subparser
279 + args.insert(0, "serve")
280 + # Create a dummy config file if the test case includes it
281 + if "config.yaml" in args:
282 + # Create a dummy config file if the test case includes it
283 + config_path = tmp_path / "config.yaml"
284 + config_path.write_text("model: user/model" if raises is None else "port: 8000")
285 + args[args.index("config.yaml")] = config_path.as_posix()
286 + # Do the parsing and check for expected exceptions or values
287 + if raises is None:
288 + parsed_args = vllm_parser.parse_args(args=args)
289 + expected = "user/model"
290 + assert parsed_args.model_tag == expected or parsed_args.model == expected
291 + else:
292 + with pytest.raises(raises):
293 + vllm_parser.parse_args(args=args)
vllm/utils/argparse_utils.py
+15 -4
@@ -184,13 +184,11 @@ class FlexibleArgumentParser(ArgumentParser):
184 if args is None:
185 args = sys.argv[1:]
186
187 - # Check for --model in command line arguments first
187 if args and args[0] == "serve":
188 + # Check for --model in command line arguments first
189 try:
190 model_idx = next(
191 - i
192 - for i, arg in enumerate(args)
193 - if arg == "--model" or arg.startswith("--model=")
191 + i for i, arg in enumerate(args) if re.match(r"^--model(=.+|$)", arg)
192 )
193 logger.warning(
194 "With `vllm serve`, you should provide the model as a "
@@ -219,6 +217,19 @@ class FlexibleArgumentParser(ArgumentParser):
217 ]
218 except StopIteration:
219 pass
220 + # Check for --served-model-name without a positional model argument
221 + if (
222 + len(args) > 1
223 + and args[1].startswith("-")
224 + and not any(re.match(r"^--config(=.+|$)", arg) for arg in args)
225 + and any(
226 + re.match(r"^--served[-_]model[-_]name(=.+|$)", arg) for arg in args
227 + )
228 + ):
229 + raise ValueError(
230 + "`model` should be provided as the first positional argument when "
231 + "using `vllm serve`. i.e. `vllm serve <model> --<arg> <value>`."
232 + )
233
234 if "--config" in args:
235 args = self._pull_args_from_config(args)