OpenDiLoCo

Four GPU machines on two continents, joined by slow internet, trained one 1.1 billion parameter model. They shared their work every 500 steps instead of every step, and spent only 6.9% of the time waiting on the network.

An open-source recipe for training a language model on machines that sit far apart, where a message takes minutes, not milliseconds.

Pick how often the workers sync, then watch one worker’s two hours. Teal is useful work. Yellow is waiting on the network. Then we build, piece by piece, the method, the code, and the results.

You need a rough idea of what a training step does (it nudges the model’s numbers to lower the error). We build the rest from zero, including every word on the page.

A reading of OpenDiLoCo: An Open-Source Framework for Globally Distributed Low-Communication Training by Sami Jaghouar, Jack Min Ong and Johannes Hagemann (Prime Intellect, 2024). It reproduces DiLoCo by Douillard et al. The background is taught in DiLoCo and Low-Communication Pretraining. Why it matters now: the Core Automation post The Hitchhiker’s Guide to Training on Compute Islands by Rohan Anil.

Choose the sync interval

From the paper (1.1B model, four workers in Canada, Finland and the United States): 500 local steps take about 67.5 minutes, so one step takes 8.1 s, and one all-reduce averaged 300 s. Perplexity is Table 2 (10.52 for the data-parallel baseline, 10.76 and 11.14 for DiLoCo with 125 and 500 steps). Assumption, ours: every sync costs the same 300 s whatever the interval, so the busy share is computed, not measured, for 1 and 125.

Chapter 0

Why Slow Links Break Normal Training

See why a cluster of fast machines trains well and the same machines across the internet crawl, and what the paper changes

Picture a kitchen with four cooks making one huge soup. Each cook tastes the soup, and after every single spoonful they all shout their opinions across the room and agree on one fix. In a small kitchen this works. The cooks stand a metre apart and the shouting takes a second.

Now move the cooks to four cities. Each shout takes minutes to arrive. If they still agree after every spoonful, they spend nearly all day waiting and almost no time cooking. That is the problem this paper solves, with GPUs instead of cooks.

What training actually does

A language model is a program that guesses the next word. It guesses with a long list of numbers called weights. A training step shows the model some text, measures how wrong the guess was, and nudges every weight a little to be less wrong. The nudge for each weight is its gradient. A model with 1.1 billion weights has 1.1 billion gradients per step.

One GPU (a chip that does this arithmetic very fast) is not enough for a big model. So we use many GPUs together. The simplest way is data parallel training: every GPU keeps a full copy of the model, reads different text, and computes its own gradients. Then all the GPUs average their gradients, so every copy takes the same nudge and stays identical.

That averaging step has a name: all-reduce. Every worker sends in its gradient, every worker gets back the average. It happens after every step. The paper calls the standard method DDP, short for distributed data parallel.

Why the network becomes the wall

All-reduce moves one number per weight. For a 1.1 billion weight model, stored as 32-bit numbers (4 bytes each), that is 4.4 billion bytes, or 35.2 billion bits, every step. The speed of a link is its bandwidth, counted in bits per second. Mbit/s means millions of bits per second. A fast data-centre link carries thousands of times more than your home internet.

Inside one building, GPUs are joined by special cables that move far more than a million Mbit/s between neighbours, so DDP works. Between cities, the paper measured links of 127 to 935 Mbit/s between its four workers (Figure 8, measured with the iperf tool). A rough lower bound on one transfer is simply size divided by speed. Try it below.

Time the wire takes

The two curves show the shortest possible time to send 1.1 billion numbers once. Drag the bandwidth. The shaded band is what the paper measured between its workers. The dashed line is the 300 s the paper saw for a whole all-reduce.

127 Mbit/s

Our arithmetic: 1.1 billion numbers times 4 bytes (FP32) or 2 bytes (FP16), times 8 bits, divided by the link speed. It ignores delays and the extra passes a real all-reduce makes, so real time is longer. The 127 to 935 Mbit/s band is from the paper’s Figure 8; 300 s is the paper’s average all-reduce time in its world run (Section 3). The 25,000 Mbit/s end is the 25 Gbps link in the Core Automation post.

At 127 Mbit/s even 16-bit numbers need at least 139 seconds. DDP would pay that after every step, and a step takes about 8 seconds. The workers would idle most of the day. The hero at the top shows the same thing: syncing every step keeps the GPUs busy only 2.6% of the time under the paper’s 300 s sync cost.

The fix in one sentence

Let each worker take hundreds of steps on its own, and only then compare notes. This is the idea behind DiLoCo (Distributed Low-Communication training) by Douillard and colleagues at Google DeepMind. It uses two optimizers, an inner one that trains each worker and an outer one that merges the workers. With 8 workers it matched fully synchronous training while communicating 500 times less. Chapter 1 builds the idea, and the background lesson DiLoCo and Low-Communication Pretraining goes deeper into its history.

What OpenDiLoCo adds

The original DiLoCo code was not public. This paper, from the company Prime Intellect, makes four contributions:

The Core Automation post you may have come from calls this setting compute islands: pools of GPUs that are fast inside and slow between. OpenDiLoCo is one of the post’s cited starting points, and our lessons on local SGD and bandwidth arithmetic teach the ground it stands on. For how normal all-reduce works inside a cluster, see Distributed Training.

The road

  1. Local SGD: many steps alone, then average. The saving, in a toy you can run.
  2. The outer optimizer: the pseudo-gradient and Nesterov momentum, with numbers.
  3. The code: two copies of the model and the short outer step.
  4. Hivemind: peers, a hash table, workers that come and go.
  5. FP16 all-reduce: half the bytes, no loss in quality.
  6. The replication: Figure 3 and Table 1.
  7. The ablations: workers and FLOP efficiency.
  8. The 1.1B world run: Table 2 and the 6.9% sync share.
  9. Field guide: numbers, terms, checklist, code.
Why does ordinary data parallel training slow down badly between distant machines?

Chapter 1

Local SGD: Work Alone, Then Compare Notes

Let each worker take many steps by itself, then average, and count how much talking you save

Go back to the four cooks in four cities. A sensible cook stops shouting after every spoonful. Each one cooks for an hour alone, tasting and fixing their own pot. Then they phone each other, and everyone agrees on one blend. They talk once an hour, not once a minute.

That is local SGD. SGD is stochastic gradient descent: take a small random batch of text, find the gradient, and move each weight a little downhill. Local means each worker runs this loop by itself, on its own copy of the model, for H steps. Only after H steps do the workers average their weights, which means adding them up and dividing by the number of workers. Everyone then restarts from the average.

The rule, with every symbol

Write it for worker i. Between syncs, each worker applies its own steps. At a sync, all workers replace their weights with the mean.

θi(t)
The weights of worker i at step t. Theta is the usual name for “all the weights as one long list”. The small number in brackets is the step.
η gi
The learning rate eta times worker i’s gradient g. The learning rate is how big a nudge to take. The gradient comes from worker i’s own batch of text, so it differs between workers.
H
The number of local steps between syncs. H = 1 is ordinary data parallel training. The paper uses H = 500 and sometimes 50 or 125.
(1/k) ∑ θj
The mean over the k workers. Sigma means “add up”. Every worker ends the sync holding the same weights.

A worked example with one weight and four workers. After 500 local steps they hold 0.8, 0.6, 1.0 and 0.6. The mean is (0.8 + 0.6 + 1.0 + 0.6) / 4 = 3.0 / 4 = 0.75. All four restart from 0.75. In real training each of the 1.1 billion weights is averaged this way.

Counting the saving

Every sync costs one all-reduce. Over N training steps, DDP does N all-reduces, because it syncs at H = 1. Local SGD does N / H. In the paper’s main run, N is 88,000 and H is 500, so DiLoCo syncs 176 times instead of 88,000. That is the “500 times less communication” in the abstract.

The saving is not free. Workers who go a long way alone can wander in different directions, and their average may be worse than the path one big batch would have taken. The paper’s early curves show exactly this. Try a small version below. It trains one loss with four workers whose data differ a little.

Fewer syncs, same destination

The dashed grey line syncs every step. The teal line syncs every H steps. Lower is better. The ticks along the bottom mark when the teal workers talk. Drag H up and watch the ticks thin out.

50

Toy, not the paper’s: four workers, each with a slightly different two-weight bowl-shaped loss and noisy gradients (learning rate 0.15, noise 0.5, seeded so it is the same on every visit). “Excess loss” is the average loss of the averaged weights minus the best value any weights can reach. The real model has 150 million to 1.1 billion weights.

Even in this tiny bowl you can see the pattern. After 200 steps, the line with far fewer syncs lands close to the every-step line. Early on it lags a little. The paper sees the same thing at a larger scale, and Chapter 7 returns to it.

A short history

Averaging models trained apart is old. Zinkevich and colleagues showed it in 2010. Federated averaging (FedAvg, McMahan et al. 2016) made it standard for phones training on private data. Stich (2019) proved local SGD converges and communicates little. The paper calls DiLoCo “a local SGD algorithm (Stich, 2019)” and adds two changes. First, each worker uses AdamW, a stronger optimizer, for the local steps. Second, the average is not applied as a plain replacement. It goes through a second optimizer. Chapter 2 explains both. For the theory, see Local SGD and Model Averaging and the paper lesson Local SGD Converges Fast and Communicates Little, and Federated Averaging for the phone setting.

What is new at the scale of language models is not the averaging. It is showing that with the right inner and outer optimizers, hundreds of local steps still reach the quality of syncing every step.

A run takes 88,000 steps and syncs every 500 steps. How many all-reduces does it perform, compared with syncing every step?

Chapter 2

The Pseudo-Gradient and the Outer Optimizer

Turn the distance the workers travelled into a gradient, then let a second optimizer with momentum use it

You and three friends each walk alone for an hour in a thick fog, trying to reach the bottom of the same valley. At the hour mark you all stop and compare positions. Each of you started at the same spot, call it the start point. You now each stand somewhere else. What should the group do next?

One answer: everyone walks to the average of your four positions. That is plain model averaging from Chapter 1. A cleverer answer: look at how far and in which direction the group moved from the start point. That movement is a hint about where downhill is. Treat it like a gradient, and then apply a second, smarter walking rule to it.

The pseudo-gradient

A real gradient is a direction computed from one batch of text. The group’s movement is not that, but it acts like one. So the paper calls it a pseudo-gradient: a stand-in gradient built from distance travelled. Take the weights at the start of the round, θ(t). Take the average of the workers’ weights after H local steps. Subtract.

Δ
The pseudo-gradient. Delta is the usual symbol for “a difference”. It has one number per weight, the same shape as the model.
θ(t)
The shared weights at the start of the round. The paper keeps a saved copy of these.
(1/k) ∑i θi(t+H)
The average of the k workers’ weights after H local steps.

The sign is chosen so that Δ points uphill, like a real gradient. Walking against it moves the weights toward where the workers went. Here is why it earns the name. If H = 1 and each worker used plain SGD, then θi(t+1) = θ(t) − ηgi. Averaging gives θ(t) minus η times the average gradient, so Δ = η times the average gradient. For H = 1 it is the usual gradient, scaled. For larger H it is the sum of many steps.

Two optimizers

An optimizer is the rule that turns a gradient into a weight change. DiLoCo uses two. The inner optimizer runs on every worker for every step. The paper uses AdamW with learning rate 4e−4, 1,000 warm-up steps (the rate ramps up from zero) and weight decay 0.1 (a small pull that shrinks weights to keep them tame). Adam keeps running averages of each weight’s gradient so that every weight gets its own step size.

The outer optimizer runs once per round, on the pseudo-gradient. The paper uses SGD with Nesterov momentum, outer learning rate 0.7, momentum 0.9. Momentum means the optimizer remembers where it was heading and keeps some of that speed, like a ball rolling downhill. Nesterov momentum adds a look-ahead: it steps as if it had already moved a little further.

b
The velocity buffer: a running memory of past pseudo-gradients. It starts at zero.
μ
Momentum, 0.9 in the paper. Each round keeps 90% of the old velocity.
α
The outer learning rate, 0.7 in the paper.
Δ + μ b
The Nesterov look-ahead step: the new pseudo-gradient plus 90% of the updated velocity. This is PyTorch’s form of Nesterov SGD.

Worked example, one weight. The start point is θ = 1.0. The four workers end at 0.8, 0.6, 1.0, 0.6, so their mean is 0.75 and Δ = 1.0 − 0.75 = 0.25.

  1. Velocity: b = 0.9 × 0 + 0.25 = 0.25.
  2. Look-ahead step: 0.25 + 0.9 × 0.25 = 0.475.
  3. New weight: 1.0 − 0.7 × 0.475 = 0.6675.

Plain averaging would have landed on 0.75. The outer optimizer went further, because it trusts the direction. In round 2, say Δ = 0.2: b = 0.9 × 0.25 + 0.2 = 0.425, step = 0.2 + 0.9 × 0.425 = 0.5825, weight = 0.6675 − 0.7 × 0.5825 = 0.25975. The velocity is building.

Plain average vs outer momentum

One weight starts at 1.0 and the target is 0. Each round the outer optimizer takes one step. The grey line is plain averaging (learning rate 1, momentum 0). The teal line uses your settings. Try the paper’s 0.7 and 0.9, then push momentum higher.

0.70
0.90

Toy, not the paper’s: the loss is 0.5 × weight squared, each worker takes H = 5 inner steps with learning rate 0.02 and the workers’ noise averages out, so every round the mean worker weight is 0.985 = 0.904 times the start. The outer update is the exact formula above with α and μ from the sliders. 0.7 and 0.9 are the paper’s values.

With the paper’s settings the weight reaches the target far sooner than plain averaging, but it also swings past it. Momentum keeps pushing after the target is reached. That is the failure mode. The symptom is a weight, or a loss, that overshoots and swings. The measurement is the sign flip in the plot above. The fix is a lower outer learning rate or lower momentum. The paper keeps 0.7 and 0.9 from the original DiLoCo, where they worked for language models.

The idea of momentum on periodic averages is older than DiLoCo. SlowMo (Wang et al., 2019) did it for local SGD, and the Core Automation post names it as a precursor. For the full story of the original method, see the background lesson DiLoCo and Low-Communication Pretraining, and for how momentum works in ordinary training see Optimizers and Momentum.

In OpenDiLoCo, what is the pseudo-gradient?

Chapter 3

Two Copies of the Model: The Method as Code

Walk through the paper’s outer-step code, line by line, and watch each number change

Think of a hiker who wants to know how far they walked today. They must remember where they started. If they forget the trailhead, the odometer on their watch is useless. A worker in DiLoCo has the same problem. After H local steps its weights have changed, and it needs the weights it started with to compute the pseudo-gradient.

So each worker holds two copies of the model. The paper names them: the main model, which the inner optimizer keeps changing, and a copy of the original weights from the start of the round. The inner optimizer runs at the end of every step. The outer optimizer runs only once per round. Here is the paper’s Figure 1, the outer step in the plain PyTorch version, with its line numbers.

python # OpenDiLoCo Figure 1, torch.distributed version (one worker's loop). Last line indented under the if, as the algorithm needs
for batch, step in enumerate(train_loader):
    ...  # loss calculation
    inner_optimizer.step()
    if real_step % local_steps == 0:
        for old_param, param in zip(original_params, model.parameters()):
            param.grad = old_param - param.data
            dist.all_reduce(tensor=param.grad, op=dist.ReduceOp.AVG)
            param.data = old_param
        outer_optimizer.step()
        original_params = [p.detach().clone() for p in model.parameters()]

Reading it line by line

Take param, one weight tensor. In the 150M model the word-embedding table is a tensor with shape [32000, 1024]: 32,000 words in the vocabulary, 1,024 numbers each (Table 3). The code treats every tensor the same way, one at a time.

  1. param.grad = old_param - param.data. Subtract the live weights from the saved ones. The answer has the same shape as the tensor. It is stored in the slot where PyTorch normally keeps the gradient. The paper says both implementations compute pseudo-gradients by hand and keep them in FP32.
  2. dist.all_reduce(..., op=AVG). All k workers swap and average their param.grad tensors. Afterwards every worker holds the same average, which is Δ from Chapter 2.
  3. param.data = old_param. Put the weights back to the start point. This is the clever line. The outer optimizer updates param.data using param.grad, so param.data must hold θ(t), not the workers’ scattered weights.
  4. outer_optimizer.step(). One Nesterov step from the start point along Δ. Because all workers have identical θ(t), identical Δ and identical buffer b, they all land on identical new weights without sending the weights themselves.
  5. The last line saves a new copy of the weights. That copy is the start point for the next round.

Step through it with four workers and one weight. These are the same numbers as Chapter 2: start 1.0, workers end at 0.8, 0.6, 1.0, 0.6.

Step the outer step

Each row is a worker. Press Next line to run the next line of the code and watch which box changes. Boxes that just changed glow teal.


    

Toy numbers (illustrative): one weight per worker instead of millions. The code lines are the paper’s Figure 1. The outer step uses learning rate 0.7 and momentum 0.9 as in the paper, with the velocity buffer starting at zero.

The mixed precision detail

Mixed precision training does most arithmetic in 16-bit numbers to go faster. Gradients in 16 bits can be so small that they round to zero, which is called underflow. A gradient scaler multiplies the loss by a big number first, so gradients stay in range, and divides it out later. The paper says to call the scaler in the inner step but not the outer one. The pseudo-gradients are computed by subtraction in FP32, so nothing needs rescaling.

Two implementations, two limits

The plain version above runs on torch.distributed with the NCCL backend (NVIDIA’s fast GPU communication library). The paper lists its two limits. It needs custom training code, because there are two optimizers, so it does not drop into Hugging Face or PyTorch Lightning scripts. And NCCL cannot cross a NAT, the address-translating box in a home or cloud network that hides machines from the outside, so it cannot run over the open internet. Chapter 4 fixes both.

The failure mode here is a quiet one. Symptom: workers drift apart and the loss differs between them after a sync. Measurement: compare a checksum of the weights on two workers after the outer step. They must match exactly. A likely cause is a worker that skipped or reordered one of the lines, for example forgetting param.data = old_param. The fix is to keep these lines in one function that every worker runs the same way.

Why does the code set param.data = old_param before calling the outer optimizer?

Chapter 4

Hivemind: Training Over the Open Internet

Replace the data-centre network library with a peer-to-peer one, so workers can join, leave and fail

Imagine a group chat for four friends who live in four countries. There is no admin. Anyone can leave, and anyone can come back. If one friend’s phone dies, the other three keep talking. To find each other at all, they share a list of who is online and how to reach them.

The paper builds its practical training system the same way. The plain PyTorch version of Chapter 3 needs a fixed group of machines on one network. The second version, built on a library called Hivemind, lets the group behave like that chat.

The three words you need

Peer-to-peer means no machine is in charge. Every worker is a peer, and each one talks directly to other peers. The paper states it flatly: there is no master node, and all communication is peer to peer.

A hash table is a phone book: you look something up by a name (a key) and get back a value. A distributed hash table (DHT) is a phone book with no single copy. Each peer keeps a slice, and together they hold all of it. Hivemind uses a DHT spread across the workers to share small facts such as who is online and when the next sync starts. It is built on libp2p, an open-source toolkit for peer-to-peer networking.

A NAT (network address translator) is the box at the edge of a home or cloud network that lets you reach out but hides you from callers. Chapter 3 said NCCL cannot cross NAT. libp2p is designed to connect peers behind NAT, which is why Hivemind can run on the open internet.

What stays the same and what changes

The maths does not change. The same inner AdamW, the same pseudo-gradient, the same outer Nesterov step. What changes is how the all-reduce is carried out. Instead of torch.distributed, Hivemind uses the DHT to find peers and runs its own all-reduce, which the paper calls “an optimized all-reduce algorithm designed for execution on a pool of poorly connected workers”.

The paper also wraps both optimizers into one class. The user writes (paraphrasing Figure 2): build a DiLoCoOptimizer from a batch size, a learning rate scheduler, a DHT(), an inner optimizer, an outer optimizer and the model’s parameters. Then the usual loop is just loss.backward(), optimizer.step(), optimizer.zero_grad(). The outer step, the peer sync and the communication are triggered automatically after all local steps. Because it looks like one ordinary optimizer, it works with training code that assumes a single optimizer, such as the Hugging Face Trainer. That removes the first limit from Chapter 3.

The setup works with FSDP, PyTorch’s method for splitting one model across several GPUs, so one DiLoCo worker can be a whole cluster of machines. In the 1.1B experiments each worker is one node of eight H100 GPUs. FSDP and NCCL handle the fast links inside a node, and Hivemind handles the slow link between nodes. The paper uses FSDP’s no-shard strategy, because Hivemind’s state averager (the part that averages weights) was incompatible with sharded tensors. The paper’s baselines instead use FSDP with hybrid sharding on two co-located nodes.

The properties the paper lists

Try those properties. Switch peers off and on, then run a sync. The average is taken over whoever is online.

Peers come and go

Each peer holds its own pseudo-gradient. Click a peer button to take it offline or bring it back, then press Run a sync. Dots travel along the purple peer links.

Toy values (illustrative): the four pseudo-gradients are the numbers from Chapters 2 and 3, 0.2, 0.4, 0.0 and 0.4. The real DHT and all-reduce are Hivemind’s; the paper describes their purpose, not their message format. Dropping a peer here only shows the average being taken over the peers that remain.

When a peer drops, the average changes (here from 0.25 to 0.33 if peer 2 leaves), but the round still completes. That is the whole idea of fault tolerance at this level: the group does not wait for a missing peer forever. The world run in Chapter 8 also saw a different problem the paper reports plainly: the fastest worker finishes its 500 steps first and then sits idle, because the cloud machines had different CPU and memory settings.

The failure mode is the opposite of a crash: a slow peer. Symptom: all-reduce time much longer than the other rounds. Measurement: log each round’s all-reduce time. The paper reports an average of 300 s in its world run. The paper’s own future-work fix is asynchronous averaging that overlaps communication with the next round’s computing, which it cites from Liu et al. (2024).

For the theory of unreliable peers, see Heterogeneous and Unreliable Compute and Decentralized and Gossip Training. For the distributed-training basics behind FSDP, see Parallelism, Pipelines and FSDP.

Which two limits of the torch.distributed version does the Hivemind version remove?

Chapter 5

Sending Half the Bytes: FP16 All-Reduce

Round the pseudo-gradient to 16 bits before it travels and measure what it costs

You are mailing a heavy parcel and the post office charges by weight. You could ship every number written to seven decimal places. Or you could round each one to three places, and the parcel weighs half as much. If the receiver only needs the rough size of each number, the cheap parcel is just as good.

That is the whole idea of this chapter. The pseudo-gradient is a huge list of numbers that must cross the slow link. The paper asks: can we send it in half the bytes?

What FP32 and FP16 are

A computer writes a number like scientific notation: a sign, a few significant digits, and a power of two. FP32 (32-bit floating point) spends 32 bits: 1 for the sign, 8 for the power, 23 for the digits. FP16 spends 16 bits: 1, 5 and 10. Fewer digit bits mean fewer correct digits, about 3 decimal digits instead of 7. Fewer power bits mean a narrower range.

The cost of rounding to FP16 is bounded. With 10 digit bits, rounding changes a number by at most one part in 211, about 0.05%, as long as the number sits in the normal range.

|fl(x) − x| / |x|
The relative error: how far the rounded number fl(x) is from the true number x, as a fraction of x.
2−11
One half of the gap between neighbouring FP16 numbers, in units of the number itself. About 0.049%.

Worked example. The number 0.0123456789 becomes 0.0123443604 in FP16. The error is 0.0000013185, or 0.011% of the number. That is well inside 0.049%.

Where FP16 fails: the edges

The range is the catch. The smallest normal FP16 number is about 6.1 × 10−5. Below that, FP16 keeps fewer and fewer digits (the subnormal zone). Below about 3 × 10−8 a number rounds to exactly zero. We say it flushes to zero. At the top, anything past about 65,500 becomes infinity. This is why mixed precision training needs a gradient scaler (Chapter 3). Drag the typical size of the numbers below and watch where they land.

Where do your numbers land

The bars show 1,000 sample numbers by size. Green: FP16 is accurate. Yellow: it keeps only a few digits. Red: it rounds to zero. Drag the typical size and read the share in each zone.

0.001

Toy, not the paper’s: 1,000 numbers whose sizes are spread evenly in power-of-ten terms around the typical size (spread of one power of ten), rounded with a real FP16 rounding routine. The paper did not report the sizes of its pseudo-gradients. It tested the result by training, which is what the next paragraph describes.

What the paper measured

The paper’s main experiments sent the pseudo-gradient in FP32, as DiLoCo did. Then it repeated the DiLoCo run with FP16. It tried two settings: 4 workers with 50 local steps, and 8 workers with 500 local steps (Figure 6, loss against training steps). The curves for FP16 and FP32 sit on top of each other. The paper’s words: “no noticeable impact on performance”. The abstract adds that the pseudo-gradients can be all-reduced in FP16 “without any performance degradation”.

The saving is exact because it is only bytes. A 1.1 billion weight model in FP32 is 4.4 GB per transfer. In FP16 it is 2.2 GB. The paper says this “can halve the communication time required for the all-reduce operation”. At the slowest measured link, 127 Mbit/s, that is the difference between at least 277 s and at least 139 s for one pass of bytes (the lower bound from Chapter 0). The world run in Chapter 8 used FP16.

Why this works: the order of operations

Two design choices make it safe. First, the pseudo-gradient is computed by hand as a subtraction in FP32, so the difference between weights keeps its full precision. Only the copy that travels is rounded. Second, the averaging itself is a sum of a few rounded numbers, divided by the worker count. Rounding errors of 0.05% are random in sign and partly cancel across workers. They are also tiny next to the noise already in each worker’s pseudo-gradient from its small batches of text.

The failure mode is a run where many numbers fall in the red zone. Symptom: some weights stop moving after the outer step. Measurement: count exact zeros in the received tensor. Fix: keep those tensors in FP32, or scale them up before rounding, which is what a gradient scaler does. The paper did not need this at its scale, but the device shows why the check is cheap insurance. More aggressive shrinking (quantization, sparsification) is a whole field: see Communication Compression and the papers QSGD and PowerSGD.

What does the paper’s Figure 6 show about FP16 all-reduce?

Chapter 6

The Replication: 150 Million Parameters, 8 Workers

Read Figure 3 and Table 1 and see how 500 times less talking reaches the same perplexity

A cooking show claims a new recipe uses five hundred times less phone time and tastes the same. A careful viewer cooks it in their own kitchen to check. This chapter is that check. The authors rebuilt DiLoCo from the original paper’s description and ran the same experiment.

What they trained

The model is a Llama-style transformer with 150 million weights (Table 3: 12 layers, hidden size 1,024, 16 attention heads, vocabulary 32,000). A transformer is the standard language model design, and the Gleam Transformer teaches it from zero. The original DiLoCo authors used the Chinchilla architecture. The paper says the two are similar but differ in details: Llama uses the SwiGLU activation in its MLP (the small feed-forward block in each layer) with a hidden size of two thirds of 4d instead of 4d.

The data is C4 (the Colossal Clean Crawled Corpus, a large cleaned web text dataset from Raffel et al.). The task is language modelling: predict the next token. The quality score is perplexity. It measures how surprised the model is by the held-out text: a perplexity of 16 means the model is, on average, as unsure as if it were picking between 16 equally likely words. Lower is better.

The settings follow DiLoCo: inner learning rate 4e−4, 1,000 warm-up steps, weight decay 0.1, batch size 512, sequence length 1,024, outer Nesterov learning rate 0.7 and momentum 0.9. The run lasts 88,000 steps. The one planned difference is the Llama architecture.

The three runs

  1. Weak baseline. One machine, no replicas, 88,000 steps. Cheapest and slowest to learn.
  2. Strong baseline. Data parallel with an 8 times larger batch: it uses the same total compute as eight workers, and all-reduces at every step.
  3. DiLoCo. Eight replicas, 500 local steps between syncs.

The second and third runs spend the same compute and the same data in the same time. They differ in one thing: how often they talk. That makes them the fair pair to compare. Table 1 gives the result. Switch between its columns below.

Read Table 1

Choose a column of the paper’s Table 1. Each bar is one run. Watch how the DiLoCo bar sits next to the strong baseline on quality but far from it on communication.

Table 1 of the paper, 150M Llama on C4 after 88,000 steps: perplexity 16.17, 13.68 and 13.73; compute and data 1×, 8×, 8×; communication 0, 8×N and 8×N/H with N = 88,000 steps and H = 500. The rounds count is our reading of N and N/H.

The result: DiLoCo reaches perplexity 13.73. The strong baseline reaches 13.68. The gap is 0.05, or 0.4%. The weak baseline sits at 16.17, so both big runs improve on it by about 2.4. DiLoCo did that with 176 syncs instead of 88,000. The abstract and Figure 3 caption describe this as communicating 500 times less.

What Figure 3 adds

Figure 3 plots perplexity against training steps for all three runs. The curves tell a story the table hides. The DiLoCo curve is not on top of the strong baseline for most of the run. It starts slower and catches up. In the original DiLoCo paper, the DiLoCo run was already approaching and passing the strong baseline at around 64,000 steps. In OpenDiLoCo it only matches the strong baseline at the very end, at 88,000 steps.

The authors offer one possible reason: the original experiments started from a checkpoint with 24,000 pre-training steps, but OpenDiLoCo trains from scratch. The paper does not test this explanation, so treat it as a guess.

A fair reading

Three things the table does not say. First, it does not say DiLoCo is faster in wall-clock time on a fast cluster. The two big runs take the same number of steps; the saving is in network use. Second, it is one model size and one dataset. Third, the perplexity gap to the strong baseline is small but not zero, and Chapter 7 shows that it depends on how many workers you use and how long you train.

The failure mode a reader should watch for is judging by the last number alone. Symptom: a method looks equal at the end. Measurement: read the whole curve. Here, the curve shows DiLoCo trailing for most of training. Fix: ask for the full curve, and the budget at each point.

The original method is reviewed in DiLoCo and Low-Communication Pretraining. The Core Automation post lists this paper in its timeline as “Method + demo” (July 2024): an open implementation, models up to 1.1B, and a real run across three countries on two continents.

In Table 1, which comparison is the fair one for judging DiLoCo, and what does it show?

Chapter 7

The Ablations: How Many Workers Is Too Many?

Count steps the way the paper does, and see why more workers did not mean faster early progress

A restaurant owner adds more cooks to the kitchen. The soup improves. Does that mean each cook is as useful as the first? Not necessarily. Maybe the first cook does most of the work and the eighth mostly gets in the way. To find out, you must count how much cooking time you spent, not only how good the soup is.

An ablation is a test that changes one thing and holds the rest fixed, to see what that thing does. The paper runs one ablation on the number of DiLoCo workers (1, 2, 4 and 8) and reads it two ways. The reading is the lesson.

The setup

The experiment copies the main run of Chapter 6, with one change: the local steps drop from 500 to 50, so syncs happen ten times more often. Each run trains the same 150M model with 1, 2, 4 or 8 DiLoCo workers. With one worker, DiLoCo still has an inner and an outer optimizer, but nobody to average with. The paper adds a note: because of the compute cost, these ablations were not run to 88,000 steps.

Two ways to count

Figure 4 puts local steps on the horizontal axis: the number of steps each worker has taken. At the same local step, an 8-worker run has trained 8 batches for every one of a single machine. It has seen eight times more text. The paper’s result on this plot is a steady improvement: more workers, lower perplexity.

That comparison is generous to DiLoCo, because the 8-worker run has paid for eight times the compute. So Figure 5 repeats the same curves with global steps on the axis: the steps of all workers added together, which is a better stand-in for total compute. Use the device to see the difference in what each point costs.

Local steps or global steps

Drag the number of local steps. Each bar is a run with that many workers, and its length is the global steps it has spent. The vertical line is where one machine would be at the same point of Figure 4.

12,500

Arithmetic, not data: global steps = workers × local steps, which is how we read Figure 5’s change of axis (“the total amount of compute spent”). The ablation used 50 local steps between syncs and 1, 2, 4 and 8 workers; the range of the slider follows the horizontal axis of Figure 4 (up to about 25,000 steps). The perplexity curves themselves are in the paper’s figures and are described, not redrawn, here.

On the global-step axis the picture flips. The paper writes that DiLoCo with more than one worker is “initially not as compute efficient” as the same number of global steps on a single machine or with DDP. It adds that DiLoCo “may only achieve comparable FLOP efficiency after a large number of steps due to slower initial convergence”, as the main run of Figure 3 also showed. A FLOP is one floating point operation, a single multiply or add. FLOP efficiency asks: how much quality do I get for each unit of arithmetic?

The practical advice

The authors turn this into advice using their main result. Eight DiLoCo workers reach a final perplexity comparable to DDP after 88,000 steps. But training for only 44,000 steps with eight workers gives a model clearly worse than DDP with the same number of global steps. In that case, four DiLoCo workers are the more efficient choice.

The interpretation the paper gives: with eight DiLoCo workers the final model is stronger, but adding workers does not speed up the early phase of learning the way data parallelism would. One plausible reason, our guess and not a test in the paper, is that each worker wanders alone between syncs, and early in training the best direction changes fast.

What to take from it

The failure mode to expect is paying for compute that does not buy quality. Symptom: a bigger DiLoCo run barely beats a smaller one at equal budget. Measurement: plot quality against global steps, as Figure 5 does. Fix: choose the worker count for your step budget, as the 4-versus-8 advice shows.

This is the same trade-off that appears in the literature on local methods generally. See the Core Automation post’s history table and our lesson Local SGD and Model Averaging. For how to count compute in ordinary data parallel training, see Distributed Training.

Why does the paper redraw the worker ablation with global steps on the horizontal axis?

Chapter 8

Scaling Up: 1.1 Billion Parameters Across Three Countries

Follow the 1.1B runs, match tokens per sync, and read the real-world 6.9% sync share

A bridge that holds a bicycle may not hold a lorry. The 150M model of Chapter 6 is the bicycle. The original DiLoCo paper tested up to 400 million weights. Real language models are far bigger, so the authors ask: does it still hold at 1.1 billion, three times the original size? Then they ask a second question that matters more: does it work over the real internet?

Scaling to 1.1 billion weights

The model follows TinyLlama (a small open Llama model with 1.1B weights): 22 layers, hidden size 2,048, 32 attention heads (Table 3). The learning rate stays 4e−4, the outer learning rate stays 0.7, and the batch size grows to 2,048, four times bigger than the 150M run. There are four DiLoCo workers, each a node of eight H100 GPUs, and the run is limited to 44,000 steps.

The baselines use PyTorch FSDP with hybrid sharding on two co-located nodes of eight H100s each. The DiLoCo workers use FSDP inside a node (no-shard, Chapter 4) and Hivemind between nodes.

The authors run DiLoCo two ways, with 500 local steps and with 125. Why 125? Here is the tokens-per-sync trick. In the 150M run, a worker used 500 steps of 512 sequences between syncs. With a batch four times bigger, 125 steps carry the same amount of text per sync. The paper says the 125-step run “effectively has the same number of tokens per outer step on each DiLoCo worker as the main experiment with 500 local steps”.

Match the text per sync

Top: sequences one worker reads between two syncs (batch size times local steps). Choose a batch size and drag the local steps until the teal bar matches the grey main-run bar. Bottom: one round of the world run, drawn to scale.

125

Arithmetic on the paper’s settings: batch 512 × 500 steps = 256,000 sequences, and batch 2,048 × 125 steps = 256,000. We read the batch size as per worker, which matches the paper’s statement about tokens per outer step on each worker. Bottom bar: Section 3, the world run, about 67.5 minutes (4,050 s) of local steps and an average 300 s all-reduce.

Table 2

After 44,000 steps the perplexities are: no replica, 11.85; 4× batch data parallel, 10.52; DiLoCo with 125 local steps, 10.76; DiLoCo with 500 local steps, 11.14. Both DiLoCo runs beat the weak baseline. The 125-step run is 0.24 behind the strong baseline while communicating 125 times less. The 500-step run is 0.62 behind.

The paper explains the gap with the tokens trick. The 500-step run, for the same number of training tokens, syncs a quarter as often as the 150M run did. That makes 125 the fairer comparison. Even the 500-step run converges faster late in training and slowly catches up to the strong baseline. The authors state the limit plainly: further work is needed to make DiLoCo work with even larger batch sizes and more local steps.

The run across the world

Now the real test. The authors use the Hivemind version with four DiLoCo workers, each with eight H100 GPUs. They sit in Canada, Finland, and two different states of the United States (Texas and Delaware), hosted by four different cloud providers. The bandwidth between them, measured with the iperf tool, ranged from 127 to 935 Mbit/s. They train the 1.1B model with 500 local steps, and all-reduce the pseudo-gradients in FP16.

Here are the paper’s numbers, and a check by hand:

  1. Workers run on their own for about 67.5 minutes: 67.5 × 60 = 4,050 s, so about 8.1 s per step.
  2. Then the average all-reduce takes 300 s.
  3. One round is 4,050 + 300 = 4,350 s, and the all-reduce share is 300 / 4,350 = 6.9%. The paper reports exactly that: the all-reduce bottleneck accounts for 6.9% of training time.
  4. So the sync alone costs about 7% of the time. The paper’s summary is 90 to 95% compute utilization. The gap below 100% includes time the fastest worker spent idle, because the cloud machines, although they had the same GPU type, differed in CPU cores and memory and so took slightly different time for 500 steps.

If the same run had synced every step, it would have waited for an all-reduce after every 8.1 s step. Even if each of those took the same 300 s (our assumption, as in the hero), the GPUs would be busy only 2.6% of the time. That is the whole case for the method, in one pair of numbers.

The paper also lists what it did not solve. A slower worker still makes the others wait. Future work in the paper is asynchronous averaging that interleaves the weight-averaging communication with the next round’s computing, as in Liu et al. (2024). The Core Automation post builds on those same ideas, with fragment-wise and asynchronous updates.

The failure mode in the field is the idle fastest worker. Symptom: utilization stuck near 90%. Measurement: log time-to-finish per worker for each round. Fix: balance the work to equal time, or go asynchronous. The Core Automation post, for instance, tuned microbatch and accumulation settings so both sites took similar time per step.

In the world run, workers computed for about 67.5 minutes and the average all-reduce took 300 s. About what share of the time went to the all-reduce?

Chapter 9

Field Guide

Keep the numbers, the terms, the checklist and the core code on one page

OpenDiLoCo is an open, working version of a simple trade. Let each worker take hundreds of steps alone, then merge the workers with a second optimizer that treats their travelled distance as a gradient. The paper reproduces DiLoCo on a 150M model, stretches it to 1.1B, and trains across three countries at 90 to 95% compute utilization. Everything below is the paper’s own, with the chapter that explains it.

The numbers

WhatValueWhere
Inner optimizerAdamW, learning rate 4e−4, 1,000 warm-up steps, weight decay 0.1Sec 3, Table 3; Ch 2
Outer optimizerSGD with Nesterov momentum, learning rate 0.7, momentum 0.9Sec 2, Table 3; Ch 2
150M runLlama, C4, batch 512, sequence 1,024, 88,000 steps, 8 workers, 500 local stepsSec 3; Ch 6
Perplexity, 150M16.17 (no replica), 13.68 (8× batch DDP), 13.73 (DiLoCo)Table 1; Ch 6
Communication saved500 times fewer syncs at H = 500Fig 3, Table 1; Ch 1, 6
Worker ablation1, 2, 4, 8 workers at 50 local steps; 8 workers lag at equal global steps early onFigs 4 and 5; Ch 7
FP16 all-reduceNo noticeable impact; halves all-reduce timeFig 6; Ch 5
Perplexity, 1.1B11.85 (no replica), 10.52 (4× batch DDP), 10.76 (DiLoCo H = 125), 11.14 (H = 500)Table 2; Ch 8
1.1B settingsTinyLlama size, batch 2,048, 4 workers, 44,000 stepsSec 3, Table 3; Ch 8
World run4 workers of 8 H100s in Canada, Finland and two US states; 127 to 935 Mbit/s; 67.5 min of local steps; 300 s average all-reduce; 6.9% of time in all-reduce; 90 to 95% utilizationSec 3, Fig 8; Ch 8
Reference codeA concise 180-line PyTorch version, plus a Hivemind version with FSDPAbstract; Ch 3, 4

The words

TermIn plain words
All-reduceEvery worker sends a tensor in and gets the average back.
Bandwidth, Mbit/sHow many millions of bits a link carries each second.
Local steps (H)Training steps one worker takes between two syncs.
Inner / outer optimizerThe rule for every worker step / the rule for the merge at each sync.
Pseudo-gradientSaved start weights minus averaged end weights, used as a gradient by the outer optimizer.
Nesterov momentumKeep some of the old direction and step with a look-ahead.
Hivemind, DHT, libp2pA peer-to-peer training library, its shared phone book, and the networking toolkit under it.
NAT, NCCLThe box that hides a machine from the internet / NVIDIA’s fast GPU communication library.
FSDPPyTorch’s way to split one model across the GPUs of a worker.
FP16 / FP3216-bit and 32-bit number formats; FP16 halves the bytes.
PerplexityHow surprised the model is by held-out text. Lower is better.
AblationA test that changes one part and holds the rest fixed.

A checklist for your own run

  1. Keep the saved start weights on every worker. Without them there is no pseudo-gradient.
  2. Compute the pseudo-gradient yourself, in FP32, as saved minus live.
  3. Use the gradient scaler in the inner step only.
  4. All-reduce with AVG. FP16 on the wire is fine; the paper saw no loss.
  5. Reset the live weights to the saved weights, then take the outer step.
  6. Clone the new weights as the next round’s start point.
  7. After each sync, check that weights match on two workers.
  8. Pick the worker count for your step budget: the paper found four more efficient than eight at 44,000 steps.
  9. When you raise the batch size, cut the local steps to keep the text per sync the same.
  10. Log the all-reduce time and each worker’s finish time. The slowest and the fastest worker decide your utilization.

The core as code

python # One DiLoCo round on one worker (our rewrite of the paper's Figure 1)
import torch, torch.distributed as dist

def diloco_round(model, original_params, outer_opt):
    # model has just finished H inner AdamW steps on this worker's own batches
    for old, p in zip(original_params, model.parameters()):
        p.grad = old - p.data                           # pseudo-gradient, FP32, same shape as p
        dist.all_reduce(p.grad, op=dist.ReduceOp.AVG)   # mean over all k workers
        p.data = old                                    # go back to the shared start point
    outer_opt.step()                                # SGD(lr=0.7, momentum=0.9, nesterov=True)
    return [p.detach().clone() for p in model.parameters()]

# setup, once
inner_opt = torch.optim.AdamW(model.parameters(), lr=4e-4, weight_decay=0.1)
outer_opt = torch.optim.SGD(model.parameters(), lr=0.7, momentum=0.9, nesterov=True)
original_params = [p.detach().clone() for p in model.parameters()]

for step, batch in enumerate(loader, 1):
    loss = loss_fn(model, batch); loss.backward()
    inner_opt.step(); inner_opt.zero_grad()
    if step % 500 == 0:                                  # H = 500 local steps
        original_params = diloco_round(model, original_params, outer_opt)

The Hivemind version hides all of this behind one optimizer, which the paper shows as DiLoCoOptimizer(bs, ls, DHT(), i_opt, o_opt, m.params()). The code above is the idea, not the repository; the real one is at github.com/PrimeIntellect-ai/OpenDiLoCo.

Where it sits, and what it leaves open

OpenDiLoCo is a data-parallel method: every site holds a full copy of the model. The Core Automation post separates this family from model-parallel methods that split one model across participants. It places OpenDiLoCo in July 2024 as “Method + demo” and follows it with Streaming DiLoCo, Decoupled DiLoCo, INTELLECT-1 and others.

The paper’s own limits are short and honest. Eight workers do not match DDP’s efficiency at a short budget. Larger batches and more local steps need more work. The slowest peer holds everyone back. More sophisticated model merging, asynchronous communication and bigger models are left for later.

Keep going

The takeaway. When the network is the slowest part, stop using it every step. Let each worker walk alone for hundreds of steps, treat the distance the group walked as a gradient, and give it to a second optimizer with momentum. The paper shows this keeps GPUs 90 to 95% busy over links of 127 to 935 Mbit/s, at a small cost in quality.

Credit. This lesson re-teaches “OpenDiLoCo: An Open-Source Framework for Globally Distributed Low-Communication Training” by Sami Jaghouar, Jack Min Ong and Johannes Hagemann of Prime Intellect (arXiv 2407.07852, read the paper), which reproduces DiLoCo by Arthur Douillard and colleagues. All numbers are the paper’s except those marked as our arithmetic or toy values. The context comes from Rohan Anil’s Core Automation post, The Hitchhiker’s Guide to Training on Compute Islands.

Now press Present or Teach and explain from memory why syncing every 500 steps keeps the GPUs busy, what the pseudo-gradient is, and what the outer optimizer does with it. Then go back to the sync buttons at the top, pick each interval, and say which chapter explains the bar you see.

OpenDiLoCo
Read the paper · DiLoCo background · Back to Gleams