Skip to content

[checkpoint] Configure concurrent file reads for torch_checkpointing loads - #6197

Open
ivy-zhou wants to merge 2 commits into
mainfrom
pr6197
Open

ivy-zhou wants to merge 2 commits into
mainfrom
pr6197

Conversation

@ivy-zhou

@ivy-zhou ivy-zhou commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

I want to give Titan side a control to up the concurrency of reading, I think this can be faster under some storage setups.

Why

torch_checkpointing's DefaultLoadPlanExecutor keeps 24 file reads in flight per host, split across the host's ranks: 3 per rank with 8 ranks. The best number depends on the storage, and the backend can't see the relevant settings. On a FUSE-mounted remote store, the mount's readahead decides it:

  • With a 16 MiB readahead, the mount prefetches past every read. Sharded loads read strided slices, so most of that prefetch is wasted, and more reads in flight make it worse. The default of 3 per rank is the fastest.
  • With readahead off, each 1 MiB request waits for its own fetch, so a host needs more reads in flight to fill the link. 6 per rank is the fastest.

The FUSE mount sets readahead for the whole mount, so a job can't turn it off just for checkpoint reads. Today TorchTitan always uses the backend's default load config, so there's no way to match the worker count to the storage.

Example.

# Before: 24 // LOCAL_WORLD_SIZE reads per rank, fixed.
TorchCheckpointingManager.Config(initial_load_path=path)

# After: 6 concurrent file reads per rank, for native and HF loads.
TorchCheckpointingManager.Config(initial_load_path=path, file_read_workers=6)

What changed

  • TorchCheckpointingManager.Config.file_read_workers: int | None = None sets DefaultLoadPlanExecutor(file_read_workers=...) in the backend's load config.
    • None builds DefaultLoadPlanExecutor(), the same executor the backend uses when no executor is configured, so leaving the field unset doesn't change load behavior.
    • Values below 1 raise ValueError when the config is built.
  • The temporary manager for HF loads reuses that load config, so HF loads use the same setting.
  • .ci/docker/requirements.txt: pin torch_checkpointing to meta-pytorch/torch_checkpointing 5c45dc3, the first commit with DefaultLoadPlanExecutor. These lines are identical to [checkpoint] TorchCheckpointingManager: checkpoints on fsspec URIs such as gs:// #6169's.

Alternatives considered

  • Change the backend default, e.g. count only the ranks that load: the best value depends on the storage's readahead, which the backend can't detect, so no single default fits every setup.
  • Turn off readahead for checkpoint reads only: the FUSE mount has no per-file or per-process readahead setting.

User-facing changes

Config Before After
file_read_workers not available concurrent file reads per rank; None keeps the backend default

Performance

DeepSeek-V3 671B HF checkpoint load, 64 GPUs on 8 hosts (8 ranks per host), from a FUSE-mounted remote store. Header reads take about 7.3 s in every run.

Readahead Reads per rank Model read Total load
16 MiB (default) 3 (default) 57.1 s 64.9 s
16 MiB (default) 6 68.4 s 76.1 s
16 MiB (default) 12 70.1 s 77.9 s
16 MiB (default) 24 80.6 s 88.3 s
2 MiB 3 45.6 s 53.4 s
0 6 48.3 s 56.3 s

With readahead off, a raw read benchmark on one host got 4.6 GB/s at 3 reads per rank and 6.6 GB/s at 6.

Testing

  • test_rejects_file_read_workers_below_one: file_read_workers=0 raises at config time instead of failing during the load.
  • All 127 tests in tests/unit_tests/cpu/components/checkpointer/ pass against torch_checkpointing 5c45dc3.

Known issues / follow-ups

  • torch_checkpointing is pinned to a commit. Switch to a release pin once one includes DefaultLoadPlanExecutor.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 18, 2026
@ivy-zhou
ivy-zhou marked this pull request as ready for review November 18, 2026 23:57
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 18, 2026
…loads

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
torch_checkpointing's `DefaultLoadPlanExecutor` reads 24 files at a time per host, split evenly across the host's ranks (`LOCAL_WORLD_SIZE`): 3 per rank with 8 ranks. That assumes every local rank is a trainer loading at the same time. When it isn't, or when storage wants more reads in flight, there is no way to change it: TorchTitan uses the backend's default load config.

**Example.**
```python
# Before: 24 // LOCAL_WORLD_SIZE reads per rank, fixed.
TorchCheckpointingManager.Config(initial_load_path=path)

# After: 8 concurrent file reads per rank, for native and HF loads.
TorchCheckpointingManager.Config(initial_load_path=path, file_read_workers=8)
```

## What changed
- `TorchCheckpointingManager.Config.file_read_workers: int | None = None` sets `DefaultLoadPlanExecutor(file_read_workers=...)` in the backend's load config. `None` keeps the backend default.
- The temporary manager for HF loads reuses that load config, so HF loads use the same setting.

## User-facing changes
| Config | Before | After |
| --- | --- | --- |
| `file_read_workers` | not available | concurrent file reads per rank; `None` keeps the default |

## Testing
- `test_file_read_workers_configures_the_load_plan_executor` in `tests/unit_tests/cpu/components/checkpointer/test_torch_checkpointing.py`: `file_read_workers=5` reaches the load config's `DefaultLoadPlanExecutor`.
- All 47 tests in the file pass against a torch_checkpointing that has `default_load_plan_executor`.

## Known issues / follow-ups
- Blocked on torch_checkpointing: its GitHub main, which CI installs, has no `torch_checkpointing.default_load_plan_executor` and no `CheckpointLoaderConfig(load_plan_executor=...)`. Until it does, pyrefly and the RL CPU unit tests fail on this PR with `ModuleNotFoundError`.
@tianyu-l

Copy link
Copy Markdown
Contributor

@ivy-zhou as general suggestion, could you get @claude review approval before human review?

@ivy-zhou

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ivy-zhou's task in 1m 16s —— View job


Request changes -- review posted. Blocked on a torch_checkpointing release and pin bump (pinned 0.1.1 lacks DefaultLoadPlanExecutor), and needs load-time numbers for the new knob.

@claude claude Bot 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.

Verdict: Request changes -- this can't merge yet. It needs a torch_checkpointing API that the pinned version (0.1.1) doesn't have, and the new knob has no measurement showing it makes loads faster.

What this PR does. It adds TorchCheckpointingManager.Config.file_read_workers and passes it to the backend as DefaultLoadPlanExecutor(file_read_workers=...). Native loads use it, and so does the temporary manager built for HF loads. None is meant to keep the backend default, which is 24 // LOCAL_WORLD_SIZE reads per rank.

Example.

# 8 GPUs/host, all ranks load: backend default = 24 // 8 = 3 reads in flight per rank.
TorchCheckpointingManager.Config(initial_load_path=p)
# Only 1 of 8 local ranks is a trainer (e.g. RL colocated generator): still 3 per rank,
# so the host has 3 reads in flight instead of 24. With this PR:
TorchCheckpointingManager.Config(initial_load_path=p, file_read_workers=24)

Must fix

  1. Evidence the knob matters. The summary says "I think this can be faster under some storage setups". .claude/rules/config.md asks that a new knob be backed by a verified use and answer "how would a user decide how to set this?". Please post load times from a real checkpoint, default vs. one or two file_read_workers values, and name the storage and the setup (ranks per host, how many of them load). If a single value always wins in some setup, consider fixing the backend's default (for example, counting only the ranks that actually load) instead of adding a TorchTitan field.
  2. torchtitan/components/checkpointer/torch_checkpointing.py:34 -- the import breaks on the pinned torch_checkpointing == 0.1.1. Bump the pin in this PR once upstream has released the API.
  3. torchtitan/components/checkpointer/torch_checkpointing.py:235 -- validate file_read_workers >= 1 in __post_init__, and document how to choose a value.
  4. tests/unit_tests/cpu/components/checkpointer/test_torch_checkpointing.py:381 -- the test only re-reads a config value and depends on a private upstream attribute. Delete it.

Should consider

  • torchtitan/components/checkpointer/torch_checkpointing.py:194 -- load_config is always passed now. Make it required and drop the fallback.

Not verified: I couldn't confirm that DefaultLoadPlanExecutor(file_read_workers=None) gives exactly the backend's default CheckpointLoaderConfig() executor, because the API isn't in the installed version. If the two differ, this PR changes load behavior for every user who leaves the field unset.

CheckpointSaverConfig,
SyncCheckpointSaverConfig,
)
from torch_checkpointing.default_load_plan_executor import DefaultLoadPlanExecutor

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.

CI pins torch_checkpointing == 0.1.1 (.ci/docker/requirements.txt:19), and that version has no torch_checkpointing.default_load_plan_executor module or CheckpointLoaderConfig(load_plan_executor=...). So once this merges, importing the checkpointer fails with ModuleNotFoundError, and every user on the pinned version is broken, not only CI. Fix: wait for a torch_checkpointing release that ships this API, then bump the pin in this same PR.

Comment on lines +235 to +238
file_read_workers: int | None = None
"""Checkpoint files each rank reads concurrently when loading. None
uses the backend's default, which splits a per-host number of reads
across the ranks on the host."""

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.

Nothing checks this value at config time. If file_read_workers=0 or a negative number is set, it goes straight to the backend, and the failure (or a hang, if the backend builds a zero-worker pool) only shows up at load time. That can be many minutes into a job. Please raise a ValueError in __post_init__ when self.file_read_workers is not None and self.file_read_workers < 1.

The docstring should also tell the user how to pick a value: for example, raise it when ranks on a host don't all load at once, or when remote storage benefits from more reads in flight. Back it with the measurement asked for in the review body.

Comment on lines 194 to +214
@@ -208,6 +211,7 @@ def _default_backend_config(
items=_item_specs() if items is None else items,
default=default,
save=save_config,
load=CheckpointLoaderConfig() if load_config is None else load_config,

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.

Both callers of _default_backend_config (lines 314 and 407) now pass load_config, so the None default and the CheckpointLoaderConfig() fallback never run. Make it a required keyword (load_config: CheckpointLoaderConfig) and pass load=load_config directly. If a future caller forgets it, that should fail loudly instead of quietly dropping the user's setting.

Comment on lines +381 to +391
def test_file_read_workers_configures_the_load_plan_executor(self) -> None:
config = TorchCheckpointingManager.Config(
keep_latest_k=0, load_only=True, file_read_workers=5
)

manager, _ = self._build_manager(config)

executor = manager._manager_config.load.load_plan_executor
self.assertIsInstance(executor, DefaultLoadPlanExecutor)
self.assertEqual(executor._file_read_workers, 5)
manager.close()

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.

This test only checks that a config value set two lines earlier comes back out. .claude/rules/tests.md says not to add tests that only re-read a config. It also reads the backend's private _file_read_workers, so it will break whenever torch_checkpointing renames an internal. And it skips the HF path, which is the less obvious part of the plumbing (line 410). Please delete it. If you want coverage, a __post_init__ test that file_read_workers=0 raises would guard a real contract, the validation requested at line 235.

…anExecutor

Pin torch_checkpointing to meta-pytorch/torch_checkpointing 5c45dc3, the same commit #6169 pins; PyPI 0.1.1 has no `DefaultLoadPlanExecutor`. Reject `file_read_workers < 1` when the config is built, say when to raise it, and replace the test that re-read the config with one for the validation.
@ivy-zhou

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @ivy-zhou's task in 1m 38s —— View job


Request changes -- review posted. The pin, validation and test fixes are resolved, but the benchmark still doesn't show file_read_workers beating the default: the fastest load (2 MiB readahead) uses 3 reads per rank, and there's no end-to-end readahead-0 run at 3 reads per rank to compare against.

@claude claude Bot 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.

Verdict: Request changes -- the code now imports, validates and tests correctly, but the benchmark still doesn't show the new knob doing better than the default. In the table, the fastest load uses the default worker count.

What this PR does. It adds TorchCheckpointingManager.Config.file_read_workers and passes it to the backend as DefaultLoadPlanExecutor(file_read_workers=...), for native loads and HF loads. It pins torch_checkpointing to 5c45dc3, which has that API. file_read_workers < 1 raises in __post_init__.

Example. This is the PR's DeepSeek-V3 671B HF load (8 hosts x 8 ranks, FUSE mount):

readahead 16 MiB, default 3/rank  -> 64.9 s   (best at this readahead; raising the knob is 11-23 s slower)
readahead 2 MiB,  default 3/rank  -> 53.4 s   (best overall, knob not needed)
readahead 0,      file_read_workers=6 -> 56.3 s   (only row that uses the knob)
readahead 0,      default 3/rank  -> not measured end-to-end

Re-review of the earlier must-fix items

  • Import breaks on pinned 0.1.1: resolved. The pin is now 5c45dc3.
  • Validate >= 1 in __post_init__: resolved.
  • Test that re-read the config: resolved. It was replaced with a validation test.
  • Evidence that the knob matters: partly resolved. See Must fix 1.
  • My earlier should-consider (make load_config required in _default_backend_config) was wrong. _save_hf_checkpoint calls it without load_config (torch_checkpointing.py:622), and so do two tests. Keep the fallback.

Must fix

  1. The value of the knob isn't shown yet. The only row that sets file_read_workers (readahead 0, 6/rank, 56.3 s) is slower than the default on a 2 MiB mount (53.4 s). There is no end-to-end row for readahead 0 with the default 3/rank, which is the comparison that would show what the knob adds. The 4.6 vs 6.6 GB/s single-host raw read is the only evidence for it. Please (a) add the readahead-0, 3/rank end-to-end load, and (b) explain why a 2 MiB readahead mount isn't the answer: does readahead have to be 0 for some other workload, such as dataset reads? If the answer is "set readahead to about 2 MiB", the field has no consumer and should be dropped, per .claude/rules/config.md "Few Knobs".
  2. torch_checkpointing.py:236 -- the docstring's guidance ("raise it when only some ranks load") hasn't been measured and contradicts the data you have. Inline comment has a suggestion.

Should consider

  • .ci/docker/requirements.txt:19 -- the TODO names only the fsspec commit, not DefaultLoadPlanExecutor. Inline comment has a suggestion.

Not verified: that DefaultLoadPlanExecutor(file_read_workers=None) matches the backend's executor when no load config is given. The PR description says it does; I couldn't check the upstream source from this job. A maintainer still needs to review, since this touches the core checkpointer.

Comment on lines +236 to +239
"""Checkpoint files each rank reads concurrently when loading. None
uses the backend's default, which splits a per-host number of reads
across the ranks on the host. That default assumes every rank on the
host loads at once; raise it when only some of them do."""

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.

The docstring tells users to raise this "when only some of them [ranks] do" load. That case isn't measured anywhere in the PR. The one case you did measure points the other way: storage with readahead off, where 6 per rank beat 3 in the raw benchmark, and on a 16 MiB readahead mount raising it made loads slower (64.9 s -> 76.1-88.3 s). If you follow the docstring, you can make loads slower. Describe the measured case instead, and say that with large readahead the default is best:

Suggested change
"""Checkpoint files each rank reads concurrently when loading. None
uses the backend's default, which splits a per-host number of reads
across the ranks on the host. That default assumes every rank on the
host loads at once; raise it when only some of them do."""
"""Checkpoint files each rank reads concurrently when loading. None
uses the backend's default, which splits a per-host number of reads
across the ranks on the host. Raise it only on storage without
readahead, where each read waits for its own fetch; with large
readahead, extra reads in flight waste prefetch and slow loads."""

Comment on lines +19 to +20
# TODO: pin a release once torch_checkpointing publishes one with the
# fsspec storage backend (meta-pytorch/torch_checkpointing 5bda153).

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.

This TODO was copied from #6169 and only names the fsspec backend (5bda153). This PR needs the pin because of DefaultLoadPlanExecutor. If #6169 lands first or gets dropped, nothing here says the pin is also required for this import, and a later "bump to a release with fsspec" could pick a release that doesn't have it. Name both requirements. #6169 can take the same text, so the two PRs still don't conflict:

Suggested change
# TODO: pin a release once torch_checkpointing publishes one with the
# fsspec storage backend (meta-pytorch/torch_checkpointing 5bda153).
# TODO: pin a release once torch_checkpointing publishes one with the
# fsspec storage backend (5bda153) and DefaultLoadPlanExecutor (5c45dc3).

@ivy-zhou

Copy link
Copy Markdown
Contributor Author

To clarify, the knob doesn't have to do better than the default. I'm merely trying to show with the example that if you've configured less readahead with your filesystem (which is outside the scope of this PR, and up to the user's discretion) it's useful to provide a knob that is able to tune the value.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/docker ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl 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.

2 participants