Repository navigation
Load the data files a caller asked for from script-based repos - #353
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The Hub fallback path needs additional hardening (empty/unsupported data_files validation and consistent application of revision) to avoid crashes or loading the wrong dataset revision.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes incorrect HuggingFace Hub fallback behavior when datasets refuses legacy dataset scripts by ensuring the fallback loads exactly the caller-declared data_files (instead of widening selection via subset substring matching). It also expands DataSource.data_files to support multi-file splits (via tuple[str, ...]) while preserving stable serialization for existing single-file tasks, and it introduces sandbox “stage files then execute” support to avoid OS argv size limits for large fixtures.
Changes:
- Update HuggingFace backend hub-file fallback to honor explicit
data_files, with tests covering non-widening behavior and subset fallback behavior. - Allow
DataSource.data_filesto bestr | tuple[str, ...]and serialize tuples as lists while keeping single strings unchanged; add tests for hashing and serialization. - Add sandbox file staging support (
write_files,execute_with_files) plus protocol surface (StagingExecutionEnvironment) and concurrency tests.
File summaries
| File | Description |
|---|---|
| tests/data/test_sources.py | Adds coverage for tuple data_files persistence, serialization, and hashability. |
| tests/data/test_hub_file_selection.py | New tests ensuring hub fallback loads only declared files and still supports subset matching. |
| tests/core/harness/test_sandbox_file_staging.py | New tests for staging files before execution and ensuring correct executor affinity/capacity behavior. |
| src/olmo_eval/harness/sandbox/manager.py | Adds execute_with_files to route staging+execution through a single executor lease. |
| src/olmo_eval/harness/sandbox/executor.py | Adds write_files to send file contents via request body instead of argv. |
| src/olmo_eval/data/sources.py | Extends DataSource.data_files type and updates dict serialization for tuples. |
| src/olmo_eval/data/backends/huggingface.py | Implements declared-file selection in hub fallback; normalizes tuple data_files for datasets.load_dataset. |
| src/olmo_eval/common/execution/environment.py | Introduces StagingExecutionEnvironment protocol for environments that can stage files. |
| src/olmo_eval/common/execution/init.py | Exports StagingExecutionEnvironment from the execution package. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| declared = kwargs.get("data_files") | ||
| if declared is not None: | ||
| # An explicit file list names the split exactly; subset matching | ||
| # would silently widen it to every data file in the repository. | ||
| candidates = [declared] if isinstance(declared, str) else list(declared) | ||
| else: |
| candidates = [declared] if isinstance(declared, str) else list(declared) | ||
| else: | ||
| api = HfApi(token=token) | ||
| repo_files = api.list_repo_files(path, repo_type="dataset") |
| f"No data files matching subset '{subset}' in {path}. " | ||
| f"This dataset has a legacy loading script that is no longer supported." | ||
| ) | ||
|
|
||
| ext = candidates[0].rsplit(".", 1)[-1] |
datasets 4.x refuses to run a repository's legacy loading script, so the HuggingFace backend falls back to reading the repository's data files directly. That fallback picked files by testing whether the subset name appears in each filename, and with no subset configured the empty string matches every filename in the repository. Any explicitly declared data file was therefore ignored, and a request for one file quietly returned all of them. On livecodebench/code_generation_lite, asking for the 400 problems in test.jsonl returned all 1055 across the six release files, with nothing to indicate the request had been widened. The fallback now loads exactly the files a caller declared, and falls back to subset matching only when none were. DataSource.data_files accepts a tuple as well as a string, since a split can span several files, which the underlying load_dataset has always supported. Existing single-file declarations stay strings and serialize as strings. That matters because DataSource.to_dict feeds compute_task_hash, and results are stored under that hash: emitting a list for those tasks would move the hash for every task declaring data_files and detach their stored results from future runs. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 4780dff)
4780dff to
eece26a
Compare
…hat cannot be read Review feedback on the Hub fallback. The fallback ignored DataSource.revision, though the primary load path honors it. A pinned dataset that fell back therefore read whatever the default branch holds, silently, which is the same class of bug this change set exists to fix: a caller's selection quietly replaced by something else. frontierscience pins a revision alongside data_files today. The revision now reaches both the file listing, so selection is computed against the contents being read, and the file URLs. An empty data_files raised IndexError from candidates[0]. It now says what is wrong, since an empty selection is a caller mistake rather than a missing file. The loader module was taken from the first file's extension without checking it. Naming a file the fallback cannot read, such as a documentation file reached by a typo, surfaced as an obscure parsing error, and a mixed set was read entirely as whatever the first file happened to be. Both now fail with a message naming the offending files. The supported types live in one mapping that the subset filter shares, rather than being spelled out twice. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Thanks — all three were right and are fixed in 3bd8b5a.
I had actually written the Empty No extension validation for declared files — correct, and slightly worse than described. The loader module was taken from the first file's extension with no check, so a mixed set like Six new tests cover the revision on both paths, the unpinned case, and the three rejections. One note on the review's file list: it covered 9 files including the sandbox staging ones, because this branch was stacked on #352 when the review ran. They're now both based on |
abhishekraok
left a comment
There was a problem hiding this comment.
Thanks for the fixes. One issue remains.
Claude: Test coverage doesn't reach load(). Every test calls the private _load_from_hub_files and passes data_files=/revision= explicitly while also setting them on the source, so nothing asserts that load() forwards them into kwargs — the integration where the bug actually lived. No test drives load() through the fallback at all.
The existing tests called _load_from_hub_files directly and handed it the data_files and revision kwargs, so nothing asserted that load() builds those kwargs from the source and forwards them, and nothing exercised the error matching that dispatches to the fallback at all. Deleting load()'s entire kwargs block left the whole suite green. Drive the fallback through load() instead: a loader stub fails the first call the way datasets rejects a legacy loading script, and the tests assert on both the attempted call and the one the fallback makes. This pins the tuple-to-list conversion datasets requires, the revision, and both error strings that trigger the fallback, and keeps unrelated failures propagating.
The bug
datasets4.x refuses to run a repository's legacy loading script, soHuggingFaceBackendfalls back to reading the repository's data files directly. That fallback chose files by testing whether the subset name appears in the filename:With no subset configured,
subsetis""— and"" in filenameis true for every file in the repository. Any explicitly declareddata_fileswas ignored, and a request for one file quietly returned all of them.Measured on
livecodebench/code_generation_lite, whose six files are separate benchmark releases: asking for the 400 problems intest.jsonlreturned all 1055 across all six, with nothing to indicate the request had been widened. A caller gets a plausible-looking dataset that is not the one they asked for.Fix
The fallback now loads exactly the files a caller declared, and falls back to subset matching only when none were declared.
DataSource.data_filesalso accepts atuple[str, ...]as well as astr, since one split can span several files — something the underlyingload_datasethas always supported (str | Sequence[str] | Mapping[...]) and thatDataSourcehad narrowed since the initial commit.Why the union type, and not tuple everywhere
tuplealone would be a quiet breaking change.DataSource.to_dict()feedsTaskConfig.to_dict(), which feedscompute_task_hash(), and results are stored under that hash. Serializing"olympiad/test.jsonl"as["olympiad/test.jsonl"]moves the hash:11 registered tasks declare
data_filestoday (frontierscience_*,astabench_*, eightbasic_skills_*). Moving their hashes would detach every stored result from future runs, and the analysis tooling joins ontask_hash.So existing single-file declarations stay strings and serialize as strings. A separate consideration:
data_sourceis reachable from CLI overrides, where values arrive as strings, and an always-tuple field would silentlylist()a string into seven single-character filenames.Tests
tests/data/test_hub_file_selection.py— declared files are the only ones loaded; a single declared file is not widened; subset matching still works when nothing is declared; a missing subset still raises.tests/data/test_sources.py— tupledata_filessurviveswith_split/with_subset, serializes as a list, leaves single-file declarations untouched, and keepsDataSourcehashable.Independent of #352 — the two share no files and can be reviewed in either order. #354 (LiveCodeBench) depends on both and contains them.
🤖 Generated with Claude Code