Skip to content

Commit deae5a4

Browse files
Imss27Alvant
authored andcommitted
[Bugfix] Fix order of arguments matters in config.yaml (vllm-project#8960)
Signed-off-by: Alvant <[email protected]>
1 parent 1677a09 commit deae5a4

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

docs/source/serving/openai_compatible_server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ $ vllm serve SOME_MODEL --config config.yaml
140140
```
141141
---
142142
**NOTE**
143-
In case an argument is supplied using command line and the config file, the value from the commandline will take precedence.
143+
In case an argument is supplied simultaneously using command line and the config file, the value from the commandline will take precedence.
144144
The order of priorities is `command line > config file values > defaults`.
145145

146146
---

tests/data/test_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
port: 12312
2+
served_model_name: mymodel
23
tensor_parallel_size: 2

tests/test_utils.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def parser():
136136
def parser_with_config():
137137
parser = FlexibleArgumentParser()
138138
parser.add_argument('serve')
139+
parser.add_argument('model_tag')
140+
parser.add_argument('--served-model-name', type=str)
139141
parser.add_argument('--config', type=str)
140142
parser.add_argument('--port', type=int)
141143
parser.add_argument('--tensor-parallel-size', type=int)
@@ -190,33 +192,47 @@ def test_missing_required_argument(parser):
190192

191193
def test_cli_override_to_config(parser_with_config):
192194
args = parser_with_config.parse_args([
193-
'serve', '--config', './data/test_config.yaml',
195+
'serve', 'mymodel', '--config', './data/test_config.yaml',
194196
'--tensor-parallel-size', '3'
195197
])
196198
assert args.tensor_parallel_size == 3
197199
args = parser_with_config.parse_args([
198-
'serve', '--tensor-parallel-size', '3', '--config',
200+
'serve', 'mymodel', '--tensor-parallel-size', '3', '--config',
199201
'./data/test_config.yaml'
200202
])
201203
assert args.tensor_parallel_size == 3
204+
assert args.port == 12312
205+
args = parser_with_config.parse_args([
206+
'serve', 'mymodel', '--tensor-parallel-size', '3', '--config',
207+
'./data/test_config.yaml', '--port', '666'
208+
])
209+
assert args.tensor_parallel_size == 3
210+
assert args.port == 666
202211

203212

204213
def test_config_args(parser_with_config):
205214
args = parser_with_config.parse_args(
206-
['serve', '--config', './data/test_config.yaml'])
215+
['serve', 'mymodel', '--config', './data/test_config.yaml'])
207216
assert args.tensor_parallel_size == 2
208217

209218

210219
def test_config_file(parser_with_config):
211220
with pytest.raises(FileNotFoundError):
212-
parser_with_config.parse_args(['serve', '--config', 'test_config.yml'])
221+
parser_with_config.parse_args(
222+
['serve', 'mymodel', '--config', 'test_config.yml'])
213223

214224
with pytest.raises(ValueError):
215225
parser_with_config.parse_args(
216-
['serve', '--config', './data/test_config.json'])
226+
['serve', 'mymodel', '--config', './data/test_config.json'])
217227

218228
with pytest.raises(ValueError):
219229
parser_with_config.parse_args([
220-
'serve', '--tensor-parallel-size', '3', '--config', '--batch-size',
221-
'32'
230+
'serve', 'mymodel', '--tensor-parallel-size', '3', '--config',
231+
'--batch-size', '32'
222232
])
233+
234+
235+
def test_no_model_tag(parser_with_config):
236+
with pytest.raises(ValueError):
237+
parser_with_config.parse_args(
238+
['serve', '--config', './data/test_config.yaml'])

vllm/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,11 +1201,21 @@ def _pull_args_from_config(args: List[str]) -> List[str]:
12011201
config_args = FlexibleArgumentParser._load_config_file(file_path)
12021202

12031203
# 0th index is for {serve,chat,complete}
1204+
# followed by model_tag (only for serve)
12041205
# followed by config args
12051206
# followed by rest of cli args.
12061207
# maintaining this order will enforce the precedence
12071208
# of cli > config > defaults
1208-
args = [args[0]] + config_args + args[1:index] + args[index + 2:]
1209+
if args[0] == "serve":
1210+
if index == 1:
1211+
raise ValueError(
1212+
"No model_tag specified! Please check your command-line"
1213+
" arguments.")
1214+
args = [args[0]] + [
1215+
args[1]
1216+
] + config_args + args[2:index] + args[index + 2:]
1217+
else:
1218+
args = [args[0]] + config_args + args[1:index] + args[index + 2:]
12091219

12101220
return args
12111221

0 commit comments

Comments
 (0)