Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
05ccd0aa
Unverified
Commit
05ccd0aa
authored
Mar 18, 2025
by
Woosuk Kwon
Committed by
GitHub
Mar 18, 2025
Browse files
[V1] Ensure using int64 for sampled token ids (#15065)
Signed-off-by:
Woosuk Kwon
<
woosuk.kwon@berkeley.edu
>
parent
f690372b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
vllm/v1/sample/sampler.py
vllm/v1/sample/sampler.py
+8
-1
No files found.
vllm/v1/sample/sampler.py
View file @
05ccd0aa
...
@@ -47,6 +47,11 @@ class Sampler(nn.Module):
...
@@ -47,6 +47,11 @@ class Sampler(nn.Module):
logits
=
self
.
apply_penalties
(
logits
,
sampling_metadata
)
logits
=
self
.
apply_penalties
(
logits
,
sampling_metadata
)
# Sample the next token.
# Sample the next token.
sampled
=
self
.
sample
(
logits
,
sampling_metadata
)
sampled
=
self
.
sample
(
logits
,
sampling_metadata
)
# Convert sampled token ids to int64 (long) type to ensure compatibility
# with subsequent operations that may use these values as indices.
# This conversion is necessary because FlashInfer sampling operations
# return int32 (while PyTorch argmax and topk return int64).
sampled
=
sampled
.
long
()
# Gather the logprobs of the topk and sampled token (if requested).
# Gather the logprobs of the topk and sampled token (if requested).
# Get logprobs and rank tensors (if requested)
# Get logprobs and rank tensors (if requested)
...
@@ -139,19 +144,21 @@ class Sampler(nn.Module):
...
@@ -139,19 +144,21 @@ class Sampler(nn.Module):
or sampled tokens (if sampled
or sampled tokens (if sampled
logprobs); 1D token ID tensor
logprobs); 1D token ID tensor
with (num tokens) elements
with (num tokens) elements
Must be int64.
Returns:
Returns:
Top-k int indices tensor, (num tokens) x (num_logprobs + 1)
Top-k int indices tensor, (num tokens) x (num_logprobs + 1)
Top-k float logprobs tensor, (num tokens) x (num_logprobs + 1)
Top-k float logprobs tensor, (num tokens) x (num_logprobs + 1)
Sampled token rank tensor, (num tokens)
Sampled token rank tensor, (num tokens)
"""
"""
assert
token_ids
.
dtype
==
torch
.
int64
# Find the topK values.
# Find the topK values.
topk_logprobs
,
topk_indices
=
torch
.
topk
(
logprobs
,
topk_logprobs
,
topk_indices
=
torch
.
topk
(
logprobs
,
num_logprobs
,
num_logprobs
,
dim
=-
1
)
dim
=-
1
)
# Get with the logprob of the prompt or sampled token.
# Get with the logprob of the prompt or sampled token.
token_ids
=
token_ids
.
unsqueeze
(
-
1
)
.
to
(
torch
.
long
)
token_ids
=
token_ids
.
unsqueeze
(
-
1
)
token_logprobs
=
logprobs
.
gather
(
-
1
,
token_ids
)
token_logprobs
=
logprobs
.
gather
(
-
1
,
token_ids
)
# Compute the ranks of the actual token.
# Compute the ranks of the actual token.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment