-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
[V1][TPU] Remove unnecessary padding for running on TPU. #14467
Conversation
Signed-off-by: Xiongfei Wei <[email protected]>
👋 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 🚀 |
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.
NUM_KV_PAGES_PER_BLOCK is no longer used in tpu_model_runner.py after this change. Is that intentional?
Signed-off-by: Xiongfei Wei <[email protected]>
Yea, NUM_KV_PAGES_PER_BLOCK is used for padding. Since we don't need to pad anymore, we no longer need it. |
Signed-off-by: Xiongfei Wei <[email protected]>
self.max_num_tokens = _get_padded_number( | ||
scheduler_config.max_num_batched_tokens, NUM_QUERIES_PER_BLOCK) | ||
self.max_num_reqs = _get_padded_number(scheduler_config.max_num_seqs, | ||
NUM_QUERIES_PER_BLOCK) | ||
self.max_num_tokens = scheduler_config.max_num_batched_tokens | ||
self.max_num_reqs = scheduler_config.max_num_seqs |
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.
Rounding these up was intentional since the user could specify odd values non divisible by our constraints. I think we should keep this
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.
Are these constrains from kernel? If yes, we no longer need these paddings because the new kernel removed all the constrains. We can save tons of memory and computing by removing these paddings.
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.
Thanks for the review!
@mgoin , by "user could specify odd values", what "value" are you referring to?
Here both NUM_KV_PAGES_PER_BLOCK, NUM_QUERIES_PER_BLOCK are tunable parameter of the ragged kernel. The padding is needed mainly because the kernel v1 has the constraint that self.max_num_tokens%NUM_QUERIES_PER_BLOCK==0 and self.max_num_blocks_per_req%NUM_KV_PAGES_PER_BLOCK==0.
Early this week we switched the kernel from v1 to v2 where in v2 we don't have such constraints, that's why I think we can remove these constraints.
Also note that here are the "max" num_tokens instead of the actual num_tokens we would use. For the actual num_tokens in the real workload and "warmup", we still pad to the next power of 2: https://github.com/vllm-project/vllm/blob/8ed5421aaa7da24051acdae53c860e6ce6598403/vllm/v1/worker/tpu_model_runner.py#L420C45-L420C66.
Thanks @mgoin for the review! |
Remove unnecessary padding for running on TPU. Also update the tunable block size (NUM_QUERIES_PER_BLOCK, NUM_KV_PAGES_PER_BLOCK) for the ragged kernel.
Test plan: