Skip to content

Commit

Permalink
[Bugfix] Fix order of arguments matters in config.yaml (#8960)
Browse files Browse the repository at this point in the history
  • Loading branch information
Imss27 authored Oct 5, 2024
1 parent cfadb9c commit 5df1834
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/source/serving/openai_compatible_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

---
Expand Down
1 change: 1 addition & 0 deletions tests/data/test_config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
port: 12312
served_model_name: mymodel
tensor_parallel_size: 2
30 changes: 23 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'])
12 changes: 11 additions & 1 deletion vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5df1834

Please sign in to comment.