Skip to content

[CI] Fix mypy for vllm/engine and vllm/utils#26540

Closed
wwl2755 wants to merge 24 commits intovllm-project:mainfrom
wwl2755:mypy
Closed

[CI] Fix mypy for vllm/engine and vllm/utils#26540
wwl2755 wants to merge 24 commits intovllm-project:mainfrom
wwl2755:mypy

Conversation

@wwl2755
Copy link
Copy Markdown
Contributor

@wwl2755 wwl2755 commented Oct 9, 2025

Part of #26533

Fix mypy precommit issues under "vllm/engine" and "vllm/utils" and move them to "FILES"

CC: @hmellor @yewentao256

Original:

Run mypy for local Python installation..............................................................Failed
- hook id: mypy-local
- exit code: 1

$ mypy --python-version 3.12 --follow-imports skip 
vllm/transformers_utils/tokenizers/mistral.py:354: error: Argument 1 to "encode_one" of "MistralTokenizer" has incompatible type "str | int"; expected "str"  [arg-type]
vllm/transformers_utils/tokenizers/mistral.py:359: error: Incompatible types in assignment (expression has type "str | list[str] | list[int]", variable has type "list[int] | list[list[int]]")  [assignment]
vllm/transformers_utils/tokenizers/mistral.py:362: error: Argument 1 to "encode_one" of "MistralTokenizer" has incompatible type "str | list[str] | list[int]"; expected "str"  [arg-type]
vllm/multimodal/parse.py:369: error: Value of type "object" is not indexable  [index]
vllm/multimodal/parse.py:437: error: Incompatible types in assignment (expression has type "list[float] | Any | list[list[float] | Any | Any | tuple[Any, float] | Any | None]", variable has type "list[list[float] | Any | tuple[Any, float] | list[list[float] | Any | Any | tuple[Any, float] | Any | None]]")  [assignment]
vllm/multimodal/parse.py:501: error: Incompatible types in assignment (expression has type "list[Any] | Any | list[list[Any] | Any | Any | Any | tuple[list[Any] | Any | Any, dict[str, Any]] | None] | tuple[Any, ...]", variable has type "list[list[Any] | Any | tuple[list[Any] | Any | Any, dict[str, Any]] | list[list[Any] | Any | Any | Any | tuple[list[Any] | Any | Any, dict[str, Any]] | None]]")  [assignment]
vllm/engine/arg_utils.py:1246: error: Argument "tokenizer" to "maybe_override_with_speculators" has incompatible type "str | None"; expected "str"  [arg-type]
vllm/engine/arg_utils.py:1271: error: Argument 1 to "_set_default_args" of "EngineArgs" has incompatible type "UsageContext | None"; expected "UsageContext"  [arg-type]
Found 8 errors in 3 files (checked 164 source files)

$ mypy --python-version 3.12 --follow-imports skip 
vllm/utils/jsontree.py:97: error: Incompatible return value type (got "list[_U | dict[str, _U]]", expected "BatchedTensorInputs | _JSONTree[_U]")  [return-value]
vllm/utils/jsontree.py:148: error: Type variable "vllm.utils.jsontree._U" is unbound  [valid-type]
vllm/utils/jsontree.py:148: note: (Hint: Use "Generic[_U]" or "Protocol[_U]" base class to bind "_U" inside a class)
vllm/utils/jsontree.py:148: note: (Hint: Use "_U" in function signature to bind "_U" inside a function)
vllm/utils/jsontree.py:157: error: Incompatible return value type (got "object", expected "_T | _U")  [return-value]
vllm/utils/jsontree.py:157: note: Error code "return-value" not covered by "type: ignore" comment
vllm/utils/__init__.py:489: error: Need type annotation for "awaits"  [var-annotated]
vllm/utils/__init__.py:489: error: Argument 1 to "create_task" of "AbstractEventLoop" has incompatible type "Awaitable[T]"; expected "Coroutine[Any, Any, Never]"  [arg-type]
vllm/utils/__init__.py:498: error: Argument 1 to "anext" has incompatible type "AsyncGenerator[Any, None]"; expected "_SupportsSynchronousAnext[Coroutine[Any, Any, Any]]"  [arg-type]
vllm/utils/__init__.py:1167: error: Item "None" of "list[str] | None" has no attribute "__iter__" (not iterable)  [union-attr]


$ mypy --python-version 3.12 
vllm/engine/arg_utils.py:218: error: Too few arguments  [call-arg]
vllm/engine/arg_utils.py:351: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "list[int]")  [assignment]
vllm/engine/arg_utils.py:377: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "EPLBConfig")  [assignment]
vllm/engine/arg_utils.py:412: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "dict[str, Any]")  [assignment]
vllm/engine/arg_utils.py:415: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "dict[str, Any] | Callable[[Any], Any]")  [assignment]
vllm/engine/arg_utils.py:420: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "dict[str, int | dict[str, int]]")  [assignment]
vllm/engine/arg_utils.py:424: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "dict[str, dict[str, Any]]")  [assignment]
vllm/engine/arg_utils.py:439: error: Incompatible types in assignment (expression has type "float | None", variable has type "float")  [assignment]
vllm/engine/arg_utils.py:454: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "dict[Any, Any]")  [assignment]
vllm/engine/arg_utils.py:455: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "str | list[str]")  [assignment]
vllm/engine/arg_utils.py:464: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "StructuredOutputsConfig")  [assignment]
vllm/engine/arg_utils.py:492: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "CompilationConfig")  [assignment]
vllm/engine/arg_utils.py:501: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "dict[str, Any]")  [assignment]
vllm/engine/arg_utils.py:505: error: Incompatible types in assignment (expression has type "str | None", variable has type "str")  [assignment]
vllm/engine/arg_utils.py:511: error: Incompatible types in assignment (expression has type "Field[Any]", variable has type "dict[str, Any]")  [assignment]
vllm/engine/arg_utils.py:514: error: Incompatible types in assignment (expression has type "str | dict[str, str]", variable has type "str")  [assignment]
vllm/engine/arg_utils.py:1104: error: Argument "tokenizer" to "ModelConfig" has incompatible type "str | None"; expected "str"  [arg-type]
vllm/engine/arg_utils.py:1118: error: Argument "max_model_len" to "ModelConfig" has incompatible type "int | None"; expected "int"  [arg-type]
vllm/engine/arg_utils.py:1307: error: Argument "block_size" to "CacheConfig" has incompatible type "Literal[1, 8, 16, 32, 64, 128] | None"; expected "Literal[1, 8, 16, 32, 64, 128]"  [arg-type]
vllm/engine/arg_utils.py:1455: error: Argument "data_parallel_backend" to "ParallelConfig" has incompatible type "str"; expected "Literal['ray', 'mp']"  [arg-type]
vllm/engine/arg_utils.py:1493: error: Argument "max_num_batched_tokens" to "SchedulerConfig" has incompatible type "int | None"; expected "int"  [arg-type]
vllm/engine/arg_utils.py:1494: error: Argument "max_num_seqs" to "SchedulerConfig" has incompatible type "int | None"; expected "int"  [arg-type]
vllm/engine/arg_utils.py:1521: error: Argument "max_lora_rank" to "LoRAConfig" has incompatible type "int"; expected "Literal[1, 8, 16, 32, 64, 128, 256, 320, 512]"  [arg-type]
vllm/engine/arg_utils.py:1525: error: Argument "lora_extra_vocab_size" to "LoRAConfig" has incompatible type "int"; expected "Literal[256, 512]"  [arg-type]
vllm/engine/arg_utils.py:1548: error: "StructuredOutputsConfig" has no attribute "guided_decoding_backend"  [attr-defined]
vllm/engine/arg_utils.py:1550: error: "StructuredOutputsConfig" has no attribute "guided_decoding_disable_fallback"  [attr-defined]
vllm/engine/arg_utils.py:1554: error: "StructuredOutputsConfig" has no attribute "guided_decoding_disable_any_whitespace"  [attr-defined]
vllm/engine/arg_utils.py:1558: error: "StructuredOutputsConfig" has no attribute "guided_decoding_disable_additional_properties"; maybe "disable_additional_properties"?  [attr-defined]
vllm/engine/arg_utils.py:1602: error: Argument "feature_name" to "_raise_or_fallback" has incompatible type "list[str]"; expected "str"  [arg-type]
vllm/engine/arg_utils.py:1718: error: Item "None" of "PoolerConfig | None" has no attribute "pooling_type"  [union-attr]
vllm/engine/metrics.py:54: error: Item "None" of "ObservabilityConfig | None" has no attribute "show_hidden_metrics"  [union-attr]
Found 31 errors in 2 files (checked 171 source files)

@mergify mergify bot added the multi-modality Related to multi-modality (#4194) label Oct 9, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request focuses on fixing mypy pre-commit issues to enable stricter type checking for the vllm/engine module. The changes primarily involve adding explicit type casts, updating type hints, and using type: ignore to resolve type errors reported by mypy. The fixes are generally correct and achieve the goal of making the code mypy-compliant. However, I've identified two instances in vllm/multimodal/parse.py where using # type: ignore hides a potential runtime error. In these cases, the code does not handle None values that can appear in a list of multimodal data, which could lead to exceptions. I've suggested a more robust fix that handles these None values gracefully while also resolving the type error.

@mergify
Copy link
Copy Markdown

mergify bot commented Oct 9, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @wwl2755.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Oct 9, 2025
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
@wwl2755 wwl2755 changed the title [CI] Fix mypy precommit under "vllm/engine" [CI] Fix mypy precommit under "vllm/engine" and "vllm/utils" Oct 10, 2025
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
@mergify mergify bot added the needs-rebase label Oct 14, 2025
Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also fix the pre-commit issue and merge from main, so that we can get this landed

Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
@mergify
Copy link
Copy Markdown

mergify bot commented Oct 15, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @wwl2755.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Oct 15, 2025
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
@mergify mergify bot removed the needs-rebase label Oct 16, 2025

# Setup Scheduler With Mock External Cache Hit.
BLOCK_SIZE = 4
BLOCK_SIZE = 8
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes to block size intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. To satisfy the type validation, block size has to be one of [1, 8, 16, 32, 64, 128] cc: @hmellor

Copy link
Copy Markdown
Member

@DarkLight1337 DarkLight1337 Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @heheda12345 @tlrmchlsmth is it ok to change these tests to use the correct block sizes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, we were not validating the block size but we did specify a list of valid block sizes. We should either update the test or update the possible valid block sizes

Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
Signed-off-by: wwl2755 <wangwenlong2755@gmail.com>
@mergify
Copy link
Copy Markdown

mergify bot commented Oct 16, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @wwl2755.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Oct 16, 2025
@mergify mergify bot removed the needs-rebase label Oct 16, 2025
Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the CI issue, try if we can reproduce it locally

@wwl2755
Copy link
Copy Markdown
Contributor Author

wwl2755 commented Oct 17, 2025

Thanks! I can reproduce it offline. It seems using pydantic.Field leads to more validation errors in the tests. And simpliy SkipValidation seems not solve all problems.

@hmellor
Copy link
Copy Markdown
Member

hmellor commented Oct 17, 2025

I'll take a look at the failures too

@hmellor
Copy link
Copy Markdown
Member

hmellor commented Oct 17, 2025

Looks like I fixed this locally and forgot to push... One moment

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

mergify bot commented Oct 21, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @wwl2755.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Oct 21, 2025
Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the pre-commit and conflicts so that we can land this PR

@hmellor
Copy link
Copy Markdown
Member

hmellor commented Dec 17, 2025

superseded by #29674

@hmellor hmellor closed this Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

multi-modality Related to multi-modality (#4194) needs-rebase ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants