Conversation
IterableDataset.shard documents that num_shards must not exceed dataset.num_shards, but violating it (or passing index >= num_shards) crashed with an opaque IndexError from the list comprehension in _merge_gen_kwargs - and for contiguous sharding, shard(n, 0) with n > num_shards silently returned the whole dataset instead of one shard. Validate both arguments in shard() and raise a ValueError that names the expected bounds. Signed-off-by: simpleqt <89645338+simpleqt@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
IterableDataset.sharddocuments that "n should be less or equal to the number of shards in the datasetdataset.num_shards", but violating that (or passingindex >= num_shards) crashes with an opaqueIndexErrorfrom deep inside_merge_gen_kwargs:Worse, for contiguous sharding
shard(num_shards=3, index=0)on a single-shard dataset silently returned the whole dataset instead of one shard (reproduced on the latestmainand on the released 4.4.1).Fix
Validate both arguments in
IterableDataset.shardand raise aValueErrorthat names the expected bounds:Internal callers are unaffected:
mapalready lowersnum_proctonum_shardsbefore callingshard, and every path that used to survive produced either the whole dataset or an empty shard.Tests
test_shard_with_too_many_shards_raises_clear_errorandtest_shard_with_out_of_range_index_raises_clear_error; on unfixedmainthey fail with theIndexErrorabove (verified by temporarily reverting the fix).pytest tests/test_iterable_dataset.py -k "shard or map": 155 passed.ruff check+ruff format --checkclean.