advanced28 min studyLesson 25 in Engineering

Checkpoints and storage

Design training recovery around complete state, crash-consistent publication, validated restore, and checkpoint overhead.

On this page

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.

eligible⁡(v)=published⁡(v)∧⋀i∈Svverified⁡(i)\operatorname{eligible}(v)=\operatorname{published}(v)\land\bigwedge_{i\in S_v}\operatorname{verified}(i)
Sv is the set of required shards for checkpoint v. Eligibility is a logical invariant, not a storage API: publication must only become visible after the referenced snapshot has met the required integrity and durability checks.↔ Scroll wide equations horizontally.

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 CC seconds every τ\tau seconds of useful work adds overhead C/τC/\tau. With independent rare failures of mean interval MM, uniformly located failures lose roughly half an interval, adding τ/(2M)\tau/(2M). 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.

f(τ)≈Cτ+τ2M,τ∗≈2CMf(\tau)\approx\frac{C}{\tau}+\frac{\tau}{2M},\qquad \tau_*\approx\sqrt{2CM}
C, τ, and M are seconds. The dimensionless wasted-time fraction assumes rare independent failures, constant blocking save cost, and negligible recovery cost for this interval optimization; correlated failures and asynchronous I/O require a richer model.↔ Scroll wide equations horizontally.

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.

  1. Convert the failure interval to matching units: 20 hours = 72,000 seconds.

  2. Compute the candidate useful-work interval: square root of 2 × 40 × 72,000 is 2,400 seconds, or 40 minutes.

  3. At that interval, save overhead is 40/2,400 ≈ 1.67%, and expected lost-work overhead is 2,400/(2 × 72,000) ≈ 1.67%.

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

The result

A 40-minute useful-work interval is a defensible initial experiment under these assumptions, with approximately 3.33% modeled save-plus-recomputation overhead.

Explore the model

Interactive lab

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.

Explore the effect of failuresA 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. Current readings: Available replicas: 4 of 5; Majority needed: 3; Majority available?: Yes. All parameters are adjustable with the labeled controls below.Majority available · need 3 of 5Playback highlights fixed statesR1 · upR2 · upR3 · upR4 · upR5 · downCyan mark: majority threshold
AvailableUnavailableMajority threshold
Available replicas
4 of 5
Majority needed
3
Majority available?
Yes
t = 0 s

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.

Check your understanding

A latest pointer references eight shards, but the eighth upload failed. What failed in the checkpoint design?

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.

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.