Revert "[Sampler] Stop upcasting logits to fp32 in apply_sampling_params" (#48641) (#49033)

Co-authored-by: vllm-agent <vllm-agent@users.noreply.github.com>
This commit is contained in:
vllm-agent
2026-07-21 09:36:45 +01:00
committed by GitHub
co-authored by vllm-agent
parent 3e0c887511
commit 1134545b6f
5 changed files with 25 additions and 85 deletions
+4 -6
View File
@@ -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)