Skip to content

Commit 1c0c682

Browse files
authored
Fix per file ruff ignores related to typing (#26254)
Signed-off-by: Harry Mellor <[email protected]>
1 parent 5f31753 commit 1c0c682

File tree

32 files changed

+258
-285
lines changed

32 files changed

+258
-285
lines changed

pyproject.toml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ include = ["vllm*"]
115115
"vllm/distributed/parallel_state.py" = ["SIM108"]
116116
"vllm/entrypoints/chat_utils.py" = ["SIM108"]
117117
"vllm/entrypoints/llm.py" = ["SIM108"]
118+
"vllm/executor/ray_distributed_executor.py" = ["SIM108", "SIM112"]
118119
"vllm/model_executor/layers/batch_invariant.py" = ["SIM108"]
119120
"vllm/model_executor/layers/fla/ops/chunk_o.py" = ["SIM108"]
120121
"vllm/model_executor/layers/fused_moe/fused_moe.py" = ["SIM108"]
@@ -134,23 +135,6 @@ include = ["vllm*"]
134135
"tools/profiler/print_layerwise_table.py" = ["SIM118"]
135136
## Loop variable binding issues
136137
"tests/kernels/mamba/test_mamba_ssm_ssd.py" = ["B023"]
137-
## Type annotation modernization and other rules
138-
"vllm/attention/backends/abstract.py" = ["UP035", "UP006"]
139-
"vllm/attention/layer.py" = ["UP035", "UP006"]
140-
"vllm/attention/layers/chunked_local_attention.py" = ["UP035", "UP006"]
141-
"vllm/attention/ops/flashmla.py" = ["UP035", "UP006"]
142-
"vllm/attention/ops/paged_attn.py" = ["UP035", "UP006"]
143-
"vllm/engine/arg_utils.py" = ["UP035", "UP006"]
144-
"vllm/engine/metrics.py" = ["UP035", "UP006"]
145-
"vllm/engine/metrics_types.py" = ["UP035", "UP006"]
146-
"vllm/executor/executor_base.py" = ["UP035", "UP006"]
147-
"vllm/executor/msgspec_utils.py" = ["UP035", "UP006"]
148-
"vllm/executor/ray_distributed_executor.py" = ["UP035", "UP006", "SIM108", "SIM112"]
149-
"vllm/executor/ray_utils.py" = ["UP035", "UP006"]
150-
"vllm/executor/uniproc_executor.py" = ["UP035", "UP006"]
151-
"vllm/model_executor/layers/fused_moe/flashinfer_trtllm_moe.py" = ["UP035"]
152-
## Type comparison issues
153-
"vllm/multimodal/inputs.py" = ["E721"]
154138
# End of temporary ignores
155139

156140
[tool.ruff.lint]

tests/compile/test_full_graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import logging
77
import tempfile
8-
from typing import Any, Optional, Union
8+
from typing import Any, Union
99

1010
import pytest
1111
import torch
@@ -21,7 +21,7 @@
2121
from ..utils import create_new_process_for_each_test
2222

2323

24-
def models_list(*, all: bool = True, keywords: Optional[list[str]] = None):
24+
def models_list(*, all: bool = True, keywords: list[str] | None = None):
2525
TEST_MODELS: list[tuple[str, dict[str, Any]]] = [
2626
("facebook/opt-125m", {}),
2727
(

tests/entrypoints/openai/test_serving_chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import asyncio
77
from contextlib import suppress
88
from dataclasses import dataclass, field
9-
from typing import TYPE_CHECKING, Any, Optional
9+
from typing import TYPE_CHECKING, Any
1010
from unittest.mock import AsyncMock, MagicMock
1111

1212
import pytest
@@ -233,9 +233,9 @@ class MockModelConfig:
233233
multimodal_config = MultiModalConfig()
234234
hf_config = MockHFConfig()
235235
logits_processor_pattern = None
236-
diff_sampling_param: Optional[dict] = None
236+
diff_sampling_param: dict | None = None
237237
allowed_local_media_path: str = ""
238-
allowed_media_domains: Optional[list[str]] = None
238+
allowed_media_domains: list[str] | None = None
239239
encoder_config = None
240240
generation_config: str = "auto"
241241
media_io_kwargs: dict[str, dict[str, Any]] = field(default_factory=dict)

tests/plugins/prithvi_io_processor_plugin/prithvi_io_processor/prithvi_processor.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import tempfile
1010
import urllib.request
1111
from collections.abc import Sequence
12-
from typing import Any, Optional, Union
12+
from typing import Any, Union
1313

1414
import albumentations
1515
import numpy as np
@@ -98,9 +98,9 @@ def _convert_np_uint8(float_image: torch.Tensor):
9898

9999

100100
def read_geotiff(
101-
file_path: Optional[str] = None,
102-
path_type: Optional[str] = None,
103-
file_data: Optional[bytes] = None,
101+
file_path: str | None = None,
102+
path_type: str | None = None,
103+
file_data: bytes | None = None,
104104
) -> tuple[torch.Tensor, dict, tuple[float, float] | None]:
105105
"""Read all bands from *file_path* and return image + meta info.
106106
@@ -114,8 +114,8 @@ def read_geotiff(
114114

115115
if all([x is None for x in [file_path, path_type, file_data]]):
116116
raise Exception("All input fields to read_geotiff are None")
117-
write_to_file: Optional[bytes] = None
118-
path: Optional[str] = None
117+
write_to_file: bytes | None = None
118+
path: str | None = None
119119
if file_data is not None:
120120
# with tempfile.NamedTemporaryFile() as tmpfile:
121121
# tmpfile.write(file_data)
@@ -162,9 +162,9 @@ def read_geotiff(
162162
def load_image(
163163
data: Union[list[str]],
164164
path_type: str,
165-
mean: Optional[list[float]] = None,
166-
std: Optional[list[float]] = None,
167-
indices: Optional[Union[list[int], None]] = None,
165+
mean: list[float] | None = None,
166+
std: list[float] | None = None,
167+
indices: Union[list[int], None] | None = None,
168168
):
169169
"""Build an input example by loading images in *file_paths*.
170170
@@ -278,7 +278,7 @@ def output_to_response(
278278
def pre_process(
279279
self,
280280
prompt: IOProcessorInput,
281-
request_id: Optional[str] = None,
281+
request_id: str | None = None,
282282
**kwargs,
283283
) -> Union[PromptType, Sequence[PromptType]]:
284284
image_data = dict(prompt)
@@ -359,7 +359,7 @@ def pre_process(
359359
def post_process(
360360
self,
361361
model_output: Sequence[PoolingRequestOutput],
362-
request_id: Optional[str] = None,
362+
request_id: str | None = None,
363363
**kwargs,
364364
) -> IOProcessorOutput:
365365
pred_imgs_list = []

tests/v1/engine/test_llm_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import random
6-
from typing import TYPE_CHECKING, Optional
6+
from typing import TYPE_CHECKING
77

88
import pytest
99

@@ -78,7 +78,7 @@ def vllm_model_skip_tokenizer_init(vllm_runner, request, monkeypatch):
7878

7979
def _get_test_sampling_params(
8080
prompt_list: list[str],
81-
seed: Optional[int] = 42,
81+
seed: int | None = 42,
8282
structured_outputs: bool = False,
8383
) -> tuple[list[SamplingParams], list[int]]:
8484
"""Generate random sampling params for a batch."""

vllm/attention/backends/abstract.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33

44
from abc import ABC, abstractmethod
5-
from typing import Generic, List, Optional, Protocol, Tuple, Type, TypeVar
5+
from typing import Generic, Optional, Protocol, TypeVar
66

77
import torch
88

@@ -48,12 +48,12 @@ def get_name() -> str:
4848

4949
@staticmethod
5050
@abstractmethod
51-
def get_impl_cls() -> Type["AttentionImpl"]:
51+
def get_impl_cls() -> type["AttentionImpl"]:
5252
raise NotImplementedError
5353

5454
@staticmethod
5555
@abstractmethod
56-
def get_metadata_cls() -> Type["AttentionMetadata"]:
56+
def get_metadata_cls() -> type["AttentionMetadata"]:
5757
raise NotImplementedError
5858

5959
@classmethod
@@ -73,11 +73,11 @@ def get_kv_cache_shape(
7373
num_kv_heads: int,
7474
head_size: int,
7575
cache_dtype_str: str = "auto",
76-
) -> Tuple[int, ...]:
76+
) -> tuple[int, ...]:
7777
raise NotImplementedError
7878

7979
@staticmethod
80-
def get_kv_cache_stride_order() -> Tuple[int, ...]:
80+
def get_kv_cache_stride_order() -> tuple[int, ...]:
8181
raise NotImplementedError
8282

8383
@classmethod
@@ -147,7 +147,7 @@ def __init__(
147147
head_size: int,
148148
scale: float,
149149
num_kv_heads: Optional[int] = None,
150-
alibi_slopes: Optional[List[float]] = None,
150+
alibi_slopes: Optional[list[float]] = None,
151151
sliding_window: Optional[int] = None,
152152
kv_cache_dtype: str = "auto",
153153
logits_soft_cap: Optional[float] = None,

vllm/attention/layer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33
"""Attention layer."""
44

5-
from typing import Callable, List, Optional
5+
from typing import Callable, Optional
66

77
import torch
88
import torch.nn as nn
@@ -126,7 +126,7 @@ def __init__(
126126
head_size: int,
127127
scale: float,
128128
num_kv_heads: Optional[int] = None,
129-
alibi_slopes: Optional[List[float]] = None,
129+
alibi_slopes: Optional[list[float]] = None,
130130
cache_config: Optional[CacheConfig] = None,
131131
quant_config: Optional[QuantizationConfig] = None,
132132
logits_soft_cap: Optional[float] = None,
@@ -586,7 +586,7 @@ def wait_for_kv_layer_from_connector(layer_name: str):
586586

587587
def maybe_save_kv_layer_to_connector(
588588
layer_name: str,
589-
kv_cache_layer: List[torch.Tensor],
589+
kv_cache_layer: list[torch.Tensor],
590590
):
591591
if not has_kv_transfer_group() or not is_v1_kv_transfer_group():
592592
return

vllm/attention/layers/chunked_local_attention.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33
import functools
4-
from typing import ClassVar, List, Optional
4+
from typing import ClassVar, Optional
55

66
import torch
77

@@ -61,7 +61,7 @@ def __init__(
6161
scale: float,
6262
attention_chunk_size: int,
6363
num_kv_heads: Optional[int] = None,
64-
alibi_slopes: Optional[List[float]] = None,
64+
alibi_slopes: Optional[list[float]] = None,
6565
cache_config: Optional[CacheConfig] = None,
6666
quant_config: Optional[QuantizationConfig] = None,
6767
kv_sharing_target_layer_name: Optional[str] = None,

vllm/attention/ops/flashmla.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33
# adapted from: https://github.com/deepseek-ai/FlashMLA/blob/main/flash_mla/flash_mla_interface.py
4-
from typing import Optional, Tuple
4+
from typing import Optional
55

66
import torch
77

@@ -31,7 +31,7 @@
3131
_flashmla_extension_C_AVAILABLE = False
3232

3333

34-
def is_flashmla_supported() -> Tuple[bool, Optional[str]]:
34+
def is_flashmla_supported() -> tuple[bool, Optional[str]]:
3535
"""
3636
Return: is_supported_flag, unsupported_reason (optional).
3737
"""
@@ -57,7 +57,7 @@ def get_mla_metadata(
5757
num_heads_q: Optional[int] = None,
5858
is_fp8_kvcache: bool = False,
5959
topk: Optional[int] = None,
60-
) -> Tuple[torch.Tensor, torch.Tensor]:
60+
) -> tuple[torch.Tensor, torch.Tensor]:
6161
"""
6262
Arguments:
6363
- cache_seqlens: (batch_size), dtype torch.int32.
@@ -101,7 +101,7 @@ def flash_mla_with_kvcache(
101101
descale_k: Optional[torch.Tensor] = None,
102102
is_fp8_kvcache: bool = False,
103103
indices: Optional[torch.Tensor] = None,
104-
) -> Tuple[torch.Tensor, torch.Tensor]:
104+
) -> tuple[torch.Tensor, torch.Tensor]:
105105
"""
106106
Arguments:
107107
- q: (batch_size, seq_len_q, num_heads_q, head_dim).
@@ -183,7 +183,7 @@ def flash_mla_sparse_prefill(
183183
indices: torch.Tensor,
184184
sm_scale: float,
185185
d_v: int = 512,
186-
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
186+
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
187187
"""
188188
Sparse attention prefill kernel
189189

vllm/attention/ops/paged_attn.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33

44
from dataclasses import dataclass
5-
from typing import List, Optional, Tuple
5+
from typing import Optional
66

77
import torch
88

@@ -41,7 +41,7 @@ class PagedAttentionMetadata:
4141

4242
class PagedAttention:
4343
@staticmethod
44-
def get_supported_head_sizes() -> List[int]:
44+
def get_supported_head_sizes() -> list[int]:
4545
return [32, 64, 80, 96, 112, 120, 128, 192, 256]
4646

4747
@staticmethod
@@ -51,15 +51,15 @@ def get_kv_cache_shape(
5151
num_kv_heads: int,
5252
head_size: int,
5353
cache_dtype_str: str = "auto",
54-
) -> Tuple[int, ...]:
54+
) -> tuple[int, ...]:
5555
return (2, num_blocks, block_size * num_kv_heads * head_size)
5656

5757
@staticmethod
5858
def split_kv_cache(
5959
kv_cache: torch.Tensor,
6060
num_kv_heads: int,
6161
head_size: int,
62-
) -> Tuple[torch.Tensor, torch.Tensor]:
62+
) -> tuple[torch.Tensor, torch.Tensor]:
6363
x = 16 // kv_cache.element_size()
6464
num_blocks = kv_cache.shape[1]
6565

@@ -255,7 +255,7 @@ def swap_blocks(
255255

256256
@staticmethod
257257
def copy_blocks(
258-
kv_caches: List[torch.Tensor],
258+
kv_caches: list[torch.Tensor],
259259
src_to_dists: torch.Tensor,
260260
) -> None:
261261
key_caches = [kv_cache[0] for kv_cache in kv_caches]

0 commit comments

Comments
 (0)