fix: include boundary token in top-p nucleus sampling#1171
Open
zhuxiaoxuhit wants to merge 2 commits intofishaudio:mainfrom
Open
fix: include boundary token in top-p nucleus sampling#1171zhuxiaoxuhit wants to merge 2 commits intofishaudio:mainfrom
zhuxiaoxuhit wants to merge 2 commits intofishaudio:mainfrom
Conversation
nucleus sampling with cum_probs > top_p excludes the token that first pushes the cumulative probability over the threshold, so the actual nucleus covers less than top_p of the probability mass. shift the mask right by one to include that boundary token, matching the standard implementation in transformers and other LLM toolkits.
Member
|
This fix is still needed, but the PR has merge conflicts with the current main branch (logits_to_probs has been refactored). Could you please rebase onto the latest main? Thanks! |
Contributor
Author
|
Hi @Stardust-minus , the merge conflicts have been resolved. Please review when you have a minute. Thanks! |
Contributor
|
This PR is stale because it has been open for 30 days with no activity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current implementation uses
cum_probs > top_pto build the removal mask,which marks the token that first pushes the cumulative probability over
top_pas removed. This means the actual nucleus covers less probability mass than
intended.
Example with top_p=0.9 and probs [0.50, 0.35, 0.10, 0.05]:
cum_probs = [0.50, 0.85, 0.95, 1.00]
current: keeps tokens at 0.50+0.35=0.85 (under-samples the nucleus)
correct: keeps tokens at 0.50+0.35+0.10=0.95 (covers top_p)
The fix shifts the removal mask right by one position before applying it,
so the token that first crosses the threshold is included. This matches
the standard implementation in transformers (TopPLogitsWarper) and other
LLM inference libraries.