mirror of
https://github.com/vllm-project/vllm.git
synced 2025-10-20 14:53:52 +08:00
Fix and simplify deprecated=True
CLI kwarg
(#17781)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
@ -7,9 +7,8 @@ from vllm.utils import FlexibleArgumentParser
|
||||
def create_parser():
|
||||
parser = FlexibleArgumentParser()
|
||||
# Add engine args
|
||||
engine_group = parser.add_argument_group("Engine arguments")
|
||||
EngineArgs.add_cli_args(engine_group)
|
||||
engine_group.set_defaults(model="meta-llama/Llama-3.2-1B-Instruct")
|
||||
EngineArgs.add_cli_args(parser)
|
||||
parser.set_defaults(model="meta-llama/Llama-3.2-1B-Instruct")
|
||||
# Add sampling params
|
||||
sampling_group = parser.add_argument_group("Sampling parameters")
|
||||
sampling_group.add_argument("--max-tokens", type=int)
|
||||
|
@ -7,9 +7,8 @@ from vllm.utils import FlexibleArgumentParser
|
||||
def create_parser():
|
||||
parser = FlexibleArgumentParser()
|
||||
# Add engine args
|
||||
engine_group = parser.add_argument_group("Engine arguments")
|
||||
EngineArgs.add_cli_args(engine_group)
|
||||
engine_group.set_defaults(model="meta-llama/Llama-3.2-1B-Instruct")
|
||||
EngineArgs.add_cli_args(parser)
|
||||
parser.set_defaults(model="meta-llama/Llama-3.2-1B-Instruct")
|
||||
# Add sampling params
|
||||
sampling_group = parser.add_argument_group("Sampling parameters")
|
||||
sampling_group.add_argument("--max-tokens", type=int)
|
||||
|
@ -833,6 +833,7 @@ class EngineArgs:
|
||||
parser.add_argument('--use-v2-block-manager',
|
||||
action='store_true',
|
||||
default=True,
|
||||
deprecated=True,
|
||||
help='[DEPRECATED] block manager v1 has been '
|
||||
'removed and SelfAttnBlockSpaceManager (i.e. '
|
||||
'block manager v2) is now the default. '
|
||||
|
@ -41,7 +41,6 @@ from collections.abc import (AsyncGenerator, Awaitable, Generator, Hashable,
|
||||
from concurrent.futures.process import ProcessPoolExecutor
|
||||
from dataclasses import dataclass, field
|
||||
from functools import cache, lru_cache, partial, wraps
|
||||
from gettext import gettext as _gettext
|
||||
from types import MappingProxyType
|
||||
from typing import (TYPE_CHECKING, Any, Callable, Generic, Literal, NamedTuple,
|
||||
Optional, Sequence, Tuple, Type, TypeVar, Union, cast,
|
||||
@ -1333,31 +1332,10 @@ class SortedHelpFormatter(ArgumentDefaultsHelpFormatter):
|
||||
super().add_arguments(actions)
|
||||
|
||||
|
||||
class _FlexibleArgumentGroup(_ArgumentGroup):
|
||||
|
||||
def __init__(self, parser: FlexibleArgumentParser, *args, **kwargs):
|
||||
self._parser = parser
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def add_argument(self, *args: Any, **kwargs: Any):
|
||||
if sys.version_info < (3, 13):
|
||||
deprecated = kwargs.pop('deprecated', False)
|
||||
action = super().add_argument(*args, **kwargs)
|
||||
object.__setattr__(action, 'deprecated', deprecated)
|
||||
if deprecated and action.dest not in \
|
||||
self._parser.__class__._deprecated:
|
||||
self._parser._deprecated.add(action)
|
||||
return action
|
||||
|
||||
# python>3.13
|
||||
return super().add_argument(*args, **kwargs)
|
||||
|
||||
|
||||
class FlexibleArgumentParser(ArgumentParser):
|
||||
"""ArgumentParser that allows both underscore and dash in names."""
|
||||
|
||||
_deprecated: set[Action] = set()
|
||||
_seen: set[str] = set()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Set the default 'formatter_class' to SortedHelpFormatter
|
||||
@ -1366,39 +1344,36 @@ class FlexibleArgumentParser(ArgumentParser):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
if sys.version_info < (3, 13):
|
||||
# Enable the deprecated kwarg for Python 3.12 and below
|
||||
|
||||
def parse_known_args( # type: ignore[override]
|
||||
self,
|
||||
args: Sequence[str] | None = None,
|
||||
namespace: Namespace | None = None,
|
||||
) -> tuple[Namespace | None, list[str]]:
|
||||
def parse_known_args(self, args=None, namespace=None):
|
||||
namespace, args = super().parse_known_args(args, namespace)
|
||||
for action in FlexibleArgumentParser._deprecated:
|
||||
if action.dest not in FlexibleArgumentParser._seen and getattr(
|
||||
namespace, action.dest,
|
||||
None) != action.default: # noqa: E501
|
||||
self._warning(
|
||||
_gettext("argument '%(argument_name)s' is deprecated")
|
||||
% {'argument_name': action.dest})
|
||||
FlexibleArgumentParser._seen.add(action.dest)
|
||||
if (hasattr(namespace, dest := action.dest)
|
||||
and getattr(namespace, dest) != action.default):
|
||||
logger.warning_once("argument '%s' is deprecated", dest)
|
||||
return namespace, args
|
||||
|
||||
def add_argument(self, *args: Any, **kwargs: Any):
|
||||
# add a deprecated=True compatibility
|
||||
# for python < 3.13
|
||||
deprecated = kwargs.pop('deprecated', False)
|
||||
def add_argument(self, *args, **kwargs):
|
||||
deprecated = kwargs.pop("deprecated", False)
|
||||
action = super().add_argument(*args, **kwargs)
|
||||
object.__setattr__(action, 'deprecated', deprecated)
|
||||
if deprecated and \
|
||||
action not in FlexibleArgumentParser._deprecated:
|
||||
self._deprecated.add(action)
|
||||
|
||||
if deprecated:
|
||||
FlexibleArgumentParser._deprecated.add(action)
|
||||
return action
|
||||
|
||||
def _warning(self, message: str):
|
||||
self._print_message(
|
||||
_gettext('warning: %(message)s\n') % {'message': message},
|
||||
sys.stderr)
|
||||
class _FlexibleArgumentGroup(_ArgumentGroup):
|
||||
|
||||
def add_argument(self, *args, **kwargs):
|
||||
deprecated = kwargs.pop("deprecated", False)
|
||||
action = super().add_argument(*args, **kwargs)
|
||||
if deprecated:
|
||||
FlexibleArgumentParser._deprecated.add(action)
|
||||
return action
|
||||
|
||||
def add_argument_group(self, *args, **kwargs):
|
||||
group = self._FlexibleArgumentGroup(self, *args, **kwargs)
|
||||
self._action_groups.append(group)
|
||||
return group
|
||||
|
||||
def parse_args( # type: ignore[override]
|
||||
self,
|
||||
@ -1575,15 +1550,6 @@ class FlexibleArgumentParser(ArgumentParser):
|
||||
|
||||
return processed_args
|
||||
|
||||
def add_argument_group(
|
||||
self,
|
||||
*args: Any,
|
||||
**kwargs: Any,
|
||||
) -> _FlexibleArgumentGroup:
|
||||
group = _FlexibleArgumentGroup(self, self, *args, **kwargs)
|
||||
self._action_groups.append(group)
|
||||
return group
|
||||
|
||||
|
||||
async def _run_task_with_lock(task: Callable, lock: asyncio.Lock, *args,
|
||||
**kwargs):
|
||||
|
Reference in New Issue
Block a user