Skip to content

[CI] Pin datasets < 4.8.0 to avoid streaming sharding regression - #2631

Merged
wwwjn merged 1 commit into
mainfrom
pin-datasets-version
Mar 20, 2026
Merged

wwwjn merged 1 commit into
mainfrom
pin-datasets-version

Conversation

@wwwjn

@wwwjn wwwjn commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

datasets 4.8.x introduced a bug in StepExamplesIterable._iter_arrow where single-row Arrow batches cause split_dataset_by_node to yield 0 samples for non-zero ranks when num_shards < world_size. This breaks Flux training with the cc12m-test and coco-validation datasets.

datasets 4.8.x introduced a bug in StepExamplesIterable._iter_arrow
where single-row Arrow batches cause split_dataset_by_node to yield
0 samples for non-zero ranks when num_shards < world_size. This
breaks Flux training with the cc12m-test and coco-validation datasets.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 19, 2026

@shuhuayu shuhuayu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious that why we do not pin dependencies' version for ci tests? and maybe schedule regular dependencies check. If we want to depend on the latest version, then we should adapt our own code.

@wwwjn

wwwjn commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

Close because of #2629 (comment), locally verified it works well

@wwwjn wwwjn closed this Mar 19, 2026
@wwwjn wwwjn reopened this Mar 20, 2026
@wwwjn

wwwjn commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Not sure why CI haven't pickup datasets==4..8.3 till today, let land this PR to unblock and revisit the datasets version after. cc @tianyu-l

@wwwjn
wwwjn merged commit c0c0bf9 into main Mar 20, 2026
47 of 58 checks passed
mori360 pushed a commit to mori360/torchtitan that referenced this pull request Mar 23, 2026
…orch#2631)

`datasets` 4.8.x introduced a bug in StepExamplesIterable._iter_arrow
where single-row Arrow batches cause split_dataset_by_node to yield 0
samples for non-zero ranks when **num_shards < world_size**. This breaks
Flux training with the cc12m-test and coco-validation datasets.
pytorch-bot Bot pushed a commit that referenced this pull request Mar 27, 2026
`datasets` 4.8.x introduced a bug in StepExamplesIterable._iter_arrow
where single-row Arrow batches cause split_dataset_by_node to yield 0
samples for non-zero ranks when **num_shards < world_size**. This breaks
Flux training with the cc12m-test and coco-validation datasets.
TXacs pushed a commit to McmillanTAC/torchtitan that referenced this pull request Apr 13, 2026
…orch#2631)

`datasets` 4.8.x introduced a bug in StepExamplesIterable._iter_arrow
where single-row Arrow batches cause split_dataset_by_node to yield 0
samples for non-zero ranks when **num_shards < world_size**. This breaks
Flux training with the cc12m-test and coco-validation datasets.
ACharacterInASimulation pushed a commit to ACharacterInASimulation/torchtitan that referenced this pull request Apr 21, 2026
…orch#2631)

`datasets` 4.8.x introduced a bug in StepExamplesIterable._iter_arrow
where single-row Arrow batches cause split_dataset_by_node to yield 0
samples for non-zero ranks when **num_shards < world_size**. This breaks
Flux training with the cc12m-test and coco-validation datasets.
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.
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`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants