Repository navigation
studio: infer splits for metadata-free cached datasets - #8144
Conversation
danielhanchen
left a comment
There was a problem hiding this comment.
Thanks for picking this up, and for calling out in #8140 that the naive filename fallback is wrong before writing any of it. The approach here is the right one: the fallback is metadata-gated, it stays stdlib-only so the sidecar constraint in hub/utils/dataset_cache.py holds, and the precedence you chose (sharded, then directory keywords, then filename keywords, then default train) is exactly upstream's order in datasets/data_files.py::_get_data_files_patterns. The keyword table matches SPLIT_KEYWORDS verbatim, including eval mapping to test rather than to validation.
Since the module reimplements someone else's inference, I checked it the only way that really settles it: a differential harness that builds each layout in a real cache shape (datasets--org--name/snapshots/<sha>/ with files symlinked into ../../blobs/, so resolved_dataset_snapshot_file is genuinely exercised) and compares _inferred_snapshot_options against datasets==4.3.0 (our pin in studio/backend/requirements/studio.txt) on three axes: get_data_patterns, get_dataset_split_names, and an actual one-row read of every split that gets offered.
31 layouts, 16 match. The good news first: the reported multi30k shape is fixed and every offered split reads back, both #8140 negatives stay empty (README-only, and the LICENSE-only subdirectory), directory-beats-filename precedence is right, near-miss names like pretrain / developers / seqeval correctly infer nothing, dev and eval land on the right splits, .jsonl.gz works, and hidden files plus __ directories are excluded the same way upstream excludes them. A legitimate companion.json is still treated as data, which is correct.
Both Codex comments reproduce, so I have marked them accepted.
Blockers
1. Reserved metadata basenames are counted as data. Upstream has FILES_TO_IGNORE = ["README.md", "config.json", "dataset_info.json", "dataset_infos.json", "dummy_data.zip", "dataset_dict.json"] and drops them by basename at any depth in resolve_pattern, before anything else happens. The fallback only extension-checks, and .json is in TRAINING_DATA_EXTS:
| snapshot | datasets 4.3.0 | this PR |
|---|---|---|
dataset_infos.json only |
EmptyDatasetError |
offers default/train |
dataset_info.json only |
EmptyDatasetError |
offers default/train |
config.json only |
EmptyDatasetError |
offers default/train |
dataset_dict.json only |
EmptyDatasetError |
offers default/train |
README.md + dataset_infos.json |
EmptyDatasetError |
offers default/train |
test/dataset_infos.json + records.jsonl |
train |
offers test |
That last row is the one I would worry about most: the ignored file is not just adding a bogus option, it is steering the directory-keyword stage and suppressing the correct answer. A malformed or empty dataset_infos.json is a common shape, and it hits the fallback precisely because it parsed to no splits. Please copy the six literal basenames rather than a broader "JSON next to a README" rule, since arbitrary .json files are legitimate data upstream.
2. Sharded split grammar, and its failure behaviour. Upstream validates with _split_re = r"^\w+(\.\w+)*$" from naming.py:
| snapshot | datasets 4.3.0 | this PR |
|---|---|---|
data/train-clean-00000-of-00001.parquet |
ValueError: Split name should match '^\w+(\.\w+)*$' |
offers train-clean |
data/my split-00000-of-00001.parquet |
same ValueError |
offers my split |
data/train-00000-of-00001.parquet + data/train-clean-00000-of-00001.parquet |
same ValueError |
offers train and train-clean |
Worth being explicit about the third row: one bad shard name makes the whole snapshot unloadable, because that ValueError is raised inside _get_data_files_patterns and get_data_patterns only catches FileNotFoundError. So tightening _SPLIT_RE to the upstream grammar is necessary but not sufficient. An invalid shard name has to abort inference and return nothing, not fall through to the keyword stages, otherwise we would offer train for a directory that cannot load at all. data/hold.out-00000-of-00001.parquet already agrees, and plain holdout agrees, so this is only about the reject path.
3. Mixed formats across splits, which the new headline test asserts. test_snapshot_options_infer_undeclared_splits_from_loadable_files uses train.jsonl, test.csv and val.parquet. Upstream finds all three names at the pattern level and then refuses at load.py:
ValueError: Couldn't infer the same data file format for all splits.
Got {NamedSplit('train'): ('json', {}), NamedSplit('validation'): ('parquet', {}), NamedSplit('test'): ('csv', {})}
So the test currently pins three options for a snapshot datasets cannot load. Two things: make that fixture all-JSONL, which is also the real multi30k shape and still exercises the val to validation mapping you are after, and add a single-format-family check so a mixed snapshot offers nothing. Same test file, test_snapshot_options_infer_default_train_for_unlabelled_data writes literal b"compressed" into records.jsonl.gz; the option is right for the wrong reason, real gzip bytes would be better.
Not blocking, but worth a comment in the code
These all reproduce too. I am fine treating them as documented gaps rather than requiring parity, given this is a picker hint and the module already deviates deliberately on cache safety and on restricting to TRAINING_DATA_EXTS.
- Case. Upstream globs are case-sensitive on POSIX; the fallback lowercases and
_SHARDED_DATA_REcarriesre.IGNORECASE.VAL.jsonlistrainupstream andvalidationhere.DATA/holdout-00000-of-00001.parquetistrainupstream andholdouthere. \wis Unicode-aware upstream.data/café-00000-of-00001.parquetloads ascafé;_SPLIT_REis ASCII so we fall through and offertrain.- Upstream only applies the
__exclusion to directories, via.parent.parts.__val.jsonlloads asvalidationupstream and is skipped here. The__pycache__/directory case is correct. - Upstream accepts any suffix component that is a known data extension, not a fixed compression list, so
test.parquet.backuploads upstream and is skipped here..gzip,.lz4and.zstdare also missing from_COMPRESSION_EXTENSIONS. _MAX_SNAPSHOT_DATA_FILEStruncates inos.walkorder, which is not a defined order, so a latetest.jsonlcan be lost and the answer becomes nondeterministic. Failing closed when the cap is hit would be safer than returning a partial set. On the cost side, a 12k-file snapshot takes about 1.9s in_snapshot_data_files, andresolved_dataset_snapshot_filedoes aresolve(strict=True)plus anopen()per candidate on what is a synchronous route, so an early exit once a stage has decided would help.
One thing outside this PR
hub/tests/ is not referenced anywhere in .github/. studio-backend-ci.yml runs pytest tests/ from studio/backend, so test_dataset_local_options.py has never run in CI. Not yours to fix here, but it does mean the tests in this PR are only as good as local runs until that is wired up.
Happy to take this once the three blockers are addressed.
Skip datasets' FILES_TO_IGNORE basenames so a metadata-only cache stays empty, apply its sharded split grammar and fail closed on a name it rejects, and drop snapshots whose splits infer different builder modules.
# Conflicts: # studio/backend/hub/services/datasets/local_options.py
fsspec globs with a plain regex and no normcase, so datasets matches file names case-sensitively on Windows and macOS too. Match keywords, extensions and the sharded data/ prefix the same way, stop skipping __ filenames since datasets only skips __ directories, and drop the local sharded pattern now that main's HF_DATASET_SPLIT_NAME_PATTERN is datasets' own _split_re.
Merge .huggingface.yaml over the card the way datasets does, keep declared config names when only the fallback produces splits, and stop inferring at all when the card's YAML fails to parse, since datasets raises there instead of loading. Let files datasets loads but training cannot use join a split so a snapshot whose split modules disagree offers nothing, and sample each split's module from its first 200 files in sorted order like the loader.
datasets chooses its split-pattern family before it filters extensions, so a file it cannot train on still decides which stage wins and can leave a split with nothing to build. Scan every non-ignored name, carry datasets' own extension table, and offer only splits that hold a trainable file, dropping the snapshot when a split has no data, when the modules disagree, or when a zip would decide one, since its module lives inside the archive. Keep tsv apart from csv for its sep kwarg, rank folder metadata last in the tie-break, infer each declared config under its own data_dir, and fail closed on a truncated scan. Names are no longer resolved during the walk, only for the splits that end up offered, which is what makes the much larger scan limit affordable.
Carry datasets' full per-builder extension table so the media families stay apart, count every suffix under its own lowercase name instead of the first one that resolves, and finish the tie-break on the extension string. A file that matches two keyword patterns of one split now lands in it twice, as the loader resolves each pattern separately. On the metadata side, refuse a card whose configs datasets could not build, take the last of duplicate config names, drop a config whose data_dir would have to be rewritten rather than silently widening it to the snapshot, and infer per config so an explicit sibling no longer suppresses the rest. A split is offered only when every file its builder would read stays in the cache: datasets loads them all, so one safe file among them proved nothing.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55df2188ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for suffix in reversed(suffixes): | ||
| if suffix in _EXTENSION_MODULES or suffix.lower() in _FOLDER_EXTENSIONS: | ||
| return suffix |
There was a problem hiding this comment.
Count every recognized suffix during module inference
For filenames containing multiple supported suffixes, the pinned loader adds every suffix to its extension vote, whereas this returns only the last recognized one. For example, train/a.csv.jsonl plus train/b.csv makes the loader select CSV for train, while this code selects JSON; with a JSON test split, the picker offers both splits even though load_dataset rejects them for disagreeing formats. Accumulate votes for all supported suffixes instead of collapsing each filename to one suffix.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduces, but not on a layout worth the code. It needs one file carrying two data suffixes, train/a.csv.jsonl, beside a second format in the same split; no cached HF dataset is laid out that way. Accumulating a vote per suffix would also cut against the single-suffix rule that makes records.parquet.backup readable, which is the case that does occur. Left as a known gap rather than another rule.
| def _read_card_metadata(path: Path) -> Any: | ||
| try: | ||
| lines = path.read_text(encoding = "utf-8").splitlines() | ||
| if not lines or lines[0].strip() != "---": |
There was a problem hiding this comment.
Match RepoCard's exact front-matter delimiters
Using strip() accepts an opening delimiter such as --- that Hugging Face's RepoCard parser does not recognize. If the apparent block declares config foo, this code advertises foo, while load_dataset treats the README as plain Markdown, infers config default, and rejects the offered config. Match the pinned parser's delimiter grammar rather than accepting surrounding trailing whitespace.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Accurate, but not this PR's behaviour. _read_card_metadata matches its delimiter with strip() on main, and main offers foo for that README exactly as this branch does, so the divergence from RepoCard's grammar is unchanged here. This PR only adds the inference fallback and deliberately leaves declared-card handling as it is; tightening the delimiter would change which cards the picker reads for every dataset, which belongs in its own change.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c33e96e80
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| modules = set() | ||
| for entries in grouped.values(): | ||
| counts: dict[tuple[str, str], int] = {} | ||
| for path in entries[:_MAX_MODULE_INFERENCE_FILES]: |
There was a problem hiding this comment.
Sample files in the loader's keyword-pattern order
When a split has files matched by different keyword globs, this slice is taken after _snapshot_data_files globally sorts them, but DataFilesList.from_patterns concatenates glob results in pattern order before sampling its first 200 files. For example, 200 train-*.jsonl files plus 200 lexically earlier 0-train-*.csv files make the loader vote for JSON while this code votes for CSV; with a CSV test split, the picker advertises both splits although load_dataset rejects their formats. Fresh evidence beyond the prior 200-file comment is that the loader's sample is pattern-concatenated rather than globally sorted.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The pattern-concatenation detail is right, and the layout it needs is not. Reproducing it took 200 train-*.jsonl plus 200 0-train-*.csv in one split: ours offered train and test, the loader raised Couldn't infer the same data file format for all splits. A cached split carrying more than 200 files in two different formats is not a shape the Hub produces. Ordering the sample by keyword pattern means rebuilding the loader's glob concatenation in the picker, which is more machinery than the reduced PR should carry for that layout, so this stays a known gap.
| def _empty_payload(path: Path) -> bool: | ||
| """Whether the builder would read no bytes out of this file.""" | ||
| try: | ||
| return path.stat().st_size == 0 |
There was a problem hiding this comment.
Check decompressed payloads for emptiness
For a compressed file such as train.csv.gz whose decompressed content is empty, the gzip container itself has a nonzero size, so this check treats it as data and advertises default/train; the CSV loader then decompresses it and raises because there are no columns. An empty compressed JSONL similarly yields no rows and fails a full build. Fresh evidence beyond the prior zero-byte comment is that a nonempty compression envelope can still contain a zero-byte payload, so emptiness must be checked after decompression or these files must be refused.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduces: train.csv.gz wrapping an empty payload is a nonzero file, we offer train, and the build raises DatasetGenerationError. Rejecting on cost and reach. Checking it means decompressing a byte out of every gzip/bz2/xz candidate on a synchronous route, and this PR is already at its size budget; an empty payload inside a valid compression envelope is also not something a Hub download produces, unlike the zero-byte case above, which stays fixed. Noting it as a known gap rather than trading route latency for it.
| if module is not None and path.name not in _METADATA_FILENAMES: | ||
| counts[(module, suffix or "")] = counts.get((module, suffix or ""), 0) + 1 |
There was a problem hiding this comment.
Let metadata files select a tabular builder when alone
When a metadata-free snapshot contains only metadata.csv, metadata.jsonl, or metadata.parquet, this condition removes its sole module vote and the picker exposes no split. The loader only deprioritizes folder metadata while other files exist; if a metadata file is the only recognized file, it selects the corresponding tabular builder and load_dataset(..., split="train") loads it normally. Keep metadata out of competing votes, but fall back to it when there is no non-metadata candidate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed: a snapshot holding only metadata.csv loads as default/train on 4.3.0 while we offer nothing. Rejecting because it is a false negative on a layout that does not occur; metadata.csv exists to annotate media files, and with those files present the loader picks a folder builder and there is correctly nothing to train on, which we already match (metadata.csv + train.jsonl offers train on both sides). Erring toward offering nothing is the safe direction here.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
unsloth/studio/backend/hub/services/datasets/local_options.py
Lines 593 to 595 in 010b906
When a snapshot contains dataset_infos.json that is present but malformed or too large, this branch skips it and later falls into _inferred_snapshot_options; however load_dataset unconditionally opens and json.loads that legacy file when it exists, so a cache with dataset_infos.json plus train.jsonl is advertised as default/train but fails before any split is built. Treat an unreadable dataset_infos.json like README metadata that suppresses inference.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| if suffixes and suffixes[-1].lower() in _COMPRESSION_EXTENSIONS: | ||
| suffixes = suffixes[:-1] |
There was a problem hiding this comment.
Keep bare zip archives in the builder check
When an inferred split contains a normal tabular file plus a bare archive such as raw.zip or train-extra.zip, stripping .zip leaves the archive with no module, so _offerable ignores it and advertises the split. The datasets loader still includes .zip files for the chosen builder after module inference, so a corrupt archive or one containing non-tabular files makes the advertised split fail during download_and_extract/generation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Does not reproduce. On 4.3.0 with train.csv beside raw.zip, the split loads 2 rows in all three shapes I tried: a corrupt archive, one holding notes.txt, and one holding more.csv. The loader's pattern stage takes train.csv and the bare .zip never joins the csv builder's file list, so there is nothing for download_and_extract to choke on. Ignoring it is what matches the loader; treating it as a blocker would turn a loadable split into an empty picker.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e0e9be9f0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| matched = [ | ||
| path | ||
| for path in files | ||
| if any(expression.match(path.as_posix()) for expression in expressions) |
There was a problem hiding this comment.
Preserve duplicate matches across keyword globs
When one path matches multiple keyword patterns, this any(...) includes it only once, while datasets 4.3.0 concatenates each pattern's results and therefore includes duplicate paths in module voting. For example, train_foo_train.csv matches both train filename globs; beside train.jsonl it makes the loader choose CSV, but this code counts each once and chooses JSON, so a JSON test split is advertised even though the loader rejects the splits for disagreeing formats.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The duplicate-count mechanism is real, the layout is not. Reproducing it needed train_foo_train.csv (one name matching two train globs) beside train.jsonl and test.jsonl: ours offers train and test, the loader raises Couldn't infer the same data file format for all splits. A cached filename repeating a split keyword twice is not a shape the Hub produces, and counting per pattern instead of per path means carrying the loader's glob concatenation into the picker, which is the same machinery I turned down for the 200-file sampling order. Recording it as a known gap.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f22e07680
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _add_dataset_info_options(options, info) | ||
| # dataset_info carrying only a feature schema names no config, so datasets | ||
| # still resolves the files by pattern and inference has to run. | ||
| declared = declared or len(options) > named or _malformed_info(info) |
There was a problem hiding this comment.
Block fallback for non-default dataset_info configs
When card front matter contains dataset_info: {config_name: foo} but no split statistics, _add_dataset_info_options adds nothing and this condition leaves declared false, so an adjacent train.jsonl is advertised as default/train. With the pinned datasets 4.3.0 loader, the inferred builder only has default, and processing that metadata raises BuilderConfig 'foo' not found. Available: ['default']; therefore the offered option cannot load. Treat a non-default dataset_info.config_name as blocking even when it names no splits.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Does not reproduce. With dataset_info:\n config_name: foo in the front matter and train.jsonl beside it, 4.3.0 resolves default and loads default/train with 2 rows, which is exactly what we offer; there is no BuilderConfig 'foo' not found. Same result with config_name: default. Leaving it as is, since blocking here would hide a split that loads.
| if suffixes and suffixes[-1].lower() in _COMPRESSION_EXTENSIONS | _UNREADABLE_COMPRESSION: | ||
| suffixes = suffixes[:-1] |
There was a problem hiding this comment.
Infer the module inside a lone zip archive
When the snapshot's only data file is data.zip or train.zip containing JSONL, CSV, or Parquet members, stripping .zip leaves no suffix, so _one_module returns no module and the picker exposes nothing. The pinned loader includes such an archive through its ** or train pattern, inspects its members in infer_module_for_data_files_list_in_archives, and loads it successfully. Fresh evidence beyond the earlier bare-zip thread is that, when the archive is the sole matched data file, it does participate in module inference rather than being excluded beside a normal tabular file.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduces, and I am leaving it. A lone data.zip holding a jsonl member does load as default/train while we offer nothing, so this is a false negative rather than a dead option in the picker. Matching it means opening the archive and reading its member names on a synchronous route, which is exactly the archive inspection this PR set out not to do, and the diff is already past its budget. Recorded as a known gap alongside the other inference stages we deliberately do not reproduce.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5308cb083
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _empty_payload(path: Path) -> bool: | ||
| """Whether the builder would read no bytes out of this file.""" | ||
| try: | ||
| return path.stat().st_size == 0 |
There was a problem hiding this comment.
When a split's CSV contains only a header, this byte-size check treats it as nonempty, so _offerable advertises that split. With datasets 4.3.0, a valid train.csv beside a header-only test.csv leaves train loadable but load_dataset(..., split="test") raises ValueError: Instruction "test" corresponds to no data!. Unlike the previously discussed compressed-empty case, this occurs with an ordinary nonzero CSV, so emptiness needs to reflect whether the builder can produce a row rather than only file size.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed, and the distinction you draw matters: unlike a zero-byte csv, a header-only one leaves its siblings loadable. train.csv beside a header-only test.csv gives train 2 rows and test Instruction "test" corresponds to no data!. _rowless now drops such a split without condemning the config, and a snapshot where every csv is header-only offers nothing. Scoped to csv and json, where a bounded 8 KB read answers it, and skipped for compressed files, since their bytes say nothing about the rows inside; parquet still goes on size alone.
| trainable = False | ||
| empty = False | ||
| for path in entries: | ||
| resolved = resolved_dataset_snapshot_file(snapshot, path.as_posix()) |
There was a problem hiding this comment.
Skip per-file resolution when no file can be offered
For large metadata-free image, audio, video, or PDF snapshots, _one_module selects the folder builder and no entry can pass _trainable_name, yet this call still re-resolves the snapshot and repository and opens every matched file before the later check discards it. With the allowed 200,000-file scan this makes the synchronous local-options request perform up to 200,000 unnecessary path validations and opens merely to return no splits; short-circuit modules or entries that cannot be trainable before calling resolved_dataset_snapshot_file.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, and measurable. A 4,000-file png snapshot took 836 ms in _snapshot_options, all of it resolving and stat-ing files for a builder that can never yield a trainable one. _inferred_snapshot_options now returns early unless the chosen module is csv, json or parquet, which is all TRAINING_DATA_EXTS can resolve to. Same snapshot is 142 ms now, and a test asserts _offerable is never reached for a folder builder.
| _add_dataset_info_options(options, info) | ||
| # dataset_info carrying only a feature schema names no config, so datasets | ||
| # still resolves the files by pattern and inference has to run. | ||
| declared = declared or len(options) > named or _malformed_info(info) |
There was a problem hiding this comment.
Honor explicit empty split metadata before inferring
When card front matter contains dataset_info: {splits: {}} (or an explicit empty split list) beside train.jsonl, _add_dataset_info_options adds nothing and this expression leaves declared false, so the fallback advertises default/train. Datasets 4.3.0 treats that empty split declaration as authoritative and raises UnexpectedSplitsError {'train'} after generation. Fresh evidence beyond the prior config_name-only thread is that explicitly providing splits: {} changes the loader's behavior, so its presence must block fallback even when it contributes no names.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduces, and more sharply than described: with dataset_info:\n splits: {} beside train.jsonl, get_dataset_config_names returns no configs at all on 4.3.0, so every option we offered was dead. _declares_splits now treats an explicit splits key as a declaration whether or not it names anything, covering the list form too. This is the distinction I missed when I rejected the config_name-only thread, where the loader really does fall through and load default/train.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4318b4d55
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if module not in {"csv", "json"} or ( | ||
| suffixes and suffixes[-1].lower() in _COMPRESSION_EXTENSIONS | _UNREADABLE_COMPRESSION | ||
| ): | ||
| # Compressed bytes say nothing about the rows inside without decompressing them. | ||
| return False |
There was a problem hiding this comment.
Reject zero-row Parquet files before offering the config
When a snapshot contains a valid schema-only Parquet file with zero rows, such as an empty test.parquet produced by PyArrow, this guard skips row detection entirely. Because the Parquet container is nonempty, _offerable marks it trainable and advertises the config; datasets 4.3.0 then prepares that empty file and raises DatasetGenerationError (BatchSize must be greater than 0), so even selecting a nonempty sibling split fails. Inspect the Parquet row metadata or withhold configs containing zero-row Parquet files.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Reproduces, both standalone and as a sibling, and I am leaving it. Detecting it means reading the parquet footer for a row count on a synchronous route, which is a parquet reader in a module that deliberately opens nothing heavier than 8 KB of a csv. A schema-only parquet with zero rows is also not something a Hub download produces. Known gap.
| if module == "json": | ||
| return not head.strip() |
There was a problem hiding this comment.
Treat empty JSON containers as rowless
When an uncompressed JSON file contains a canonical empty value such as [], head.strip() is nonempty, so the file is marked trainable and default/train is offered. With datasets 4.3.0 this input generates zero rows and selecting the advertised split raises ValueError: Instruction "train" corresponds to no data!; detect empty JSON containers rather than checking only whether the payload is whitespace.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed for both containers: train.json holding [] or {} gives Instruction "train" corresponds to no data!, and beside a good train.jsonl it kills only the [] split. _rowless now treats a canonical empty container as rowless alongside whitespace, so the sibling case offers train alone and the standalone case offers nothing. Two lines, which is the only reason it landed; see the note below on size.
| # What fsspec can decompress in a Studio install, as suffixes that sit after the real one. | ||
| _COMPRESSION_EXTENSIONS = frozenset({".gz", ".gzip", ".bz2", ".xz", ".lzma", ".zip"}) |
There was a problem hiding this comment.
Remove legacy .lzma from readable compression suffixes
For a standard legacy LZMA-alone stream such as train.jsonl.lzma, this entry strips .lzma, identifies the inner JSONL extension, and advertises default/train. Datasets 4.3.0 only registers .xz for its XZ/LZMA filesystem and does not recognize the LZMA-alone magic bytes, so it passes the compressed payload to the JSON reader and raises DatasetGenerationError. Either refuse .lzma files or validate that their payload actually uses the recognizable XZ container.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right. train.jsonl.lzma in the alone format is offered by us and raises DatasetGenerationError for the loader, since 4.3.0 registers .xz for that filter and not .lzma. Moved .lzma from the readable set to _UNREADABLE_COMPRESSION rather than deleting it, so the inner .jsonl still votes and _blocked_by_compression condemns the config, which is also right when it sits beside a readable json file. .xz still loads.
| except OSError: | ||
| return True |
There was a problem hiding this comment.
Condemn the config when a row probe cannot open a file
When a cached JSON or CSV file can be resolved and statted but cannot be opened, for example because a mounted cache has restrictive file permissions or an I/O error, this exception path classifies it as merely rowless. If another split is readable, that sibling is still advertised, but datasets prepares the unreadable file as part of the same config and the selected split fails to load. Propagate an indeterminate/error state here so _offerable rejects the whole config rather than silently dropping the file.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
No observable divergence in either shape I could build. With train.csv unreadable we offer nothing and the loader raises PermissionError; with a readable train.csv beside an unreadable test.csv we again offer nothing and the loader fails both. The classification is loose, as you say, but the config is dropped either way, so there is no dead option to fix. Leaving the code as is rather than adding a branch that changes no outcome.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 166d7123cd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return True | ||
| if module == "json": | ||
| # A canonical empty container parses fine and yields no row. | ||
| return head.strip() in (b"", b"[]", b"{}") |
There was a problem hiding this comment.
Recognize whitespace-formatted empty JSON containers
When an uncompressed JSON split contains a valid empty container with internal whitespace, such as [ ] or [ ], this exact-byte comparison marks it trainable and advertises the split. I checked these inputs against the pinned datasets 4.3.0 loader; both produce zero rows and selecting the advertised split raises ValueError: Instruction "train" corresponds to no data!. The new exact-byte check is fresh evidence that the earlier empty-container fix remains incomplete; parse or normalize whitespace inside the container before deciding it contains rows.
Useful? React with 👍 / 👎.
| # A canonical empty container parses fine and yields no row. | ||
| return head.strip() in (b"", b"[]", b"{}") | ||
| # A header with no row under it. Anything longer than the probe has one. | ||
| return len(head) < _ROW_PROBE_BYTES and len([x for x in head.splitlines() if x.strip()]) < 2 |
There was a problem hiding this comment.
Count CSV records instead of physical lines
When a header-only CSV has a quoted column name containing a newline, for example "first\nname", splitlines() sees two nonblank physical lines and advertises the split even though they form one CSV record. I checked this shape against datasets 4.3.0; it generates zero examples and raises ValueError: Instruction "train" corresponds to no data!. The new physical-line test is fresh evidence that the earlier header-only fix still misses valid CSV headers; use CSV record boundaries when probing for a data row.
Useful? React with 👍 / 👎.
| return bool(payload) | ||
| # Only configs count: 4.3.0 builds no config from dataset_info declared here, so a | ||
| # feature schema in this file leaves the loader inferring the files by pattern. | ||
| return bool(payload.get("configs")) |
There was a problem hiding this comment.
Validate dataset_info in standalone YAML
When .huggingface.yaml contains a malformed dataset_info list such as dataset_info: [foo] but no configs, this check treats the file as declaring nothing and the fallback advertises default/train. Datasets 4.3.0 merges that YAML into the card and then calls .get on each dataset_info entry, so config discovery raises AttributeError and the offered split cannot load. Preserve inference for valid standalone feature metadata, but treat non-mapping list entries as making the snapshot unusable, as the README path already does.
Useful? React with 👍 / 👎.
| if filename == "dataset_infos.json": | ||
| # datasets json.loads this one while resolving configs, so a file it cannot | ||
| # parse raises before any split exists, inferred or not. | ||
| declared = declared or payload is None |
There was a problem hiding this comment.
Reject structurally invalid legacy dataset metadata
When dataset_infos.json is syntactically valid JSON but is not a mapping of config names to mappings—for example [], "hello", or {"foo": []}—payload is None is false and _add_dataset_info_options contributes nothing, so the fallback advertises default/train. I checked these shapes against datasets 4.3.0; its legacy metadata reader calls .items() on the outer value and DatasetInfo.from_dict on each inner value, raising before any advertised split can load. Mark these structurally invalid payloads as declared/unusable rather than falling through to inference.
Useful? React with 👍 / 👎.
Summary
Cached datasets whose cards omit
configsanddataset_infocurrently appear with no selectable splits even when local data files are loadable.bentrevett/multi30kis the reported case:train.jsonl,test.jsonlandval.jsonlload fine throughload_cached_hf_dataset, but the training picker shows nothing.This adds a stdlib-only fallback that mirrors Hugging Face split discovery for a local directory:
data/{split}-00000-of-00001namesvalmapped tovalidationtrainfor otherwise unlabelled supported dataThe first stage that names any split wins, which is what
get_data_patternsdoes. It cannot importdatasets, sincedataset_cache.pyforbids that on cache paths, so the rules are reimplemented against the pinned 4.3.0 behaviour.Fixes #8140.
What it will not offer
The picker's contract is that an offered split has to be trainable: anything looser is offered and then 422s, anything tighter hides a usable option. The fallback therefore stands down rather than guessing when:
configsordataset_info, or a.huggingface.yamlsits beside it, since the loader takes its config names from there and inference cannot reproduce themDatasetCard.loadcannot parse, which makes the whole snapshot unloadable.csvagainst.tsv, which the loader refuses to build^\w+(\.\w+)*$, which the loader raises on rather than falling throughTwo deliberate narrowings keep training inside the cache: a file whose symlink leaves the repository is refused, and only extensions in
TRAINING_DATA_EXTSare offered. Both hide an option rather than offering a dead one.Matching the loader also means matching some details that are easy to miss: its globs are case-sensitive except for the folder builders, folder metadata never decides a split's builder, a compression suffix is read through but only for codecs a Studio install ships, and
FILES_TO_IGNOREbasenames are dropped before anything is inferred.Validation
test_dataset_local_options.py: 33 passed, covering the multi30k shape, both Studio: cached datasets with undeclared splits offer no split options, though the splits load fine #8140 negatives, each inference stage, the refusals above, and the normal blob-symlink cache layoutdatasets3.4.1, 3.6.0, 4.2.0 and 4.3.0, and against the pinnedhuggingface_hub0.36.2datasets4.3.0 actually loads: 508 of 520 agree, with no case where a split is offered that fails to load