Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vllm/engine/arg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def add_cli_args(parser: FlexibleArgumentParser) -> FlexibleArgumentParser:
description=DecodingConfig.__doc__,
)
guided_decoding_group.add_argument("--guided-decoding-backend",
deprecated=True,
**guided_decoding_kwargs["backend"])
guided_decoding_group.add_argument(
"--guided-decoding-disable-fallback",
Expand Down
75 changes: 73 additions & 2 deletions vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
import warnings
import weakref
from argparse import (Action, ArgumentDefaultsHelpFormatter, ArgumentParser,
ArgumentTypeError)
ArgumentTypeError, _ArgumentGroup)
from asyncio import FIRST_COMPLETED, AbstractEventLoop, Task
from collections import UserDict, defaultdict
from collections.abc import (AsyncGenerator, Awaitable, Generator, Hashable,
Iterable, Iterator, KeysView, Mapping)
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,
Expand Down Expand Up @@ -70,6 +71,8 @@
from vllm.logger import enable_trace_function_call, init_logger

if TYPE_CHECKING:
from argparse import Namespace

from vllm.config import ModelConfig, VllmConfig

logger = init_logger(__name__)
Expand Down Expand Up @@ -1323,16 +1326,78 @@
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._warning(
_gettext("argument '%(argument_name)s' is deprecated") %
{'argument_name': action.dest})
self._parser._deprecated.add(action.dest)
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[str] = set()

def __init__(self, *args, **kwargs):
# Set the default 'formatter_class' to SortedHelpFormatter
if 'formatter_class' not in kwargs:
kwargs['formatter_class'] = SortedHelpFormatter
super().__init__(*args, **kwargs)

def parse_args(self, args=None, namespace=None):
def add_argument(self, *args: Any, **kwargs: Any):
# add a deprecated=True with optional deprecated_reason to signify
# reasons for deprecating this args
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 FlexibleArgumentParser._deprecated:
self._warning(
_gettext("argument '%(argument_name)s' is deprecated") %
{'argument_name': action.dest})
self._deprecated.add(action.dest)

return action

# python>3.13
return super().add_argument(*args, **kwargs)

def _warning(self, message: str):
self._print_message(
_gettext('warning: %(message)s\n') % {'message': message},
sys.stderr)

def parse_known_args(

Check failure on line 1387 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Signature of "parse_known_args" incompatible with supertype "ArgumentParser" [override]

Check failure on line 1387 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Signature of "parse_known_args" incompatible with supertype "ArgumentParser" [override]

Check failure on line 1387 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Signature of "parse_known_args" incompatible with supertype "ArgumentParser" [override]

Check failure on line 1387 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Signature of "parse_known_args" incompatible with supertype "ArgumentParser" [override]

Check failure on line 1387 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Signature of "parse_known_args" incompatible with supertype "ArgumentParser" [override]
self,
args: list[str],
namespace: Namespace,
) -> tuple[Namespace, list[str]]:
namespace, args = super().parse_known_args(args, namespace)
print(namespace)
return namespace, args

def parse_args( # type: ignore[override]
self,
args: Sequence[str] | None = None,
namespace: Namespace | None = None,
):
if args is None:
args = sys.argv[1:]

Expand All @@ -1347,7 +1412,7 @@
"the `--model` option.")

if '--config' in args:
args = self._pull_args_from_config(args)

Check failure on line 1415 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Argument 1 to "_pull_args_from_config" of "FlexibleArgumentParser" has incompatible type "Sequence[str]"; expected "list[str]" [arg-type]

Check failure on line 1415 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Argument 1 to "_pull_args_from_config" of "FlexibleArgumentParser" has incompatible type "Sequence[str]"; expected "list[str]" [arg-type]

Check failure on line 1415 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Argument 1 to "_pull_args_from_config" of "FlexibleArgumentParser" has incompatible type "Sequence[str]"; expected "list[str]" [arg-type]

Check failure on line 1415 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Argument 1 to "_pull_args_from_config" of "FlexibleArgumentParser" has incompatible type "Sequence[str]"; expected "list[str]" [arg-type]

Check failure on line 1415 in vllm/utils.py

View workflow job for this annotation

GitHub Actions / pre-commit

Argument 1 to "_pull_args_from_config" of "FlexibleArgumentParser" has incompatible type "Sequence[str]"; expected "list[str]" [arg-type]

# Convert underscores to dashes and vice versa in argument names
processed_args = []
Expand Down Expand Up @@ -1503,6 +1568,12 @@

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):
Expand Down