@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / b6087a6bee
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 16, 03:15 UTC

[mypy] Pass type checking in vllm/inputs (#11680)

Signed-off-by: Tobias Pitters <tobias.pitters@gmail.com>

Tobias Pitters committed Jan 2, 2025 at 17:18 UTC b6087a6beead9165f4c77ceba592b3651bb37de9
4 files changed +16 -14
tools/mypy.sh
+1
@@ -23,6 +23,7 @@ run_mypy vllm/compilation
23 run_mypy vllm/distributed
24 run_mypy vllm/engine
25 run_mypy vllm/executor
26 +run_mypy vllm/inputs
27 run_mypy vllm/lora
28 run_mypy vllm/model_executor
29 run_mypy vllm/plugins
vllm/inputs/data.py
+11 -10
@@ -250,7 +250,7 @@ class SingletonInputsAdapter:
250 if inputs["type"] == "token" or inputs["type"] == "multimodal":
251 return inputs.get("prompt")
252
253 - assert_never(inputs)
253 + assert_never(inputs) # type: ignore[arg-type]
254
255 @cached_property
256 def prompt_token_ids(self) -> List[int]:
@@ -259,7 +259,7 @@ class SingletonInputsAdapter:
259 if inputs["type"] == "token" or inputs["type"] == "multimodal":
260 return inputs.get("prompt_token_ids", [])
261
262 - assert_never(inputs)
262 + assert_never(inputs) # type: ignore[arg-type]
263
264 @cached_property
265 def token_type_ids(self) -> List[int]:
@@ -268,7 +268,7 @@ class SingletonInputsAdapter:
268 if inputs["type"] == "token" or inputs["type"] == "multimodal":
269 return inputs.get("token_type_ids", [])
270
271 - assert_never(inputs)
271 + assert_never(inputs) # type: ignore[arg-type]
272
273 @cached_property
274 def prompt_embeds(self) -> Optional[torch.Tensor]:
@@ -277,7 +277,7 @@ class SingletonInputsAdapter:
277 if inputs["type"] == "token" or inputs["type"] == "multimodal":
278 return None
279
280 - assert_never(inputs)
280 + assert_never(inputs) # type: ignore[arg-type]
281
282 @cached_property
283 def multi_modal_data(self) -> "MultiModalDataDict":
@@ -289,7 +289,7 @@ class SingletonInputsAdapter:
289 if inputs["type"] == "multimodal":
290 return inputs.get("mm_kwargs", {})
291
292 - assert_never(inputs)
292 + assert_never(inputs) # type: ignore[arg-type]
293
294 @cached_property
295 def multi_modal_inputs(self) -> Union[Dict, "MultiModalKwargs"]:
@@ -301,7 +301,7 @@ class SingletonInputsAdapter:
301 if inputs["type"] == "multimodal":
302 return inputs.get("mm_kwargs", {})
303
304 - assert_never(inputs)
304 + assert_never(inputs) # type: ignore[arg-type]
305
306 @cached_property
307 def multi_modal_hashes(self) -> List[str]:
@@ -311,9 +311,10 @@ class SingletonInputsAdapter:
311 return inputs.get("multi_modal_hashes", [])
312
313 if inputs["type"] == "multimodal":
314 - return inputs.get("mm_hashes", [])
314 + # only the case when we use MultiModalInputsV2
315 + return inputs.get("mm_hashes", []) # type: ignore[return-value]
316
316 - assert_never(inputs)
317 + assert_never(inputs) # type: ignore[arg-type]
318
319 @cached_property
320 def multi_modal_placeholders(self) -> "MultiModalPlaceholderDict":
@@ -325,7 +326,7 @@ class SingletonInputsAdapter:
326 if inputs["type"] == "multimodal":
327 return inputs.get("mm_placeholders", {})
328
328 - assert_never(inputs)
329 + assert_never(inputs) # type: ignore[arg-type]
330
331 @cached_property
332 def mm_processor_kwargs(self) -> Dict[str, Any]:
@@ -337,7 +338,7 @@ class SingletonInputsAdapter:
338 if inputs["type"] == "multimodal":
339 return {}
340
340 - assert_never(inputs)
341 + assert_never(inputs) # type: ignore[arg-type]
342
343
344 ProcessorInputs = Union[DecoderOnlyInputs, EncoderDecoderInputs]
vllm/inputs/preprocess.py
+3 -3
@@ -436,7 +436,7 @@ class InputPreprocessor:
436 or encoder_inputs["type"] == "multimodal"):
437 pass
438 else:
439 - assert_never(encoder_inputs)
439 + assert_never(encoder_inputs) # type: ignore[arg-type]
440
441 if decoder_inputs is None:
442 dec_token_ids = self._prepare_decoder_input_ids_for_generation(
@@ -452,7 +452,7 @@ class InputPreprocessor:
452 raise ValueError("Multi-modal decoder inputs of encoder-"
453 "decoder models are not supported yet")
454 else:
455 - assert_never(encoder_inputs)
455 + assert_never(encoder_inputs) # type: ignore[arg-type]
456
457 return EncoderDecoderInputs(
458 encoder=encoder_inputs,
@@ -569,7 +569,7 @@ class InputPreprocessor:
569 prompt_adapter_request=prompt_adapter_request,
570 )
571 else:
572 - assert_never(prompt_inputs)
572 + assert_never(prompt_inputs) # type: ignore[arg-type]
573
574 return prompt_inputs
575
vllm/inputs/registry.py
+1 -1
@@ -419,7 +419,7 @@ class InputRegistry:
419 # Be more strict in V2
420 assert "mm_kwargs" in inputs
421 else:
422 - assert_never(inputs["type"])
422 + assert_never(inputs["type"]) # type: ignore[arg-type]
423
424 def process_input(self, model_config: "ModelConfig",
425 inputs: ProcessorInputs) -> ProcessorInputs: