@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / fb946a7f89
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 9, 10:00 UTC

Make `mypy` opt-out instead of opt-in (#33205)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Harry Mellor committed Jan 29, 2026 at 09:12 UTC fb946a7f893da21808a016c86973bdeb2b3c6c95
11 files changed +35 -57
tools/pre_commit/mypy.py
+17 -40
@@ -23,39 +23,8 @@ import sys
23
24 import regex as re
25
26 -FILES = [
27 - "vllm/*.py",
28 - "vllm/assets",
29 - "vllm/compilation",
30 - "vllm/distributed",
31 - "vllm/engine",
32 - "vllm/entrypoints",
33 - "vllm/executor",
34 - "vllm/inputs",
35 - "vllm/logging_utils",
36 - "vllm/multimodal",
37 - "vllm/platforms",
38 - "vllm/plugins",
39 - "vllm/renderers",
40 - "vllm/tokenizers",
41 - "vllm/transformers_utils",
42 - "vllm/triton_utils",
43 - "vllm/usage",
44 - "vllm/utils",
45 - "vllm/worker",
46 - "vllm/v1/attention",
47 - "vllm/v1/core",
48 - "vllm/v1/engine",
49 - "vllm/v1/executor",
50 - "vllm/v1/metrics",
51 - "vllm/v1/pool",
52 - "vllm/v1/sample",
53 - "vllm/v1/structured_output",
54 - "vllm/v1/worker",
55 -]
56 -
26 # After fixing errors resulting from changing follow_imports
58 -# from "skip" to "silent", move the following directories to FILES
27 +# from "skip" to "silent", remove its directory from SEPARATE_GROUPS.
28 SEPARATE_GROUPS = [
29 "tests",
30 # v0 related
@@ -74,6 +43,16 @@ EXCLUDE = [
43 "vllm/model_executor/layers/fla/ops",
44 # Ignore triton kernels in ops.
45 "vllm/v1/attention/ops",
46 + # TODO: Remove these entries after fixing mypy errors.
47 + "vllm/benchmarks",
48 + "vllm/config",
49 + "vllm/device_allocator",
50 + "vllm/profiler",
51 + "vllm/reasoning",
52 + "vllm/tool_parser",
53 + "vllm/v1/cudagraph_dispatcher.py",
54 + "vllm/outputs.py",
55 + "vllm/logger.py",
56 ]
57
58
@@ -88,7 +67,6 @@ def group_files(changed_files: list[str]) -> dict[str, list[str]]:
67 A dictionary mapping file group names to lists of changed files.
68 """
69 exclude_pattern = re.compile(f"^{'|'.join(EXCLUDE)}.*")
91 - files_pattern = re.compile(f"^({'|'.join(FILES)}).*")
70 file_groups = {"": []}
71 file_groups.update({k: [] for k in SEPARATE_GROUPS})
72 for changed_file in changed_files:
@@ -96,14 +74,13 @@ def group_files(changed_files: list[str]) -> dict[str, list[str]]:
74 if exclude_pattern.match(changed_file):
75 continue
76 # Group files by mypy call
99 - if files_pattern.match(changed_file):
100 - file_groups[""].append(changed_file)
101 - continue
77 + for directory in SEPARATE_GROUPS:
78 + if re.match(f"^{directory}.*", changed_file):
79 + file_groups[directory].append(changed_file)
80 + break
81 else:
103 - for directory in SEPARATE_GROUPS:
104 - if re.match(f"^{directory}.*", changed_file):
105 - file_groups[directory].append(changed_file)
106 - break
82 + if changed_file.startswith("vllm/"):
83 + file_groups[""].append(changed_file)
84 return file_groups
85
86
vllm/_aiter_ops.py
+1 -1
@@ -349,7 +349,7 @@ def _rocm_aiter_mla_decode_fwd_impl(
349 ) -> None:
350 from aiter.mla import mla_decode_fwd
351
352 - kwargs = {
352 + kwargs: dict[str, float | torch.Tensor | None] = {
353 "sm_scale": sm_scale,
354 "logit_cap": logit_cap,
355 }
vllm/config/compilation.py
+2 -1
@@ -570,7 +570,7 @@ class CompilationConfig:
570 pass_config: PassConfig = field(default_factory=PassConfig)
571 """Custom inductor passes, see PassConfig for more details"""
572
573 - max_cudagraph_capture_size: int | None = field(default=None)
573 + max_cudagraph_capture_size: int = field(default=None)
574 """The maximum cudagraph capture size.
575
576 If cudagraph_capture_sizes is specified, this will be set to the largest
@@ -743,6 +743,7 @@ class CompilationConfig:
743 "level",
744 "mode",
745 "cudagraph_mode",
746 + "max_cudagraph_capture_size",
747 "use_inductor_graph_partition",
748 mode="wrap",
749 )
vllm/config/utils.py
+2 -2
@@ -9,7 +9,7 @@ import inspect
9 import json
10 import pathlib
11 import textwrap
12 -from collections.abc import Callable, Iterable, Mapping, Sequence, Set
12 +from collections.abc import Callable, Mapping, Sequence, Set
13 from dataclasses import MISSING, Field, dataclass, field, fields, is_dataclass, replace
14 from itertools import pairwise
15 from typing import TYPE_CHECKING, Any, Protocol, TypeVar
@@ -75,7 +75,7 @@ def get_field(cls: ConfigType, name: str) -> Field:
75
76 def getattr_iter(
77 object: object,
78 - names: Iterable[str],
78 + names: Sequence[str],
79 default: Any | None = None,
80 default_factory: Callable[[], Any] | None = None,
81 warn: bool = False,
vllm/env_override.py
+1 -1
@@ -382,7 +382,7 @@ def _patch_get_raw_stream_if_needed():
382 if hasattr(torch._C, "_cuda_getCurrentRawStream"):
383 from torch._C import _cuda_getCurrentRawStream as _get_raw_stream
384
385 - builtins.get_raw_stream = _get_raw_stream
385 + builtins.get_raw_stream = _get_raw_stream # type: ignore[attr-defined]
386
387
388 _patch_get_raw_stream_if_needed()
vllm/envs.py
+1
@@ -1680,6 +1680,7 @@ def disable_envs_cache() -> None:
1680 global __getattr__
1681 # If __getattr__ is wrapped by functions.cache, unwrap the caching layer.
1682 if _is_envs_cache_enabled():
1683 + assert hasattr(__getattr__, "__wrapped__")
1684 __getattr__ = __getattr__.__wrapped__
1685
1686
vllm/forward_context.py
+1 -1
@@ -270,7 +270,7 @@ def create_forward_context(
270 cudagraph_runtime_mode: CUDAGraphMode = CUDAGraphMode.NONE,
271 batch_descriptor: BatchDescriptor | None = None,
272 ubatch_slices: UBatchSlices | None = None,
273 - slot_mapping: dict[str, torch.Tensor] | None = None,
273 + slot_mapping: dict[str, torch.Tensor] | list[dict[str, torch.Tensor]] | None = None,
274 additional_kwargs: dict[str, Any] | None = None,
275 skip_compiled: bool = False,
276 ):
vllm/logger.py
+1 -1
@@ -157,7 +157,7 @@ _METHODS_TO_PATCH = {
157
158
159 def _configure_vllm_root_logger() -> None:
160 - logging_config = dict[str, Any]()
160 + logging_config = dict[str, dict[str, Any] | Any]()
161
162 if not envs.VLLM_CONFIGURE_LOGGING and envs.VLLM_LOGGING_CONFIG_PATH:
163 raise RuntimeError(
vllm/logprobs.py
+3 -3
@@ -28,7 +28,7 @@ LogprobsOnePosition = dict[int, Logprob]
28
29
30 @dataclass
31 -class FlatLogprobs(MutableSequence[LogprobsOnePosition]):
31 +class FlatLogprobs(MutableSequence[LogprobsOnePosition | None]):
32 """
33 Flat logprobs of a request into multiple primitive type lists.
34
@@ -140,7 +140,7 @@ class FlatLogprobs(MutableSequence[LogprobsOnePosition]):
140 def __delitem__(self, item) -> None:
141 raise TypeError("Cannot delete logprobs from FlatLogprobs")
142
143 - def insert(self, item) -> None:
143 + def insert(self, index: int, value: dict[int, Logprob] | None) -> None:
144 raise TypeError("Cannot insert logprobs to FlatLogprobs")
145
146 def __iter__(self) -> Iterator[LogprobsOnePosition]:
@@ -161,7 +161,7 @@ SampleLogprobs = FlatLogprobs | list[LogprobsOnePosition]
161
162 def create_prompt_logprobs(flat_logprobs: bool) -> PromptLogprobs:
163 """Creates a container to store prompt logprobs for a request"""
164 - logprobs = FlatLogprobs() if flat_logprobs else []
164 + logprobs: PromptLogprobs = FlatLogprobs() if flat_logprobs else []
165 # NOTE: logprob of first prompt token is None.
166 logprobs.append(None)
167 return logprobs
vllm/profiler/utils.py
+5 -6
@@ -4,6 +4,7 @@
4 import dataclasses
5 from collections.abc import Callable
6
7 +from _typeshed import DataclassInstance
8 from torch._C._profiler import _EventType, _ProfilerEvent, _TensorMetadata
9
10 #
@@ -11,7 +12,7 @@ from torch._C._profiler import _EventType, _ProfilerEvent, _TensorMetadata
12 #
13
14
14 -def trim_string_front(string, width):
15 +def trim_string_front(string: str, width: int) -> str:
16 if len(string) > width:
17 offset = len(string) - width + 3
18 string = string[offset:]
@@ -20,7 +21,7 @@ def trim_string_front(string, width):
21 return string
22
23
23 -def trim_string_back(string, width):
24 +def trim_string_back(string: str, width: int) -> str:
25 if len(string) > width:
26 offset = len(string) - width + 3
27 string = string[:-offset]
@@ -30,15 +31,13 @@ def trim_string_back(string, width):
31
32
33 class TablePrinter:
33 - def __init__(
34 - self, row_cls: type[dataclasses.dataclass], column_widths: dict[str, int]
35 - ):
34 + def __init__(self, row_cls: type[DataclassInstance], column_widths: dict[str, int]):
35 self.row_cls = row_cls
36 self.fieldnames = [x.name for x in dataclasses.fields(row_cls)]
37 self.column_widths = column_widths
38 assert set(self.column_widths.keys()) == set(self.fieldnames)
39
41 - def print_table(self, rows: list[dataclasses.dataclass]):
40 + def print_table(self, rows: list[DataclassInstance]):
41 self._print_header()
42 self._print_line()
43 for row in rows:
vllm/v1/kv_cache_interface.py
+1 -1
@@ -98,7 +98,7 @@ class FullAttentionSpec(AttentionSpec):
98 In this case, we use FullAttentionSpec and record the sliding window size.
99 """
100
101 - head_size_v: int | None = None
101 + head_size_v: int = None # type: ignore[assignment]
102
103 sliding_window: int | None = None
104 """