Fix per file ruff ignores related to typing (#26254)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
+48
-51
@@ -68,7 +68,6 @@ from typing import (
|
||||
Generic,
|
||||
Literal,
|
||||
NamedTuple,
|
||||
Optional,
|
||||
TextIO,
|
||||
TypeVar,
|
||||
Union,
|
||||
@@ -247,9 +246,7 @@ class CacheInfo(NamedTuple):
|
||||
|
||||
|
||||
class LRUCache(cachetools.LRUCache[_K, _V], Generic[_K, _V]):
|
||||
def __init__(
|
||||
self, capacity: float, getsizeof: Optional[Callable[[_V], float]] = None
|
||||
):
|
||||
def __init__(self, capacity: float, getsizeof: Callable[[_V], float] | None = None):
|
||||
super().__init__(capacity, getsizeof)
|
||||
|
||||
self.pinned_items = set[_K]()
|
||||
@@ -324,15 +321,15 @@ class LRUCache(cachetools.LRUCache[_K, _V], Generic[_K, _V]):
|
||||
self._LRUCache__order[key] = None # type: ignore
|
||||
|
||||
@overload
|
||||
def get(self, key: _K, /) -> Optional[_V]: ...
|
||||
def get(self, key: _K, /) -> _V | None: ...
|
||||
|
||||
@overload
|
||||
def get(self, key: _K, /, default: Union[_V, _T]) -> Union[_V, _T]: ...
|
||||
|
||||
def get(
|
||||
self, key: _K, /, default: Optional[Union[_V, _T]] = None
|
||||
) -> Optional[Union[_V, _T]]:
|
||||
value: Optional[Union[_V, _T]]
|
||||
self, key: _K, /, default: Union[_V, _T] | None = None
|
||||
) -> Union[_V, _T] | None:
|
||||
value: Union[_V, _T] | None
|
||||
if key in self:
|
||||
value = self.__getitem__(key, update_info=False) # type: ignore[call-arg]
|
||||
|
||||
@@ -350,9 +347,9 @@ class LRUCache(cachetools.LRUCache[_K, _V], Generic[_K, _V]):
|
||||
def pop(self, key: _K, default: Union[_V, _T]) -> Union[_V, _T]: ...
|
||||
|
||||
def pop(
|
||||
self, key: _K, default: Optional[Union[_V, _T]] = None
|
||||
) -> Optional[Union[_V, _T]]:
|
||||
value: Optional[Union[_V, _T]]
|
||||
self, key: _K, default: Union[_V, _T] | None = None
|
||||
) -> Union[_V, _T] | None:
|
||||
value: Union[_V, _T] | None
|
||||
if key not in self:
|
||||
return default
|
||||
|
||||
@@ -379,7 +376,7 @@ class LRUCache(cachetools.LRUCache[_K, _V], Generic[_K, _V]):
|
||||
"""
|
||||
self.pinned_items.remove(key)
|
||||
|
||||
def _on_remove(self, key: _K, value: Optional[_V]) -> None:
|
||||
def _on_remove(self, key: _K, value: _V | None) -> None:
|
||||
pass
|
||||
|
||||
def remove_oldest(self, *, remove_pinned: bool = False) -> None:
|
||||
@@ -705,7 +702,7 @@ def in_loop(event_loop: AbstractEventLoop) -> bool:
|
||||
|
||||
|
||||
def make_async(
|
||||
func: Callable[P, T], executor: Optional[concurrent.futures.Executor] = None
|
||||
func: Callable[P, T], executor: concurrent.futures.Executor | None = None
|
||||
) -> Callable[P, Awaitable[T]]:
|
||||
"""Take a blocking function, and run it on in an executor thread.
|
||||
|
||||
@@ -940,7 +937,7 @@ def _get_open_port() -> int:
|
||||
return s.getsockname()[1]
|
||||
|
||||
|
||||
def find_process_using_port(port: int) -> Optional[psutil.Process]:
|
||||
def find_process_using_port(port: int) -> psutil.Process | None:
|
||||
# TODO: We can not check for running processes with network
|
||||
# port on macOS. Therefore, we can not have a full graceful shutdown
|
||||
# of vLLM. For now, let's not look for processes in this case.
|
||||
@@ -1025,8 +1022,8 @@ def _generate_random_fp8(
|
||||
|
||||
|
||||
def get_kv_cache_torch_dtype(
|
||||
cache_dtype: Optional[Union[str, torch.dtype]],
|
||||
model_dtype: Optional[Union[str, torch.dtype]] = None,
|
||||
cache_dtype: Union[str, torch.dtype] | None,
|
||||
model_dtype: Union[str, torch.dtype] | None = None,
|
||||
) -> torch.dtype:
|
||||
if isinstance(cache_dtype, str):
|
||||
if cache_dtype == "auto":
|
||||
@@ -1053,11 +1050,11 @@ def create_kv_caches_with_random_flash(
|
||||
num_layers: int,
|
||||
num_heads: int,
|
||||
head_size: int,
|
||||
cache_dtype: Optional[Union[str, torch.dtype]],
|
||||
model_dtype: Optional[Union[str, torch.dtype]] = None,
|
||||
seed: Optional[int] = None,
|
||||
device: Optional[str] = "cuda",
|
||||
cache_layout: Optional[str] = "NHD",
|
||||
cache_dtype: Union[str, torch.dtype] | None,
|
||||
model_dtype: Union[str, torch.dtype] | None = None,
|
||||
seed: int | None = None,
|
||||
device: str | None = "cuda",
|
||||
cache_layout: str | None = "NHD",
|
||||
) -> tuple[list[torch.Tensor], list[torch.Tensor]]:
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
@@ -1095,10 +1092,10 @@ def create_kv_caches_with_random(
|
||||
num_layers: int,
|
||||
num_heads: int,
|
||||
head_size: int,
|
||||
cache_dtype: Optional[Union[str, torch.dtype]],
|
||||
model_dtype: Optional[Union[str, torch.dtype]] = None,
|
||||
seed: Optional[int] = None,
|
||||
device: Optional[str] = "cuda",
|
||||
cache_dtype: Union[str, torch.dtype] | None,
|
||||
model_dtype: Union[str, torch.dtype] | None = None,
|
||||
seed: int | None = None,
|
||||
device: str | None = "cuda",
|
||||
) -> tuple[list[torch.Tensor], list[torch.Tensor]]:
|
||||
if cache_dtype == "fp8" and head_size % 16:
|
||||
raise ValueError(
|
||||
@@ -1156,7 +1153,7 @@ def is_uva_available() -> bool:
|
||||
|
||||
|
||||
class DeviceMemoryProfiler:
|
||||
def __init__(self, device: Optional[torch.types.Device] = None):
|
||||
def __init__(self, device: torch.types.Device | None = None):
|
||||
self.device = device
|
||||
|
||||
def current_memory_usage(self) -> float:
|
||||
@@ -1184,7 +1181,7 @@ def make_ndarray_with_pad(
|
||||
pad: T,
|
||||
dtype: npt.DTypeLike,
|
||||
*,
|
||||
max_len: Optional[int] = None,
|
||||
max_len: int | None = None,
|
||||
) -> npt.NDArray:
|
||||
"""
|
||||
Make a padded array from 2D inputs.
|
||||
@@ -1209,8 +1206,8 @@ def make_tensor_with_pad(
|
||||
pad: T,
|
||||
dtype: torch.dtype,
|
||||
*,
|
||||
max_len: Optional[int] = None,
|
||||
device: Optional[Union[str, torch.device]] = None,
|
||||
max_len: int | None = None,
|
||||
device: Union[str, torch.device] | None = None,
|
||||
pin_memory: bool = False,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
@@ -1405,7 +1402,7 @@ def find_nccl_library() -> str:
|
||||
return so_file
|
||||
|
||||
|
||||
def find_nccl_include_paths() -> Optional[list[str]]:
|
||||
def find_nccl_include_paths() -> list[str] | None:
|
||||
"""
|
||||
We either use the nccl.h specified by the `VLLM_NCCL_INCLUDE_PATH`
|
||||
environment variable, or we find the library file brought by
|
||||
@@ -1525,7 +1522,7 @@ F = TypeVar("F", bound=Callable[..., Any])
|
||||
def deprecate_args(
|
||||
start_index: int,
|
||||
is_deprecated: Union[bool, Callable[[], bool]] = True,
|
||||
additional_message: Optional[str] = None,
|
||||
additional_message: str | None = None,
|
||||
) -> Callable[[F], F]:
|
||||
if not callable(is_deprecated):
|
||||
is_deprecated = partial(identity, is_deprecated)
|
||||
@@ -1565,7 +1562,7 @@ def deprecate_args(
|
||||
def deprecate_kwargs(
|
||||
*kws: str,
|
||||
is_deprecated: Union[bool, Callable[[], bool]] = True,
|
||||
additional_message: Optional[str] = None,
|
||||
additional_message: str | None = None,
|
||||
) -> Callable[[F], F]:
|
||||
deprecated_kws = set(kws)
|
||||
|
||||
@@ -1598,7 +1595,7 @@ def deprecate_kwargs(
|
||||
|
||||
|
||||
@lru_cache(maxsize=8)
|
||||
def _cuda_device_count_stateless(cuda_visible_devices: Optional[str] = None) -> int:
|
||||
def _cuda_device_count_stateless(cuda_visible_devices: str | None = None) -> int:
|
||||
# Note: cuda_visible_devices is not used, but we keep it as an argument for
|
||||
# LRU Cache purposes.
|
||||
|
||||
@@ -1746,7 +1743,7 @@ class FlexibleArgumentParser(ArgumentParser):
|
||||
' --json-arg \'{"key4": ["value3", "value4", "value5"]}\'\n'
|
||||
" --json-arg.key4+ value3 --json-arg.key4+='value4,value5'\n\n"
|
||||
)
|
||||
_search_keyword: Optional[str] = None
|
||||
_search_keyword: str | None = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Set the default "formatter_class" to SortedHelpFormatter
|
||||
@@ -2245,7 +2242,7 @@ def supports_kw(
|
||||
|
||||
def get_allowed_kwarg_only_overrides(
|
||||
callable: Callable[..., object],
|
||||
overrides: Optional[Mapping[str, object]],
|
||||
overrides: Mapping[str, object] | None,
|
||||
*,
|
||||
requires_kw_only: bool = True,
|
||||
allow_var_kwargs: bool = False,
|
||||
@@ -2695,10 +2692,10 @@ vllm_lib = Library("vllm", "FRAGMENT") # noqa
|
||||
def direct_register_custom_op(
|
||||
op_name: str,
|
||||
op_func: Callable,
|
||||
mutates_args: Optional[list[str]] = None,
|
||||
fake_impl: Optional[Callable] = None,
|
||||
target_lib: Optional[Library] = None,
|
||||
dispatch_key: Optional[str] = None,
|
||||
mutates_args: list[str] | None = None,
|
||||
fake_impl: Callable | None = None,
|
||||
target_lib: Library | None = None,
|
||||
dispatch_key: str | None = None,
|
||||
tags: tuple[torch.Tag, ...] = (),
|
||||
):
|
||||
"""
|
||||
@@ -3016,7 +3013,7 @@ def split_zmq_path(path: str) -> tuple[str, str, str]:
|
||||
return scheme, host, port
|
||||
|
||||
|
||||
def make_zmq_path(scheme: str, host: str, port: Optional[int] = None) -> str:
|
||||
def make_zmq_path(scheme: str, host: str, port: int | None = None) -> str:
|
||||
"""Make a ZMQ path from its parts.
|
||||
|
||||
Args:
|
||||
@@ -3039,9 +3036,9 @@ def make_zmq_socket(
|
||||
ctx: Union[zmq.asyncio.Context, zmq.Context], # type: ignore[name-defined]
|
||||
path: str,
|
||||
socket_type: Any,
|
||||
bind: Optional[bool] = None,
|
||||
identity: Optional[bytes] = None,
|
||||
linger: Optional[int] = None,
|
||||
bind: bool | None = None,
|
||||
identity: bytes | None = None,
|
||||
linger: int | None = None,
|
||||
) -> Union[zmq.Socket, zmq.asyncio.Socket]: # type: ignore[name-defined]
|
||||
"""Make a ZMQ socket with the proper bind/connect semantics."""
|
||||
|
||||
@@ -3098,9 +3095,9 @@ def make_zmq_socket(
|
||||
def zmq_socket_ctx(
|
||||
path: str,
|
||||
socket_type: Any,
|
||||
bind: Optional[bool] = None,
|
||||
bind: bool | None = None,
|
||||
linger: int = 0,
|
||||
identity: Optional[bytes] = None,
|
||||
identity: bytes | None = None,
|
||||
) -> Iterator[zmq.Socket]:
|
||||
"""Context manager for a ZMQ socket"""
|
||||
|
||||
@@ -3163,7 +3160,7 @@ def get_mp_context():
|
||||
def bind_kv_cache(
|
||||
ctx: dict[str, Any],
|
||||
kv_cache: list[list[torch.Tensor]], # [virtual_engine][layer_index]
|
||||
shared_kv_cache_layers: Optional[dict[str, str]] = None,
|
||||
shared_kv_cache_layers: dict[str, str] | None = None,
|
||||
) -> None:
|
||||
# Bind the kv_cache tensor to Attention modules, similar to
|
||||
# ctx[layer_name].kv_cache[ve]=kv_cache[ve][extract_layer_index(layer_name)]
|
||||
@@ -3379,7 +3376,7 @@ def swap_dict_values(obj: dict[_K, _V], key1: _K, key2: _K) -> None:
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def cprofile_context(save_file: Optional[str] = None):
|
||||
def cprofile_context(save_file: str | None = None):
|
||||
"""Run a cprofile
|
||||
|
||||
Args:
|
||||
@@ -3401,7 +3398,7 @@ def cprofile_context(save_file: Optional[str] = None):
|
||||
prof.print_stats(sort="cumtime")
|
||||
|
||||
|
||||
def cprofile(save_file: Optional[str] = None, enabled: bool = True):
|
||||
def cprofile(save_file: str | None = None, enabled: bool = True):
|
||||
"""Decorator to profile a Python method using cProfile.
|
||||
|
||||
Args:
|
||||
@@ -3608,7 +3605,7 @@ def _add_prefix(file: TextIO, worker_name: str, pid: int) -> None:
|
||||
file.write = write_with_prefix # type: ignore[method-assign]
|
||||
|
||||
|
||||
def decorate_logs(process_name: Optional[str] = None) -> None:
|
||||
def decorate_logs(process_name: str | None = None) -> None:
|
||||
"""
|
||||
Adds a process-specific prefix to each line of output written to stdout and
|
||||
stderr.
|
||||
@@ -3631,8 +3628,8 @@ def decorate_logs(process_name: Optional[str] = None) -> None:
|
||||
|
||||
|
||||
def length_from_prompt_token_ids_or_embeds(
|
||||
prompt_token_ids: Optional[list[int]],
|
||||
prompt_embeds: Optional[torch.Tensor],
|
||||
prompt_token_ids: list[int] | None,
|
||||
prompt_embeds: torch.Tensor | None,
|
||||
) -> int:
|
||||
"""Calculate the request length (in number of tokens) give either
|
||||
prompt_token_ids or prompt_embeds.
|
||||
|
||||
@@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
import functools
|
||||
import importlib
|
||||
import os
|
||||
from typing import Any, Callable, NoReturn, Optional
|
||||
from typing import Any, Callable, NoReturn
|
||||
|
||||
import torch
|
||||
|
||||
@@ -325,7 +325,7 @@ def calc_diff(x: torch.Tensor, y: torch.Tensor):
|
||||
def should_use_deepgemm_for_fp8_linear(
|
||||
output_dtype: torch.dtype,
|
||||
weight: torch.Tensor,
|
||||
supports_deep_gemm: Optional[bool] = None,
|
||||
supports_deep_gemm: bool | None = None,
|
||||
):
|
||||
if supports_deep_gemm is None:
|
||||
supports_deep_gemm = is_deep_gemm_supported()
|
||||
|
||||
@@ -12,7 +12,7 @@ import functools
|
||||
import importlib
|
||||
import importlib.util
|
||||
import os
|
||||
from typing import Any, Callable, NoReturn, Optional
|
||||
from typing import Any, Callable, NoReturn
|
||||
|
||||
import requests
|
||||
import torch
|
||||
@@ -202,14 +202,14 @@ def supports_trtllm_attention() -> bool:
|
||||
|
||||
|
||||
@functools.cache
|
||||
def _force_use_trtllm_attention(env_value: Optional[bool]) -> Optional[bool]:
|
||||
def _force_use_trtllm_attention(env_value: bool | None) -> bool | None:
|
||||
"""Cache the env value for VLLM_USE_TRTLLM_ATTENTION"""
|
||||
if env_value is not None:
|
||||
logger.info_once("VLLM_USE_TRTLLM_ATTENTION is set to %s", env_value)
|
||||
return env_value
|
||||
|
||||
|
||||
def force_use_trtllm_attention() -> Optional[bool]:
|
||||
def force_use_trtllm_attention() -> bool | None:
|
||||
"""
|
||||
Return ``None`` if VLLM_USE_TRTLLM_ATTENTION is not set,
|
||||
return ``True`` if TRTLLM attention is forced to be used,
|
||||
@@ -401,7 +401,7 @@ def flashinfer_scaled_fp8_mm(
|
||||
scale_a: torch.Tensor,
|
||||
scale_b: torch.Tensor,
|
||||
out_dtype: torch.dtype,
|
||||
bias: Optional[torch.Tensor] = None,
|
||||
bias: torch.Tensor | None = None,
|
||||
) -> torch.Tensor:
|
||||
assert a.ndim == 2 and b.ndim == 2
|
||||
assert a.shape[1] == b.shape[0]
|
||||
|
||||
Reference in New Issue
Block a user