-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
) | ||
|
||
for gen_kwags in islice( | ||
_split_gen_kwargs(kwargs_with_shuffled_shards, max_num_jobs=self.num_shards), shard_idx_start, None | ||
): | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. how is it different from shard_example_idx ? |
||
|
||
for key, pa_table in self.generate_tables_fn(**gen_kwags): | ||
shard_example_idx += len(pa_table) | ||
if shard_example_idx <= shard_example_idx_start: | ||
batch_size = len(pa_table) | ||
|
||
if shard_example_idx + batch_size <= shard_example_idx_start: | ||
shard_example_idx += batch_size | ||
continue | ||
|
||
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 | ||
Comment on lines
+339
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
if self._state_dict: | ||
self._state_dict["shard_example_idx"] += len(pa_table) | ||
examples_in_current_batch = len(pa_table) | ||
self._state_dict["shard_example_idx"] = ( | ||
shard_example_idx_start + examples_seen_in_current_shard + examples_in_current_batch | ||
) | ||
|
||
yield key, pa_table | ||
shard_example_idx += batch_size | ||
examples_seen_in_current_shard += len(pa_table) | ||
|
||
if self._state_dict: | ||
self._state_dict["shard_idx"] += 1 | ||
self._state_dict["shard_example_idx"] = 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.
is this expected ? I think ShuffledDataSourcesArrowExamplesIterable has its own
_iter_arrow()
implementation