Skip to content

Fix bug in min_p sampling #513

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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: 2 additions & 2 deletions mamba_ssm/utils/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def reset(self, max_seqlen, max_batch_size):

def modify_logits_for_min_p_filtering(logits, min_p):
"""Set the logits for none min_p values to -inf. Done in-place."""
if min_p <= 0.0 or min_p >= 1.0:
if (min_p <= 0.0).any() or (min_p >= 1.0).any():
return
indices_to_remove = logits < min_p
logits.masked_fill_(indices_to_remove, float("-Inf"))
Expand Down Expand Up @@ -103,7 +103,7 @@ def sample(logits, top_k=1, top_p=0.0, min_p=0.0, temperature=1.0):
else:
if min_p > 0.0:
logits_top = logits.clone()
max_prob = logits_top[..., 0].item()
max_prob, _ = (torch.softmax(logits_top, dim=-1)).max(dim=-1, keepdim=True)
min_prob = max_prob * min_p
modify_logits_for_min_p_filtering(logits_top, min_prob)
if temperature != 1.0:
Expand Down