Repository navigation
Avoid using skip() in hf_datasets - #838
Merged
Merged
Conversation
mori360
marked this pull request as ready for review
February 12, 2025 20:34
tianyu-l
reviewed
Feb 13, 2025
| if isinstance(self._data, Dataset) and self._sample_idx == len(self._data): | ||
| return iter([]) | ||
|
|
||
| return iter(self._data.skip(self._sample_idx)) |
Contributor
There was a problem hiding this comment.
I think we need to understand if skip causes error in both map-style and Iterable datasets, or only in the newly added IterableDataset case.
If it's the latter we should just revert #521, rather than universally use next for both, because it would make the healthy case slow too.
Contributor
There was a problem hiding this comment.
I would suggest that we land the PR first. It is better to have a slower checkpoint resume than an incorrect silent accuracy failure. It's blocking several accuracy verifications. Or at least we should make the default C4 dataset work for now.
tianyu-l
approved these changes
Feb 13, 2025
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
stamp to unblock, but we should follow up with more robust tests.
Merged
tianyu-l
pushed a commit
that referenced
this pull request
May 16, 2025
This PR makes resuming dataset iteration from a checkpoint fast again. This performance regression comes from #838. In that PR, `.skip` is removed for both map-style and iterable-style datasets for correctness reasons. However, `.skip` works as expected for map-style datasets, so the change can be reverted for that case. On the other hand, for iterable-style datasets, calling `.skip` after `split_dataset_by_node` splits the number of elements to skip **across the ranks** (e.g. calling `.skip(10)` after `split_dataset_by_node(<rank>, 2)` effectively skips 5 (`10 // 2 = 5`) elements on each rank), which isn'r what we want/expect, so removing `.skip` was justified there. Still, we can make the whole thing much faster using the [`state_dict` API](https://huggingface.co/docs/datasets/v3.5.0/en/stream#save-a-dataset-checkpoint-and-resume-iteration) for iterable-style datasets, which avoids re-iterating past shards/files when resuming.
xrsrke
pushed a commit
to NousResearch/torchtitan
that referenced
this pull request
Feb 13, 2026
Fix issue pytorch#809 The current `self._data.skip(self._sample_idx)` could not get the correct data for c_4 dataset. Thus we switch to next() first before the fix is landed. Test plan: We reproduce the pytorch#809 by resuming from checkpoint at step 500, then compare the loss curve in 3 conditions: 1. the origin curve running from step 0 to 750 2. the resumed curve keeping .skip() 3. the resumed curve switch to next(), with this PR change <img width="354" alt="Screenshot 2025-02-12 at 11 19 24 AM" src="https://github.com/user-attachments/assets/0ad38637-a071-4f8c-9c4c-5cfd8699ad93" /> Warning for c_4 dataset, if we resume from a large enough step, we call next() for `self._sample_idx` times, resuming from checkpoint would be much slower than using .skip() Next step: add unit test: 1. test the state_dict check between dcp.save/load and torch.save/load 2. test the difference between next() and .skip()
xrsrke
pushed a commit
to NousResearch/torchtitan
that referenced
this pull request
Feb 13, 2026
This PR makes resuming dataset iteration from a checkpoint fast again. This performance regression comes from pytorch#838. In that PR, `.skip` is removed for both map-style and iterable-style datasets for correctness reasons. However, `.skip` works as expected for map-style datasets, so the change can be reverted for that case. On the other hand, for iterable-style datasets, calling `.skip` after `split_dataset_by_node` splits the number of elements to skip **across the ranks** (e.g. calling `.skip(10)` after `split_dataset_by_node(<rank>, 2)` effectively skips 5 (`10 // 2 = 5`) elements on each rank), which isn'r what we want/expect, so removing `.skip` was justified there. Still, we can make the whole thing much faster using the [`state_dict` API](https://huggingface.co/docs/datasets/v3.5.0/en/stream#save-a-dataset-checkpoint-and-resume-iteration) for iterable-style datasets, which avoids re-iterating past shards/files when resuming.
xrsrke
pushed a commit
to NousResearch/torchtitan
that referenced
this pull request
Feb 25, 2026
Fix issue pytorch#809 The current `self._data.skip(self._sample_idx)` could not get the correct data for c_4 dataset. Thus we switch to next() first before the fix is landed. Test plan: We reproduce the pytorch#809 by resuming from checkpoint at step 500, then compare the loss curve in 3 conditions: 1. the origin curve running from step 0 to 750 2. the resumed curve keeping .skip() 3. the resumed curve switch to next(), with this PR change <img width="354" alt="Screenshot 2025-02-12 at 11 19 24 AM" src="https://github.com/user-attachments/assets/0ad38637-a071-4f8c-9c4c-5cfd8699ad93" /> Warning for c_4 dataset, if we resume from a large enough step, we call next() for `self._sample_idx` times, resuming from checkpoint would be much slower than using .skip() Next step: add unit test: 1. test the state_dict check between dcp.save/load and torch.save/load 2. test the difference between next() and .skip()
xrsrke
pushed a commit
to NousResearch/torchtitan
that referenced
this pull request
Feb 25, 2026
This PR makes resuming dataset iteration from a checkpoint fast again. This performance regression comes from pytorch#838. In that PR, `.skip` is removed for both map-style and iterable-style datasets for correctness reasons. However, `.skip` works as expected for map-style datasets, so the change can be reverted for that case. On the other hand, for iterable-style datasets, calling `.skip` after `split_dataset_by_node` splits the number of elements to skip **across the ranks** (e.g. calling `.skip(10)` after `split_dataset_by_node(<rank>, 2)` effectively skips 5 (`10 // 2 = 5`) elements on each rank), which isn'r what we want/expect, so removing `.skip` was justified there. Still, we can make the whole thing much faster using the [`state_dict` API](https://huggingface.co/docs/datasets/v3.5.0/en/stream#save-a-dataset-checkpoint-and-resume-iteration) for iterable-style datasets, which avoids re-iterating past shards/files when resuming.
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.
Fix issue #809
The current
self._data.skip(self._sample_idx)could not get the correct data for c_4 dataset.Thus we switch to next() first before the fix is landed.
Test plan:
We reproduce the #809 by resuming from checkpoint at step 500, then compare the loss curve in 3 conditions:
Warning
for c_4 dataset, if we resume from a large enough step, we call next() for
self._sample_idxtimes, resuming from checkpoint would be much slower than using .skip()Next step:
add unit test: