-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
[Perf] Dont create unnecessary pooling params #22876
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
[Perf] Dont create unnecessary pooling params #22876
Conversation
Signed-off-by: Lucas Wilkinson <[email protected]>
There was a problem hiding this 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 introduces a performance optimization in _init_model_kwargs
by avoiding the creation of pooling_metadata
when there are no pooling requests. The change correctly checks for the presence of pooling requests before creating expensive objects. However, there's a minor maintainability concern in how num_pooling_reqs
is derived, which could lead to inconsistencies in the future. I've provided a suggestion to improve the robustness of this logic.
num_pooling_reqs = len(self.input_batch.pooling_params) | ||
|
||
if num_pooling_reqs == 0: | ||
return model_kwargs | ||
|
||
pooling_params = self.input_batch.pooling_metadata.pooling_params | ||
|
||
assert num_pooling_reqs == num_reqs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the optimization is correct, this implementation introduces a potential for future bugs. num_pooling_reqs
is derived from self.input_batch.pooling_params
, but the pooling_params
variable that is used in the rest of the function is derived from self.input_batch.pooling_metadata
. If the logic inside the pooling_metadata
property changes in the future (e.g., to filter some requests), len(pooling_params)
might no longer be equal to the originally computed num_pooling_reqs
, which could lead to subtle issues.
To make the code more robust, it's better to derive num_pooling_reqs
directly from the pooling_params
list after it has been created. The initial check can be simplified to check if self.input_batch.pooling_params
is empty.
num_pooling_reqs = len(self.input_batch.pooling_params) | |
if num_pooling_reqs == 0: | |
return model_kwargs | |
pooling_params = self.input_batch.pooling_metadata.pooling_params | |
assert num_pooling_reqs == num_reqs | |
if not self.input_batch.pooling_params: | |
return model_kwargs | |
pooling_params = self.input_batch.pooling_metadata.pooling_params | |
num_pooling_reqs = len(pooling_params) | |
assert num_pooling_reqs == num_reqs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I think this only avoids attribute access, not creating the pooling params?
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run 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 either: Add 🚀 |
Python is sometimes a blessing and a curse haha; thats the gotcha, its actually a vllm/vllm/v1/worker/gpu_input_batch.py Lines 675 to 692 in a353bd0
|
Maybe we should make this a method to avoid hiding this fact... but anyway, let's merge this PR first |
Thanks for the fix! |
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]> Signed-off-by: Duncan Moss <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]> Signed-off-by: Xiao Yu <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]> Signed-off-by: Xiao Yu <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Signed-off-by: Lucas Wilkinson <[email protected]>
Purpose
Don't create pooling_metadata when its not needed (overhead introduced in #21985)
cc @maxdebayser
Test Plan
Test Result
(Optional) Documentation Update
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.