Skip to content

perf(ckpt): reuse DCP's save plan across saves - #4890

Open
MarioSieg wants to merge 4 commits into
mainfrom
mario/ckpt-plan-caching
Open

MarioSieg wants to merge 4 commits into
mainfrom
mario/ckpt-plan-caching

Conversation

@MarioSieg

@MarioSieg MarioSieg commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Pass DefaultSavePlanner(enable_plan_caching=True) to both DCP saves in CheckpointManager (the synchronous save and the async writer thread).
  • Every save after the first in a trainer process reuses the cached global plan instead of rank 0 gathering, deduplicating and validating every rank's plan again. A rank whose checkpointed tensors change name, shape or sharding sends its new plan and rank 0 replans; tensor values are always read fresh, so checkpoints are unchanged.
  • Expected win: planning per save drops from ~0.2-0.3 s to ~0.03 s at 32 ranks, and much more at larger rank counts (planning cost grows with ranks x tensors). Each new process, including a resume, still plans its first save in full.
  • Always on; no config change. Documented under "Asynchronous Checkpoints" in docs/training.md.

Test plan

  • uvx ruff check / uvx ruff format --check on ckpt.py
  • pytest tests/unit/train/test_ckpt.py tests/unit/train/test_checkpoint_writer.py tests/unit/train/test_checkpoint_model_files.py (CPU): 17 passed
  • CPU gloo script, 2 ranks: five DCP saves through CheckpointWriter (small max_file_bytes, so ranks split into several files) with plan caching on, including a shape change at the fourth save; each checkpoint loads back bitwise equal

Note

Low Risk
Checkpoint write path only; plan caching is a PyTorch DCP optimization with replan on layout changes, and saves still read fresh tensor values.

Overview
Trainer checkpoints now pass DefaultSavePlanner(enable_plan_caching=True) to PyTorch DCP on both the synchronous save path and the async background writer, so after the first save in a process the distributed save plan is reused instead of rank 0 re-gathering and validating every rank's plan on each step.

Planning once is documented under asynchronous checkpoints: the first save still plans globally; later saves keep the cached plan while tensor names, shapes, and shards are unchanged, and replan only when a rank's layout changes. Checkpoint contents and behavior are unchanged—this is always-on with no new config knob.

Reviewed by Cursor Bugbot for commit 419cfe6. Bugbot is set up for automated code reviews on this repo. Configure here.

Pass DefaultSavePlanner(enable_plan_caching=True) to both DCP saves, so
every save after the first in a process reuses the previous global plan
instead of rank 0 gathering and validating every rank's plan again. A
rank whose tensors' names, shapes or shards change sends a new plan and
rank 0 replans.
@MarioSieg
MarioSieg marked this pull request as ready for review December 3, 2026 19:44

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant