Unit 5 of 11 · about 5 hours · explain, measure
Coordinated saves, asynchronous checkpointing and staging memory
Synchronous saves stop the world; asynchronous saves move the cost to host memory and a background thread. Ranks that disagree on participation corrupt the checkpoint either way.
You'll be able to
- Explain who must participate in a save and where the barriers go, including the separate-group isolation pattern.
- Measure synchronous pause against asynchronous overlap on CPU and state the staging memory cost of each mode.
Covers
Read
In this order, only the parts listed
0 of 4 done
- The async DCP recipePyTorch Distributed Checkpoint Recipes
Asynchronous Checkpointing Overview: copy to CPU buffers first, memory rises by per-rank size times ranks, one outstanding request at a time; Fully Asynchronous Staging with
DefaultStager(new in 2.9):staging_completionbeforeoptimizer.step,upload_completionjoin; Even more performance with Pinned Memory:FileSystemWriter(cache_staged_state_dict=True)keeps a persistent buffer (page read 2026-10-14) - Coordinated async with an isolated groupTorchFeather - Distributed Checkpoint Manager
AsyncModewithdist.new_group(backend="gloo")forasync_save_pgwith all ranks participating;_async_waitbefore each new save and inclose; the last-step save forced synchronous; garbage collection around async saves - Async modes and staging waitsTorchTitan - Checkpointing
AsyncModewithDISABLED,ASYNCandASYNC_WITH_PINNED_MEM;DefaultStagerwithStagingOptions;_maybe_wait_for_stagingseparating staging from upload completion - All ranks enter every saveDistributed Training Guide - Sharded Checkpoints, Determinism and Elastic Training
Saving a sharded checkpoint:
dist.barrier, then all ranks callget_state_dictbecause every shard is needed
Focus on
- Every rank participates in every save. DCP plans across the group, so a rank that skips
savebreaks the plan for all. Barrier before, join the future before the next save. - Async staging copies parameters to CPU buffers first so training continues. The copy costs per-rank size times ranks of host memory, and pinned buffers persist between saves instead of releasing.
- With a
DefaultStagerdoing asynchronous staging,async_savereturns two futures with two deadlines:staging_completionmust resolve beforeoptimizer.stepmutates the parameters, andupload_completionbefore the next save reuses the buffers or the job exits. The CPU default path stages synchronously and returns one future; join it before the next save or the exit. - Isolate checkpoint collectives on their own process group, as TorchFeather's gloo
async_save_pgdoes, so save coordination never interleaves with training collectives.
Common mistakes · 3
- Queueing a second
async_savebefore joining the first. Each outstanding request holds a full staging copy, and on onegloogroup the two background saves interleave their collectives: in a 2-process CPU run both timed out and neither checkpoint was written. - Calling
optimizer.stepright afterasync_savewith aDefaultStager. The device-to-host copy may still be in flight, so wait onstaging_completionfirst or the checkpoint captures half-updated weights. - Tearing down while the future is pending. Join first, as TorchFeather's
closedoes with_async_waitbefore destroying its group: destroying the group with the save in flight produced.metadataplus one of two shards and a clean exit code.
Try it yourself
Closed-book, before checking anything
dcp.save calls against 5 async_save calls with joining on CPU, and report both totals plus how many staging copies are held at once. Then destroy the process group right after the last async_save without joining: on 2 CPU processes with PyTorch 2.14.1 this left .metadata plus only rank 0's shard, with exit code 0. A plain exit without the destroy still completes, because the interpreter waits for the background thread.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Training continues immediately after
async_savereturns. What protects the checkpoint from the nextoptimizer.step?AnswerThe staging copy: parameters are first copied to CPU buffers, and the step mutates device weights, not the staged copy. With
DefaultStagerthe copy itself is asynchronous, sostaging_completionmust resolve before the step.2.Two ranks save while a third skips the call and keeps training. What happens at load?Answer
The save plan assumed all ranks, so the checkpoint is missing a shard while
.metadatadisagrees with the files. Every rank must enter every save.3.Why does TorchFeather create a separate gloo group for async saves instead of reusing the training group?Answer
So checkpoint coordination traffic and barriers never interleave with training collectives on the default group. The save path gets its own ordering domain.
4.Host memory grows with every checkpoint although each save completes. What was kept, and what releases it?Answer
The pinned staging buffer from
cache_staged_state_dict=True, which persists between saves by design. Only destroying the writer releases it; without the cache, buffers release at each save's completion.
Practice
- PyTorch async DCP recipe loop, CPU-ported
Port the 10-step
async_saveloop to CPU gloo: one outstanding request with a.result()join per step, then add theDefaultStagervariant withstaging_completionbeforeoptimizer.stepandupload_completionat the end; time the pause against synchronousdcp.saveThe recipe uses CUDA devices. On CPU there is no device-to-host copy, so timings compare API overhead and disk writes only. GPU staging overlap needs two or more GPUs; state that condition in your notes.
You're done when
Your CPU port joins exactly one outstanding request per step, separates staging from upload completion in the DefaultStager variant, and your timings state which costs transfer to GPUs and which do not.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 9 more in the section
- PyTorch Distributed Checkpoint RecipesPyTorch · required
Complete the distributed checkpoint recipe with a tiny sharded model on CPU, then
dcp.async_savefrom the 2.14 reference at https://docs.pytorch.org/docs/2.14/distributed.checkpoint.html. The recipe saves model and optimizer only: add scheduler, scaler, RNG and dataloader state yourself, then inject partial directories, missing shards and a changed world-size restore. - TorchFeather - Distributed Checkpoint ManagerTorchFeather · required
Trace components/checkpoint.py through state wrappers, DCP save and load, asynchronous mode, retention and cleanup. Write a failure table for every barrier, future, temporary artifact and deletion boundary.
- Distributed Training Guide - Sharded Checkpoints, Determinism and Elastic TrainingLambda Labs · required
Run
related-topics/elastic-training/toy.pywith two CPU processes (hide any GPU so it uses Gloo) to see a crash-and-restart loop, then read the determinism related topic and the Chapter 4 sharded save and load. Prove the same next batches and updates after one interrupted run. - TorchTitan - CheckpointingPyTorch · support
Read
docs/checkpoint.mdand the checkpointer component at a pinned commit: intervals, model-only and export saves, asynchronous modes and keys excluded from loading.
Also in this section
- Machine Learning Systems Volume II - Chapter 7 Fault ToleranceML Systems Textbook · primary
Read Failure Analysis at Scale, Hardware Fault Taxonomy, Check-and-Verify, Fault Injection Tools and Frameworks, Checkpointing, Failure Detection and Recovery, Elastic Recovery and Distributed Debugging and Observability. Turn them into a failure matrix before implementing the PyTorch DCP lab.
- Machine Learning Engineering Open Book - Checkpoints, Storage and Fault ToleranceStas Bekman · required
Read
training/fault-tolerance/README.md(frequent checkpoints, kill and save switches, watchdogs, preemption) and the "Don't forget the checksums" and benchmark sections ofstorage/README.md. Turn them into an operational save, verify, publish, retain and recover runbook. - Picotron - Checkpoint StateHugging Face · support
Inspect picotron/checkpoint.py and every call site in train.py. List which state is saved, how ranks participate and which DT-1 reproducibility requirements need to be added in your project.
- Nanotron - Distributed SerializationHugging Face · support
Read the serialization section of
docs/docs.md(metadata, per-rank optimizer and RNG shards) and its statement that checkpoints are not topology agnostic, then the reasons insrc/nanotron/serialize/. Use it as the worked example of why resharding is hard. - PyTorch Elastic Run DocumentationPyTorch · support
Use failure modes and membership changes to understand agent, worker group, rendezvous and restart semantics. Implement only bounded local restart tests; elasticity is not a substitute for checkpoint correctness.
- torchftPyTorch · support
Read the README and
train_ddp.py: per-step quorum through the lighthouse, fault-tolerant DDP and HSDP, and live peer recovery. Compare per-step healing with restart-from-checkpoint. - The Llama 3 Herd of Models - Reliability and Operational ChallengesLlama Team, Meta (2024) · support
Read the reliability section and its interruption table (root causes of unexpected interruptions over a 54-day snapshot) and use it to set failure rates in your checkpoint-interval model.
- Bumblebee - DCP and Checkpoint Smoke TestsBumblebee · depth
Only as a possible capstone target: read
primitive/ckpt/dcp.pyand the checkpoint smoke tests in a clean checkout. Its own roadmap lists reshardable optimizer state as a gap. - OLMo-core CheckpointerAi2 · support
Read
src/olmo_core/train/checkpoint.py(_temporary_wd,_get_tmp_dir,_teardown_tmp_dir,_save_metadata) for temp-directory atomic publish with barrier discipline, andsrc/test/train/checkpoint_test.py(run_checkpointer) for the save, find and reload assertions.