Skip to content

Commit f2bc45f

Browse files
hidvakwang1012
authored andcommitted
[Core] simplify logits resort in _apply_top_k_top_p (vllm-project#8619)
1 parent c4ed6c1 commit f2bc45f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

vllm/model_executor/layers/sampler.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,9 @@ def _apply_top_k_top_p(
433433
logits_sort.masked_fill_(top_p_mask, -float("inf"))
434434

435435
# Re-sort the probabilities.
436-
src = torch.arange(logits_idx.shape[-1],
437-
device=logits_idx.device).expand_as(logits_idx)
438-
logits_idx_inv = torch.empty_like(logits_idx).scatter_(dim=-1,
439-
index=logits_idx,
440-
src=src)
441-
logits = torch.gather(logits_sort, dim=-1, index=logits_idx_inv)
436+
logits = torch.empty_like(logits_sort).scatter_(dim=-1,
437+
index=logits_idx,
438+
src=logits_sort)
442439
return logits
443440

444441

0 commit comments

Comments
 (0)