Build a Fault-Tolerant Checkpoint and Resume System for Training Runs
distributed-systems cloud-infrastructure reliability
AI System Design Deep Dive
Fault-Tolerant Checkpoint and Resume
Sixteen live copies of the model already exist. Use them before you touch the disk.
Picture a newsroom with 16 copy desks, each holding an identical, current copy of the same manuscript. When one desk catches fire, nobody drives to the archive in the basement. The editor walks over to the next desk and photocopies the pages. The archive exists for the day the whole building burns, and for the day someone discovers that one desk has been quietly misprinting a word for hours. A plain data parallel training run is that newsroom, and most checkpoint systems behave as if the 16 desks did not exist.
Here are the numbers. We train a 70B dense model on 64 p5.48xlarge nodes (512 H100 GPUs) with the TP=8 x PP=4 x DP=16 layout from the previous post, for 36 days. With a node MTBF of 2,000 hours the cluster fails every 31.25 hours, so we expect 27.6 node failures before the run ends. Counting the real tensors (80 layers, hidden size 8192, a 28,672 wide FFN, 8 KV heads, untied 128,256 token embedding and output matrices) the model has 70.55B parameters. A checkpoint stores 14 bytes per parameter (bf16 weights, fp32 master weights, two Adam moments), which is 987.8 GB in 512 shards of 1.87 to 1.99 GB. The earlier posts rounded this to 70B and 980 GB, and the difference is worth knowing when you size storage.
The naive recovery path fails in three different places. Restoring from object storage after every failure costs 142 s of restart plus an average of 300 s of lost work at a 10 minute interval, 442 s in total, which is $433 of idle cluster per failure at $3,522.56 per cluster hour. A restore that lets every GPU read what it needs reads 15.8 TB for a 987.8 GB checkpoint, because with plain data parallelism each of the 16 replicas needs the full state of its tensor and pipeline slice. And a checkpoint that was written from a corrupted GPU is the worst case: it loads cleanly, passes every file checksum, and poisons the run.
We need to solve for recovery time (use the live replicas first), resharding (load a checkpoint into a layout it was not saved from) and corruption detection (know the state is good before you persist it) simultaneously. Posts 31 and 32 chose the layout and the orchestrator. This post builds the layer that decides what survives a failure.
Requirements and Constraints
Functional requirements
- Recover from a single node failure without reading storage, by copying state from a data parallel peer in another rack.
- Write a durable checkpoint every 20 minutes without stalling training for more than one second.
- Load a checkpoint saved at one layout into a different
(tp, pp, dp)layout, including a smaller data parallel degree after a rack failure. - Verify every checkpoint before it becomes
LATEST, and detect silent corruption in live GPU state. - Resume with identical data order, learning rate and random state, so a restart is invisible in the loss curve.
Non-functional requirements
- Recovery time: peer path under 90 s, disk path under 8 minutes, both measured from the failure to the first completed step.
- Lost work: at most one step (8.7 s) on the peer path, at most one checkpoint interval on the disk path.
- Goodput: at least 99.7 percent, against 99.50 percent for the disk-only design from post 31.
- Snapshot stall: 0.62 s per checkpoint, the time to copy 15.4 GB per node from HBM to pinned host memory at 25 GB/s.
- Integrity: zero silent corrupt restores. The digest check must cost under 20 ms per GPU.
- Capacity: 987.8 GB per checkpoint, 3 rolling checkpoints plus one milestone every 6 hours (144 milestones, 142.2 TB at the end of the run).
- Cost: checkpoint storage under $2,500 for the run, and a recovery policy that pays for itself against the $47,555 a single dedicated spare node costs over 36 days.
Constraints
- Hardware per node: 8 H100 with 80 GB HBM3 (3.35 TB/s), 2,048 GiB of host memory, 8 x 3.84 TB NVMe, 3,200 Gbps of EFA. That is 400 GB/s per node and 50 GB/s per GPU, or 25 GB/s per GPU across the 2:1 oversubscribed spine.
- Plain data parallelism, no ZeRO and no FSDP. Every replica holds a full copy of the weights and optimizer state of its slice. This is the property the whole post leans on.
- Assumed and labelled: S3 throughput of 2.5 GB/s per node, 90 percent of failures recoverable from a peer, 25 s to rebuild NCCL communicators on a warm spare.
- Out of scope: silent data corruption inside compute kernels, encryption of checkpoints, and checkpointing the dataset itself (the loader is a pure function of the global step).
Every non-functional target is a statement about the tail. The average failure costs 75 s on the peer path, but the number that sizes the system is the correlated failure that needs the disk, because it is 10 percent of the events and about half of the lost time.
High-Level Architecture
The system has six components. The Snapshotter copies each GPU’s 1/16 slice into pinned host memory and writes it to NVMe and S3 in the background. The Digest Voter hashes live state on every GPU and compares the 16 replicas. The Peer Restorer rebuilds a lost node from a clean replica in a different rack. The Checkpoint Coordinator runs the two phase commit and owns the catalog. The Resharding Loader maps a saved checkpoint onto any target layout. The Retention Manager keeps three rolling checkpoints and the 6 hour milestones.
A healthy checkpoint cycle runs in the background. Every 20 minutes (about 138 steps) the Snapshotter copies each GPU’s slice to pinned host memory, which blocks training for 0.62 s. Before it does, the Digest Voter has already compared the 16 replicas of every slice, so a corrupt replica is excluded before its bytes reach a file. A background thread writes the shard to NVMe and uploads it to S3 (6.2 s per node), and the Coordinator marks the checkpoint committed only after every shard is verified.
A failure takes the other branch. The orchestrator fences the old epoch and swaps in a warm spare (post 31). The 15 healthy replicas abort the step but keep their weights, because the optimizer has not touched them. The spare copies its slice from a clean peer, every rank checks that its digest matches, and training resumes at the same step with the same batch. The disk path runs only when no clean replica exists for some slice.
The architecture treats the 16 data parallel replicas as the first checkpoint tier and storage as the second. Tier 0 is free, current to the last optimizer step, and 5.8 times faster end to end: 75.6 s against 442 s per failure.
The Snapshotter
The Snapshotter’s job is to turn live GPU state into durable files while costing the training loop less than a second.
A snapshot is like photographing a whiteboard before someone erases it. The photo must be taken in one instant, but developing it can take as long as it likes. The instant is the copy from HBM into pinned host memory (15.4 GB per node at 25 GB/s, 0.62 s). Everything after that, the NVMe write and the S3 upload (6.2 s at 2.5 GB/s per node), runs on a background thread while the GPUs are already on the next step.
The non-obvious part is what each rank writes. With plain data parallelism all 16 replicas hold the same bytes, so writing all of them would produce 16 times the data. Each data parallel rank writes 1/16 of the rows of every tensor in its (tp, pp) slice, which gives 512 shards that together hold exactly one copy of the model state. The shard is a self-describing file: a header lists every chunk as (tensor name, global shape, box), so a loader never needs to know the layout the file was written from.
# Async snapshot: HBM to pinned host memory on a side stream, then NVMe and S3 in a background thread (needs a GPU, not run here)
import hashlib, json, queue, threading
import torch
class Snapshotter:
def __init__(self, shard_bytes: int, upload):
self.host = torch.empty(shard_bytes, dtype=torch.uint8, pin_memory=True)
self.stream = torch.cuda.Stream()
self.jobs: queue.Queue = queue.Queue()
self.busy = threading.Event() # set from snapshot() until the upload finishes, so the host buffer is never overwritten
self.upload = upload
threading.Thread(target=self._drain, daemon=True).start()
def snapshot(self, step: int, chunks: list) -> None:
"""chunks: [(name, global_shape, box, gpu_tensor)] already restricted to this rank's rows."""
if self.busy.is_set():
raise RuntimeError(f"snapshot {step}: previous one still draining, skip this interval")
self.busy.set()
header, off = [], 0
with torch.cuda.stream(self.stream):
for name, shape, box, t in chunks:
n = t.numel() * t.element_size()
self.host[off:off + n].copy_(t.view(torch.uint8).flatten(), non_blocking=True)
header.append({"name": name, "shape": shape, "box": box, "dtype": str(t.dtype), "off": off, "len": n})
off += n
self.stream.synchronize() # the only point where training waits: about 0.62 s
self.jobs.put((step, header, off))
def _drain(self) -> None:
while True:
step, header, n = self.jobs.get()
blob = self.host[:n].numpy()
digest = hashlib.sha256(blob).hexdigest()
self.upload(step, json.dumps(header).encode(), blob, digest) # NVMe first, then S3 with a checksum header
self.busy.clear()
Phase two is the commit. A checkpoint is invisible until the Coordinator has seen all 512 shard reports, checked every sha256, and confirmed that the digest vote found no suspect. Then it publishes in two writes. The catalog row in Postgres says what the checkpoint is. The pointer in etcd says which one to load, and that write is fenced by the orchestrator’s epoch, so a zombie worker from a dead epoch cannot publish anything.
/* Phase 2a: mark the checkpoint committed in the catalog (the checkpoint table is from post 31, state and plan_hash are added below) */
UPDATE checkpoint
SET state = 'committed', verified_at = now()
WHERE run_id = $1 AND step = $2 AND epoch = $3 AND state = 'verified'
AND (SELECT count(*) FROM ckpt_shard WHERE run_id = $1 AND step = $2 AND verified) = 512
AND NOT EXISTS (SELECT 1 FROM corruption_event WHERE run_id = $1 AND step = $2 AND action = 'blocked');
# Phase 2b: etcdctl txn from stdin. The put happens only if the epoch is still the one that wrote the shards
compares:
value("/run71/epoch") = "3"
success requests (get, put, del):
put /run71/checkpoint/prev "step-47862/epoch-3/manifest.json"
put /run71/checkpoint/latest "step-48000/epoch-3/manifest.json"
failure requests (get, put, del):
get /run71/epochPremium Content
Unlock the full article along with everything else in the archive — all in one place.