Skip to content

Conversation

@swy20190
Copy link

@swy20190 swy20190 commented Nov 24, 2025

What this PR does / why we need it?

Replace pyorch implement of sampling with triton kernels

Does this PR introduce any user-facing change?

No

How was this patch tested?

@github-actions
Copy link

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 replaces several PyTorch-based sampling functions with Triton kernels, aiming to improve performance. The new kernels for expand_kernel and sample_recovered_tokens_kernel are well-implemented. However, rejection_greedy_sample_kernel and rejection_random_sample_kernel contain sequential loops over draft tokens. This is a performance anti-pattern in Triton that prevents vectorization and may not yield the desired speed-up. I've added specific comments with suggestions to vectorize these kernels for better efficiency.

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

max_spec_len,
is_greedy,
)
rejection_greedy_sample_kernel[(batch_size,)](
Copy link
Collaborator

Choose a reason for hiding this comment

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

After communicating with @wangxiyuan, you need to use HAS_TRITON check here. If user hasn't installed triton, fall back to original implementation to ensure functionality. An example is here:

else:
from vllm.v1.sample.rejection_sampler import apply_sampling_constraints

import triton.language as tl
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use from vllm.triton_utils import tl, triton here, same reason.

@whx-sjtu
Copy link
Collaborator

In conclusion, currently we need to make sure that original functionality won't be broken by new triton optimization in environments without triton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants