fix: validate fractions in get_dataset to prevent ZeroDivisionError - #7164
Open
CJstate wants to merge 2 commits into
Open
fix: validate fractions in get_dataset to prevent ZeroDivisionError#7164CJstate wants to merge 2 commits into
CJstate wants to merge 2 commits into
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.
- Add construction-time validation for negative fractions and zero-sum fractions - Reject negative values with clear ValueError - Require sum of fractions to be positive - Fixes huggingface#6981 Co-authored-by: CJstate <CJstate@users.noreply.github.com>
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 fractions in
get_dataset. Zero or negative values were accepted at construction time but caused aZeroDivisionError(or silently produced negative selection sizes) during dataset loading, as reported in #6981.The fix adds a check consistent with the existing validation for partial fractions and streaming:
Also adds parametrized regression tests covering negative fractions and zero-sum fractions.
Fixes #6981
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
Input validation and tests only; behavior for valid configs is unchanged and failures surface earlier with explicit errors.
Overview
get_datasetnow validates dataset mixturefractionvalues before loading any data, so invalid configs fail fast with clear **ValueError**s instead ofZeroDivisionErroror bad row selection during weighting.When any dataset uses
fraction, the mixture must still set it on all or none; additionally, every value must be non-negative and their sum must be positive. Regression tests cover negative fractions and all-zero sums (fixes #6981).Separately,
get_repetition_penalty_rewardrejectsngram_size <= 0at construction time (mirroring existingmax_penaltychecks), with parametrized tests for 0 and -1.Reviewed by Cursor Bugbot for commit 8668b23. Bugbot is set up for automated code reviews on this repo. Configure here.