Build a Distributed Model Training Orchestrator on GPUs
distributed-systems cloud-infrastructure reliability
AI System Design Deep Dive
Training Orchestrator on GPUs
512 GPUs act as one machine, so one sick node stalls all of them. Keep the machine whole.
Picture an orchestra of 512 musicians playing one symphony with no conductor’s baton, only a shared metronome. Every bar, each musician must finish before anyone starts the next one. If one violinist is late, or leaves the stage, the whole hall waits. A distributed training job is that orchestra: every step ends in an all-reduce, a barrier where all 512 GPUs exchange gradients, so the job runs at the speed of its slowest member and stops dead when any member disappears.
Now make the numbers concrete. We train a 70B dense model on 1.5 trillion tokens using 64 nodes of 8 H100 GPUs each. At 40 percent model FLOPs utilization that is about 482,000 tokens per second, which means 36 days of wall-clock time and roughly $3.04M of GPU rental at $55.04 per p5.48xlarge hour. Eight GPUs per node, 64 nodes, one failure domain per node. If a single node has a mean time between failures of 2,000 hours, the 64-node cluster fails once every 31 hours, so we should expect about 28 interruptions during the run.
A naive launcher, say a shell loop that starts torchrun on 64 hosts over SSH, fails in boring ways. It starts 60 of 64 nodes when four are busy and burns money waiting on a rendezvous that never completes. It restarts the survivors against a dead peer and hangs in an NCCL collective until a 30 minute timeout. It lets a zombie worker from the previous attempt write a checkpoint over the new one. It places a pipeline stage across two racks and quietly loses 8 percent of throughput to congestion that no dashboard names.
The orchestrator is the system that removes those failure modes. We need to solve for all-or-nothing placement, epoch-fenced membership, and cheap, verified recovery simultaneously, while paying for as few idle GPUs as possible.
Requirements and Constraints
Functional requirements
- Accept a job spec (model config, 512 GPUs, parallelism layout, checkpoint policy) and run it to completion or cancel it.
- Gang-schedule: either all 64 nodes are held for the run, or none are.
- Form a process group with a deterministic rank map, and re-form it after any membership change.
- Detect dead, degraded, and slow nodes, replace them from a spare pool, and resume from the latest verified checkpoint.
- Write sharded checkpoints without stalling training, and refuse to resume from a corrupt one.
Non-functional requirements
- Throughput: 482,000 tokens/s at 40 percent MFU, 942 tokens/s per GPU, global batch of 4,194,304 tokens, so one optimizer step takes 8.7 s.
- Goodput: at least 99 percent of wall-clock time spent on forward and backward passes that survive into a checkpoint.
- Recovery: detect a dead node within 45 s and be training again within 141 s of the failure.
- Quality: loss curve after any resume stays within 2 percent of the pre-failure evaluation loss, no NaN steps in the last 50.
- Cost: under $2.10 of GPU spend per million training tokens at on-demand prices.
- Capacity: checkpoint of 980 GB written as 512 shards of 1.91 GB each, with at most 1 s of training stall per snapshot.
Constraints
- Hardware: 64
p5.48xlargenodes (8 H100 80GB, NVLink inside the node, 3,200 Gbps EFA between nodes), us-east-1, organised in four leaf-switch racks of 16 nodes. - Software: PyTorch with
torchrunworkers, NCCL for collectives, etcd for coordination, S3 for checkpoints, Postgres for run metadata. - Parallelism: tensor parallel 8 inside a node, pipeline parallel 4 across nodes, data parallel 16. The layout itself is the next post’s topic; here it is an input to the orchestrator.
- Out of scope: hyperparameter search, data loading internals, RLHF, multi-cluster training.
The orchestrator never touches a gradient. Its whole job is to keep one synchronous barrier true: the same 512 ranks, the same epoch, the same checkpoint, every step.
High-Level Architecture
The system has six components, split into a control plane that decides and a data plane that trains.
- Job API validates a spec and writes a
training_runrow. It owns nothing at runtime. - Gang Scheduler reserves 64 nodes in 4-node pipeline blocks, packed into as few racks as possible, or reserves nothing.
- State Store (etcd) holds the epoch counter and one lease per node. It is the only place where membership is decided.
- Health Monitor consumes heartbeats and GPU error codes, declares nodes dead, and bumps the epoch to fence them.
- Node Agent runs on every host, launches eight workers, reports health, stages checkpoint shards on local NVMe and uploads them.
- Checkpoint Writer snapshots GPU state to host memory in under a second, then uploads to S3 while training continues.
A request flows like this. The Job API stores the spec and the scheduler waits until 64 nodes are free in 4-node-aligned blocks. It takes a reservation, tags every node with epoch N, and the node agents launch eight torchrun workers each. Workers join the rendezvous, wait at a barrier until 64 of 64 nodes have joined, receive a rank map, and start training. Every 10 minutes the agents snapshot and upload shards, and the last file written is the LATEST pointer.
When a node dies, nothing in the data plane decides what happens next. The health monitor fences the old epoch, the scheduler swaps in a spare node, and the agents restart workers at epoch N+1 from the last verified checkpoint.
The most important decision is that the control plane owns the epoch number and workers own nothing. Any worker that cannot present the current epoch is dead by definition, however alive its process looks.
The Gang Scheduler
Its job is to decide whether the job can start at all, and where every node goes, before a single GPU is touched.
Gang scheduling is boarding a ferry: the captain does not leave with 60 of 64 booked passengers, because the 4 who are missing hold the cargo that makes the trip worthwhile. A general-purpose scheduler that places pods one by one will happily start 60 workers and leave 4 pending. Those 60 hold $3,300 of GPU rental per hour while doing nothing, and two such jobs can deadlock each other by each holding half the cluster.
The scheduler therefore treats the job as one indivisible request. It filters by free capacity, packs the gang into as few racks as possible, and either returns a full plan or returns nothing and holds nothing. The packer works in 4-node blocks because a pipeline replica (4 stages of 8 GPUs) must never straddle two racks.
# Rack packer: place a gang of 64 nodes in 4-node PP blocks, never splitting a block across racks
from dataclasses import dataclass
@dataclass(frozen=True)
class Rack:
name: str
free: tuple # node ids currently idle in this rack
def pack_gang(racks, nodes_needed=64, block=4):
"""Return {rack: [node ids]} or None. All-or-nothing: partial holds are never returned."""
if nodes_needed % block:
raise ValueError("nodes_needed must be a multiple of the pipeline block size")
blocks_needed = nodes_needed // block
# Fewest racks first: sort by usable blocks, largest first, so the job spans few leaf switches
cap = sorted(((len(r.free) // block, r) for r in racks), key=lambda t: -t[0])
plan, remaining = {}, blocks_needed
for usable, rack in cap:
if remaining == 0:
break
take = min(usable, remaining)
if take:
plan[rack.name] = list(rack.free[: take * block])
remaining -= take
return plan if remaining == 0 else None
Without the block constraint, a plan could place stage 2 of a replica in rack B and stage 3 in rack C. Pipeline activations would then cross the spine once per micro-batch, and the job would be correct but slow in a way that no log line names.
Premium Content
Unlock the full article along with everything else in the archive — all in one place.