@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / bf5eec638d
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 5, 23:30 UTC

[Refactor] Remove unused utils (#38153)

Signed-off-by: yewentao256 <zhyanwentao@126.com>

Wentao Ye committed Mar 26, 2026 at 05:08 UTC bf5eec638d7571f0b88ea48a3d13709322b19a0c
3 files changed +2 -140
tests/utils_/test_func_utils.py
+1 -58
@@ -4,64 +4,7 @@
4
5 import pytest
6
7 -from vllm.utils.func_utils import deprecate_kwargs, supports_kw
8 -
9 -from ..utils import error_on_warning
10 -
11 -
12 -def test_deprecate_kwargs_always():
13 - @deprecate_kwargs("old_arg", is_deprecated=True)
14 - def dummy(*, old_arg: object = None, new_arg: object = None):
15 - pass
16 -
17 - with pytest.warns(DeprecationWarning, match="'old_arg'"):
18 - dummy(old_arg=1)
19 -
20 - with error_on_warning(DeprecationWarning):
21 - dummy(new_arg=1)
22 -
23 -
24 -def test_deprecate_kwargs_never():
25 - @deprecate_kwargs("old_arg", is_deprecated=False)
26 - def dummy(*, old_arg: object = None, new_arg: object = None):
27 - pass
28 -
29 - with error_on_warning(DeprecationWarning):
30 - dummy(old_arg=1)
31 -
32 - with error_on_warning(DeprecationWarning):
33 - dummy(new_arg=1)
34 -
35 -
36 -def test_deprecate_kwargs_dynamic():
37 - is_deprecated = True
38 -
39 - @deprecate_kwargs("old_arg", is_deprecated=lambda: is_deprecated)
40 - def dummy(*, old_arg: object = None, new_arg: object = None):
41 - pass
42 -
43 - with pytest.warns(DeprecationWarning, match="'old_arg'"):
44 - dummy(old_arg=1)
45 -
46 - with error_on_warning(DeprecationWarning):
47 - dummy(new_arg=1)
48 -
49 - is_deprecated = False
50 -
51 - with error_on_warning(DeprecationWarning):
52 - dummy(old_arg=1)
53 -
54 - with error_on_warning(DeprecationWarning):
55 - dummy(new_arg=1)
56 -
57 -
58 -def test_deprecate_kwargs_additional_message():
59 - @deprecate_kwargs("old_arg", is_deprecated=True, additional_message="abcd")
60 - def dummy(*, old_arg: object = None, new_arg: object = None):
61 - pass
62 -
63 - with pytest.warns(DeprecationWarning, match="abcd"):
64 - dummy(old_arg=1)
7 +from vllm.utils.func_utils import supports_kw
8
9
10 @pytest.mark.parametrize(
vllm/utils/func_utils.py
+1 -77
@@ -8,9 +8,8 @@ This is similar in concept to the `functools` module.
8
9 import inspect
10 import threading
11 -import warnings
11 from collections.abc import Callable, Mapping
13 -from functools import lru_cache, partial, wraps
12 +from functools import lru_cache
13 from typing import Any, TypeVar
14
15 from typing_extensions import ParamSpec
@@ -45,81 +44,6 @@ def run_once(f: Callable[P, None]) -> Callable[P, None]:
44 return wrapper
45
46
48 -def deprecate_args(
49 - start_index: int,
50 - is_deprecated: bool | Callable[[], bool] = True,
51 - additional_message: str | None = None,
52 -) -> Callable[[F], F]:
53 - if not callable(is_deprecated):
54 - is_deprecated = partial(identity, is_deprecated)
55 -
56 - def wrapper(fn: F) -> F:
57 - params = inspect.signature(fn).parameters
58 - pos_types = (
59 - inspect.Parameter.POSITIONAL_ONLY,
60 - inspect.Parameter.POSITIONAL_OR_KEYWORD,
61 - )
62 - pos_kws = [kw for kw, param in params.items() if param.kind in pos_types]
63 -
64 - @wraps(fn)
65 - def inner(*args, **kwargs):
66 - if is_deprecated():
67 - deprecated_args = pos_kws[start_index : len(args)]
68 - if deprecated_args:
69 - msg = (
70 - f"The positional arguments {deprecated_args} are "
71 - "deprecated and will be removed in a future update."
72 - )
73 - if additional_message is not None:
74 - msg += f" {additional_message}"
75 -
76 - warnings.warn(
77 - DeprecationWarning(msg),
78 - stacklevel=3, # The inner function takes up one level
79 - )
80 -
81 - return fn(*args, **kwargs)
82 -
83 - return inner # type: ignore
84 -
85 - return wrapper
86 -
87 -
88 -def deprecate_kwargs(
89 - *kws: str,
90 - is_deprecated: bool | Callable[[], bool] = True,
91 - additional_message: str | None = None,
92 -) -> Callable[[F], F]:
93 - deprecated_kws = set(kws)
94 -
95 - if not callable(is_deprecated):
96 - is_deprecated = partial(identity, is_deprecated)
97 -
98 - def wrapper(fn: F) -> F:
99 - @wraps(fn)
100 - def inner(*args, **kwargs):
101 - if is_deprecated():
102 - deprecated_kwargs = kwargs.keys() & deprecated_kws
103 - if deprecated_kwargs:
104 - msg = (
105 - f"The keyword arguments {deprecated_kwargs} are "
106 - "deprecated and will be removed in a future update."
107 - )
108 - if additional_message is not None:
109 - msg += f" {additional_message}"
110 -
111 - warnings.warn(
112 - DeprecationWarning(msg),
113 - stacklevel=3, # The inner function takes up one level
114 - )
115 -
116 - return fn(*args, **kwargs)
117 -
118 - return inner # type: ignore
119 -
120 - return wrapper
121 -
122 -
47 @lru_cache
48 def supports_kw(
49 callable: Callable[..., object],
vllm/utils/math_utils.py
-5
@@ -17,11 +17,6 @@ def next_power_of_2(n: int) -> int:
17 return 1 if n < 1 else 1 << (n - 1).bit_length()
18
19
20 -def prev_power_of_2(n: int) -> int:
21 - """The previous power of 2 (inclusive)"""
22 - return 0 if n <= 0 else 1 << (n.bit_length() - 1)
23 -
24 -
20 def round_up(x: int, y: int) -> int:
21 """Round up x to the nearest multiple of y."""
22 return ((x + y - 1) // y) * y