skip to content

How do you choose the checkpoint interval for a month-long 512-GPU pretraining run that loses a node every few days, and what does PyTorch's DCP async_save change?

level: principalimportance: should knowfreq 8%

answer

  1. two costs pulling in opposite directions
  2. blocking time per save versus rework
  3. square root of 2 x cost x MTBF
  4. async_save shrinks the blocking part
  5. one save in flight, CPU backend required

basics

~20 s

Balance each save's blocking time against the work lost per failure: an interval near sqrt(2 x blocking cost x mean time between failures) minimises the sum. DCP async_save shrinks the blocking cost to a CPU staging copy, allowing far more frequent saves.

solid answer

~50 s

Two costs pull against each other: every save stalls 512 GPUs for its blocking time C, and every failure throws away on average half an interval of work plus a fixed restart cost. Young's approximation puts the best interval near `sqrt(2 x C x M)`, with M the job's mean time between failures. With a node lost about every 72 hours and a 120 s synchronous save, that is about 2.2 hours and roughly 3% of the run lost to saves and rework. PyTorch 2.14's `dcp.async_save` copies each rank's shard to CPU memory and writes it from a background thread, so training blocks only for the copy; at about 10 s the interval drops to about 38 minutes and the overhead to under 1%. The limits: one save in flight, host memory for the staged shards, a CPU backend such as `cpu:gloo,cuda:nccl`, and storage that finishes each write within the interval.

go deeper

for a junior

Know that long runs save checkpoints so a failure loses only the work since the last save, and that saving too often also costs time.

for a middle

Explain how async_save splits a save into a blocking staging copy and a background write, and why the previous future is awaited.

for a senior

Compute the interval from measured blocking cost and job-level failure rate, and check storage throughput and host memory against it.

for a principal

Own the trade: cadence, retention, save-on-signal and restore drills as one policy, priced in GPU-hours against storage and operational cost.

## The two costs A checkpoint interval is a trade between two kinds of waste: - **Save overhead.** While a checkpoint blocks, no GPU trains. With blocking time **C** per save and interval **T**, the fraction lost is about C / T. - **Rework.** When a node dies, everything since the last complete checkpoint is redone. On average a failure lands mid-interval, so each failure costs about T / 2 of work, plus a **restart cost R** (requeue or re-rendezvous, process start, checkpoint load) that does not depend on T. Short intervals waste time saving; long ones waste time redoing. With **M** the mean time between failures *for the whole job* (not per node), Young's approximation for the interval that minimises the sum is: `T ≈ sqrt(2 × C × M)` ## Worked numbers for this run Assume the job loses a node about every 72 hours (M = 259,200 s), a month is 720 hours on 512 GPUs (368,640 GPU-hours), and a restart costs about 15 minutes. | | synchronous `dcp.save` | `dcp.async_save` | |---|---|---| | blocking cost C | 120 s | 10 s (staging copy) | | interval T | about 7,900 s (2.2 h) | about 2,280 s (38 min) | | save overhead C / T | 1.5% | 0.44% | | rework (T / 2) / M | 1.5% | 0.44% | | total, before restarts | about 3.0% (about 11,200 GPU-hours) | about 0.9% (about 3,200 GPU-hours) | The restart cost adds the same 10 failures x 15 min = 2.5 hours (0.35%) in both columns; only a faster requeue or an elastic restart reduces it. At the optimum the two variable costs are equal, which is a quick check on any proposed cadence. ## What async_save changes, and what it needs `torch.distributed.checkpoint.async_save` in PyTorch 2.14 first **stages** each rank's state dict into CPU memory and then runs the ordinary save from a background thread (the default `AsyncCheckpointerType.THREAD`; a separate process is the alternative). Training resumes after staging, so C becomes the device-to-host copy rather than the full write. It brings conditions with it: 1. **A CPU backend in the process group.** `async_save` refuses a group without one; initialise with `cpu:gloo,cuda:nccl`. 2. **One save in flight.** PyTorch's async checkpointing recipe waits on the previous future before the next `async_save`, so at most one request is queued; without that wait, staged copies can pile up in host memory. 3. **Host memory.** Each rank keeps a CPU copy of its shard while the write runs; a node needs room for all its ranks' shards on top of the data loaders. A pinned staging buffer makes the copy faster but keeps that memory for the life of the job. 4. **Storage throughput.** The background write must finish within one interval. If 512 ranks need 6 minutes to write, a 38-minute interval is fine; a 4-minute one is not. 5. **Experimental status.** PyTorch 2.14 marks `async_save` as experimental and subject to change; pin the version and rehearse restores. ## Measuring C and M honestly - **C** is the time the training loop is stalled, not the time the files take to appear: measure from the call to the moment the next step starts, on all 512 ranks, and take the slowest rank. - **M** comes from the failure history of jobs of this size on this cluster. If failures are independent per node, a node lost every 72 hours across 64 nodes means one roughly every 36 hours across 128 nodes. - Re-measure after any change to model size, sharding layout or storage, since each moves C. ## Judgment beyond the formula - **Measure M, do not guess it.** Failure rate grows with node count; use the cluster's own history for jobs of this size, and recompute when the job is resized. - **Save on warning.** A scheduled end or a preemption that sends a signal gives time to save outside the cadence; with Slurm, `sbatch --signal=USR1@300` signals the job steps about five minutes before the end time. - **Retention.** Keep the last few interval checkpoints for rollback after a silent divergence, plus milestones at a coarser cadence, and delete the rest; each 512-rank checkpoint is the full model and optimizer state. - **Completeness.** Resume only from a directory whose `.metadata` file exists; it is written last. - **Drill it.** A cadence is only real if a restore from the latest checkpoint has been run end to end on this job's layout.

  • The run is resized from 64 to 32 nodes for a week. Does the interval change?
    Yes, in both inputs. Fewer nodes fail less often, so M grows; each rank holds a larger shard, so the staging copy and C may grow too. Recompute sqrt(2 x C x M) with the new values rather than keeping the old cadence.
  • Why not simply checkpoint every few minutes once async_save makes saves cheap?
    Because the background write is not free: with one save in flight, an interval shorter than the write time makes each `async_save` wait on the previous one, which turns it back into a blocking save, and the storage system carries 512 ranks' writes continuously. The interval must stay above the write time.
  • How should a preempted job differ from a crashed one in this plan?
    A preemption that arrives with a warning can be handled by saving on the signal, so it loses almost no work and does not need the interval to cover it; a crash gives no warning, and only the cadence bounds its loss.

  • Checkpoint as often as possible; saves cost nothing but disk.
  • Use each node's failure rate as M, not the whole job's.
  • async_save makes the checkpoint cost zero, so the interval no longer matters.
  • Several async_save calls can safely overlap without waiting on the previous one.
  • async_save works with an NCCL-only process group.

Assumes PyTorch 2.14, where torch.distributed.checkpoint.async_save stages to CPU memory, defaults to a thread-based checkpointer, requires a CPU backend in the process group and is marked experimental.