Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 15 commits into from
Jan 2, 2025

Conversation

CloseChoice
Copy link
Contributor

@CloseChoice CloseChoice commented Jan 2, 2025

Supports #3680 (link existing issues this PR will resolve)

I ignored the assert_never lines since this seems like an open mypy issue:

Signed-off-by: Tobias Pitters <[email protected]>
Copy link

github-actions bot commented Jan 2, 2025

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

Signed-off-by: Tobias Pitters <[email protected]>
Signed-off-by: Tobias Pitters <[email protected]>
Signed-off-by: Tobias Pitters <[email protected]>
Signed-off-by: Tobias Pitters <[email protected]>
Signed-off-by: Tobias Pitters <[email protected]>
@CloseChoice CloseChoice marked this pull request as ready for review January 2, 2025 09:56
@@ -176,6 +177,26 @@ class TokenInputs(TypedDict):
"""


def is_token_inputs(
inputs: Union[TokenInputs,
"MultiModalInputsV2"]) -> TypeGuard[TokenInputs]:
Copy link
Member

@DarkLight1337 DarkLight1337 Jan 2, 2025

Choose a reason for hiding this comment

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

Can we use TypeIs here? Maybe it can avoid having to type ignore the rest of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


def is_multimodal_inputs(
inputs: Union[TokenInputs, "MultiModalInputsV2"]
) -> TypeGuard["MultiModalInputsV2"]:
Copy link
Member

Choose a reason for hiding this comment

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

Same comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return inputs.get("prompt")

assert_never(inputs)
assert_never(inputs) # type: ignore[arg-type]
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, if we still need to ignore this line, then I think there isn't much point in adding those two functions...

Copy link
Contributor Author

@CloseChoice CloseChoice Jan 2, 2025

Choose a reason for hiding this comment

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

We need the functions here: https://github.com/vllm-project/vllm/pull/11680/files#diff-e55f6ffbb4ac8db75ad60f0b92d2ab311493184b32bb039c2d991742f53f5c56R332 to narrow down the types. Assert_never won't work since mypy expects a "Never" object here and this is still an open issue (as mentioned in the description). I just thought, since we need the functions anyway, I consistently use them everywhere but can revert where they are not used if you prefer that.

Copy link
Member

@DarkLight1337 DarkLight1337 Jan 2, 2025

Choose a reason for hiding this comment

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

I mean that even after you added is_token_inputs and is_multimodal_inputs, you still have type ignore on the assert_never lines. In that case, what is the benefit of adding those two functions?

Copy link
Contributor Author

@CloseChoice CloseChoice Jan 2, 2025

Choose a reason for hiding this comment

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

The point is that we need to narrow down the functions to MultiModalInputsV2 here since TokenInputs does not have the "mm_hashes" key and this results then in a mypy error. So to narrow the type (actually we just need one function to narrow down to MultiModalInputsV2) I added the function and then added the other to handle these cases consistently.

Copy link
Member

@DarkLight1337 DarkLight1337 Jan 2, 2025

Choose a reason for hiding this comment

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

Running mypy on the code prior to this PR, apart from assert_never I only get one additional error (vllm/inputs/data.py:314). So, I think it's better to just type ignore that extra line rather than using these two functions.

Btw, pyright passes on this file without any changes needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, I just removed the functions and ignored the line.

tools/mypy.sh Outdated Show resolved Hide resolved
Signed-off-by: Tobias Pitters <[email protected]>
tools/mypy.sh Outdated Show resolved Hide resolved
vllm/inputs/data.py Outdated Show resolved Hide resolved
CloseChoice and others added 2 commits January 2, 2025 15:25
Co-authored-by: Cyrus Leung <[email protected]>
Signed-off-by: Tobias Pitters <[email protected]>
Co-authored-by: Cyrus Leung <[email protected]>
Signed-off-by: Tobias Pitters <[email protected]>
Signed-off-by: Tobias Pitters <[email protected]>
Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your contribution and patience!

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) January 2, 2025 14:28
@DarkLight1337 DarkLight1337 disabled auto-merge January 2, 2025 14:28
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) January 2, 2025 14:29
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Jan 2, 2025
@DarkLight1337 DarkLight1337 disabled auto-merge January 2, 2025 14:29
@DarkLight1337 DarkLight1337 changed the title fix types for vllm/inputs [mypy] pass type checking in vllm/inputs Jan 2, 2025
@DarkLight1337 DarkLight1337 changed the title [mypy] pass type checking in vllm/inputs [mypy] Pass type checking in vllm/inputs Jan 2, 2025
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) January 2, 2025 14:29
@DarkLight1337 DarkLight1337 merged commit b6087a6 into vllm-project:main Jan 2, 2025
57 of 59 checks passed
@CloseChoice CloseChoice deleted the mypy-inputs branch January 2, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants