Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/top p sampling #1360

Merged
merged 19 commits into from
May 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion litgpt/generate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def sample(
# do not use `torch.where` as in nanogpt because it will repeat top-k collisions
logits = torch.full_like(logits, float("-inf")).scatter_(-1, i, v)
# optionally scale the logits and sample from a probability distribution
if temperature > 0.0 and top_p is not None and top_p > 0.0:
if top_p is None:
belerico marked this conversation as resolved.
Show resolved Hide resolved
top_p = 1.0
if temperature > 0.0 and top_p > 0.0:
logits = logits / temperature
# optionally crop the logits to smallest set of logits with a cumulative probability above top_p
if top_p < 1.0:
Expand Down