Skip to content

Make the dataset fingerprint independent of Arrow chunking - #8339

Merged
lhoestq merged 2 commits into
huggingface:mainfrom
SuryanshSS1011:fix-fingerprint-chunk-independent-8327
Jul 22, 2026
Merged

lhoestq merged 2 commits into
huggingface:mainfrom
SuryanshSS1011:fix-fingerprint-chunk-independent-8327

Conversation

@SuryanshSS1011

@SuryanshSS1011 SuryanshSS1011 commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8327.

As discussed in the issue, the OOM in Dataset.from_pandas comes from generate_fingerprint, not from the Arrow conversion. Fingerprinting hashes dataset.__dict__, and the underlying pa.Table (and the InMemoryTable wrapping it) pickles chunk-by-chunk, so the serialized size and the hashing cost scale with the number of chunks rather than the amount of data. shuffle().to_pandas() produces one chunk per row, which is where it really blows up.

Following @lhoestq's suggestion to make the table hash chunk-count-independent (rather than calling combine_chunks() on the stored data), this PR does two things:

  • InMemoryTable now serializes via its underlying table only. The _batches/_offsets index is derived and rebuilt in __init__, so there's no need to pickle it. This mirrors how MemoryMappedTable and ConcatenationTable already define __getstate__/__setstate__.
  • pa.Table and pa.ChunkedArray get dill reducers that serialize a chunk-count-independent form. They combine one column at a time, so memory stays bounded and a table with the same data hashes the same regardless of how it's chunked.

The combine is transient and per-column, so it never materializes a full extra copy of the table.

Result

On the repro from the issue (25k rows shuffled to one chunk per row), Dataset.from_pandas goes from a ~1.5 GB allocation to a few MB. I measured RSS on the scaled 2000-chunk case: the delta across from_pandas dropped from ~1500 MB to ~4 MB.

The fingerprint is now stable across different chunkings of the same data and still distinguishes different data. pickle round-trips of a dataset reconstruct correctly. tests/test_fingerprint.py and tests/test_table.py pass (the two failures I see, test_hash_torch_compiled_module and test_move_script_doesnt_change_hash, also fail on main in my environment and are unrelated).

I added test_hash_arrow_table_is_independent_of_chunking to cover the invariant.

One thing that I would flag is that this changes the fingerprint values for existing datasets, so it will invalidate caches once. This seems unavoidable for a fix that changes how the table is hashed.

@SuryanshSS1011
SuryanshSS1011 force-pushed the fix-fingerprint-chunk-independent-8327 branch from 747cab6 to 543ee3e Compare July 16, 2026 19:22
Comment thread src/datasets/utils/_dill.py Resolved
- Preserve duplicate field names when reconstructing the arrow table
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@lhoestq lhoestq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm :)

@lhoestq
lhoestq merged commit 3bfbc67 into huggingface:main Jul 22, 2026
6 of 14 checks passed
Elsword016 pushed a commit to Elsword016/datasets that referenced this pull request Aug 6, 2026
…ce#8339)

* Make the dataset fingerprint independent of Arrow chunking

* Refactor create_arrowTable to use from_arrays 

- Preserve duplicate field names when reconstructing the arrow table
sharonyu-115 added a commit to zhangyimi/RL that referenced this pull request Sep 19, 2026
The PR lockfile refresh resolves datasets 5.0.1 and pyarrow 25.0.1.
Datasets 5.0.1 combines Arrow chunks while fingerprinting in-memory
tables (huggingface/datasets#8339). NemoGymDataset stores raw JSONL
lines in extra_env_info, so large inputs exceed the approximately
2 GiB limit of Arrow string's 32-bit offsets during Dataset.from_dict.
This raises ArrowInvalid before training starts.

Declare extra_env_info as large_string, which uses 64-bit offsets,
and keep task_name as string. Preserve raw JSON values, repetition,
and the current dependency versions. Explain the schema choice at
the construction site.

Validation: four full Slurm runs on 2e13bf9 plus this schema fix
passed the original training targets and all nine metric checks:
18926860 (SWE1), 18926861 (RLVR), 18926862 (async SWE1), and
18926863 (MOPD). These are not full-run results for the rebased head.
The updated loader is executable-code-identical to that tested fix.
CPU smoke job 18928236 verifies the updated checkout with datasets
5.0.1/pyarrow 25.0.1; focused Ruff and Pyrefly checks pass.

Signed-off-by: Shuang Yu <[email protected]>
sharonyu-115 added a commit to zhangyimi/RL that referenced this pull request Sep 19, 2026
The PR lockfile refresh resolves datasets 5.0.1 and pyarrow 25.0.1.
Datasets 5.0.1 combines Arrow chunks while fingerprinting in-memory
tables (huggingface/datasets#8339). NemoGymDataset stores raw JSONL
lines in extra_env_info, so large inputs exceed the approximately
2 GiB limit of Arrow string's 32-bit offsets during Dataset.from_dict.
This raises ArrowInvalid before training starts.

Declare extra_env_info as large_string, which uses 64-bit offsets,
and keep task_name as string. Preserve raw JSON values, repetition,
and the current dependency versions. Explain the schema choice at
the construction site.

Validation: four full Slurm runs on 2e13bf9 plus this schema fix
passed the original training targets and all nine metric checks:
18926860 (SWE1), 18926861 (RLVR), 18926862 (async SWE1), and
18926863 (MOPD). These are not full-run results for the rebased head.
The updated loader is executable-code-identical to that tested fix.
CPU smoke job 18928236 verifies the updated checkout with datasets
5.0.1/pyarrow 25.0.1; focused Ruff and Pyrefly checks pass.

Signed-off-by: Shuang Yu <[email protected]>
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.

Dataset.from_pandas allocates ~1 MB per Arrow chunk, Out of Memory errors

4 participants