Repository navigation
Fix: Dataloader restarting on second resume - #3908
Merged
Merged
Conversation
francesco-bertolotti
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
July 13, 2026 07:15
tianyu-l
approved these changes
Jul 13, 2026
jemitche1
pushed a commit
to jemitche1/torchtitan
that referenced
this pull request
Jul 15, 2026
PR fixing dataloader restarting on second resume: pytorch#3907. ## Fix datasets < 4.8.0. ## Note It should be enough to do datasets < 5.0.0. I have been a little more conservative to be consistent with https://github.com/pytorch/torchtitan/blob/51c197c86d7c703da96f666d5a7dbd5432b4afbf/.ci/docker/requirements.txt#L2
zhixiangli
added a commit
to zhixiangli/torchtitan
that referenced
this pull request
Nov 13, 2026
datasets caps fsspec in every release, and the `< 4.8.0` pin held fsspec at <= 2026.2.0. datasets 5.2.0 is the first release that allows fsspec 2026.9.0. The pin covered two upstream bugs, both fixed in datasets >= 5.1.0: - pytorch#2631: 4.8.x split_dataset_by_node gave nonzero ranks no samples when num_shards < world_size. - pytorch#3907 / pytorch#3908: 5.0.0 restarted the data stream on the second resume (huggingface/datasets#8308, fixed by huggingface/datasets#8295). test_hf_cursor_state_after_restore compared pickled Hugging Face state bytes after a restore. In datasets 5.x, load_state_dict re-initializes the child iterable's state, so RebatchedArrowExamplesIterable keeps a stale nested examples_iterable entry; resume reads previous_state instead, so the rows are unaffected. The test now checks that a state saved after a restore resumes to the same rows as the original's, which fails on datasets 5.0.0 (pytorch#3907) and passes on 4.7.0 and 5.1.0. Streaming-source dataloader state saved with datasets < 5 does not load with 5.x (the state tree gained a RebatchedArrowExamplesIterable level); it fails with a KeyError. Resume such runs with checkpointer.exclude_from_loading=["dataloader"] or finish them on the old version.
zhixiangli
added a commit
to zhixiangli/torchtitan
that referenced
this pull request
Nov 13, 2026
datasets caps fsspec in every release, and the `< 4.8.0` pin held fsspec at <= 2026.2.0. datasets 5.2.0 is the first release that allows fsspec 2026.9.0. The pin covered two upstream bugs, both fixed in datasets >= 5.1.0: - pytorch#2631: 4.8.x split_dataset_by_node gave nonzero ranks no samples when num_shards < world_size. - pytorch#3907 / pytorch#3908: 5.0.0 restarted the data stream on the second resume (huggingface/datasets#8308, fixed by huggingface/datasets#8295). test_hf_cursor_state_after_restore compared pickled Hugging Face state bytes after a restore. In datasets 5.x, load_state_dict re-initializes the child iterable's state, so RebatchedArrowExamplesIterable keeps a stale nested examples_iterable entry; resume reads previous_state instead, so the rows are unaffected. The test now checks that a state saved after a restore resumes to the same rows as the original's, which fails on datasets 5.0.0 (pytorch#3907) and passes on 4.7.0, 5.1.0, and 5.2.0. Streaming-source dataloader state saved with datasets < 5 does not load with 5.x (the state tree gained a RebatchedArrowExamplesIterable level); it fails with a KeyError. Resume such runs with checkpointer.exclude_from_loading=["dataloader"] or finish them on the old version.
This was referenced Nov 13, 2026
zhixiangli
added a commit
to zhixiangli/torchtitan
that referenced
this pull request
Nov 13, 2026
datasets caps fsspec in every release, and the `< 4.8.0` pin held fsspec at <= 2026.2.0. datasets 5.2.0 is the first release that allows fsspec 2026.9.0. The pin covered two upstream bugs, both fixed in datasets >= 5.1.0: - pytorch#2631: 4.8.x split_dataset_by_node gave nonzero ranks no samples when num_shards < world_size. - pytorch#3907 / pytorch#3908: 5.0.0 restarted the data stream on the second resume (huggingface/datasets#8308, fixed by huggingface/datasets#8295). Update test_grain_data.py: - test_hugging_face_streaming_source_shards_and_restores: assert the exact per-rank rows (`[[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]`), since the set disjoint/union assertions passed even when rank 1 received `[]` on 4.8.x. - test_hf_cursor_state_after_restore: in datasets 5.x, load_state_dict re-initializes the child iterable's state, so RebatchedArrowExamplesIterable keeps a stale nested examples_iterable entry while resume reads previous_state. Compare the rows resumed from each post-restore state against the uninterrupted original stream across the epoch boundary (fails on 5.0.0, passes on 4.7.0, 5.1.0, and 5.2.0). Streaming-source dataloader state saved with datasets < 5 does not load with 5.x (the state tree gained a RebatchedArrowExamplesIterable level); it fails with a KeyError. Resume such runs with checkpointer.exclude_from_loading=["dataloader"] or finish them on the old version. Fixes pytorch#6094
zhixiangli
added a commit
to zhixiangli/torchtitan
that referenced
this pull request
Nov 17, 2026
datasets caps fsspec in every release, and the `< 4.8.0` pin held fsspec at <= 2026.2.0. datasets 5.2.0 is the first release that allows fsspec 2026.9.0. The pin covered two upstream bugs, both fixed in datasets >= 5.1.0: - pytorch#2631: 4.8.x split_dataset_by_node gave nonzero ranks no samples when num_shards < world_size. - pytorch#3907 / pytorch#3908: 5.0.0 restarted the data stream on the second resume (huggingface/datasets#8308, fixed by huggingface/datasets#8295). Update test_grain_data.py: - test_hugging_face_streaming_source_shards_and_restores: assert the exact per-rank rows (`[[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]`), since the set disjoint/union assertions passed even when rank 1 received `[]` on 4.8.x. - test_hf_cursor_state_after_restore: in datasets 5.x, load_state_dict re-initializes the child iterable's state, so RebatchedArrowExamplesIterable keeps a stale nested examples_iterable entry while resume reads previous_state. Compare the rows resumed from each post-restore state against the uninterrupted original stream across the epoch boundary (fails on 5.0.0, passes on 4.7.0, 5.1.0, and 5.2.0). Streaming-source dataloader state saved with datasets < 5 does not load with 5.x (the state tree gained a RebatchedArrowExamplesIterable level); it fails with a KeyError. Resume such runs with checkpointer.exclude_from_loading=["dataloader"] or finish them on the old version. Fixes pytorch#6094
tianyu-l
pushed a commit
that referenced
this pull request
Nov 17, 2026
…6095) ## Summary (human-written) <!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why this approach, and what you checked yourself. --> `datasets` caps `fsspec` in every release, so `datasets >= 3.6.0, < 4.8.0` in `.ci/docker/requirements.txt` holds `fsspec <= 2026.2.0`. Both upstream bugs that motivated the pin (#2631 and #3907 / #3908) are fixed in `datasets >= 5.1.0`, and `datasets 5.2.0` is the first release that allows `fsspec 2026.9.0`. ## What changed - [`.ci/docker/requirements.txt`](.ci/docker/requirements.txt): require `datasets >= 5.2.0` (fixes #6094). - [`tests/unit_tests/cpu/components/data/test_grain_data.py`](tests/unit_tests/cpu/components/data/test_grain_data.py): - `test_hugging_face_streaming_source_shards_and_restores`: assert exact per-rank rows (`[[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]`), since the set disjoint/union checks passed even when rank 1 received `[]` on `4.8.x` (#2631). - `test_hf_cursor_state_after_restore`: compare rows resumed from each post-restore state against the uninterrupted original stream instead of raw state bytes (`RebatchedArrowExamplesIterable` in `5.x` keeps a stale child dict after `load_state_dict` while resuming from `previous_state`). ## User-facing changes | Before | After | | --- | --- | | `datasets >= 3.6.0, < 4.8.0` (`fsspec <= 2026.2.0`) | `datasets >= 5.2.0` (`fsspec <= 2026.9.0`) | | `datasets` 4.x streaming dataloader state tree | `datasets` 5.2.0 adds a `StepExamplesIterable` level to the streaming state when ranks split by example (`num_shards` not divisible by the data-parallel world size). Such `< 5.0` checkpoints fail to load with a `KeyError`; resume them with `--checkpointer.exclude_from_loading dataloader` | ## Numerics Bitwise-identical `loss` and `grad_norm` between `datasets==4.7.0` (`fsspec==2026.2.0`) and `datasets==5.2.0` (`fsspec==2026.9.0`) on A100 (`seed=42`, `deterministic=True`, `scripts/loss_compare.py --assert-equal`): | Config | GPUs | Steps | Result | | --- | --- | --- | --- | | `llama3_debugmodel` (FSDP4, `c4_test`, random access) | 4 | 20 | Bitwise identical | | `llama3_debugmodel` with the dataset overridden to `DATASETS["c4"]` (FSDP4, streaming `allenai/c4`, 1024 shards, split by shard) | 4 | 20 | Bitwise identical | | `llama3_debugmodel` with the dataset overridden to a streaming source over `tests/assets/c4_test/data.json` (FSDP4, 1 shard, split by example) | 4 | 20 | Bitwise identical | | `llama3_debugmodel_sft` (FSDP2, SFT) | 2 | 10 | Bitwise identical | | `flux_debugmodel_hsdp2x2_cp2_validation` (HSDP 2x2 + CP2, `cc12m-wds`) | 8 | 20 | Bitwise identical | ## Testing - **CPU & RL unit tests:** `pytest tests/unit_tests/cpu` (`2058 passed`), `pytest tests/rl/unit_tests/cpu` (`test_alphabet_sort.py`, `test_dapo_math.py`, `test_geometry3k.py`, `test_search_r1.py`, `test_model_defaults.py`). - **GPU integration suites (`run_tests.py`):** `features` (`50/50`) and `flux` (`hsdp+cp+validation+inference`).
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.
PR fixing dataloader restarting on second resume: #3907.
Fix
datasets < 4.8.0.
Note
It should be enough to do datasets < 5.0.0.
I have been a little more conservative to be consistent with
torchtitan/.ci/docker/requirements.txt
Line 2 in 51c197c