Unit 2 of 11 · about 4 hours · explain, implement

Full and sharded formats and distributed checkpoint state-dict contracts

Sharded checkpoints are the only format that scales past one device's memory. The state-dict contract of pre-allocated storage plus name management is what later makes resharding possible.

You'll be able to

  • Explain when each rank writes its own shard versus gathering a full copy, and what the .metadata plus one-file-per-rank layout guarantees.
  • Save and load a tiny FSDP2 model with get_state_dict and set_state_dict plus a Stateful wrapper on CPU, and convert the result to a single-file torch checkpoint.

Covers

Full versus sharded checkpoint formatsDistributed checkpoint state-dict contracts
1

Read

In this order, only the parts listed

0 of 4 done

  1. DCP save and load with FSDP2PyTorch Distributed Checkpoint Recipes

    How DCP works: parallel save, reshard at load, multiple files with at least one per rank, in-place operation, Stateful handling; Saving: AppState, get_state_dict, dcp.save; Loading: rebuild model and optimizer first, then dcp.load, at the same or a different world size (page read 2026-10-14)

  2. Sharded save and load in the distributed-training guideDistributed Training Guide - Sharded Checkpoints, Determinism and Elastic Training

    Sharded Checkpoints with StateDictOptions(full_state_dict=False, cpu_offload=True); Saving a sharded checkpoint: barrier, then all ranks call get_state_dict for one file per rank; Loading a sharded checkpoint: get_state_dict, load, set_state_dict; Converting a sharded checkpoint to a full state dict checkpoint

    The chapter links the unversioned stable reference; read the 2.14 pages instead, where FSDP2 (fully_shard) is current and FSDP1 helpers are legacy.

  3. Formats: DCP versus torch.savePyTorch Distributed Checkpoint Recipes

    Formats: dcp_to_torch_save and torch_save_to_dcp with python -m torch.distributed.checkpoint.format_utils dcp_to_torch <dir> <out> (page read 2026-10-14)

  4. Per-rank files without DCPPicotron - Checkpoint State

    CheckpointManager._get_checkpoint_path names files by TP and PP rank; save_checkpoint writes model, optimizer, trained_steps and trained_tokens with torch.save from DP and CP rank 0 only; load_checkpoint assumes the same topology

2

Focus on

  • DCP loads into pre-allocated storage: rebuild the model and optimizer before dcp.load, because sharding for the load plan comes from the live objects. torch.load needs only a path.
  • Sharded means every rank saves. The checkpoint is the set of per-rank files plus .metadata; a missing shard is a corrupt checkpoint, not a smaller one.
  • get_state_dict with full_state_dict=False keeps shards local with CPU offload; True gathers the full copy on each rank. Choose per use, not per habit: shards for training, full for export.
  • Picotron's hand-rolled per-rank torch.save files carry no resharding metadata, so restore needs the identical TP and PP layout. That limitation is what DCP's planner plus .metadata removes.
Common mistakes · 3
  • Expecting dcp.load to create the model. It updates the passed state dict in place, so an unbuilt model gives it nothing to write into.
  • Saving only on rank 0 with a sharded state dict. Skipped ranks lose their shards and .metadata describes files that do not exist.
  • Reading one rank's .distcp file as a partial model. Shards are planner-assigned ranges, not layers; only dcp.load reassembles them.
3

Try it yourself

Closed-book, before checking anything

On CPU with 2 gloo processes, save a fully_shard toy model plus Adam state with the recipe's AppState, mutate both, reload, and show all 16 flattened state entries equal with torch.equal. Then convert the directory with dcp_to_torch_save.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Why does the DCP loading example rebuild the FSDP model and optimizer before calling dcp.load?Answer

    DCP loads in place into pre-allocated storage and takes each rank's sharding from the live objects. Without them it has nowhere to write and no resharding plan.

  2. 2.A 4-rank checkpoint directory holds .metadata and three .distcp files. Is it loadable?Answer

    No. One shard is missing, so the checkpoint is incomplete. Resume must refuse it and fall back to the last known good, never train on three quarters of the state.

  3. 3.When should full_state_dict be true at save time, and what does it cost?Answer

    Only to export for single-process use such as inference. Every rank gathers the full model, so peak memory holds the whole copy instead of one shard.

  4. 4.Picotron saves one .pth per TP and PP rank with torch.save. What breaks when the job restarts with a different TP degree?Answer

    Each file holds a fixed TP slice with no resharding metadata, and load_checkpoint assumes the same topology. The slices no longer match the new layout.

5

Practice

  • PyTorch DCP recipe: FSDP save plus load, CPU-ported

    Port the Saving and Loading examples to CPU with gloo and torchrun --nproc-per-node 2 (no per-rank CUDA device): save after one step, mutate, reload, and assert bit-exact parameters and optimizer state; then run dcp_to_torch_save on the directory

    The recipe targets an 8-GPU server with NCCL but the logic is identical on gloo. Expect .metadata plus one __<rank>_0.distcp per rank.

You're done when

Your CPU port saves, reloads bit-exactly and converts to a single file, and you can state which half of the contract (get_state_dict versus set_state_dict) each failure violates.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 10 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.

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

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

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.

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

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

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

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

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