Skip to content
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

[SpecDecode][Kernel] Use Flashinfer for Rejection Sampling in Speculative Decoding #7244

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
hack for test
  • Loading branch information
LiuXiaoxuanPKU committed Aug 13, 2024
commit 7439daf60fa820185851aebf606bc411264f2068
12 changes: 12 additions & 0 deletions vllm/model_executor/layers/rejection_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,25 @@ def forward(
if batch_size == 0:
LiuXiaoxuanPKU marked this conversation as resolved.
Show resolved Hide resolved
return torch.empty(0, k + 1, device=draft_probs.device, dtype=int)

# If use Flashinfer chain_speculative_sampling kernel
# for rejection sampling
if chain_speculative_sampling is not None:
batch_size, k, _ = draft_probs.shape
uniform_samples = self._create_uniform_samples(
seeded_seqs, batch_size, k, draft_probs.device)
output_token_ids = chain_speculative_sampling(
draft_probs, draft_token_ids, uniform_samples,
target_with_bonus_probs)

# Since we do not call _create_output any more,
# we need to update metrics here.
# The num_accepted_tokens is not updated because
# flashinfer kernel does not return this value.
# The metric is meaningless when using flashinfer
# rejection sampling.
self.num_accepted_tokens += batch_size * k
self.num_emitted_tokens += (output_token_ids != -1).sum()
self.num_draft_tokens += batch_size * k
else:
accepted, recovered_token_ids = (
self._batch_modified_rejection_sampling(
Expand Down
Loading