[mypy] Fix wrong type annotations related to tuple (#25660)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung 2025-09-25 21:00:45 +08:00 committed by GitHub
parent 1e9a77e037
commit 2f17117606
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 25 additions and 20 deletions

View File

@ -79,9 +79,9 @@ def make_rand_lora_weight_tensor(
def make_rand_tensors( def make_rand_tensors(
a_shape: tuple[int], a_shape: tuple[int, ...],
b_shape: tuple[int], b_shape: tuple[int, ...],
c_shape: tuple[int], c_shape: tuple[int, ...],
a_dtype: torch.dtype, a_dtype: torch.dtype,
b_dtype: torch.dtype, b_dtype: torch.dtype,
c_dtype: torch.dtype, c_dtype: torch.dtype,
@ -243,7 +243,7 @@ class OpType(Enum):
lora_rank: int, lora_rank: int,
num_loras: int, num_loras: int,
num_slices: int, num_slices: int,
) -> tuple[tuple[int], tuple[int], tuple[int]]: ) -> tuple[tuple[int, ...], tuple[int, ...], tuple[int, ...]]:
""" """
Given num_slices, return the shapes of the A, B, and C matrices Given num_slices, return the shapes of the A, B, and C matrices
in A x B = C, for the op_type in A x B = C, for the op_type

View File

@ -50,8 +50,11 @@ def test_is_type(type_hint, type, expected):
@pytest.mark.parametrize(("type_hints", "type", "expected"), [ @pytest.mark.parametrize(("type_hints", "type", "expected"), [
({float, int}, int, True), ({float, int}, int, True),
({int, tuple}, int, True),
({int, tuple[int]}, int, True), ({int, tuple[int]}, int, True),
({int, tuple[int, ...]}, int, True),
({int, tuple[int]}, float, False), ({int, tuple[int]}, float, False),
({int, tuple[int, ...]}, float, False),
({str, Literal["x", "y"]}, Literal, True), ({str, Literal["x", "y"]}, Literal, True),
]) ])
def test_contains_type(type_hints, type, expected): def test_contains_type(type_hints, type, expected):

View File

@ -60,7 +60,7 @@ TENSORS_SHAPES_FN = [
@torch.inference_mode() @torch.inference_mode()
def test_rotary_embedding( def test_rotary_embedding(
is_neox_style: bool, is_neox_style: bool,
tensor_shape_fn: Callable[[int, int, int, int], tuple[int]], tensor_shape_fn: Callable[[int, int, int, int], tuple[int, ...]],
batch_size: int, batch_size: int,
seq_len: int, seq_len: int,
num_heads: int, num_heads: int,

View File

@ -165,7 +165,7 @@ def onednn_gemm_test_helper(primitive_cache_size: int,
def test_onednn_int8_scaled_gemm( def test_onednn_int8_scaled_gemm(
n: int, n: int,
k: int, k: int,
m_list: tuple[int], m_list: tuple[int, ...],
per_tensor_a_scale: bool, per_tensor_a_scale: bool,
per_tensor_b_scale: bool, per_tensor_b_scale: bool,
use_bias: bool, use_bias: bool,
@ -196,7 +196,7 @@ def test_onednn_int8_scaled_gemm(
def test_onednn_gemm( def test_onednn_gemm(
n: int, n: int,
k: int, k: int,
m_list: tuple[int], m_list: tuple[int, ...],
use_bias: bool, use_bias: bool,
use_stride: bool, use_stride: bool,
dtype: torch.dtype, dtype: torch.dtype,

View File

@ -101,7 +101,7 @@ class VLMTestInfo(NamedTuple):
# Function for converting ImageAssets to image embeddings; # Function for converting ImageAssets to image embeddings;
# We need to define this explicitly for embedding tests # We need to define this explicitly for embedding tests
convert_assets_to_embeddings: Optional[Callable[[ImageTestAssets], convert_assets_to_embeddings: Optional[Callable[[ImageTestAssets],
torch.Tensor]] = None list[torch.Tensor]]] = None
# Exposed options for vLLM runner; we change these in a several tests, # Exposed options for vLLM runner; we change these in a several tests,
# but the defaults are derived from VllmRunner & the engine defaults # but the defaults are derived from VllmRunner & the engine defaults
@ -137,12 +137,12 @@ class VLMTestInfo(NamedTuple):
# Default expandable params per test; these defaults can be overridden in # Default expandable params per test; these defaults can be overridden in
# instances of this object; the complete set of test cases for the model # instances of this object; the complete set of test cases for the model
# is all combinations of .models + all fields below # is all combinations of .models + all fields below
max_tokens: Union[int, tuple[int]] = 128 max_tokens: int = 128
num_logprobs: Union[int, tuple[int]] = 5 num_logprobs: int = 5
dtype: Union[str, Union[list[str], tuple[str, ...]]] = "auto" dtype: str = "auto"
distributed_executor_backend: Optional[Union[str, Iterable[str]]] = None distributed_executor_backend: Optional[str] = None
# Only expanded in video tests # Only expanded in video tests
num_video_frames: Union[int, tuple[int]] = 16 num_video_frames: int = 16
# Fixed image sizes / image size factors; most tests use image_size_factors # Fixed image sizes / image size factors; most tests use image_size_factors
# The values provided for these two fields will be stacked and expanded # The values provided for these two fields will be stacked and expanded

View File

@ -72,8 +72,10 @@ def _create_allowed_token_ids(
def _create_bad_words_token_ids( def _create_bad_words_token_ids(
batch_size: int, vocab_size: int, batch_size: int,
bad_words_lengths: list[tuple[int]]) -> dict[int, list[list[int]]]: vocab_size: int,
bad_words_lengths: tuple[int, ...],
) -> dict[int, list[list[int]]]:
bad_words_token_ids = {} bad_words_token_ids = {}
for batch_idx in range(batch_size): for batch_idx in range(batch_size):
token_ids_single_batch = [] token_ids_single_batch = []
@ -402,7 +404,7 @@ def test_sampler_allowed_token_ids(device: str, batch_size: int,
@pytest.mark.parametrize("batch_size", [1, 2, 32]) @pytest.mark.parametrize("batch_size", [1, 2, 32])
@pytest.mark.parametrize("bad_words_lengths", [(1, ), (1, 3), (2, 2)]) @pytest.mark.parametrize("bad_words_lengths", [(1, ), (1, 3), (2, 2)])
def test_sampler_bad_words(device: str, batch_size: int, def test_sampler_bad_words(device: str, batch_size: int,
bad_words_lengths: list[tuple[int]]): bad_words_lengths: tuple[int, ...]):
""" """
Test to verify that when the bad words restriction is present, tokens Test to verify that when the bad words restriction is present, tokens
are penalized based on their match with the bad words. are penalized based on their match with the bad words.

View File

@ -30,7 +30,7 @@ eagle3_dir = "yuhuili/EAGLE3-LLaMA3.1-Instruct-8B"
def _create_proposer( def _create_proposer(
method: str, method: str,
num_speculative_tokens: int, num_speculative_tokens: int,
speculative_token_tree: Optional[list[tuple[int]]] = None, speculative_token_tree: Optional[list[tuple[int, ...]]] = None,
) -> EagleProposer: ) -> EagleProposer:
model_config = ModelConfig(model=model_dir, model_config = ModelConfig(model=model_dir,
runner="generate", runner="generate",

View File

@ -178,7 +178,7 @@ class RayPPCommunicator(Communicator):
def recv( def recv(
self, self,
shape: tuple[int], shape: tuple[int, ...],
dtype: "torch.dtype", dtype: "torch.dtype",
peer_rank: int, peer_rank: int,
allocator: TorchTensorAllocator, allocator: TorchTensorAllocator,

View File

@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from collections.abc import Sequence
from typing import Callable, Union from typing import Callable, Union
import torch import torch
@ -55,7 +55,7 @@ class NoBadWordsLogitsProcessor:
def __call__( def __call__(
self, self,
past_tokens_ids: Union[list[int], tuple[int]], past_tokens_ids: Sequence[int],
logits: torch.FloatTensor, logits: torch.FloatTensor,
) -> torch.Tensor: ) -> torch.Tensor:
if self.word_bias is None: if self.word_bias is None: