Skip to content

Fix iterable dataset sharding condition when n_shards == num_processes - #3958

Merged
SunMarc merged 4 commits into
mainfrom
fix-iterable-dataset-sharding
Mar 6, 2026
Merged

Fix iterable dataset sharding condition when n_shards == num_processes#3958
SunMarc merged 4 commits into
mainfrom
fix-iterable-dataset-sharding

Conversation

@SunMarc

@SunMarc SunMarc commented Mar 5, 2026

Copy link
Copy Markdown
Member

What does this PR do

Fixes #3635 (comment)

When n_shards == num_processes, native HF dataset sharding (dataset.shard()) is not used because the condition is strictly >. This causes the code to fall through to the IterableDatasetShard wrapper, which does sample-level skipping instead of file-level assignment.
This is suboptimal since n_shards == num_processes is actually the ideal case — each process gets exactly one file shard.

Use >= instead of > so native HF dataset sharding is used when the
shard count exactly matches the process count, instead of falling back
to the less efficient IterableDatasetShard wrapper.
SunMarc added 3 commits March 5, 2026 13:09
Use >= instead of > so native HF dataset sharding is used when the
shard count exactly matches the process count, instead of falling back
to the less efficient IterableDatasetShard wrapper.
@SunMarc
SunMarc merged commit 3e27a7c into main Mar 6, 2026
29 checks passed
@SunMarc
SunMarc deleted the fix-iterable-dataset-sharding branch March 6, 2026 11:48
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.

1 participant