fix: apply temperature scaling before top-p filtering in logits_to_probs#1150
Open
Mr-Neutr0n wants to merge 1 commit intofishaudio:mainfrom
Open
fix: apply temperature scaling before top-p filtering in logits_to_probs#1150Mr-Neutr0n wants to merge 1 commit intofishaudio:mainfrom
Mr-Neutr0n wants to merge 1 commit intofishaudio:mainfrom
Conversation
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.
Summary
logits_to_probs(), temperature scaling was applied after top-p filtering, causing the cumulative probability threshold to operate on the raw (unscaled) logit distribution rather than the temperature-adjusted onelogits / temperature) to before the top-p sorting and cumulative sum, so thattop_pfilters based on the correct probability distributiontemperature < 1.0, the previous order made top-p effectively more restrictive than intended; withtemperature > 1.0, it was less restrictiveDetails
The standard sampling pipeline order is:
Previously, the code ran top-p filtering on the raw logits and only applied temperature afterwards. Since top-p computes
softmax → cumsumto decide which tokens to keep, it needs to see the temperature-adjusted logits to make the right filtering decisions. Otherwise thetop_pparameter doesn't behave as users expect whentemperature != 1.0.Test plan
temperature=1.0, behavior is unchanged (temperature scaling is a no-op)temperature < 1.0, top-p retains fewer tokens than before (correctly more peaked distribution)temperature > 1.0, top-p retains more tokens than before (correctly flatter distribution)