Skip to content

Commit a7237ac

Browse files
lucas-tuckerlucast2021
authored andcommitted
Mypy checking for vllm/compilation (vllm-project#11496)
Signed-off-by: lucast2021 <[email protected]> Co-authored-by: lucast2021 <[email protected]>
1 parent 0ccb5f1 commit a7237ac

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

vllm/compilation/backends.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ def produce_guards_expression(self, *args, **kwargs):
141141
return ""
142142

143143

144-
def wrap_inductor(graph,
144+
def wrap_inductor(graph: fx.GraphModule,
145145
example_inputs,
146146
additional_inductor_config,
147147
compilation_config: CompilationConfig,
148148
graph_index: int = 0,
149149
num_graphs: int = 1,
150150
runtime_shape: Optional[int] = None,
151-
use_inductor: bool = True):
151+
use_inductor: bool = True) -> Any:
152152
if graph_index == 0:
153153
# before compiling the first graph, record the start time
154154
global compilation_start_time
@@ -209,7 +209,7 @@ def wrap_inductor(graph,
209209
returns_tuple = graph_returns_tuple(graph)
210210

211211
# this is the graph we return to Dynamo to run
212-
def compiled_graph(*args):
212+
def compiled_graph(*args) -> Optional[fx.CompiledFxGraph]:
213213
# convert args to list
214214
list_args = list(args)
215215
graph_output = inductor_compiled_graph(list_args)
@@ -247,7 +247,7 @@ def _check_can_cache(*args, **kwargs):
247247
# see https://github.com/pytorch/pytorch/blob/9f5ebf3fc609105a74eab4ccc24932d6353ff566/torch/_inductor/codecache.py#L1221 # noqa
248248
return
249249

250-
def _get_shape_env():
250+
def _get_shape_env() -> AlwaysHitShapeEnv:
251251
return AlwaysHitShapeEnv()
252252

253253
with patch(# for hijacking the hash of the compiled graph
@@ -537,7 +537,7 @@ def __call__(self, graph: fx.GraphModule, example_inputs) -> Callable:
537537
example_inputs[x].clone() for x in self.sym_tensor_indices
538538
]
539539

540-
def copy_and_call(*args):
540+
def copy_and_call(*args) -> fx.GraphModule:
541541
list_args = list(args)
542542
for i, index in enumerate(self.sym_tensor_indices):
543543
runtime_tensor = list_args[index]

vllm/compilation/multi_output_match.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from torch._higher_order_ops.auto_functionalize import auto_functionalized
88
from torch._inductor import pattern_matcher as pm
99
from torch._ops import OpOverload
10+
from torch.fx import Node
1011

1112
from vllm.compilation.fx_utils import find_auto_fn
1213

@@ -97,7 +98,7 @@ def insert_getitems(self, tuple_node: fx.Node,
9798
self.graph.call_function(operator.getitem, (tuple_node, idx))
9899
for idx in indices)
99100

100-
def insert_auto_fn(self, op: OpOverload, kwargs):
101+
def insert_auto_fn(self, op: OpOverload, kwargs) -> Node:
101102
"""
102103
Insert an auto_functionalized node with the given op and kwargs.
103104
"""

vllm/compilation/pass_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import Any, Dict, List
22

33
from torch import fx as fx
44

@@ -53,7 +53,7 @@ def add(self, pass_: InductorPass):
5353
assert isinstance(pass_, InductorPass)
5454
self.passes.append(pass_)
5555

56-
def __getstate__(self):
56+
def __getstate__(self) -> Dict[str, List[Any]]:
5757
"""
5858
Custom pickling for the pass manager, as some passes cannot be pickled.
5959
Pickling occurs because the pass manager is set as the value of

0 commit comments

Comments
 (0)