Skip to content

Commit

Permalink
[Core] simplify logits resort in _apply_top_k_top_p (vllm-project#8619)
Browse files Browse the repository at this point in the history
  • Loading branch information
hidva authored and dtrifiro committed Sep 27, 2024
1 parent 1146071 commit ad7b835
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions vllm/model_executor/layers/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,9 @@ def _apply_top_k_top_p(
logits_sort.masked_fill_(top_p_mask, -float("inf"))

# Re-sort the probabilities.
src = torch.arange(logits_idx.shape[-1],
device=logits_idx.device).expand_as(logits_idx)
logits_idx_inv = torch.empty_like(logits_idx).scatter_(dim=-1,
index=logits_idx,
src=src)
logits = torch.gather(logits_sort, dim=-1, index=logits_idx_inv)
logits = torch.empty_like(logits_sort).scatter_(dim=-1,
index=logits_idx,
src=logits_sort)
return logits


Expand Down

0 comments on commit ad7b835

Please sign in to comment.