Unverified Commit 1e36c868 authored by Harry Mellor's avatar Harry Mellor Committed by GitHub
Browse files

[Deprecation] Remove `nullable_kvs` (#20969)


Signed-off-by: default avatarHarry Mellor <19981378+hmellor@users.noreply.github.com>
parent 5bac6136
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import json import json
from argparse import ArgumentError, ArgumentTypeError from argparse import ArgumentError
from contextlib import nullcontext from contextlib import nullcontext
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Annotated, Literal, Optional from typing import Annotated, Literal, Optional
...@@ -12,8 +12,8 @@ import pytest ...@@ -12,8 +12,8 @@ import pytest
from vllm.config import CompilationConfig, config from vllm.config import CompilationConfig, config
from vllm.engine.arg_utils import (EngineArgs, contains_type, get_kwargs, from vllm.engine.arg_utils import (EngineArgs, contains_type, get_kwargs,
get_type, get_type_hints, is_not_builtin, get_type, get_type_hints, is_not_builtin,
is_type, literal_to_kwargs, nullable_kvs, is_type, literal_to_kwargs, optional_type,
optional_type, parse_type) parse_type)
from vllm.utils import FlexibleArgumentParser from vllm.utils import FlexibleArgumentParser
...@@ -25,18 +25,10 @@ from vllm.utils import FlexibleArgumentParser ...@@ -25,18 +25,10 @@ from vllm.utils import FlexibleArgumentParser
"foo": 1, "foo": 1,
"bar": 2 "bar": 2
}), }),
(json.loads, "foo=1,bar=2", {
"foo": 1,
"bar": 2
}),
]) ])
def test_parse_type(type, value, expected): def test_parse_type(type, value, expected):
parse_type_func = parse_type(type) parse_type_func = parse_type(type)
context = nullcontext() assert parse_type_func(value) == expected
if value == "foo=1,bar=2":
context = pytest.warns(DeprecationWarning)
with context:
assert parse_type_func(value) == expected
def test_optional_type(): def test_optional_type():
...@@ -203,34 +195,6 @@ def test_get_kwargs(): ...@@ -203,34 +195,6 @@ def test_get_kwargs():
assert kwargs["from_cli_config2"]["type"]('{"field": 2}').field == 4 assert kwargs["from_cli_config2"]["type"]('{"field": 2}').field == 4
@pytest.mark.parametrize(("arg", "expected"), [
(None, dict()),
("image=16", {
"image": 16
}),
("image=16,video=2", {
"image": 16,
"video": 2
}),
("Image=16, Video=2", {
"image": 16,
"video": 2
}),
])
def test_limit_mm_per_prompt_parser(arg, expected):
"""This functionality is deprecated and will be removed in the future.
This argument should be passed as JSON string instead.
TODO: Remove with nullable_kvs."""
parser = EngineArgs.add_cli_args(FlexibleArgumentParser())
if arg is None:
args = parser.parse_args([])
else:
args = parser.parse_args(["--limit-mm-per-prompt", arg])
assert args.limit_mm_per_prompt == expected
@pytest.mark.parametrize( @pytest.mark.parametrize(
("arg", "expected"), ("arg", "expected"),
[ [
...@@ -326,18 +290,6 @@ def test_prefix_cache_default(): ...@@ -326,18 +290,6 @@ def test_prefix_cache_default():
assert not engine_args.enable_prefix_caching assert not engine_args.enable_prefix_caching
@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)
# yapf: disable # yapf: disable
@pytest.mark.parametrize(("arg", "expected", "option"), [ @pytest.mark.parametrize(("arg", "expected", "option"), [
(None, None, "mm-processor-kwargs"), (None, None, "mm-processor-kwargs"),
......
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import json
from typing import Final from typing import Final
import pytest import pytest
...@@ -29,7 +30,7 @@ def server(): ...@@ -29,7 +30,7 @@ def server():
"--enforce-eager", "--enforce-eager",
"--trust-remote-code", "--trust-remote-code",
"--limit-mm-per-prompt", "--limit-mm-per-prompt",
f"image={MAXIMUM_IMAGES}", json.dumps({"image": MAXIMUM_IMAGES}),
] ]
with RemoteOpenAIServer(MODEL_NAME, args) as remote_server: with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
......
...@@ -18,7 +18,7 @@ from typing import (TYPE_CHECKING, Annotated, Any, Callable, Dict, List, ...@@ -18,7 +18,7 @@ from typing import (TYPE_CHECKING, Annotated, Any, Callable, Dict, List,
import regex as re import regex as re
import torch import torch
from pydantic import TypeAdapter, ValidationError from pydantic import TypeAdapter, ValidationError
from typing_extensions import TypeIs, deprecated from typing_extensions import TypeIs
import vllm.envs as envs import vllm.envs as envs
from vllm.config import (BlockSize, CacheConfig, CacheDType, CompilationConfig, from vllm.config import (BlockSize, CacheConfig, CacheDType, CompilationConfig,
...@@ -65,9 +65,6 @@ def parse_type(return_type: Callable[[str], T]) -> Callable[[str], T]: ...@@ -65,9 +65,6 @@ def parse_type(return_type: Callable[[str], T]) -> Callable[[str], T]:
def _parse_type(val: str) -> T: def _parse_type(val: str) -> T:
try: try:
if return_type is json.loads and not re.match(
r"(?s)^\s*{.*}\s*$", val):
return cast(T, nullable_kvs(val))
return return_type(val) return return_type(val)
except ValueError as e: except ValueError as e:
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(
...@@ -93,42 +90,6 @@ def union_dict_and_str(val: str) -> Optional[Union[str, dict[str, str]]]: ...@@ -93,42 +90,6 @@ def union_dict_and_str(val: str) -> Optional[Union[str, dict[str, str]]]:
return optional_type(json.loads)(val) return optional_type(json.loads)(val)
@deprecated(
"Passing a JSON argument as a string containing comma separated key=value "
"pairs is deprecated. This will be removed in v0.10.0. Please use a JSON "
"string instead.")
def nullable_kvs(val: str) -> dict[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.
"""
out_dict: dict[str, int] = {}
for item in val.split(","):
kv_parts = [part.lower().strip() for part in item.split("=")]
if len(kv_parts) != 2:
raise argparse.ArgumentTypeError(
"Each item should be in the form KEY=VALUE")
key, value = kv_parts
try:
parsed_value = int(value)
except ValueError as exc:
msg = f"Failed to parse value of item {key}={value}"
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
def is_type(type_hint: TypeHint, type: TypeHintT) -> TypeIs[TypeHintT]: def is_type(type_hint: TypeHint, type: TypeHintT) -> TypeIs[TypeHintT]:
"""Check if the type hint is a specific type.""" """Check if the type hint is a specific type."""
return type_hint is type or get_origin(type_hint) is type return type_hint is type or get_origin(type_hint) is type
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment