Co-authored-by: vllm-agent <vllm-agent@users.noreply.github.com>
This commit is contained in:
@@ -392,9 +392,8 @@ def apply_top_k_top_p_pytorch(
|
||||
logits_sort.masked_fill_(top_k_mask, -float("inf"))
|
||||
|
||||
if p is not None:
|
||||
# Apply top-p. The cumsum below runs over the whole vocab, so accumulating
|
||||
# in a low-precision dtype makes the nucleus undershoot p.
|
||||
probs_sort = logits_sort.softmax(dim=-1, dtype=torch.float32)
|
||||
# Apply top-p.
|
||||
probs_sort = logits_sort.softmax(dim=-1)
|
||||
probs_sum = torch.cumsum(probs_sort, dim=-1, out=probs_sort)
|
||||
top_p_mask = probs_sum <= 1 - p.unsqueeze(dim=1)
|
||||
# at least one
|
||||
@@ -501,10 +500,9 @@ def flashinfer_sample(
|
||||
probs, k, deterministic=True
|
||||
)
|
||||
else:
|
||||
# Both top-k and top-p. FlashInfer requires contiguous fp32 logits; the
|
||||
# branches above get that from softmax().
|
||||
# Both top-k and top-p.
|
||||
next_token_ids = flashinfer.sampling.top_k_top_p_sampling_from_logits(
|
||||
logits.float().contiguous(), k, p, deterministic=True
|
||||
logits, k, p, deterministic=True
|
||||
)
|
||||
|
||||
return next_token_ids.view(-1)
|
||||
|
||||
Reference in New Issue
Block a user