-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
[KERNEL] Sampler. CUDA kernel for applying repetition penalty #18437
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Vadim Gimpelson <[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 🚀 |
@WoosukKwon @tlrmchlsmth |
can you compare this against wrapping |
Seems wrapping Same test |
@simon-mo The next proposal after my results in previous message is why don't wrap it with The first though is wrap The second though is wrap But anyway the path with implementation of wrapping standalone function with |
My thought is mostly thinking about whether this is a kernel that torch compiler or triton can generate directly if so it reduces complexity. |
@@ -281,6 +281,45 @@ def fused_add_rms_norm(input: torch.Tensor, residual: torch.Tensor, | |||
torch.ops._C.fused_add_rms_norm(input, residual, weight, epsilon) | |||
|
|||
|
|||
def apply_repetition_penalties_torch( |
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.
For example, simply put this under @torch.compile
. Does it help match the CUDA performance?
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 used the script from the PR description to compare "pure torch" vs "torch.compile
" vs "cuda kernel". Results are latency in ms
len | pure torch | torch.compile | cuda(this PR) |
---|---|---|---|
1 | 0.066 | 0.044 | 0.011 |
8 | 0.065 | 0.052 | 0.012 |
16 | 0.077 | 0.054 | 0.020 |
32 | 0.137 | 0.055 | 0.048 |
64 | 0.273 | 0.069 | 0.080 |
100 | 0.410 | 0.106 | 0.120 |
256 | 0.980 | 0.251 | 0.254 |
1024 | 3.791 | 0.984 | 0.986 |
1025 | 3.795 | 0.985 | 0.988 |
For small len(<=32), CUDA implementation is better than torch.compile
by up to 4.5x. For medium (64, 100) torch.compile
better by 10-15%. For len>=256 results the same.
I agree that |
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.
PR looks good overall. I do share the same sentiment as @simon-mo that it would be nicer to have this in triton, or to use torch.compile.
Signed-off-by: Vadim Gimpelson <[email protected]> Co-authored-by: Tyler Michael Smith <[email protected]>
dce5236
to
5a7038d
Compare
Signed-off-by: Vadim Gimpelson <[email protected]>
5a7038d
to
7757f3a
Compare
I think |
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.
Please submit a follow up PR with torch compile
# [stress, stress, stress Qwen, llama 4] | ||
VOCAB_SIZES = [17, 256, 1019, 151936, 202048] |
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.
# [stress, stress, stress Qwen, llama 4] | |
VOCAB_SIZES = [17, 256, 1019, 151936, 202048] | |
# [stress, stress, stress, Qwen3, Llama4] | |
VOCAB_SIZES = [17, 256, 1019, 151936, 202048] |
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.
fixed
CUDA_DEVICES = [ | ||
f"cuda:{i}" for i in range(1 if torch.cuda.device_count() == 1 else 2) | ||
] |
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 don't think this is needed.
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.
fixed
Signed-off-by: Vadim Gimpelson <[email protected]>
Signed-off-by: Vadim Gimpelson <[email protected]>
Signed-off-by: Vadim Gimpelson <[email protected]>
Signed-off-by: Vadim Gimpelson <[email protected]>
Signed-off-by: Vadim Gimpelson <[email protected]>
Problem
Sampler
's part that responsible for applying repetition penalty took a long time, especially for small models.Solution
This PR introduce a CUDA kernel that implements applying repetition penalty
Performance
All measurements on H100
Unit test
Tests of "torch implementation" vs "new CUDA kernel" shows speed up 2.85x-6.23x depending of input.
Benchmark source code
Benchmark results
E2E performance test
Used
benchmark_latency.py
with small modification to enable repetition penalty
Before
After
Avg latency speed up 5.9%
Correctness
Covered by added tests:
tests/kernels/test_apply_repetition_penalties.py