Skip to content

Validate dataset mixture fractions before loading - #7237

Open
lindicaphxag-tech wants to merge 2 commits into
huggingface:mainfrom
lindicaphxag-tech:fix/validate-dataset-fractions-v2
Open

lindicaphxag-tech wants to merge 2 commits into
huggingface:mainfrom
lindicaphxag-tech:fix/validate-dataset-fractions-v2

Conversation

@lindicaphxag-tech

@lindicaphxag-tech lindicaphxag-tech commented Sep 16, 2026

Copy link
Copy Markdown

What does this PR do?

Dataset mixtures with invalid fraction values currently fail after loading datasets, and an all-zero mixture raises an unhelpful ZeroDivisionError. This validates fractions before any dataset loading, rejects negative or non-finite values, and reports a clear error for a non-positive total.

This is an internal input-validation fix; no additional dependencies are required.

Before submitting

  • This PR fixes a typo or improves the docs (not applicable).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue? No issue link is available for this edge case.
  • Did you make sure to update the documentation with your changes? No documentation changes are needed for this internal validation fix.
  • Did you write any new necessary tests?

AI writing disclosure

  • No AI usage: the PR was written entirely by a human.
  • AI-assisted: some parts were suggested or improved by AI, but the PR was written and reviewed by a human.
  • AI-generated: the PR was mostly or fully generated by an AI tool.

Testing

  • python -m pytest tests/test_cli_utils.py::TestGetDataset::test_dataset_fraction_zero_sum_raises_before_loading tests/test_cli_utils.py::TestGetDataset::test_dataset_fraction_invalid_value_raises_before_loading tests/test_cli_utils.py::TestGetDataset::test_dataset_fraction -q (5 passed)
  • python -m pytest tests/test_cli_utils.py::TestGetDataset -q (15 passed; 2 pre-existing Windows NamedTemporaryFile permission failures)

Who can review?

Anyone in the community is free to review the PR once the tests have passed.


Note

Low Risk
Input validation only in dataset mixture loading; behavior for valid configs is unchanged aside from failing earlier on invalid fractions.

Overview
get_dataset now validates mixture fraction values before any load_dataset calls, so bad configs fail fast with clear errors instead of after expensive I/O (or with an unhelpful ZeroDivisionError when all fractions are zero).

When any dataset specifies a fraction, the check enforces: all-or-none fraction usage (unchanged), finite non-negative values, a strictly positive sum, and the existing no fractions with streaming rule. Mixture sizing logic after load is unchanged.

Tests assert load_dataset is never called for all-zero sums and for negative, NaN, or infinite fractions.

Reviewed by Cursor Bugbot for commit 4384e32. Bugbot is set up for automated code reviews on this repo. Configure here.

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.

1 participant