Repository navigation
[CI deps] Require datasets >= 5.2.0 so fsspec can move to the latest - #6095
Conversation
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
ab465cd to
1a81fa1
Compare
|
@claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The bump is justified: both bugs behind the old < 4.8.0 cap are fixed in >= 5.1.0, and 5.2.0 is the first release that allows the newer fsspec. The test changes check what we actually care about, which is that rows are split across ranks and resume correctly.
What this PR does. It replaces datasets >= 3.6.0, < 4.8.0 with datasets >= 5.2.0. requirements.txt and the pyproject dependencies both point at this file, so the change applies to users as well as CI. It also changes two HuggingFaceStreamingSource tests. The rank-split test now asserts the exact rows each rank gets. The cursor-restore test now compares the rows each state resumes to, instead of comparing pickled HF state bytes, because that state is no longer byte-identical after a restore in 5.x.
Example. On 4.8.x, with a single-shard JSONL file of 10 rows and 2 ranks:
old check: rank0=[0..9], rank1=[] -> disjoint and union == range(10) -> passes
new check: [[0,2,4,6,8],[1,3,5,7,9]] -> fails on 4.8.x, passes on >= 5.0
That exact assignment is the documented split_dataset_by_node behavior for num_shards < world_size (each rank keeps every world_size-th example), so the test isn't pinning an implementation detail.
Must fix
- PR description: the "Summary (human-written)" section is empty. The author needs to fill it in (see "AI-assisted contributions" in
CONTRIBUTING.md).
Should consider
.ci/docker/requirements.txt:2-- the 4.8.x and 5.0.0 exclusions are already implied by the new floor; keep only the fsspec reason (inline).tests/unit_tests/cpu/components/data/test_grain_data.py:228--_HF_SHARDED_NUM_ROWSis used only partly (sibling tests still use16), and adding it reformats an untouched helper; drop it (inline).tests/unit_tests/cpu/components/data/test_grain_data.py:315-- the docstring should name the concrete upstream behavior (RebatchedArrowExamplesIterable's stale child state afterload_state_dict) (inline).
Questions
- The numerics table lists
llama3_debugmodel (FSDP4, C4). By default that recipe usesDATASETS["c4_test"](torchtitan_recipes/tests/models/llama3.py:72), which isHuggingFaceRandomAccessSourceand never goes throughsplit_dataset_by_nodeor the streaming state. Did the run override to the streamingc4source? If not, please relabel the row. The Fluxcc12m-wdsHSDP run is then the only end-to-end evidence for the streaming path, which is fine, but the description shouldn't claim C4.
Not verified: I didn't run the CPU tests or check the datasets 5.2.0 / fsspec 2026.9.0 resolution locally (installing was blocked in this environment).
| # datasets caps fsspec in every release; 5.2.0 is the first to allow fsspec | ||
| # 2026.9.0. It also excludes 4.8.x (split_dataset_by_node yields no samples on | ||
| # nonzero ranks when num_shards < world_size) and 5.0.0 (streaming state | ||
| # restarts on a second resume). |
There was a problem hiding this comment.
The fsspec reason is what sets the floor. The 4.8.x and 5.0.0 exclusions are already implied by >= 5.2.0, so those two lines just describe past pins, and they go stale once the floor moves again. Per CLAUDE.md, comments should describe the current state. I suggest dropping them:
| # datasets caps fsspec in every release; 5.2.0 is the first to allow fsspec | |
| # 2026.9.0. It also excludes 4.8.x (split_dataset_by_node yields no samples on | |
| # nonzero ranks when num_shards < world_size) and 5.0.0 (streaming state | |
| # restarts on a second resume). | |
| # datasets caps fsspec in every release; 5.2.0 is the first to allow fsspec | |
| # 2026.9.0. |
There was a problem hiding this comment.
Done. The comment keeps only the fsspec reason.
| _HF_SHARDED_NUM_ROWS = 16 | ||
|
|
||
|
|
||
| def _hf_sharded_rows(): | ||
| return datasets.Dataset.from_dict({"id": list(range(16))}).to_iterable_dataset( | ||
| num_shards=8 | ||
| ) | ||
| return datasets.Dataset.from_dict( | ||
| {"id": list(range(_HF_SHARDED_NUM_ROWS))} | ||
| ).to_iterable_dataset(num_shards=8) |
There was a problem hiding this comment.
_HF_SHARDED_NUM_ROWS is only used here and in resumed_rows. The sibling tests that use the same fixture still hard-code 16 (lines 244, 248, 258, 298, 307). So the constant doesn't give the file one source of truth, and this hunk reformats a helper the PR doesn't otherwise need to touch. I suggest keeping the original helper and writing range(16) in resumed_rows (line 330):
| _HF_SHARDED_NUM_ROWS = 16 | |
| def _hf_sharded_rows(): | |
| return datasets.Dataset.from_dict({"id": list(range(16))}).to_iterable_dataset( | |
| num_shards=8 | |
| ) | |
| return datasets.Dataset.from_dict( | |
| {"id": list(range(_HF_SHARDED_NUM_ROWS))} | |
| ).to_iterable_dataset(num_shards=8) | |
| def _hf_sharded_rows(): | |
| return datasets.Dataset.from_dict({"id": list(range(16))}).to_iterable_dataset( | |
| num_shards=8 | |
| ) |
There was a problem hiding this comment.
Done. Reverted _hf_sharded_rows() to its original form and resumed_rows uses range(16) like the sibling tests.
| Once read, Hugging Face streaming state can carry different nested | ||
| bookkeeping after ``load_state_dict`` than an uninterrupted iterator's | ||
| for the same position, so states after advancing are compared by the rows | ||
| they resume to. |
There was a problem hiding this comment.
This docstring is the only in-code explanation of why the test no longer compares state bytes, but "can carry different nested bookkeeping" doesn't tell a reader what actually differs. The PR description has the concrete reason: in datasets 5.x, RebatchedArrowExamplesIterable keeps a stale child state dict after load_state_dict and resumes from previous_state. Please put that sentence here. Without it, someone will later "restore" the byte-equality assert and see it fail. If upstream treats this as a bug, add a TODO with the issue link.
There was a problem hiding this comment.
Done. The docstring now names the mechanism. _BaseExamplesIterable.load_state_dict calls _init_state_dict(), which gives the child a new state dict. RebatchedArrowExamplesIterable._iter_arrow calls it on its child with previous_state on the first read after a restore, so the parent's examples_iterable entry stops tracking the child, while resume reads previous_state.
Measured on 5.2.0: a restored cursor and an uninterrupted one at the same position differ only in examples_iterable.examples_iterable.shard_idx (restored stays at 1, original advances). On 4.7.0 the two states are byte-equal.
No TODO added: resume is correct, and I found no upstream issue covering the stale entry.
tianyu-l
left a comment
There was a problem hiding this comment.
thanks.
please address remaining comments, and rebase
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
Define _HF_SHARDED_NUM_ROWS = 16 for _hf_sharded_rows() and compare resumed_rows(restored.get_state()) against resumed_rows(original.get_state()) while advancing original and restored together, removing the pre-drained expected list and slice offsets.
Address review on the datasets >= 5.2.0 bump. test_hf_cursor_state_after_restore: the docstring now names why states are compared by the rows they resume to. As of datasets 5.2, the first read after load_state_dict makes RebatchedArrowExamplesIterable load previous_state into its child iterable, which re-initializes the child's state dict. The examples_iterable entry of its own state then stops tracking the child (stale shard_idx), while resume reads previous_state. Drop _HF_SHARDED_NUM_ROWS: the sibling tests on the same fixture hard-code 16, so restore _hf_sharded_rows() and use range(16) in resumed_rows. .ci/docker/requirements.txt: keep only the fsspec reason for the datasets floor. The 4.8.x and 5.0.0 exclusions are implied by >= 5.2.0.
fc28535 to
7f653b1
Compare
|
On the numerics question in the review: |
TorchCheckpointingManager imports torch_checkpointing.storage.fsspec_storage, which no PyPI release has yet (latest is 0.1.1). Pin the main commit that has it, as torch_remat is pinned, until a release is published. The [fsspec] extra is left out: it caps fsspec below 2026.6 and would undo pytorch#6095.
TorchCheckpointingManager imports torch_checkpointing.storage.fsspec_storage, which no PyPI release has yet (latest is 0.1.1). Pin the main commit that has it, as torch_remat is pinned, until a release is published. The [fsspec] extra is left out: it caps fsspec below 2026.6 and would undo pytorch#6095.
TorchCheckpointingManager imports torch_checkpointing.storage.fsspec_storage, which no PyPI release has yet (latest is 0.1.1). Pin the main commit that has it, as torch_remat is pinned, until a release is published. The [fsspec] extra is left out: it caps fsspec below 2026.6 and would undo pytorch#6095.
…ch as gs:// (#6169) ## Summary (human-written) `TorchCheckpointingManager` rejects any remote `checkpointer.folder` or `initial_load_path`, so it needs the bucket mounted, which containers without FUSE and managed platforms can't do. meta-pytorch/torch_checkpointing#13 adds an fsspec `Storage`; this PR wires it in, as DCP already has (#3887, #6061). ```python checkpointer=TorchCheckpointingManager.Config( folder="gs://my-bucket/run-1/checkpoint", initial_load_in_hf=True, # hf_assets_path stays on local disk last_save_in_hf=True, ) ``` On `main` this raises `ValueError: checkpointer.folder is a remote URI (...)`. Rejected: mounting the bucket (not available everywhere); copying the HF weights into the bucket (DCP doesn't require it). ## Why `TorchCheckpointingManager.__init__` raises on any URI in `checkpointer.folder` or `checkpointer.initial_load_path`, so its checkpoints can only live on a mounted filesystem. DCP's manager already accepts `gs://`. **Example.** ```python checkpointer=TorchCheckpointingManager.Config( folder="gs://my-bucket/run-1/checkpoint", interval=500, keep_latest_k=2, initial_load_in_hf=True, # hf_assets_path stays on local disk last_save_in_hf=True, ) # main: ValueError: checkpointer.folder is a remote URI (...) # PR: backend storage = FsspecStorageConfig(protocol="gs"), from the folder's scheme # interval save -> backend id "my-bucket/run-1/checkpoint/step-500" (no scheme) # resume, retention -> torchtitan.tools.filesystem, as DCP does on gs:// # HF initial load -> the local hf_assets_path, read with local storage # HF final export -> gs://my-bucket/run-1/checkpoint/exports/step-N ``` ## What changed 9 files, +443 / -214. - **Mechanical (can skim):** - `base.py` -> `dcp.py`: the two remote-HF config guards (`last_save_in_hf` with a remote `folder`, `initial_load_in_hf` with a remote `initial_load_path`) move unchanged to DCP's `CheckpointManager.Config`, with a TODO for pytorch/pytorch#205015. Only DCP's HF storage is local-only. - `dcp.py` -> `base.py`: `_FilesystemCheckpointStorage` moves unchanged and becomes `FilesystemCheckpointStorage`, shared by both managers. `test_checkpoint.py` only follows the rename. - **Logic (`torch_checkpointing.py`, +83 / -63):** - Remove the construction-time rejection of a remote `folder` and `initial_load_path`. - Remove the `storage_config` init parameter (added in #4188; no in-repo caller). `_storage_config(path)` derives the backend storage from each path's scheme: the backend's local default for a local path, `FsspecStorageConfig(protocol=...)` for a URI. - `_split_uri` / `_backend_path` hand paths to the backend without their scheme, because it wraps ids in `Path()`, which turns `gs://b/x` into `gs:/b/x`. A TODO links meta-pytorch/torch_checkpointing#12. - Probing and retention go through `FilesystemCheckpointStorage` (`torchtitan.tools.filesystem`), replacing `_BackendCheckpointStorage`. - A load from another protocol than `folder` (`initial_load_path`, or the local `hf_assets_path` of an HF initial load) builds a temporary synchronous manager on that path's storage. - Two checks at construction, listed under User-facing changes. - **Logic (`torchtitan/tools/filesystem.py`, +9 / -10):** for a local path, `rmtree` now ignores only a missing path instead of every error, as its remote branch already did. A failed retention delete then reaches the purge thread, which logs it. `TorchCheckpointingManager` logged these on `main` through the backend `Storage`; without this, moving to the shared adapter would have silenced them. - **Docs and tests:** a README section, "Remote storage with `TorchCheckpointingManager`", scoped to what was verified (`gs://` via `gcsfs`). Tests are listed under Testing. - **CI deps (`.ci/docker/requirements.txt`):** pin `torch_checkpointing` to `main` commit `5c45dc3` (see "Depends on"). The `[fsspec]` extra is left out: it caps `fsspec < 2026.6` and would undo #6095. ## Alternatives considered - Keep `storage_config` and route probes through the backend `Storage` (the previous revision of this PR): about 170 more net lines (`_BackendCheckpointStorage`, `_can_hold`, a storage cache) for a parameter no in-repo caller passes. Dropped on review. - Normalize `//` and `/./` in a URI instead of rejecting them: it would silently rewrite the path the user gave. ## User-facing changes | Before | After | | --- | --- | | Remote `folder` or `initial_load_path` on `TorchCheckpointingManager` -> `ValueError` | Accepted and routed by scheme. Verified on `gs://` via `gcsfs`, flat and HNS buckets. On a flat bucket a preempted commit can leave a `step-N` that looks complete (see README; meta-pytorch/torch_checkpointing#17) | | `last_save_in_hf` with a remote `folder`, or `initial_load_in_hf` with a remote `initial_load_path` -> `ValueError` in `BaseCheckpointManager.Config` | Supported on `TorchCheckpointingManager`; DCP's `CheckpointManager.Config` keeps the same guards until pytorch/pytorch#205015 | | `TorchCheckpointingManager(..., storage_config=...)` | Parameter removed; storage comes from each path's scheme | | -- | A remote `folder` or `initial_load_path` with an empty or `.` segment (`//`, `/./`) -> `ValueError` at construction. One trailing slash is accepted | | -- | A remote `folder` containing `*`, `?` or `[` -> `ValueError` at construction | | DCP, local folder: a failed retention delete is ignored silently | Logged as a warning by the purge thread, as `TorchCheckpointingManager` already did | Local folders and DCP otherwise behave as before. ## Numerics No training computation changes. llama3 debugmodel, FSDP over 8x A100 80GB, `seed=42`, deterministic, `lr_scheduler.total_steps=20` in every run. Head `7625d5e45`, base `168567471`. torch `2.16.0.dev20261116+cu132`, torch_checkpointing `5c45dc3`, gcsfs `2026.10.1`, fsspec `2026.9.0`. Local runs use a plain local folder; `gs://` runs use a flat bucket and a hierarchical-namespace (HNS) bucket in us-central1. `loss_metrics/global_avg_loss`, `loss_metrics/global_max_loss` and `grad_norm` were compared at full precision from TensorBoard, with exact equality. | Comparison (same commit, storage is the only difference) | Steps | Flat | HNS | | --- | --- | --- | --- | | Save to `gs://` vs. local (interval 5, `keep_latest_k=2`) | 1-10 | Bitwise identical | Bitwise identical | | Resume from `step-10` on `gs://` vs. local (retention deletes `step-5`, `step-10`; `step-15`, `step-20` remain) | 11-20 | Bitwise identical | Bitwise identical | | The same save and resume with `async_mode="async_with_pinned_mem"` | 1-20 | Bitwise identical | Bitwise identical | | HF initial load from a local `hf_assets_path`, `gs://` folder vs. local folder | 1-10 | Bitwise identical | Bitwise identical | | Native `initial_load_path` (model only, `step-20`): `gs://` -> local folder, and local -> `gs://` folder, vs. local -> local | 1-10 | Bitwise identical | Bitwise identical | | Final HF export (`exports/step-10`), `gs://` vs. local, sha256 | -- | Identical HF files | Identical HF files | "Identical HF files": the 8 `model-0000N-of-00008.safetensors`, `model.safetensors.index.json` and the 8 per-rank `sharded/model_N.safetensors` are byte-identical. The bytes of `sharded/metadata.pkl` differ, but it unpickles to the same content once dict order is ignored. Local folder, base `168567471` vs. this PR: save steps 1-10 and resume steps 11-20 are bitwise identical. Local folder, async vs. sync saves on this PR: also bitwise identical. ## Testing `pytest tests/unit_tests/cpu/components/checkpointer/`: 128 passed, and `pytest tests/unit_tests/cpu/tools/test_filesystem.py`: 14 passed (CPU, torch_checkpointing `5c45dc3`). New tests and the regression each catches: - `test_remote_folder_uses_fsspec_storage_and_scheme_less_save_ids`: a `gs://` id reaching the backend with its scheme; a remote path with `//`, `/./` or a doubled trailing slash, or a remote folder with a glob character, being accepted. - `test_remote_folder_round_trip` (`file://`, real backend): broken save -> retention -> resume on a URI folder, including an abandoned staging directory. - `test_remote_folder_hf_round_trip` (`memory://`, real backend): broken HF export -> HF load on a URI folder. - `test_hf_initial_load_reads_local_assets_with_a_remote_folder` and `test_initial_load_path_on_other_storage_than_the_folder`: a load path on other storage being read through the folder's storage. - `test_rmtree_propagates_a_failed_local_delete`: a failed local delete being swallowed, so the purge thread reports a deletion that did not happen. On real flat and HNS GCS buckets, the 8x A100 runs under Numerics cover interval saves, `keep_latest_k`, resume, both initial-load directions and HF export, in sync and async mode. A simulated interrupted commit on a flat bucket (single process, CPU, at `4477ebb38`) reproduces the README caveat: `step-1` holds only `metadata.pkl`, resume selects it, and the load raises `FileNotFoundError`. On the HNS bucket the commit is a single folder rename. **Depends on** meta-pytorch/torch_checkpointing#13, which landed on `main` as `5bda153` but is not in a release yet (latest is `0.1.1`). `.ci/docker/requirements.txt` pins `main` at `5c45dc3` (one commit after `5bda153`, a test type-check fix) until a release is published. ## Known issues / follow-ups - **Flat-bucket commits:** meta-pytorch/torch_checkpointing#17. Until it is fixed, prefer HNS buckets for `gs://`. - **Glob characters in remote deletes:** `torchtitan.tools.filesystem.rmtree` lets fsspec expand `*`, `?` and `[`. This PR rejects such folders for `TorchCheckpointingManager` only; DCP on `main` has the same exposure. - **`CheckpointStorage` protocol:** both managers now use the one `FilesystemCheckpointStorage`, so the protocol can be folded into `BaseCheckpointManager`. - **URIs that carry a host or port** (e.g. `hdfs://host:8020/path`) are not supported: the host would be read as part of the path. - **Re-saving an existing step or export:** replace stale `step-N` / `tmp_step-N` / `exports/step-N` and drain in-flight purges. - **Remote `hf_assets_path`** (tokenizer, safetensors index): #6102. - **Release pin:** replace the `torch_checkpointing` git pin with the first release that includes `5bda153`. - **`write_to_temp_dir` warning:** `_writer_config(use_barrier=False)` should set `write_to_temp_dir=False`; torch_checkpointing warns this will become an error. - **Repeated resume checks:** `_is_resumable_checkpoint` runs three times for the selected checkpoint (`_find_load_step`, `BaseCheckpointManager.load()`, `TorchCheckpointingManager._load_checkpoint()`). Fixes #6103
Summary (human-written)
datasetscapsfsspecin every release, sodatasets >= 3.6.0, < 4.8.0in.ci/docker/requirements.txtholdsfsspec <= 2026.2.0. Both upstream bugs that motivated the pin (#2631 and #3907 / #3908) are fixed indatasets >= 5.1.0, anddatasets 5.2.0is the first release that allowsfsspec 2026.9.0.What changed
.ci/docker/requirements.txt: requiredatasets >= 5.2.0(fixes [CI deps] Bump datasets >= 5.2.0 to unblock fsspec <= 2026.9.0 #6094).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[]on4.8.x([CI] Pin datasets < 4.8.0 to avoid streaming sharding regression #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 (RebatchedArrowExamplesIterablein5.xkeeps a stale child dict afterload_state_dictwhile resuming fromprevious_state).User-facing changes
datasets >= 3.6.0, < 4.8.0(fsspec <= 2026.2.0)datasets >= 5.2.0(fsspec <= 2026.9.0)datasets4.x streaming dataloader state treedatasets5.2.0 adds aStepExamplesIterablelevel to the streaming state when ranks split by example (num_shardsnot divisible by the data-parallel world size). Such< 5.0checkpoints fail to load with aKeyError; resume them with--checkpointer.exclude_from_loading dataloaderNumerics
Bitwise-identical
lossandgrad_normbetweendatasets==4.7.0(fsspec==2026.2.0) anddatasets==5.2.0(fsspec==2026.9.0) on A100 (seed=42,deterministic=True,scripts/loss_compare.py --assert-equal):llama3_debugmodel(FSDP4,c4_test, random access)llama3_debugmodelwith the dataset overridden toDATASETS["c4"](FSDP4, streamingallenai/c4, 1024 shards, split by shard)llama3_debugmodelwith the dataset overridden to a streaming source overtests/assets/c4_test/data.json(FSDP4, 1 shard, split by example)llama3_debugmodel_sft(FSDP2, SFT)flux_debugmodel_hsdp2x2_cp2_validation(HSDP 2x2 + CP2,cc12m-wds)Testing
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).run_tests.py):features(50/50) andflux(hsdp+cp+validation+inference).