The Straggler

../_static/data/straggler_illustration.png

In distributed training, there are cases where one rank is significantly slower than the rest, which degrades the overall training speed.

Such a rank is sometimes called a “straggler.” When there is a straggler, we often observe that nccl:all_reduce takes a significant amount of time on other ranks.

The following animation illustrates how slow data loading creates a straggler. Each of the four ranks loads its own data, runs the forward and backward passes, synchronizes the gradients with the other ranks through an all-reduce, which can start only when every rank has arrived, and updates the model.

Every data loader has the same speed, slightly slower than the training step. At the start, the first few batches of rank 2 happen to take a little longer. While the other ranks wait for rank 2 in the all-reduce, their loaders keep working and fill their queues. From then on, the loader of rank 2 has no time to get ahead: it waits for data in every step, and the other ranks wait for it in the all-reduce. The animation then jumps 25 steps ahead. A few more batches of rank 2 happened to be slow in between, and each one gave the other ranks more time, so their queues are now full while the queue of rank 2 is still empty.

Animation of four ranks, each with a data loader, a queue, forward, backward, an all-reduce across all ranks and an update. All loaders take 32 ms per batch, slightly longer than the 28 ms training step, but the first batches of rank 2 are slower. The other ranks fill their queues while they wait for rank 2 in the all-reduce. After a jump of 25 steps, the queues of the other ranks are full while rank 2 still waits for data with an empty queue in every step.

The loader speed matters. If the loaders were faster than the training step, the late rank would catch up after a few steps. If they had exactly the same speed, the late rank would never catch up but nobody would wait.

There are many reasons why one rank can be slower than the rest. For example, hardware failure is a common issue in large-scale distributed training.

Slow data loading can also cause a straggler.

The following figure shows the trace of the straggler from the same trace as the previous one. It is blocked on next(dataloader).

../_static/data/straggler_trace.png

When slow data loading is the cause, we often observe that the rank of the straggler changes from epoch to epoch.

The following is a plot of Data Readiness for a distributed training setup consisting of 8 ranks.

The data readiness at the sink stage indicates whether data loading is faster than the training process. A value of 1 means data loading is fast enough, and 0 means data loading is the bottleneck.

The plot suggests that there is one rank that is not fast enough (a straggler), but the struggling rank changes from epoch to epoch. Earlier in the training, rank 4 is the slowest, but later, rank 0 becomes the slowest.

How does this happen? It is quite simple.

When the pipeline starts, one rank can be slightly slower than the others. The other ranks gain a window of time while waiting for the slower rank to do additional data loading work, putting them ahead of the slow one.

As training progresses, the difference between the slow rank and the others becomes significant, and the slow rank becomes the straggler.

Since this difference arises from subtle perturbations in computation speed, any rank can become the straggler. However, rank 0 is more susceptible than the others because it usually has more work than the rest.

When a straggler is found and the straggler changes each epoch, it indicates that data loading is not fast enough.