Conversation
Zero or negative ngram_size values were accepted at construction time but caused a ZeroDivisionError (or silently empty n-grams) during reward computation. Add construction-time validation consistent with the existing max_penalty check. Fixes huggingface#7015.
Member
|
Duplicate of: |
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?
Adds construction-time validation for
ngram_sizeinget_repetition_penalty_reward. Zero or negative values were accepted at construction time but caused aZeroDivisionError(or silently produced empty n-grams) during reward computation, as reported in #7015.The fix adds a check consistent with the existing
max_penaltyvalidation:Also adds a parametrized regression test covering
ngram_size=0andngram_size=-1.Fixes #7015
Before submitting
AI writing disclosure
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.
Note
Low Risk
Small input-validation change in a reward helper with regression tests; no auth, data, or training-path behavior changes beyond failing fast on invalid config.
Overview
get_repetition_penalty_rewardnow rejects non-positivengram_sizeat construction with aValueError, matching the existingmax_penaltyguard. Previously,0or negative values could slip through and fail during scoring (e.g.ZeroDivisionErrorwhenngram_size=0).A parametrized test in
tests/test_rewards.pyasserts thatngram_size0and-1raiseValueError.Reviewed by Cursor Bugbot for commit 4eec16b. Bugbot is set up for automated code reviews on this repo. Configure here.