Repository navigation
Report min_length as 0 when no sample has content - #7872
Merged
oobabooga merged 2 commits intoAug 7, 2026
Merged
Conversation
validate_dataset seeds min_length with float("inf") and only ever lowers
it inside the loop, on exactly the iterations that also append to
text_lengths. The inf->0 normalisation sat inside `if text_lengths:`, so
within that guard it could never see inf: the branch was dead, and the
case it existed for, a dataset where no sample has content, skipped the
line entirely and handed the caller min_length = inf.
all rows blank -> min_length=inf max_length=0 avg=0
zero rows -> min_length=inf max_length=0 avg=0
max_length and avg_length beside it are correctly 0 for the same input,
so the dict is internally inconsistent as well as wrong.
Hoist the normalisation out of the guard, and move the short-sample
warning onto text_lengths at the same time: with min_length now 0 for an
empty dataset, `0 < 10` would newly claim "Some samples are very short"
about zero measured samples. A genuinely short sample still warns.
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
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.
The bug
TextPreprocessor.validate_datasethands backmin_length: infwhenever no sample has content:The dict is internally inconsistent as well as wrong:
max_lengthandavg_lengthare correctly0for exactly the same input, and onlymin_lengthcomes back as a float infinity. Anything that formats, compares or serialises the stats then has to cope with aninfthat the other two fields never produce.Root cause
min_lengthis seeded withfloat("inf")and lowered only inside the loop:so it is lowered on exactly the iterations that also append to
text_lengths. The normalisation that exists to undo the seed sits insideif text_lengths::Inside that guard
min_lengthcan never beinf, because a non-emptytext_lengthsmeans themin()ran at least once. So the branch is dead, and the one case it was written for, no sample with content, skips the line entirely.The fix
Two lines. Hoist the normalisation out of the guard so it runs whether or not anything was measured, and move the short-sample warning onto
text_lengthsat the same time:That guard reads
min_length, which isinftoday, andinf < 10is false. Once the normalisation is hoisted it becomes0, and0 < 10would newly claim "Some samples are very short" about zero measured samples. So the warning has to key offtext_lengthsinstead, which is the thing that actually says whether anything was measured. Hoisting alone would trade one wrong output for another.After:
and a genuinely short sample still warns:
Scope, stated plainly
This is a correctness fix on a diagnostics dict rather than on training data.
validate_datasetis public (unsloth/dataprep/__init__.pydoesfrom .raw_text import *) so a caller can see theinf, but nothing inside the repo consumes these stats, so the blast radius is the returned value and the warning list. I would rather say that up front than dress it up.Tests
Added
test_validate_dataset_reports_zero_min_length_when_nothing_has_contentto the existingtests/test_raw_text.py, following that file's convention of a plain function that asserts, prints and returnsTrue, and wired into the__main__block with the others. It covers both empty shapes (all-blank rows and zero rows), asserts no spurious "very short" warning, and separately asserts that a genuinely short sample still warns, so a fix that hoisted the normalisation without moving the guard would fail it.Three runs, including a clean-tree control:
ruff checkwith the repo's ownpyproject.tomlreportsAll checks passed!on both changed files, and the same on the unmodified ones, so that is a real comparison rather than a config that checks nothing.The file is picked up by
Repo tests (CPU)instudio-backend-ci.yml, which auto-discoverstests/and does not ignore this path, so the new test runs in CI without a workflow change.Prior art
None.
gh issue list --search "validate_dataset min_length" --state allreturns nothing;gh pr list --search "validate_dataset" --state allreturns nothing;--search "raw_text" --state allreturns only #3612, the PR that introduced the file. No open PR touchesunsloth/dataprep/raw_text.py.