Repository navigation
Conversation
…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`.
|
@ivy-zhou as general suggestion, could you get |
|
@claude review |
There was a problem hiding this comment.
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
- Evidence the knob matters. The summary says "I think this can be faster under some storage setups".
.claude/rules/config.mdasks 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 twofile_read_workersvalues, 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. torchtitan/components/checkpointer/torch_checkpointing.py:34-- the import breaks on the pinnedtorch_checkpointing == 0.1.1. Bump the pin in this PR once upstream has released the API.torchtitan/components/checkpointer/torch_checkpointing.py:235-- validatefile_read_workers >= 1in__post_init__, and document how to choose a value.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_configis 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 |
There was a problem hiding this comment.
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.
| 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.""" |
There was a problem hiding this comment.
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.
| @@ -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, | |||
There was a problem hiding this comment.
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.
| 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() |
There was a problem hiding this comment.
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.
|
@claude review |
|
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 |
There was a problem hiding this comment.
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
>= 1in__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_configrequired in_default_backend_config) was wrong._save_hf_checkpointcalls it withoutload_config(torch_checkpointing.py:622), and so do two tests. Keep the fallback.
Must fix
- 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". 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, notDefaultLoadPlanExecutor. 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.
| """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.""" |
There was a problem hiding this comment.
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:
| """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.""" |
| # TODO: pin a release once torch_checkpointing publishes one with the | ||
| # fsspec storage backend (meta-pytorch/torch_checkpointing 5bda153). |
There was a problem hiding this comment.
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:
| # 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). |
|
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. |
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
DefaultLoadPlanExecutorkeeps 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: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.
What changed
TorchCheckpointingManager.Config.file_read_workers: int | None = NonesetsDefaultLoadPlanExecutor(file_read_workers=...)in the backend's load config.NonebuildsDefaultLoadPlanExecutor(), the same executor the backend uses when no executor is configured, so leaving the field unset doesn't change load behavior.ValueErrorwhen the config is built..ci/docker/requirements.txt: pintorch_checkpointingto meta-pytorch/torch_checkpointing5c45dc3, the first commit withDefaultLoadPlanExecutor. These lines are identical to [checkpoint] TorchCheckpointingManager: checkpoints on fsspec URIs such as gs:// #6169's.Alternatives considered
User-facing changes
file_read_workersNonekeeps the backend defaultPerformance
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.
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=0raises at config time instead of failing during the load.tests/unit_tests/cpu/components/checkpointer/pass against torch_checkpointing5c45dc3.Known issues / follow-ups
torch_checkpointingis pinned to a commit. Switch to a release pin once one includesDefaultLoadPlanExecutor.