-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
[V1][Sampler] Faster top-k only implementation #15478
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
Conversation
Signed-off-by: Nick Hill <nhill@redhat.com>
|
👋 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.
Tested on TPU this won't work out of the box due to some broadcasting issue.
Signed-off-by: Nick Hill <nhill@redhat.com>
|
@NickLucche that's strange. Which op has that issue? |
|
Not too surprising, torch xla has more constraining rules on broadcasting. on the |
Signed-off-by: Nick Hill <nhill@redhat.com>
| """ | ||
| if k is None and p is None: | ||
| if p is None: | ||
| if k is None: |
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.
Do we have a unit test checking the correctness of 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.
We should really have blanket coverage for this kind of thing, including different combinations of parameters (i.e. top-k with/without top-p etc.). I'm not sure whether we do though. I will check and add a unit test to compare the two impls.
Signed-off-by: Nick Hill <nhill@redhat.com>
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.
I tested this version again today and it's working on TPU too, nice one @njhill thanks!
I was wondering could we still factor-out this topk opt into its own function so I can call it from TPU side?
We agreed with @WoosukKwon to try and keep things separated, I'd like to keep forward_tpu around.
|
Something like a5bf849#diff-6047245d864bf5fd68b5b947b735beca94723bad40d20bfc0803d9b3eea5c1edR121-R136. |
Signed-off-by: Nick Hill <nhill@redhat.com>
|
Thanks @NickLucche, I've split into separate function. And @WoosukKwon I've added a correctness test. |
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.
LGTM! Thanks for addressing my comments.
|
@njhill really neat idea to threshold the logits! However I think one corner case where this would break is if there are duplicate elements in the logit that equal the cut off value (i.e. In #15736 I use a similar thresholding logic for top-p, but introduced a small random perturbation to break the ties. Maybe the same idea can be used here for top-k as well. |
Signed-off-by: Nick Hill <nhill@redhat.com> Signed-off-by: xinyuxiao <xinyuxiao2024@gmail.com>
Signed-off-by: Nick Hill <nhill@redhat.com> Signed-off-by: Louis Ulmer <ulmerlouis@gmail.com>
Signed-off-by: Nick Hill <nhill@redhat.com>
Signed-off-by: Nick Hill <nhill@redhat.com>
Signed-off-by: Nick Hill <nhill@redhat.com> Signed-off-by: Mu Huai <tianbowen.tbw@antgroup.com>
When there's top-k in the batch but no top-p.
For 128k vocab, 1024 batch size, 500 ops on A100, where max top k is 10:
Before: 11.571 sec
After: 2.136 sec