Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
1c1bb388
Unverified
Commit
1c1bb388
authored
Sep 16, 2024
by
Alex Brooks
Committed by
GitHub
Sep 17, 2024
Browse files
[Frontend] Improve Nullable kv Arg Parsing (#8525)
Signed-off-by:
Alex-Brooks
<
Alex.Brooks@ibm.com
>
parent
546034b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
8 deletions
+40
-8
tests/engine/test_arg_utils.py
tests/engine/test_arg_utils.py
+19
-1
vllm/engine/arg_utils.py
vllm/engine/arg_utils.py
+21
-7
No files found.
tests/engine/test_arg_utils.py
View file @
1c1bb388
from
argparse
import
ArgumentTypeError
import
pytest
from
vllm.engine.arg_utils
import
EngineArgs
from
vllm.engine.arg_utils
import
EngineArgs
,
nullable_kvs
from
vllm.utils
import
FlexibleArgumentParser
...
...
@@ -13,6 +15,10 @@ from vllm.utils import FlexibleArgumentParser
"image"
:
16
,
"video"
:
2
}),
(
"Image=16, Video=2"
,
{
"image"
:
16
,
"video"
:
2
}),
])
def
test_limit_mm_per_prompt_parser
(
arg
,
expected
):
parser
=
EngineArgs
.
add_cli_args
(
FlexibleArgumentParser
())
...
...
@@ -22,3 +28,15 @@ def test_limit_mm_per_prompt_parser(arg, expected):
args
=
parser
.
parse_args
([
"--limit-mm-per-prompt"
,
arg
])
assert
args
.
limit_mm_per_prompt
==
expected
@
pytest
.
mark
.
parametrize
(
(
"arg"
),
[
"image"
,
# Missing =
"image=4,image=5"
,
# Conflicting values
"image=video=4"
# Too many = in tokenized arg
])
def
test_bad_nullable_kvs
(
arg
):
with
pytest
.
raises
(
ArgumentTypeError
):
nullable_kvs
(
arg
)
vllm/engine/arg_utils.py
View file @
1c1bb388
...
...
@@ -44,22 +44,36 @@ def nullable_str(val: str):
def
nullable_kvs
(
val
:
str
)
->
Optional
[
Mapping
[
str
,
int
]]:
"""Parses a string containing comma separate key [str] to value [int]
pairs into a dictionary.
Args:
val: String value to be parsed.
Returns:
Dictionary with parsed values.
"""
if
len
(
val
)
==
0
:
return
None
out_dict
:
Dict
[
str
,
int
]
=
{}
for
item
in
val
.
split
(
","
):
try
:
key
,
value
=
item
.
split
(
"="
)
except
TypeError
as
exc
:
msg
=
"Each item should be in the form KEY=VALUE"
raise
ValueError
(
msg
)
from
exc
kv_parts
=
[
part
.
lower
().
strip
()
for
part
in
item
.
split
(
"="
)]
if
len
(
kv_parts
)
!=
2
:
raise
argparse
.
Argument
TypeError
(
"Each item should be in the form KEY=VALUE"
)
key
,
value
=
kv_parts
try
:
out_dict
[
key
]
=
int
(
value
)
parsed_value
=
int
(
value
)
except
ValueError
as
exc
:
msg
=
f
"Failed to parse value of item
{
key
}
=
{
value
}
"
raise
ValueError
(
msg
)
from
exc
raise
argparse
.
ArgumentTypeError
(
msg
)
from
exc
if
key
in
out_dict
and
out_dict
[
key
]
!=
parsed_value
:
raise
argparse
.
ArgumentTypeError
(
f
"Conflicting values specified for key:
{
key
}
"
)
out_dict
[
key
]
=
parsed_value
return
out_dict
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment