[Deprecation] Disallow pos-args other than model when initializing LLM (#18802)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung 2025-05-30 00:36:58 +08:00 committed by GitHub
parent 1b7cfd5a36
commit c29034037d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 41 deletions

View File

@ -1,24 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
import pytest
from vllm import LLM
from ...utils import error_on_warning
MODEL_NAME = "facebook/opt-125m"
def test_pos_args_deprecated():
with error_on_warning(DeprecationWarning):
LLM(model=MODEL_NAME, tokenizer=MODEL_NAME)
with error_on_warning(DeprecationWarning):
LLM(MODEL_NAME, tokenizer=MODEL_NAME)
with pytest.warns(DeprecationWarning, match="'tokenizer'"):
LLM(MODEL_NAME, MODEL_NAME)
with pytest.warns(DeprecationWarning,
match="'tokenizer', 'tokenizer_mode'"):
LLM(MODEL_NAME, MODEL_NAME, "auto")

View File

@ -45,8 +45,7 @@ from vllm.sampling_params import (BeamSearchParams, GuidedDecodingParams,
from vllm.transformers_utils.tokenizer import (AnyTokenizer, MistralTokenizer, from vllm.transformers_utils.tokenizer import (AnyTokenizer, MistralTokenizer,
get_cached_tokenizer) get_cached_tokenizer)
from vllm.usage.usage_lib import UsageContext from vllm.usage.usage_lib import UsageContext
from vllm.utils import (Counter, Device, deprecate_args, deprecate_kwargs, from vllm.utils import Counter, Device, deprecate_kwargs, is_list_of
is_list_of)
if TYPE_CHECKING: if TYPE_CHECKING:
from vllm.v1.metrics.reader import Metric from vllm.v1.metrics.reader import Metric
@ -143,12 +142,6 @@ class LLM:
DEPRECATE_LEGACY: ClassVar[bool] = True DEPRECATE_LEGACY: ClassVar[bool] = True
"""A flag to toggle whether to deprecate the legacy generate/encode API.""" """A flag to toggle whether to deprecate the legacy generate/encode API."""
DEPRECATE_INIT_POSARGS: ClassVar[bool] = True
"""
A flag to toggle whether to deprecate positional arguments in
[LLM.__init__][].
"""
@classmethod @classmethod
@contextmanager @contextmanager
def deprecate_legacy_api(cls): def deprecate_legacy_api(cls):
@ -158,16 +151,11 @@ class LLM:
cls.DEPRECATE_LEGACY = False cls.DEPRECATE_LEGACY = False
@deprecate_args(
start_index=2, # Ignore self and model
is_deprecated=lambda: LLM.DEPRECATE_INIT_POSARGS,
additional_message=(
"All positional arguments other than `model` will be "
"replaced with keyword arguments in an upcoming version."),
)
def __init__( def __init__(
self, self,
model: str, model: str,
*,
task: TaskOption = "auto",
tokenizer: Optional[str] = None, tokenizer: Optional[str] = None,
tokenizer_mode: TokenizerMode = "auto", tokenizer_mode: TokenizerMode = "auto",
skip_tokenizer_init: bool = False, skip_tokenizer_init: bool = False,
@ -189,8 +177,6 @@ class LLM:
hf_token: Optional[Union[bool, str]] = None, hf_token: Optional[Union[bool, str]] = None,
hf_overrides: Optional[HfOverrides] = None, hf_overrides: Optional[HfOverrides] = None,
mm_processor_kwargs: Optional[dict[str, Any]] = None, mm_processor_kwargs: Optional[dict[str, Any]] = None,
# After positional args are removed, move this right below `model`
task: TaskOption = "auto",
override_pooler_config: Optional[PoolerConfig] = None, override_pooler_config: Optional[PoolerConfig] = None,
compilation_config: Optional[Union[int, dict[str, Any]]] = None, compilation_config: Optional[Union[int, dict[str, Any]]] = None,
**kwargs, **kwargs,