fix: validate dataset mixture fractions before loading - #7142
Open
behroozazarkhalili wants to merge 4 commits into
Open
behroozazarkhalili wants to merge 4 commits into
behroozazarkhalili wants to merge 4 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
6 tasks
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.
Dataset mixtures with zero total fractions failed after downloading data, while negative fractions became negative weights. I moved validation before dataset loading and required fractions to be consistently set, nonnegative, and positive in total. The fraction tests pass and verify that invalid mixtures never call the dataset loader.
Fixes #6981.
Note
Low Risk
Input validation and error-message changes in dataset mixture loading; behavior for valid configs is unchanged aside from failing earlier on invalid fractions.
Overview
get_datasetnow validates mixturefractionsettings before anydatasets.load_datasetcall, so bad configs fail fast instead of downloading data and then hittingZeroDivisionError(all-zero fractions) or mis-normalizing negative values.The pre-load checks cover the existing rules (all-or-none fractions, no fractions with streaming) and add non-negative fractions and a strictly positive sum. Weight normalization reuses the validated
total_fraction. TheDatasetConfigdocstring documents the new constraints.A parametrized test covers all-zero and negative fraction cases and asserts
load_datasetis never invoked when validation fails.Reviewed by Cursor Bugbot for commit 81b5ebf. Bugbot is set up for automated code reviews on this repo. Configure here.