Checkpoints and storage
Design training recovery around complete state, crash-consistent publication, validated restore, and checkpoint overhead.
On this page
The question for today
What you’ll understand
- Distinguish an inference export from a resumable training checkpoint.
- Design a publication protocol that avoids selecting partial checkpoints.
- Estimate the tradeoff between checkpoint overhead and lost work.
Saving a file named model.pt is not a recovery plan. A restart may need optimizer moments, the learning-rate schedule, random generators, data position, and the identities of all participating shards. The checkpoint is useful only if another process can discover a complete version, verify it, restore compatible state, and continue without silently changing the training experiment. Design the restore path at the same time as the save path.
Define the state that must survive
An inference export can contain only weights and model configuration. A training checkpoint usually needs more: optimizer and scheduler state, update count, gradient-scaling state where applicable, random-number-generator state, and data-sampler position. Include dataset release identity, code revision, and relevant environment information. Decide how to handle accumulated gradients if a save occurs between optimizer steps; checkpointing at an agreed update boundary is often easier to reason about than reconstructing a partially accumulated update.
Distributed training adds ownership and consistency requirements. Each shard must correspond to the same logical step and compatible layout. PyTorch Distributed Checkpoint supports saving and loading distributed state, including resharding supported state across different layouts. That does not eliminate the need to test your model's state mapping or version compatibility. Record an explicit format version and verify recovery across the hardware and software changes you intend to support, rather than assuming every future environment can read every old artifact.
Publish a complete version, not an attractive filename
Write checkpoint objects under a fresh immutable version. Record expected shards, sizes, hashes, and logical step in a manifest. Publish the version as eligible for restore only after all required data is durably written and validated. A crash before publication leaves an incomplete candidate that readers ignore. A crash after publication must leave every referenced object readable according to the storage system's contract. Garbage collection should retain objects referenced by live manifests and allow time for readers using an older version.
The publication primitive depends on storage semantics. A single-filesystem rename may support atomic visibility, but multi-file durability also depends on flush and directory behavior. Object stores do not generally provide a universal atomic directory rename. Use documented conditional writes or a transactional metadata store when coordinating a latest pointer, and verify the specific backend. Checksums detect corruption; they do not prove that independently saved shards share one training step. Asynchronous saves also require a stable staged snapshot so training cannot mutate buffers still being serialized.
Choose an interval using measured failure and save costs
Frequent checkpoints reduce recomputation but consume bandwidth and pause or compete with training. In a simple model, a save costing seconds every seconds of useful work adds overhead . With independent rare failures of mean interval , uniformly located failures lose roughly half an interval, adding . Minimizing their sum gives an approximate interval. This is a planning model, not a universal recommendation for correlated rack failures or variable save times.
Recovery time is separate from recomputed work. Measure checkpoint discovery, download, validation, process launch, communicator setup, and the first successful update. Practice restoring under missing-shard, truncated-object, and incompatible-version scenarios. Keep at least one older known-good checkpoint rather than immediately replacing every recovery option with the newest write. Storage lifecycle rules and access permissions must preserve the recovery horizon, and a verified save should still be followed by periodic end-to-end restore drills.
Work it through
Estimate a first checkpoint interval
A fictional job pauses 40 seconds to create a durable checkpoint. Its observed mean interval between job-stopping failures is 20 hours. Use the simple independent-failure model.
Convert the failure interval to matching units: 20 hours = 72,000 seconds.
Compute the candidate useful-work interval: square root of 2 × 40 × 72,000 is 2,400 seconds, or 40 minutes.
At that interval, save overhead is 40/2,400 ≈ 1.67%, and expected lost-work overhead is 2,400/(2 × 72,000) ≈ 1.67%.
The estimated sum is 3.33%. Validate that the save actually fits in 40 seconds under load and that a restore is complete; do not treat the formula as evidence of crash consistency.
A 40-minute useful-work interval is a defensible initial experiment under these assumptions, with approximately 3.33% modeled save-plus-recomputation overhead.
The living notebook
Explore the model
Interactive lab · reliability
Explore the effect of failures
Change replica count n and unavailable count k to inspect whether the remaining replicas meet floor(n/2) + 1. This counts majority availability only: surviving replicas do not establish a complete checkpoint, durable publication, or the interval formula.
- Available replicas
- 4 of 5
- Majority needed
- 3
- Majority available?
- Yes
A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forHaving a majority of machines alive is a different property from having a verified recoverable snapshot.
Pause & reason
Check your understanding
Your turn
Try it yourself
A save costs 90 seconds and the mean independent failure interval is 8 hours. Estimate the model's preferred interval. Name two pieces of state missing from a weights-only export that can alter resumed training.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Convert hours to seconds and evaluate the square root. Think about both the optimizer's history and the next examples the run will consume.
Compare with the solution
M = 28,800 seconds, so the estimated interval is √(2 × 90 × 28,800) ≈ 2,277 seconds, or about 38 minutes. Optimizer moments and data-sampler position are two important missing states; scheduler, random-generator, and scaling states may also matter. The estimate does not establish that any particular storage backend safely publishes the snapshot.
Keep the idea
Take it with you
- A resumable checkpoint includes the experiment's evolving state, not only weights.
- Completeness, integrity, visibility, and durability are distinct requirements.
- Choose intervals from measured costs and verify them with restore drills.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.