Skip to content

Commit

Permalink
sampler: simplify logits resort in _apply_top_k_top_p (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpinDale authored Jan 3, 2025
1 parent 61aed09 commit ca7028d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions aphrodite/modeling/layers/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,12 +885,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 ca7028d

Please sign in to comment.