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

Fix ValueError for LMTokenMask.log_prob() when the mask has no support #21

Merged
merged 2 commits into from
Jan 15, 2025
Merged
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
7 changes: 6 additions & 1 deletion hfppl/distributions/lmcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ async def log_prob(self, v):
if v
else self.ctx.model_mask - self.mask
)
if len(good_tokens) == 0:
# If there are no good tokens, the log probability of v under the mask is -inf
logprob_good = float("-inf")
else:
logprob_good = logsumexp(self.ctx.next_token_logprobs[list(good_tokens)])

bad_tokens = [i for i in self.ctx.model_mask if i not in good_tokens]
logprob_good = logsumexp(self.ctx.next_token_logprobs[list(good_tokens)])
self.ctx.next_token_logprobs[bad_tokens] = float("-inf")
self.ctx.next_token_logprobs -= logprob_good
self.ctx.model_mask = good_tokens
Expand Down