Skip to content

Commit 126249b

Browse files
lengrongfuepwalsh
authored andcommitted
[Bugfix] fix when config.yaml config value is list parse error (vllm-project#23528)
Signed-off-by: rongfu.leng <[email protected]>
1 parent cd53ee6 commit 126249b

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

tests/utils_/test_utils.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import asyncio
66
import hashlib
77
import json
8+
import os
89
import pickle
910
import socket
11+
import tempfile
1012
from collections.abc import AsyncIterator
13+
from pathlib import Path
1114
from unittest.mock import patch
1215

1316
import pytest
1417
import torch
18+
import yaml
1519
import zmq
1620
from transformers import AutoTokenizer
1721
from vllm_test_utils.monitor import monitor
@@ -991,3 +995,40 @@ def child_thread_func():
991995
child_thread.join(timeout=5)
992996
if child_thread.is_alive():
993997
pytest.fail("Child thread failed to exit properly")
998+
999+
1000+
def test_load_config_file(tmp_path):
1001+
# Define the configuration data
1002+
config_data = {
1003+
"enable-logging": True,
1004+
"list-arg": ["item1", "item2"],
1005+
"port": 12323,
1006+
"tensor-parallel-size": 4
1007+
}
1008+
1009+
# Write the configuration data to a temporary YAML file
1010+
config_file_path = tmp_path / "config.yaml"
1011+
with open(config_file_path, "w") as config_file:
1012+
yaml.dump(config_data, config_file)
1013+
1014+
# Initialize the parser
1015+
parser = FlexibleArgumentParser()
1016+
1017+
# Call the function with the temporary file path
1018+
processed_args = parser.load_config_file(str(config_file_path))
1019+
1020+
# Expected output
1021+
expected_args = [
1022+
"--enable-logging",
1023+
"--list-arg",
1024+
"item1",
1025+
"item2",
1026+
"--port",
1027+
"12323",
1028+
"--tensor-parallel-size",
1029+
"4",
1030+
]
1031+
1032+
# Assert that the processed arguments match the expected output
1033+
assert processed_args == expected_args
1034+
os.remove(str(config_file_path))

vllm/utils/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ def _pull_args_from_config(self, args: list[str]) -> list[str]:
19741974

19751975
file_path = args[index + 1]
19761976

1977-
config_args = self._load_config_file(file_path)
1977+
config_args = self.load_config_file(file_path)
19781978

19791979
# 0th index is for {serve,chat,complete}
19801980
# optionally followed by model_tag (only for serve)
@@ -2005,7 +2005,7 @@ def _pull_args_from_config(self, args: list[str]) -> list[str]:
20052005

20062006
return args
20072007

2008-
def _load_config_file(self, file_path: str) -> list[str]:
2008+
def load_config_file(self, file_path: str) -> list[str]:
20092009
"""Loads a yaml file and returns the key value pairs as a
20102010
flattened list with argparse like pattern
20112011
```yaml
@@ -2046,6 +2046,11 @@ def _load_config_file(self, file_path: str) -> list[str]:
20462046
if isinstance(value, bool) and key not in store_boolean_arguments:
20472047
if value:
20482048
processed_args.append('--' + key)
2049+
elif isinstance(value, list):
2050+
if value:
2051+
processed_args.append('--' + key)
2052+
for item in value:
2053+
processed_args.append(str(item))
20492054
else:
20502055
processed_args.append('--' + key)
20512056
processed_args.append(str(value))

0 commit comments

Comments
 (0)