[Bugfix][Core] Emit --no-{key} for false BooleanOptionalAction flags in YAML config (#51573)

Signed-off-by: Raj Firke <79653531+rajfirke@users.noreply.github.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Raj Vijay Firke committed Aug 10, 2026 at 16:35 UTC 3dafaef02735de08f16298bac42fe18dd930d2ee
2 files changed +24
tests/utils_/test_argparse_utils.py
+22
@@ -4,6 +4,7 @@
4
5 import json
6 import os
7 +from argparse import BooleanOptionalAction
8
9 import pytest
10 import yaml
@@ -379,6 +380,27 @@ def test_load_config_file(tmp_path):
380 os.remove(str(config_file_path))
381
382
383 +def test_load_config_file_false_store_true_dropped(tmp_path):
384 + """False values for store_true flags are silently dropped (correct)."""
385 + config_data = {
386 + "enable-feature": False,
387 + "port": 8000,
388 + }
389 +
390 + config_file_path = tmp_path / "config.yaml"
391 + with open(config_file_path, "w") as config_file:
392 + yaml.dump(config_data, config_file)
393 +
394 + parser = FlexibleArgumentParser()
395 + parser.add_argument("--enable-feature", action=BooleanOptionalAction)
396 + parser.add_argument("--port", type=int)
397 +
398 + processed_args = parser.load_config_file(str(config_file_path))
399 +
400 + assert "--enable-feature" not in processed_args
401 + assert "--no-enable-feature" in processed_args
402 +
403 +
404 def test_load_config_file_nested(tmp_path):
405 """Test that nested dicts in YAML config are converted to JSON strings."""
406 config_data = {
vllm/utils/argparse_utils.py
+2
@@ -573,6 +573,8 @@ class FlexibleArgumentParser(ArgumentParser):
573 if isinstance(value, bool):
574 if value:
575 processed_args.append("--" + key)
576 + elif (no_key := f"--no-{key}") in self._option_string_actions:
577 + processed_args.append(no_key)
578 elif isinstance(value, list):
579 if value:
580 processed_args.append("--" + key)