[Misc][BE] Type coverage for vllm/compilation [2/3] (#31744)

This commit is contained in:
Lucas Kabela
2026-01-09 18:30:38 -05:00
committed by GitHub
parent 3adffd5b90
commit aaf4b70aae
12 changed files with 161 additions and 91 deletions
+16 -7
View File
@@ -4,6 +4,8 @@
import inspect
import os
import pickle
from collections.abc import Callable, Sequence
from typing import Any, Literal
from unittest.mock import patch
import torch
@@ -25,7 +27,7 @@ assert isinstance(SerializableCallable, type)
logger = init_logger(__name__)
class VllmSerializableFunction(SerializableCallable):
class VllmSerializableFunction(SerializableCallable): # type: ignore[misc]
"""
A wrapper around a compiled function by vllm. It will forward the tensor
inputs to the compiled function and return the result.
@@ -38,8 +40,13 @@ class VllmSerializableFunction(SerializableCallable):
"""
def __init__(
self, graph_module, example_inputs, prefix, optimized_call, is_encoder=False
):
self,
graph_module: torch.fx.GraphModule,
example_inputs: Sequence[Any],
prefix: str,
optimized_call: Callable[..., Any],
is_encoder: bool = False,
) -> None:
assert isinstance(graph_module, torch.fx.GraphModule)
self.graph_module = graph_module
self.example_inputs = example_inputs
@@ -53,7 +60,7 @@ class VllmSerializableFunction(SerializableCallable):
if sym_input is not None:
self.shape_env = sym_input.node.shape_env
def __call__(self, *args, **kwargs):
def __call__(self, *args: Any, **kwargs: Any) -> Any:
return self.optimized_call(*args, **kwargs)
@classmethod
@@ -73,7 +80,9 @@ class VllmSerializableFunction(SerializableCallable):
graph_reducer_override = GraphPickler.reducer_override
def _graph_reducer_override(self, obj):
def _graph_reducer_override(
self: GraphPickler, obj: Any
) -> tuple[Callable[..., Any], tuple[Any, ...]] | Any:
if (
inspect.isclass(obj)
and issubclass(obj, sympy.Function)
@@ -114,7 +123,7 @@ class VllmSerializableFunction(SerializableCallable):
get_current_vllm_config(), state["prefix"], is_encoder
)
def optimized_call(*example_inputs):
def optimized_call(*example_inputs: Any) -> Any:
"""
On the first run of the optimized call, we rerun the compiler
backend which should result in a cache hit. After the backend
@@ -136,7 +145,7 @@ class VllmSerializableFunction(SerializableCallable):
return fn
@property
def co_name(self):
def co_name(self) -> Literal["VllmSerializableFunction"]:
"""
Used for depyf debugging.
"""