A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 07:15 UTC
Fix underscores in dict keys passed via CLI (#19030)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Harry Mellor committed
Jun 3, 2025 at 15:39 UTC
476844d44cbf315c6c1e8431946bdecfe9823834
2 files changed
+21
-3
tests/test_utils.py
+11
@@ -259,11 +259,18 @@ def test_dict_args(parser):
259
"--model-name=something.something",
260
"--hf-overrides.key1",
261
"val1",
262
+ # Test nesting
263
"--hf-overrides.key2.key3",
264
"val2",
265
"--hf-overrides.key2.key4",
266
"val3",
267
+ # Test = sign
268
"--hf-overrides.key5=val4",
269
+ # Test underscore to dash conversion
270
+ "--hf_overrides.key_6",
271
+ "val5",
272
+ "--hf_overrides.key-7.key_8",
273
+ "val6",
274
]
275
parsed_args = parser.parse_args(args)
276
assert parsed_args.model_name == "something.something"
@@ -274,6 +281,10 @@ def test_dict_args(parser):
281
"key4": "val3",
282
},
283
"key5": "val4",
284
+ "key_6": "val5",
285
+ "key-7": {
286
+ "key_8": "val6",
287
+ },
288
}
289
290
vllm/utils.py
+10
-3
@@ -1456,17 +1456,24 @@ class FlexibleArgumentParser(ArgumentParser):
1456
if '--config' in args:
1457
args = self._pull_args_from_config(args)
1458
1459
+ def repl(match: re.Match) -> str:
1460
+ """Replaces underscores with dashes in the matched string."""
1461
+ return match.group(0).replace("_", "-")
1462
+
1463
+ # Everything between the first -- and the first .
1464
+ pattern = re.compile(r"(?<=--)[^\.]*")
1465
+
1466
# Convert underscores to dashes and vice versa in argument names
1467
processed_args = []
1468
for arg in args:
1469
if arg.startswith('--'):
1470
if '=' in arg:
1471
key, value = arg.split('=', 1)
1465
- key = '--' + key[len('--'):].replace('_', '-')
1472
+ key = pattern.sub(repl, key, count=1)
1473
processed_args.append(f'{key}={value}')
1474
else:
1468
- processed_args.append('--' +
1469
- arg[len('--'):].replace('_', '-'))
1475
+ key = pattern.sub(repl, arg, count=1)
1476
+ processed_args.append(key)
1477
elif arg.startswith('-O') and arg != '-O' and len(arg) == 2:
1478
# allow -O flag to be used without space, e.g. -O3
1479
processed_args.append('-O')