From 5df183489537a155bbaad9232f25b8e57694d7b8 Mon Sep 17 00:00:00 2001 From: Andy Dai <76841985+Imss27@users.noreply.github.com> Date: Sat, 5 Oct 2024 10:35:11 -0700 Subject: [PATCH] [Bugfix] Fix order of arguments matters in config.yaml (#8960) --- .../serving/openai_compatible_server.md | 2 +- tests/data/test_config.yaml | 1 + tests/test_utils.py | 30 ++++++++++++++----- vllm/utils.py | 12 +++++++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/docs/source/serving/openai_compatible_server.md b/docs/source/serving/openai_compatible_server.md index 8bb7067faa97c..9132e12a36ba5 100644 --- a/docs/source/serving/openai_compatible_server.md +++ b/docs/source/serving/openai_compatible_server.md @@ -140,7 +140,7 @@ $ vllm serve SOME_MODEL --config config.yaml ``` --- **NOTE** -In case an argument is supplied using command line and the config file, the value from the commandline will take precedence. +In case an argument is supplied simultaneously using command line and the config file, the value from the commandline will take precedence. The order of priorities is `command line > config file values > defaults`. --- diff --git a/tests/data/test_config.yaml b/tests/data/test_config.yaml index 20d499624de2e..42f4f6f7bb992 100644 --- a/tests/data/test_config.yaml +++ b/tests/data/test_config.yaml @@ -1,2 +1,3 @@ port: 12312 +served_model_name: mymodel tensor_parallel_size: 2 diff --git a/tests/test_utils.py b/tests/test_utils.py index c7cb663068c0f..f3017a8582ea8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -136,6 +136,8 @@ def parser(): def parser_with_config(): parser = FlexibleArgumentParser() parser.add_argument('serve') + parser.add_argument('model_tag') + parser.add_argument('--served-model-name', type=str) parser.add_argument('--config', type=str) parser.add_argument('--port', type=int) parser.add_argument('--tensor-parallel-size', type=int) @@ -190,33 +192,47 @@ def test_missing_required_argument(parser): def test_cli_override_to_config(parser_with_config): args = parser_with_config.parse_args([ - 'serve', '--config', './data/test_config.yaml', + 'serve', 'mymodel', '--config', './data/test_config.yaml', '--tensor-parallel-size', '3' ]) assert args.tensor_parallel_size == 3 args = parser_with_config.parse_args([ - 'serve', '--tensor-parallel-size', '3', '--config', + 'serve', 'mymodel', '--tensor-parallel-size', '3', '--config', './data/test_config.yaml' ]) assert args.tensor_parallel_size == 3 + assert args.port == 12312 + args = parser_with_config.parse_args([ + 'serve', 'mymodel', '--tensor-parallel-size', '3', '--config', + './data/test_config.yaml', '--port', '666' + ]) + assert args.tensor_parallel_size == 3 + assert args.port == 666 def test_config_args(parser_with_config): args = parser_with_config.parse_args( - ['serve', '--config', './data/test_config.yaml']) + ['serve', 'mymodel', '--config', './data/test_config.yaml']) assert args.tensor_parallel_size == 2 def test_config_file(parser_with_config): with pytest.raises(FileNotFoundError): - parser_with_config.parse_args(['serve', '--config', 'test_config.yml']) + parser_with_config.parse_args( + ['serve', 'mymodel', '--config', 'test_config.yml']) with pytest.raises(ValueError): parser_with_config.parse_args( - ['serve', '--config', './data/test_config.json']) + ['serve', 'mymodel', '--config', './data/test_config.json']) with pytest.raises(ValueError): parser_with_config.parse_args([ - 'serve', '--tensor-parallel-size', '3', '--config', '--batch-size', - '32' + 'serve', 'mymodel', '--tensor-parallel-size', '3', '--config', + '--batch-size', '32' ]) + + +def test_no_model_tag(parser_with_config): + with pytest.raises(ValueError): + parser_with_config.parse_args( + ['serve', '--config', './data/test_config.yaml']) diff --git a/vllm/utils.py b/vllm/utils.py index a025c3c40a434..197584867d8b0 100644 --- a/vllm/utils.py +++ b/vllm/utils.py @@ -1201,11 +1201,21 @@ def _pull_args_from_config(args: List[str]) -> List[str]: config_args = FlexibleArgumentParser._load_config_file(file_path) # 0th index is for {serve,chat,complete} + # 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 - args = [args[0]] + config_args + args[1:index] + args[index + 2:] + if args[0] == "serve": + if index == 1: + raise ValueError( + "No model_tag specified! Please check your command-line" + " arguments.") + args = [args[0]] + [ + args[1] + ] + config_args + args[2:index] + args[index + 2:] + else: + args = [args[0]] + config_args + args[1:index] + args[index + 2:] return args