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