Unit 4 of 11 · about 4 hours · implement

Atomic publish, commit markers, checksums and corruption detection

A crash during a write is normal at scale. Without atomic publish the newest checkpoint is the corrupt one, and without checksums that corruption trains silently.

You'll be able to

  • Publish a sharded checkpoint so readers only ever see complete versions: temp directory, barrier, atomic replace, manifest last.
  • Detect corruption with per-shard checksums plus a completeness check, and fall back to the last known good.

Covers

Atomic publish with temporary paths and commit markersChecksums, completeness validation and corruption detection
1

Read

In this order, only the parts listed

0 of 4 done

  1. Temporary-directory publish with barriersOLMo-core Checkpointer

    _temporary_wd with _get_tmp_dir (<name>-tmp), _teardown_tmp_dir (barrier, rank-0 replace, visibility wait_for), _prepare_dir barrier discipline, _save_metadata writing rank-0 .metadata.json last

  2. Checksums on every syncMachine Learning Engineering Open Book - Checkpoints, Storage and Fault Tolerance

    Don't forget the checksums: verify MD5 or SHA256 on sync because some tools skip it; slow but safe

  3. Commit marker on the read pathTorchFeather - Distributed Checkpoint Manager

    _find_load_step .metadata probe for newest complete step; _purge_stale_checkpoints rank-0 only with sorted step-* selection

  4. Check-and-verify against silent corruptionMachine Learning Systems Volume II - Chapter 7 Fault Tolerance

    Check-and-Verify: Defending Against Silent Data Corruption, with Napkin Math 1.2: hash each gradient shard or reduced buffer and block the optimizer step on digest mismatch

2

Focus on

  • Publish order is the whole protocol: write shards to a temp directory, barrier, atomically replace onto the final name, then write the manifest. Readers list only final names and require the manifest.
  • The manifest is the commit marker. A directory without it is garbage from an interrupted write, however new its shards are.
  • Checksums catch bit rot and truncated transfers; completeness (every shard present, sizes matching the manifest) catches interruption. Run both: a complete set of corrupt shards and a pristine subset both refuse.
  • Hash in-flight reductions too, not just files at rest. Check-and-verify compares digests across ranks before the optimizer step, because a corrupt buffer poisons weights no disk checksum can see.
Common mistakes · 3
  • Writing shards straight into the final directory. A crash mid-write leaves the newest version half complete, and the loader cannot tell it from a good one.
  • Checksumming the archive but skipping per-shard hashes. One corrupt shard then invalidates the whole checkpoint with no way to name the bad file.
  • Syncing file data but ignoring the directory entry. The earlier unit Files, page cache, fsync, atomic rename and durability covers the full contract: each file made durable first, then the rename, with the containing directory made durable.
3

Try it yourself

Closed-book, before checking anything

Kill a two-process CPU save between the last shard write and the replace, and show the loader ignores the temp directory and loads the previous complete checkpoint. Then flip one byte in a good shard and show the checksum check refuses the checkpoint.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Ranks finish writing shards at different times and rank 0 replaces the temp directory as soon as its own shard lands. What breaks?Answer

    The replace publishes an incomplete checkpoint. The barrier before teardown exists so every rank's shards are durable before any reader can see the final name.

  2. 2.Every shard verifies against its checksum but training still diverges right after resume. Which check is missing?Answer

    Completeness against the manifest: a stale shard from an older step carries a valid checksum. Sizes, versions and the full shard set must match too.

  3. 3.Why is the manifest written after the replace rather than before the shards?Answer

    The manifest is the commit marker. Written early it commits shards that do not exist yet; written last it certifies exactly what is durable.

  4. 4.A gradient shard's checksum matches on disk but the loss spikes after one AllReduce. Where did verification miss?Answer

    In flight: silent corruption during the reduction never touched the disk copy. Check-and-verify hashes reduced buffers across ranks before the optimizer step.

5

Practice

  • Atomic publish plus tamper refusal in your own harness

    Mirror the run_checkpointer assertions (dir_is_checkpoint, find_checkpoints, latest_checkpoint, reload equivalence) for a temp-dir publish with manifest plus per-shard SHA256, and add a one-byte tamper case that refuses the checkpoint

    Implement in your own repository on CPU with small shards. The OLMo suite is the layout contract, not a drop-in dependency.

You're done when

An interrupted publish never appears on the load path, a tampered shard is named by its checksum failure, and both cases fall back to the previous complete checkpoint.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 9 more in the 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.

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

Also in this 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.

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