fix: validate dataset mixture fractions before loading - #7142
Open
behroozazarkhalili wants to merge 3 commits into
Open
fix: validate dataset mixture fractions before loading#7142behroozazarkhalili wants to merge 3 commits into
behroozazarkhalili wants to merge 3 commits into
Conversation
8 tasks
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Fractions are checked before any load_dataset call: all set or all unset, non-negative, and summing to a positive value, so an all-zero mixture no longer raises ZeroDivisionError after downloading every dataset and a negative fraction no longer becomes a negative weight. Based on the approach proposed in huggingface#6982. Fixes huggingface#6981.
behroozazarkhalili
force-pushed
the
reopen/6982
branch
from
September 9, 2026 17:25
3778a42 to
8ecd180
Compare
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?
get_datasetnormalizes mixturefractionvalues by their sum, so an all-zero mixture raisesZeroDivisionErrorafter every dataset has already been downloaded, and a negative fraction is silently turned into a negative weight. The validation now runs before anyload_datasetcall: fractions must all be set or all unset (moved up from the post-load site), non-negative, and sum to a positive value. Individual zero fractions with a positive total stay allowed. The streaming guard moves up with it. A parametrized regression test pins each rejection and asserts thatdatasets.load_datasetwas never called.Fixes #6981
Credit
The approach comes from #6982 by @cananoo, which was closed on 2026-09-09; this PR carries it as a single commit of mine, rebased onto current main.
Verification
tests/test_cli_utils.py -k fraction: 6 passed on the rebased branch (3 new cases, 3 existing).Before submitting
fractiondocstring now states the constraint.Note
Low Risk
Behavior change is limited to invalid fraction configs; valid mixtures behave the same, with earlier, clearer errors and no accidental downloads.
Overview
get_datasetnow validates mixturefractionsettings before any Hub/local load, so bad configs fail fast with clearValueErrors instead of downloading everything and then hittingZeroDivisionError(all zeros) or odd negative weights.The pre-load checks cover: fractions must be set on all datasets or none (moved up from after load), each value must be non-negative, the sum must be > 0, and fraction + streaming is still rejected. Weight normalization reuses the precomputed
total_fraction. TheDatasetConfig.fractiondocstring documents the non-negative / positive-sum rule.Tests add a parametrized case for zero-sum and negative fractions and assert
datasets.load_datasetis never called when validation fails.Reviewed by Cursor Bugbot for commit ebf4e9c. Bugbot is set up for automated code reviews on this repo. Configure here.