Skip to content

Load the data files a caller asked for from script-based repos - #353

Merged
gregorybchris merged 4 commits into
mainfrom
chrisg/hf-data-files-selection
Sep 9, 2026
Merged

gregorybchris merged 4 commits into
mainfrom
chrisg/hf-data-files-selection

Conversation

@gregorybchris

@gregorybchris gregorybchris commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

The bug

datasets 4.x refuses to run a repository's legacy loading script, so HuggingFaceBackend falls back to reading the repository's data files directly. That fallback chose files by testing whether the subset name appears in the filename:

subset = source.subset or ""
candidates = [f for f in repo_files if subset in f and ...]

With no subset configured, subset is "" — and "" in filename is true for every file in the repository. Any explicitly declared data_files was 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 in test.jsonl returned 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_files also accepts a tuple[str, ...] as well as a str, since one split can span several files — something the underlying load_dataset has always supported (str | Sequence[str] | Mapping[...]) and that DataSource had narrowed since the initial commit.

Why the union type, and not tuple everywhere

tuple alone would be a quiet breaking change. DataSource.to_dict() feeds TaskConfig.to_dict(), which feeds compute_task_hash(), and results are stored under that hash. Serializing "olympiad/test.jsonl" as ["olympiad/test.jsonl"] moves the hash:

frontierscience_olympiad, data_files as str   : 5901a8f78e0afbee
frontierscience_olympiad, data_files as tuple : 04f9e11d001651d9

11 registered tasks declare data_files today (frontierscience_*, astabench_*, eight basic_skills_*). Moving their hashes would detach every stored result from future runs, and the analysis tooling joins on task_hash.

So existing single-file declarations stay strings and serialize as strings. A separate consideration: data_source is reachable from CLI overrides, where values arrive as strings, and an always-tuple field would silently list() 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 — tuple data_files survives with_split/with_subset, serializes as a list, leaves single-file declarations untouched, and keeps DataSource hashable.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_files to be str | 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.

Comment on lines +94 to +99
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")
Comment on lines 112 to 116
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)
…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]>
@gregorybchris

Copy link
Copy Markdown
Collaborator Author

Thanks — all three were right and are fixed in 3bd8b5a.

revision ignored in the fallback (both the listing and the file fetch) — correct, and this was the most important of the three. The primary path honors revision; the fallback silently didn't, so a pinned dataset that fell back read whatever the default branch holds. That is the same class of bug this PR exists to fix: a caller's selection quietly replaced by something else. It is not hypothetical either — frontierscience pins a revision alongside data_files today.

I had actually written the @{revision} URL handling earlier and removed it as speculative while trimming scope. That was the wrong call: since the primary path honors it, the fallback dropping it is an inconsistency, not an unused feature. Both call sites now use it, and there's a test asserting the revision reaches the listing and the URLs — the listing matters because selection computed against one revision then read from another is silently wrong.

Empty data_files → IndexError — correct. An empty selection is a caller mistake rather than a missing file, so it now raises a ValueError saying so instead of failing on candidates[0].

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 ("a.jsonl", "b.parquet") was read entirely as whatever the first file happened to be. Both cases now fail with the offending filenames named: unreadable types (your README.md typo example) and mixed types. The supported types live in one mapping the subset filter also uses, so they aren't spelled out twice.

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 main independently, so this PR is 4 files.

@abhishekraok abhishekraok left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@gregorybchris
gregorybchris merged commit 263fe8f into main Sep 9, 2026
10 checks passed
@gregorybchris
gregorybchris deleted the chrisg/hf-data-files-selection branch September 23, 2026 22:57
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.

3 participants