Skip to content

[Misc][BE] Turn on strict type coverage for vllm/compilation#31756

Merged
ProExpertProg merged 6 commits intovllm-project:mainfrom
Lucaskabela:lucaskabela/compilation_strict_type_on
Jan 22, 2026
Merged

[Misc][BE] Turn on strict type coverage for vllm/compilation#31756
ProExpertProg merged 6 commits intovllm-project:mainfrom
Lucaskabela:lucaskabela/compilation_strict_type_on

Conversation

@Lucaskabela
Copy link
Copy Markdown
Contributor

@Lucaskabela Lucaskabela commented Jan 5, 2026

Purpose

This PR follows up

Test Plan

mypy vllm/compilation

Test Result

Success: no issues found in 28 source files

Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Note

Turns on strict mypy for vllm/compilation and updates pre-commit to run --strict on that directory.

  • Adds [tool.mypy.overrides] for vllm.compilation.* in pyproject.toml (disallow untyped/incomplete defs, warn return any)
  • Updates tools/pre_commit/mypy.py to detect strict paths and run separate mypy invocations for strict and non-strict groups
  • Type-safety refactors across vllm/compilation/* (e.g., explicit variable annotations/returns, boolean casts, None handling, and targeted type: ignore on decorators/union attrs)
  • No functional behavior changes; modifications are to satisfy strict typing

Written by Cursor Bugbot for commit 251bdb337dcd680d68673cd8755c230fb9e07862. This will update automatically on new commits. Configure here.


Note

Turns on strict type checking for the compilation package and adapts tooling to enforce it.

  • Adds mypy override for vllm.compilation.* in pyproject.toml (disallow untyped/incomplete defs, warn on Any returns)
  • Updates tools/pre_commit/mypy.py to detect strict paths and run separate mypy invocations (--strict for vllm/compilation, non-strict elsewhere)
  • Applies typing fixes in vllm/compilation/* (explicit annotations, temporary vars for returns, boolean casts, None checks, and scoped type: ignore on decorators/union attrs)

No functional behavior changes; changes are to satisfy stricter typing.

Written by Cursor Bugbot for commit 9e82cb8ae68eeb2f549c28a86c851178a5b7cfed. This will update automatically on new commits. Configure here.

@mergify mergify bot added the nvidia label Jan 5, 2026
@Lucaskabela Lucaskabela changed the title [BE] Turn on strict type coverage for vllm/compilation [Misc][BE] Turn on strict type coverage for vllm/compilation Jan 5, 2026
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 commendably enables strict mypy checking for the vllm/compilation module, a significant step towards improving code quality and maintainability. The changes are extensive and well-executed, adding necessary type hints and configurations. I have identified one area for improvement in vllm/compilation/decorators.py concerning the use of TypeVar, which, if addressed, would further enhance type safety and eliminate the need for several type: ignore suppressions.

@mergify
Copy link
Copy Markdown

mergify bot commented Jan 8, 2026

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

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 Jan 8, 2026
@Lucaskabela Lucaskabela force-pushed the lucaskabela/compilation_strict_type_on branch from 4e43ee8 to 34c18c8 Compare January 12, 2026 21:20
@mergify mergify bot removed the needs-rebase label Jan 12, 2026
@Lucaskabela Lucaskabela force-pushed the lucaskabela/compilation_strict_type_on branch from 34c18c8 to 251bdb3 Compare January 13, 2026 01:13
@@ -100,6 +100,12 @@ ignore_missing_imports = true
check_untyped_defs = true
follow_imports = "silent"

[[tool.mypy.overrides]]
module = "vllm.compilation.*"
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.

note for reviewer: This is not strict = True because this would cause cascading strict imports to other modules from follow_imports when checked with pre-commit only

Instead we default to a few sensible options here

@Lucaskabela Lucaskabela marked this pull request as ready for review January 13, 2026 01:15
@Lucaskabela Lucaskabela force-pushed the lucaskabela/compilation_strict_type_on branch from 251bdb3 to 9e82cb8 Compare January 13, 2026 01:23
Copy link
Copy Markdown
Collaborator

@ProExpertProg ProExpertProg left a comment

Choose a reason for hiding this comment

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

I see a ton of type[ignore]s - what are those for? Can we not fix them somehow? Because to me I think the noise of those ignores reduces the benefits of strict type checking

Comment on lines +201 to +203
hash_str: str = safe_hash(
str(factors).encode(), usedforsecurity=False
).hexdigest()[:10]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should just use the utils for hashing here that we use for other compile_hash functions (I think sha256)

Copy link
Copy Markdown
Contributor Author

@Lucaskabela Lucaskabela Jan 13, 2026

Choose a reason for hiding this comment

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

This should be the same util I believe (safe_hash)- we are just making the type checker happy by saying it is str type (since we run hexdigest()) and we reformat it due changing the line length

Signed-off-by: Lucas Kabela <lucaskabela@meta.com>
@Lucaskabela Lucaskabela force-pushed the lucaskabela/compilation_strict_type_on branch from 9e82cb8 to 7194132 Compare January 13, 2026 17:52


def ignore_torch_compile(cls: _T) -> _T:
def ignore_torch_compile(cls: type[_T]) -> type[_T]:
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.

Gemini bot caught a good bug here - _T should be type[_T] since it is the cls type

@vllm-project vllm-project deleted a comment Jan 13, 2026
return True
tp_size = get_tensor_model_parallel_world_size()
return compile_range.is_single_size() and compile_range.end % tp_size == 0
return bool(compile_range.is_single_size() and compile_range.end % tp_size == 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

how is this not already bool haha

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.

with skip follow_imports mode, it gets treated as Any by type checker - I know it is a bit silly, but imo the benefits of having strict type checking outweighs the extra syntax

Copy link
Copy Markdown
Collaborator

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

seems reasonable to me. @ProExpertProg thoughts on having strict typing? I don't think we need to block on resolving the type ignores before turning on strict typing

@github-project-automation github-project-automation bot moved this to Ready in NVIDIA Jan 20, 2026
@zou3519 zou3519 added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 21, 2026
@mergify
Copy link
Copy Markdown

mergify bot commented Jan 21, 2026

Hi @Lucaskabela, the pre-commit checks have failed. Please run:

uv pip install pre-commit
pre-commit install
pre-commit run --all-files

Then, commit the changes and push to your branch.

For future commits, pre-commit will run automatically on changed files before each commit.

Tip

Is mypy or markdownlint failing?
mypy and markdownlint are run differently in CI. If the failure is related to either of these checks, please use the following commands to run them locally:
# For mypy (substitute "3.10" with the failing version if needed)
pre-commit run --hook-stage manual mypy-3.10
# For markdownlint
pre-commit run --hook-stage manual markdownlint

Signed-off-by: Lucas Kabela <lucaskabela@meta.com>
@ProExpertProg ProExpertProg enabled auto-merge (squash) January 22, 2026 14:55
@ProExpertProg ProExpertProg merged commit 15e302d into vllm-project:main Jan 22, 2026
49 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Done in NVIDIA Jan 22, 2026
monajafi-amd pushed a commit to monajafi-amd/vllm that referenced this pull request Jan 23, 2026
…oject#31756)

Signed-off-by: Lucas Kabela <lucaskabela@meta.com>
Signed-off-by: mohammad najafi <mohammad.najafi@amd.com>
cwazai pushed a commit to cwazai/vllm that referenced this pull request Jan 25, 2026
…oject#31756)

Signed-off-by: Lucas Kabela <lucaskabela@meta.com>
Signed-off-by: 陈建华 <1647430658@qq.com>
lapy pushed a commit to lapy/vllm that referenced this pull request Jan 27, 2026
@hmellor
Copy link
Copy Markdown
Member

hmellor commented Jan 27, 2026

May I ask, what is the purpose of enabling --strict typing here?

The current goal we have for mypy is to enable --follow-imports. Adding in this second access for strict makes this harder.

@Lucaskabela Lucaskabela deleted the lucaskabela/compilation_strict_type_on branch February 19, 2026 16:40
ItzDEXX pushed a commit to ItzDEXX/vllm that referenced this pull request Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nvidia ready ONLY add when PR is ready to merge/full CI is needed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants