-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix IterableDataset state_dict shard_example_idx counting #7539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool ! I left some comments :)
Feel free to also update your branch to include CI fixes from main
@@ -317,16 +317,40 @@ def __iter__(self): | |||
|
|||
def _iter_arrow(self): | |||
shard_idx_start = self._state_dict["shard_idx"] if self._state_dict else 0 | |||
for gen_kwags in islice(_split_gen_kwargs(self.kwargs, max_num_jobs=self.num_shards), shard_idx_start, None): | |||
kwargs_with_shuffled_shards = ( | |||
_shuffle_gen_kwargs(self.generator, self.kwargs) if hasattr(self, "generator") else self.kwargs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this expected ? I think ShuffledDataSourcesArrowExamplesIterable has its own _iter_arrow()
implementation
shard_example_idx_start = self._state_dict["shard_example_idx"] if self._state_dict else 0 | ||
shard_example_idx = 0 | ||
|
||
examples_seen_in_current_shard = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is it different from shard_example_idx ?
if shard_example_idx < shard_example_idx_start: | ||
offset = shard_example_idx_start - shard_example_idx | ||
pa_table = pa_table.slice(offset) | ||
examples_seen_in_current_shard = offset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed ? we always yield full tables, so it's unlikely we end up with a shard_example_idx
that doesn't land exactly on a table boundary (except if the dataset state is manually crafted maybe)
Fix IterableDataset's state_dict shard_example_idx reporting
Description
This PR fixes issue #7475 where the
shard_example_idx
value inIterableDataset
'sstate_dict()
always equals the number of samples in a shard, even if only a few examples have been consumed.The issue is in the
_iter_arrow
method of theArrowExamplesIterable
class where it updates theshard_example_idx
state by the full length of the batch (len(pa_table)
) even when we're only partway through processing the examples.Changes
Modified the
_iter_arrow
method ofArrowExamplesIterable
to:shard_example_idx
by the number of examples actually yieldedHow to Test
I've included a simple test case that demonstrates the fix:
Implementation Details
This fix ensures that checkpointing and resuming works correctly with exactly the expected number of examples, rather than skipping ahead to the end of the batch.