diff --git a/tests/utils_/test_argparse_utils.py b/tests/utils_/test_argparse_utils.py index 53639d02bd..baf57d994f 100644 --- a/tests/utils_/test_argparse_utils.py +++ b/tests/utils_/test_argparse_utils.py @@ -4,6 +4,7 @@ import json import os +from argparse import BooleanOptionalAction import pytest import yaml @@ -379,6 +380,27 @@ def test_load_config_file(tmp_path): os.remove(str(config_file_path)) +def test_load_config_file_false_store_true_dropped(tmp_path): + """False values for store_true flags are silently dropped (correct).""" + config_data = { + "enable-feature": False, + "port": 8000, + } + + config_file_path = tmp_path / "config.yaml" + with open(config_file_path, "w") as config_file: + yaml.dump(config_data, config_file) + + parser = FlexibleArgumentParser() + parser.add_argument("--enable-feature", action=BooleanOptionalAction) + parser.add_argument("--port", type=int) + + processed_args = parser.load_config_file(str(config_file_path)) + + assert "--enable-feature" not in processed_args + assert "--no-enable-feature" in processed_args + + def test_load_config_file_nested(tmp_path): """Test that nested dicts in YAML config are converted to JSON strings.""" config_data = { diff --git a/vllm/utils/argparse_utils.py b/vllm/utils/argparse_utils.py index 84c8537571..48f7ad9199 100644 --- a/vllm/utils/argparse_utils.py +++ b/vllm/utils/argparse_utils.py @@ -573,6 +573,8 @@ class FlexibleArgumentParser(ArgumentParser): if isinstance(value, bool): if value: processed_args.append("--" + key) + elif (no_key := f"--no-{key}") in self._option_string_actions: + processed_args.append(no_key) elif isinstance(value, list): if value: processed_args.append("--" + key)