Skip to content

Commit 0ae11f7

Browse files
authored
[Mypy] Part 3 fix typing for nested directories for most of directory (#4161)
1 parent 34128a6 commit 0ae11f7

File tree

29 files changed

+126
-88
lines changed

29 files changed

+126
-88
lines changed

.github/workflows/mypy.yaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ jobs:
3232
pip install types-setuptools
3333
- name: Mypy
3434
run: |
35-
mypy vllm/attention/*.py --follow-imports=skip --config-file pyproject.toml
35+
mypy vllm/attention --config-file pyproject.toml
36+
# TODO(sang): Fix nested dir
3637
mypy vllm/core/*.py --follow-imports=skip --config-file pyproject.toml
37-
mypy vllm/distributed/*.py --follow-imports=skip --config-file pyproject.toml
38-
mypy vllm/entrypoints/*.py --follow-imports=skip --config-file pyproject.toml
39-
mypy vllm/executor/*.py --follow-imports=skip --config-file pyproject.toml
40-
mypy vllm/usage/*.py --follow-imports=skip --config-file pyproject.toml
41-
mypy vllm/*.py --follow-imports=skip --config-file pyproject.toml
42-
mypy vllm/transformers_utils/*.py --follow-imports=skip --config-file pyproject.toml
43-
44-
mypy vllm/engine/*.py --follow-imports=skip --config-file pyproject.toml
45-
mypy vllm/worker/*.py --follow-imports=skip --config-file pyproject.toml
46-
mypy vllm/spec_decode/*.py --follow-imports=skip --config-file pyproject.toml
47-
mypy vllm/model_executor/*.py --follow-imports=skip --config-file pyproject.toml
48-
# TODO(sang): Follow up
49-
# mypy vllm/lora/*.py --follow-imports=skip --config-file pyproject.toml
38+
mypy vllm/distributed --config-file pyproject.toml
39+
mypy vllm/entrypoints --config-file pyproject.toml
40+
mypy vllm/executor --config-file pyproject.toml
41+
mypy vllm/usage --config-file pyproject.toml
42+
mypy vllm/*.py --config-file pyproject.toml
43+
mypy vllm/transformers_utils --config-file pyproject.toml
44+
mypy vllm/engine --config-file pyproject.toml
45+
mypy vllm/worker --config-file pyproject.toml
46+
mypy vllm/spec_decode --config-file pyproject.toml
47+
# TODO(sang): Fix nested dir
48+
mypy vllm/model_executor/*.py --config-file pyproject.toml
49+
# TODO(sang): Fix nested dir
50+
# mypy vllm/lora/*.py --config-file pyproject.toml
5051

format.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,19 @@ echo 'vLLM yapf: Done'
9494

9595
# Run mypy
9696
echo 'vLLM mypy:'
97-
mypy vllm/attention/*.py --follow-imports=skip --config-file pyproject.toml
97+
mypy vllm/attention --config-file pyproject.toml
9898
mypy vllm/core/*.py --follow-imports=skip --config-file pyproject.toml
99-
mypy vllm/distributed/*.py --follow-imports=skip --config-file pyproject.toml
100-
mypy vllm/entrypoints/*.py --follow-imports=skip --config-file pyproject.toml
101-
mypy vllm/executor/*.py --follow-imports=skip --config-file pyproject.toml
102-
mypy vllm/usage/*.py --follow-imports=skip --config-file pyproject.toml
103-
mypy vllm/*.py --follow-imports=skip --config-file pyproject.toml
104-
mypy vllm/transformers_utils/*.py --follow-imports=skip --config-file pyproject.toml
105-
106-
# TODO(sang): Follow up
107-
mypy vllm/engine/*.py --follow-imports=skip --config-file pyproject.toml
108-
mypy vllm/worker/*.py --follow-imports=skip --config-file pyproject.toml
109-
mypy vllm/spec_decode/*.py --follow-imports=skip --config-file pyproject.toml
110-
mypy vllm/model_executor/*.py --follow-imports=skip --config-file pyproject.toml
111-
# mypy vllm/lora/*.py --follow-imports=skip --config-file pyproject.toml
99+
mypy vllm/distributed --config-file pyproject.toml
100+
mypy vllm/entrypoints --config-file pyproject.toml
101+
mypy vllm/executor --config-file pyproject.toml
102+
mypy vllm/usage --config-file pyproject.toml
103+
mypy vllm/*.py --config-file pyproject.toml
104+
mypy vllm/transformers_utils --config-file pyproject.toml
105+
mypy vllm/engine --config-file pyproject.toml
106+
mypy vllm/worker --config-file pyproject.toml
107+
mypy vllm/spec_decode --config-file pyproject.toml
108+
mypy vllm/model_executor/*.py --config-file pyproject.toml
109+
# mypy vllm/lora/*.py --config-file pyproject.toml
112110

113111

114112
CODESPELL_EXCLUDES=(

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ ignore = [
4646
python_version = "3.8"
4747

4848
ignore_missing_imports = true
49-
check_untyped_defs = true
49+
check_untyped_defs = true
50+
follow_imports = "skip"
5051

5152
files = "vllm"
5253
# TODO(woosuk): Include the code from Megatron and HuggingFace.
5354
exclude = [
5455
"vllm/model_executor/parallel_utils/|vllm/model_executor/models/",
56+
# Ignore triton kernels in ops.
57+
'vllm/attention/ops/.*\.py$'
5558
]
5659

57-
5860
[tool.codespell]
5961
ignore-words-list = "dout, te, indicies"
6062
skip = "./tests/prompts,./benchmarks/sonnet.txt"

vllm/attention/backends/abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def forward(
116116
key: torch.Tensor,
117117
value: torch.Tensor,
118118
kv_cache: torch.Tensor,
119-
attn_metadata: AttentionMetadata[AttentionMetadataPerStage],
119+
attn_metadata: AttentionMetadata,
120120
kv_scale: float,
121121
) -> torch.Tensor:
122122
raise NotImplementedError

vllm/attention/backends/rocm_flash_attn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def forward(
248248

249249
if prefill_meta := attn_metadata.prefill_metadata:
250250
# Prompt run.
251+
assert prefill_meta.prompt_lens is not None
251252
if kv_cache is None or prefill_meta.block_tables.numel() == 0:
252253
# triton attention
253254
# When block_tables are not filled, it means q and k are the

vllm/attention/backends/torch_sdpa.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def forward(
106106
key: torch.Tensor,
107107
value: torch.Tensor,
108108
kv_cache: Optional[torch.Tensor],
109-
attn_metadata: TorchSDPAMetadata,
109+
attn_metadata: TorchSDPAMetadata, # type: ignore
110110
kv_scale: float,
111111
) -> torch.Tensor:
112112
"""Forward pass with torch SDPA and PagedAttention.
@@ -136,6 +136,7 @@ def forward(
136136
kv_scale)
137137

138138
if attn_metadata.is_prompt:
139+
assert attn_metadata.prompt_lens is not None
139140
if (kv_cache is None or attn_metadata.block_tables.numel() == 0):
140141
if self.num_kv_heads != self.num_heads:
141142
key = key.repeat_interleave(self.num_queries_per_kv, dim=1)

vllm/attention/backends/xformers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def _run_memory_efficient_xformers_forward(
288288
value: shape = [num_prefill_tokens, num_kv_heads, head_size]
289289
attn_metadata: Metadata for attention.
290290
"""
291+
assert attn_metadata.prompt_lens is not None
291292
original_query = query
292293
if self.num_kv_heads != self.num_heads:
293294
# GQA/MQA requires the shape [B, M, G, H, K].

vllm/core/block/block_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def append_token_ids(self,
104104
token_ids (List[int]): The sequence of token IDs to be appended.
105105
"""
106106
assert self._is_allocated
107+
assert self._blocks is not None
107108

108109
self.ensure_num_empty_slots(num_empty_slots=len(token_ids) +
109110
num_lookahead_slots)

vllm/core/block/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(
9999
refcounter: RefCounter,
100100
allocator: BlockAllocator,
101101
):
102-
self._copy_on_writes = defaultdict(list)
102+
self._copy_on_writes: Dict[BlockId, List[BlockId]] = defaultdict(list)
103103
self._refcounter = refcounter
104104
self._allocator = allocator
105105

@@ -138,6 +138,8 @@ def cow_block_if_not_appendable(self, block: Block) -> Optional[BlockId]:
138138
prev_block=block.prev_block).block_id
139139

140140
# Track src/dst copy.
141+
assert src_block_id is not None
142+
assert block_id is not None
141143
self._copy_on_writes[src_block_id].append(block_id)
142144

143145
return block_id
@@ -180,6 +182,6 @@ def recurse(block: Block, lst: List[Block]) -> None:
180182
recurse(block.prev_block, lst)
181183
lst.append(block)
182184

183-
all_blocks = []
185+
all_blocks: List[Block] = []
184186
recurse(last_block, all_blocks)
185187
return all_blocks

vllm/core/block/interfaces.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ def __call__(
5252
class BlockAllocator(ABC):
5353

5454
@abstractmethod
55-
def allocate_mutable(self, prev_block: Optional[Block],
56-
device: Device) -> Block:
55+
def allocate_mutable(self, prev_block: Optional[Block]) -> Block:
5756
pass
5857

5958
@abstractmethod
@@ -98,8 +97,7 @@ class NoFreeBlocksError(ValueError):
9897
class DeviceAwareBlockAllocator(BlockAllocator):
9998

10099
@abstractmethod
101-
def allocate_mutable(self, prev_block: Optional[Block],
102-
device: Device) -> Block:
100+
def allocate_mutable(self, prev_block: Optional[Block]) -> Block:
103101
pass
104102

105103
@abstractmethod

0 commit comments

Comments
 (0)