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

Rank participation and coordinated save barriersSynchronous versus asynchronous checkpointingStaging buffers and host-memory pressure during async saveAsynchronous checkpoint isolation with a separate process group
1

Read

In this order, only the parts listed

0 of 4 done

  1. 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_completion before optimizer.step, upload_completion join; Even more performance with Pinned Memory: FileSystemWriter(cache_staged_state_dict=True) keeps a persistent buffer (page read 2026-10-14)

  2. Coordinated async with an isolated groupTorchFeather - Distributed Checkpoint Manager

    AsyncMode with dist.new_group(backend="gloo") for async_save_pg with all ranks participating; _async_wait before each new save and in close; the last-step save forced synchronous; garbage collection around async saves

  3. Async modes and staging waitsTorchTitan - Checkpointing

    AsyncMode with DISABLED, ASYNC and ASYNC_WITH_PINNED_MEM; DefaultStager with StagingOptions; _maybe_wait_for_staging separating staging from upload completion

  4. All ranks enter every saveDistributed Training Guide - Sharded Checkpoints, Determinism and Elastic Training

    Saving a sharded checkpoint: dist.barrier, then all ranks call get_state_dict because every shard is needed

2

Focus on

  • Every rank participates in every save. DCP plans across the group, so a rank that skips save breaks 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 DefaultStager doing asynchronous staging, async_save returns two futures with two deadlines: staging_completion must resolve before optimizer.step mutates the parameters, and upload_completion before 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_pg does, so save coordination never interleaves with training collectives.
Common mistakes · 3
  • Queueing a second async_save before joining the first. Each outstanding request holds a full staging copy, and on one gloo group the two background saves interleave their collectives: in a 2-process CPU run both timed out and neither checkpoint was written.
  • Calling optimizer.step right after async_save with a DefaultStager. The device-to-host copy may still be in flight, so wait on staging_completion first or the checkpoint captures half-updated weights.
  • Tearing down while the future is pending. Join first, as TorchFeather's close does with _async_wait before destroying its group: destroying the group with the save in flight produced .metadata plus one of two shards and a clean exit code.
3

Try it yourself

Closed-book, before checking anything

Time 5 synchronous 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.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Training continues immediately after async_save returns. What protects the checkpoint from the next optimizer.step?Answer

    The staging copy: parameters are first copied to CPU buffers, and the step mutates device weights, not the staged copy. With DefaultStager the copy itself is asynchronous, so staging_completion must resolve before the step.

  2. 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 .metadata disagrees with the files. Every rank must enter every save.

  3. 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. 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.

5

Practice

  • PyTorch async DCP recipe loop, CPU-ported

    Port the 10-step async_save loop to CPU gloo: one outstanding request with a .result() join per step, then add the DefaultStager variant with staging_completion before optimizer.step and upload_completion at the end; time the pause against synchronous dcp.save

    The 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_save from 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.py with 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.md and 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 of storage/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 in src/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.py and 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, and src/test/train/checkpoint_test.py (run_checkpointer) for the save, find and reload assertions.