Repository navigation
Fix TopHLogitsWarper: renormalized prefix entropy and full-distribution budget - #50471
Open
Andreas-Hum wants to merge 8 commits into
Open
Andreas-Hum wants to merge 8 commits into
Andreas-Hum wants to merge 8 commits into
Conversation
Extend the shared reference cases on Andreas-Hum/fix-toph-criterion and cover batch independence, shift/permutation invariance and half precision. Co-authored-by: OpenAI Codex <[email protected]>
test: add Top-H monotonicity, exponential decay, and validation checks
# Conflicts: # tests/generation/test_logits_process.py
Co-authored-by: Spartan2588 <[email protected]> Co-authored-by: 0718lol <[email protected]>
This branch has not been deployed
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.
What does this PR do?
Fixes #50228.
TopHLogitsWarperdidn't implement the rule from the Top-H paper (arXiv:2509.02510) or from its own docstring. The rule is to keep the largest prefix of the sorted tokens whose renormalized entropy is at mosttop_htimes the entropy of the full distribution. There were two problems:tauwas computed from the top-100 candidates only, not from the full distribution. On long-tailed vocabularies this made it too small.-sum p_i log p_i, not the entropy of the renormalized prefixq = p_{1..k} / P_k. SinceH(q_k) = (1/P_k) * sum_{i<=k} (-p_i log p_i) + log P_k, this is a two-line change:The docstring in
GenerationConfigalso said "smallest prefix", but the rule keeps the largest one, so that line is corrected as well.Tests.
tests/generation/test_logits_process.pygets a module-level reference,top_h_reference_num_kept, which is a plain loop over Algorithm 1 of the paper. The warper is checked against it on:-inflogits;top_h, input validation andfilter_value.Thanks to @0718lol and @Spartan2588, who wrote many of these cases (their commits are kept in this branch).
Against the current
main, 8 of the 14 Top-H tests fail.Before submitting
Pull Request checks?
to it if that's the case.
TopHLogitsWarperdoes not implement the documented Top-H rule (it bounds the unnormalized partial entropy, and takes H(p) from the top 100 tokens only) #50228Who can review?
@Cyrilvallez @Rocketknight1