diff --git a/tests/entrypoints/openai/test_cli_args.py b/tests/entrypoints/openai/test_cli_args.py index b20838956d72..9a1c0ea13b54 100644 --- a/tests/entrypoints/openai/test_cli_args.py +++ b/tests/entrypoints/openai/test_cli_args.py @@ -27,6 +27,28 @@ def serve_parser(): return make_arg_parser(parser) +### Test config parsing +def test_config_arg_parsing(serve_parser, cli_config_file): + args = serve_parser.parse_args([]) + assert args.port == 8000 + args = serve_parser.parse_args(['--config', cli_config_file]) + assert args.port == 12312 + args = serve_parser.parse_args([ + '--config', + cli_config_file, + '--port', + '9000', + ]) + assert args.port == 9000 + args = serve_parser.parse_args([ + '--port', + '9000', + '--config', + cli_config_file, + ]) + assert args.port == 9000 + + ### Tests for LoRA module parsing def test_valid_key_value_format(serve_parser): # Test old format: name=path diff --git a/vllm/utils/__init__.py b/vllm/utils/__init__.py index 60bddc5b500b..c5ed10326fd5 100644 --- a/vllm/utils/__init__.py +++ b/vllm/utils/__init__.py @@ -1976,13 +1976,16 @@ class FlexibleArgumentParser(ArgumentParser): config_args = self.load_config_file(file_path) - # 0th index is for {serve,chat,complete} + # 0th index might be the sub command {serve,chat,complete,...} # optionally followed by model_tag (only for serve) # followed by config args # followed by rest of cli args. # maintaining this order will enforce the precedence # of cli > config > defaults - if args[0] == "serve": + if args[0].startswith('-'): + # No sub command (e.g., api_server entry point) + args = config_args + args[0:index] + args[index + 2:] + elif args[0] == "serve": model_in_cli = len(args) > 1 and not args[1].startswith('-') model_in_config = any(arg == '--model' for arg in config_args)