Repository navigation
Conversation
…ke process group
## Summary (human-written)
It is useful to support fake pg to measure the storage performance and memory usage with single GPU. This PR enables this feature for torch_checkpointing.
## Why
A fake process group (`--comm.backend fake` or `real_pp_fake_spmd`) lets one GPU run as one rank of a large job to test memory and speed. `TorchCheckpointingManager` cannot save under it. torch_checkpointing reads its rank info from the default process group, so it expects the fake world size: the save barrier waits for peers that do not exist, and metadata all_gather moves no data.
**Example.** `NGPU=4` with the fake backend, logical rank 2, `interval=1`:
```
Before: manager.save(curr_step=1)
-> ValueError: FakeStore ... is unusable as a distributed barrier
After: <folder>/checkpoint/rank_2/step-1/ is a one-rank checkpoint of rank 2's shards
manager.load() restores the same values
```
## What changed
- Under a fake default process group, every backend `CheckpointManager` config (main, HF load, last-step save) gets a one-rank `RankInfo`. Each process saves its own shards as an independent one-rank checkpoint. This uses `CheckpointManager.Config.rank_info`, which the pinned torch_checkpointing commit already has.
- In fake mode the checkpoint folder gets a `rank_<global rank>` subfolder. Under `real_pp_fake_spmd` several real processes share the folder, and each has a distinct logical rank (`pp_rank * NGPU / PP`), so their paths do not collide.
- Under a fake process group, a native (non-HF) `initial_load_path` raises `ValueError`. With a one-rank `RankInfo`, the direct-read path picks the file from `RankInfo.global_rank`, so a checkpoint from a real multi-rank job would silently load rank 0's shards. HF loads still work: the resharder takes the target shard from `dist.get_rank()`. Resuming from the process's own `rank_<r>` folder also still works.
- The HF consolidation callback calls `dist.barrier()`. Under a fake group this returns at once, so no change is needed there.
## Alternatives considered
- Special-case the fake backend inside torch_checkpointing: reviewers asked to keep the override in the caller.
- A new config field: the fake backend is already known from the process group, so a knob adds nothing.
## Numerics
No change. The code only runs under a fake process group.
## Testing
- New `test_fake_process_group_round_trip_through_a_real_backend`: under a fake group of world size 4 at rank 2, saves with the real async backend, checks the `rank_2/step-1` folder, and loads the values back into a fresh model. Without this commit, the save fails at the barrier. It also checks that a native `initial_load_path` raises `ValueError`.
- `pytest tests/unit_tests/cpu/components/checkpointer` with the pinned torch_checkpointing: 133 passed.
## Known issues / follow-ups
- A native checkpoint from a real multi-rank job cannot be loaded under a fake process group. Supporting it needs torch_checkpointing to pick the direct-read file from the process group rank.
stack-info: PR: #6446, branch: fegin/stack/48
1bb509a to
781398e
Compare
|
@claude reviews this PR |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging -- the approach is small and in the right layer, but retention silently stops for every fake-PG process whose logical rank is not 0.
What this PR does. When the default process group is fake, every torch_checkpointing backend config gets a one-rank RankInfo. Each process then saves its own shards as an independent one-rank checkpoint under <folder>/rank_<logical rank>/, so it never waits on barriers or all_gathers whose peers don't exist. A native (non-HF) initial_load_path is rejected, because the one-rank RankInfo would read rank 0's shards.
Example. NGPU=4, --comm.backend real_pp_fake_spmd, PP=2, so the physical ranks 0 and 1 are logical ranks 0 and 2. interval=1, default keep_latest_k=10:
Before: save(step=1) on either process -> ValueError: FakeStore ... unusable as a distributed barrier
After: checkpoint/rank_0/step-1, checkpoint/rank_2/step-1; load() restores each process's own shards
After step 20: rank_0 keeps 10 steps, but rank_2 keeps all 20 (retention is gated on get_rank()==0)
Must fix
torchtitan/components/checkpointer/torch_checkpointing.py:308-- retention only runs on logical rank 0, so every other fake-PG process keeps all of its checkpoints. The inline comment has a drop-in_should_purgeoverride.
Should consider
torchtitan/components/checkpointer/README.md-- add one line on the fake-PG layout (<folder>/rank_<r>/step-N, plus the ban on nativeinitial_load_path), so users know where checkpoints land and why resuming from a real job's folder finds nothing.
Questions
- Did a native
initial_load_pathwork under a fake group before this PR? Without arank_infooverride, the backend'sRankInfocomes from the fake group (rank 2 of 4), so the direct-read path would pick rank 2's file. If the load path has no collectives that need real peers, this PR turns a working load into aValueError. Keeping the defaultRankInfofor theinitial_load_pathload config, and passing the one-rank one only to save and resume configs, could keep it working. That load is also a natural part of "measure storage performance", the stated goal. If it never worked onmain, the ban is fine.
Details
- Gate. The problem is real and stated with a concrete failure. torch_checkpointing reads rank info from the default PG, and the fix uses the existing
CheckpointManager.Config.rank_infofield rather than a new knob or a backend special case. Probingdist.get_backend() == "fake"matches existing usage (distributed/pipeline_parallel.py:111,models/deepseek_v4/model.py:130). The DCP manager (dcp.py) has no fake-PG handling to reuse. - Folder uniqueness. Under
real_pp_fake_spmd,init_fake_mode(logical_world_size, rank=physical_rank * spmd_world_size)(distributed/utils.py:394-396) makes the default group fake, with a distinct logical rank per process. Sorank_<r>does not collide, and_is_fake_process_group()is true there as well. - Purge.
_purge_stale_checkpoints(base.py:724) gates on_should_purge(), which requiresdist.get_rank() == 0. Under a fake PG,dist.get_rank()returns the logical rank, so logical rank 0 purges onlyrank_0/. - HF last-step export. Each process consolidates only its own shards into
rank_<r>/exports/step-N. Under fake comms the values are meaningless anyway, so I'm not flagging it. - Overlap search. I searched "fake process group checkpoint" and "torch_checkpointing". Related open PRs are #6179 (base of this stack), #6197, #6374 and #5167. None of them touches the fake-PG path.
Not verified: the description's claims about torch_checkpointing internals (that the direct-read path picks its file from RankInfo.global_rank, and that the HF resharder uses dist.get_rank()). The torch_checkpointing source wasn't available in this runner.
A maintainer still needs to review.
| # Each process writes a one-rank checkpoint, so it needs its own | ||
| # folder. The fake rank is unique per process, also under | ||
| # real-PP/fake-SPMD, where each PP process has a distinct logical rank. | ||
| self.folder = filesystem.join(self.folder, f"rank_{dist.get_rank()}") |
There was a problem hiding this comment.
With this change, each process is the only writer of its own rank_<r> folder. But retention still runs only on dist.get_rank() == 0 (BaseCheckpointManager._should_purge, base.py:653-659). Under a fake group, dist.get_rank() is the logical rank. So a process at logical rank 2 (the PR's own example), any real_pp_fake_spmd process with physical rank > 0, or fake with FAKE_PP_RANK > 0 never purges. With the default keep_latest_k = 10, its folder silently keeps every checkpoint, so a long storage benchmark eventually fills the disk. The test misses this because it uses keep_latest_k=0.
Smallest fix, local to this manager so the shared base stays unchanged:
def _should_purge(self) -> bool:
# Under a fake process group each process is the only writer of its
# own rank_<r> folder, so each one runs its own retention.
if _is_fake_process_group():
return self.keep_latest_k > 0 and self._storage.isdir(self.folder)
return super()._should_purge()To guard it cheaply, the existing fake-PG test could use keep_latest_k=1, save steps 1 and 2, and assert that only rank_2/step-2 remains.
There was a problem hiding this comment.
Good catch, fixed. TorchCheckpointingManager._should_purge now lets every process purge its own rank_<r> folder under a fake process group, and keeps the base behavior otherwise. The test now uses keep_latest_k=2, saves steps 1-3 as rank 2, and checks that only step-2 and step-3 remain. It fails without the override.
…ke process group
## Summary (human-written)
It is useful to support fake pg to measure the storage performance and memory usage with single GPU. This PR enables this feature for torch_checkpointing.
## Why
A fake process group (`--comm.backend fake` or `real_pp_fake_spmd`) lets one GPU run as one rank of a large job to test memory and speed. `TorchCheckpointingManager` cannot save under it. torch_checkpointing reads its rank info from the default process group, so it expects the fake world size: the save barrier waits for peers that do not exist, and metadata all_gather moves no data.
**Example.** `NGPU=4` with the fake backend, logical rank 2, `interval=1`:
```
Before: manager.save(curr_step=1)
-> ValueError: FakeStore ... is unusable as a distributed barrier
After: <folder>/checkpoint/rank_2/step-1/ is a one-rank checkpoint of rank 2's shards
manager.load() restores the same values
```
## What changed
- Under a fake default process group, every backend `CheckpointManager` config (main, HF load, last-step save) gets a one-rank `RankInfo`. Each process saves its own shards as an independent one-rank checkpoint. This uses `CheckpointManager.Config.rank_info`, which the pinned torch_checkpointing commit already has.
- In fake mode the checkpoint folder gets a `rank_<global rank>` subfolder. Under `real_pp_fake_spmd` several real processes share the folder, and each has a distinct logical rank (`pp_rank * NGPU / PP`), so their paths do not collide.
- Under a fake process group, a native (non-HF) `initial_load_path` raises `ValueError`. With a one-rank `RankInfo`, the direct-read path picks the file from `RankInfo.global_rank`, so a checkpoint from a real multi-rank job would silently load rank 0's shards. HF loads still work: the resharder takes the target shard from `dist.get_rank()`. Resuming from the process's own `rank_<r>` folder also still works.
- Retention runs on every process under a fake process group. `BaseCheckpointManager._should_purge` only purges on `dist.get_rank() == 0`, which is the logical rank, so every other process would keep all of its checkpoints. `TorchCheckpointingManager` overrides `_should_purge`, so the shared base is unchanged.
- `README.md`: describe the `rank_<r>/step-N` layout, the retention, and the native `initial_load_path` ban.
- The HF consolidation callback calls `dist.barrier()`. Under a fake group this returns at once, so no change is needed there.
## Alternatives considered
- Special-case the fake backend inside torch_checkpointing: reviewers asked to keep the override in the caller.
- A new config field: the fake backend is already known from the process group, so a knob adds nothing.
## Numerics
No change. The code only runs under a fake process group.
## Testing
- New `test_fake_process_group_round_trip_through_a_real_backend`: under a fake group of world size 4 at rank 2, saves steps 1-3 with the real async backend and `keep_latest_k=2`, checks that `rank_2/` holds only `step-2` and `step-3`, and loads the values back into a fresh model. Without this commit, the save fails at the barrier. Without the `_should_purge` override, `step-1` is kept. It also checks that a native `initial_load_path` raises `ValueError`.
- `pytest tests/unit_tests/cpu/components/checkpointer` with the pinned torch_checkpointing: 133 passed.
## Known issues / follow-ups
- A native checkpoint from a real multi-rank job cannot be loaded under a fake process group. Supporting it needs torch_checkpointing to pick the direct-read file from the process group rank.
stack-info: PR: #6446, branch: fegin/stack/48
781398e to
bbd0b64
Compare
|
README: added a short "Fake process groups with TorchCheckpointingManager" section (layout, retention, the native initial_load_path ban). On the initial_load_path question: we do not need it. Under a fake process group no real communication happens, so loading a real job's checkpoint gives no useful values, and the ban is intended. HF loads still work. |
Stacked PRs:
[checkpoint] Save and load torch_checkpointing checkpoints under a fake process group
Summary (human-written)
It is useful to support fake pg to measure the storage performance and memory usage with single GPU. This PR enables this feature for torch_checkpointing.
Why
A fake process group (
--comm.backend fakeorreal_pp_fake_spmd) lets one GPU run as one rank of a large job to test memory and speed.TorchCheckpointingManagercannot save under it. torch_checkpointing reads its rank info from the default process group, so it expects the fake world size: the save barrier waits for peers that do not exist, and metadata all_gather moves no data.Example.
NGPU=4with the fake backend, logical rank 2,interval=1:What changed
CheckpointManagerconfig (main, HF load, last-step save) gets a one-rankRankInfo. Each process saves its own shards as an independent one-rank checkpoint. This usesCheckpointManager.Config.rank_info, which the pinned torch_checkpointing commit already has.rank_<global rank>subfolder. Underreal_pp_fake_spmdseveral real processes share the folder, and each has a distinct logical rank (pp_rank * NGPU / PP), so their paths do not collide.initial_load_pathraisesValueError. With a one-rankRankInfo, the direct-read path picks the file fromRankInfo.global_rank, so a checkpoint from a real multi-rank job would silently load rank 0's shards. HF loads still work: the resharder takes the target shard fromdist.get_rank(). Resuming from the process's ownrank_<r>folder also still works.BaseCheckpointManager._should_purgeonly purges ondist.get_rank() == 0, which is the logical rank, so every other process would keep all of its checkpoints.TorchCheckpointingManageroverrides_should_purge, so the shared base is unchanged.README.md: describe therank_<r>/step-Nlayout, the retention, and the nativeinitial_load_pathban.dist.barrier(). Under a fake group this returns at once, so no change is needed there.Alternatives considered
Numerics
No change. The code only runs under a fake process group.
Testing
test_fake_process_group_round_trip_through_a_real_backend: under a fake group of world size 4 at rank 2, saves steps 1-3 with the real async backend andkeep_latest_k=2, checks thatrank_2/holds onlystep-2andstep-3, and loads the values back into a fresh model. Without this commit, the save fails at the barrier. Without the_should_purgeoverride,step-1is kept. It also checks that a nativeinitial_load_pathraisesValueError.pytest tests/unit_tests/cpu/components/checkpointerwith the pinned torch_checkpointing: 133 passed.Known issues / follow-ups