Catching rank desync bugs on a laptop before the GPU job. Would you use this?

I am thinking of building a small open source tool and want to know if it is worth it.

Problem: A distributed job hangs on the cluster because ranks went out of sync. One rank has an extra batch, takes a different branch, or calls a different shape. You find out after paying for the GPUs. Example: DDP: Only one rank finishing while rest hang, where one rank had 1051 batches and the others had 1052.

Idea: rankcheck (not built yet) runs your unmodified script on your laptop as N real CPU processes for a few steps. It swaps NCCL for Gloo and CUDA for CPU for you. If ranks go out of sync or stall, it stops and shows where. The output is also a small repro you can share.

# mockup of planned output
$ rankcheck torchrun --nproc_per_node=4 train.py
HANG at step 1052
  rank 3:    finished, exited train loop     train.py:88
  ranks 0-2: waiting in all_reduce (DDP backward)  train.py:97
  cause: rank 3 ran 1051 batches, ranks 0-2 ran 1052

I know about TORCH_DISTRIBUTED_DEBUG=DETAIL and LocalTensor. I tried DETAIL with 4 Gloo ranks on a Mac. It catches most mismatches, like a wrong op or wrong shape, within a second or two and gives file:line on every rank. Where it falls short is the early-exit case above. It waits out the full timeout, then reports “Rank 3 failed to pass monitoredBarrier” with a line number but no reason. You also have to set up the CPU/Gloo run yourself. LocalTensor runs one process, so it can’t catch rank-specific branches.

So rankcheck would mostly be DETAIL plus the missing parts: set up the CPU run for you, fail fast when a rank exits early, and say why (here, rank 3’s sampler gave it one fewer batch).

Have you hit this? If so, what do you use today to catch it?

Thanks.

The 1051-versus-1052 last-batch hang is a real DDP failure, so a laptop preflight would be useful if it reliably catches that class of bug. The main caveat is that swapping CUDA and NCCL for CPU and Gloo will miss desyncs that only show up with async CUDA streams or NCCL timeouts. To be worth running before a cluster job, it should hook every collective, not only all_reduce, record the call site, and also flag control-flow divergence — one rank breaking out of the loop while the others wait. Uneven DataLoader length is often already avoided with DistributedSampler and drop_last=True, so the tool is more valuable if it also catches the same number of steps but a different collective order. If it can emit a small standalone repro, I would use it.

Thanks. Yeah, drop_last=True fixes the simple case. Have you still hit hangs with it on? Like with a custom sampler, an IterableDataset, or a break inside the loop?

Yes. drop_last=True only evens out DistributedSampler when the dataset has a known length and that sampler is the one building the batches. I’ve still seen hangs with it on in three cases: a custom sampler that doesn’t pad or drop the leftover examples, so one rank gets a shorter last batch; an IterableDataset, which has no shared length and can stop on one rank while the others keep yielding; and a break or return inside the training loop on a single rank, which is a control-flow split rather than a DataLoader issue. Those are the cases where a preflight is most useful — hook every collective and the loop exit, and don’t assume the only desync is an uneven map-style DataLoader.