Skip to content

fix: validate dataset mixture fractions before loading - #7142

Open
behroozazarkhalili wants to merge 4 commits into
huggingface:mainfrom
behroozazarkhalili:reopen/6982
Open

behroozazarkhalili wants to merge 4 commits into
huggingface:mainfrom
behroozazarkhalili:reopen/6982

Conversation

@behroozazarkhalili

@behroozazarkhalili behroozazarkhalili commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

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_dataset now validates mixture fraction settings before any datasets.load_dataset call, so bad configs fail fast instead of downloading data and then hitting ZeroDivisionError (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. The DatasetConfig docstring documents the new constraints.

A parametrized test covers all-zero and negative fraction cases and asserts load_dataset is 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.

@bot-ci-comment

bot-ci-comment Bot commented Sep 9, 2026

Copy link
Copy Markdown

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug] get_dataset raises ZeroDivisionError for zero-sum fractions

1 participant