From Pieces to a Cluster

Introduction

Project introduction

From Pieces to a Cluster

You have written the pieces, which are the cost of an all-reduce, the ring that performs it, memory per worker under ZeRO, a pipeline schedule, a tensor-parallel layer, and the DiLoCo outer step.

In the notebook those pieces come already written, and you use them in training runs on a real PyTorch model. A worker is one copy of the model in a Python list, so every split can be checked against a single worker down to rounding in the 16th digit, and every number that would cross the network can be counted. One cell starts real worker processes with torch.distributed to show that the simulation is the real algorithm.

What you will see

Four workers that average their gradients end with the same weights as one worker on the whole batch. Sharding Adam across workers gives exactly the same weights while each worker stores a quarter of the optimizer state. Micro-batches through a pipeline give the same gradients as one big batch, and a split MLP gives the same output as the whole one.

Two things go wrong along the way, and the numbers give them away. Summing gradients instead of averaging them quietly multiplies the learning rate by the number of workers. And with a single micro-batch, a simple cost model shows that adding pipeline stages makes training slower, not faster. Finally DiLoCo trains with 10 times fewer synchronizations, and you measure what that costs at this small scale.

What each worker holds

4 workers

Worker 1

all 4 layers

Worker 2

all 4 layers

Worker 3

all 4 layers

Worker 4

all 4 layers

network
computing

Each worker holds the whole model, a quarter of every batch

They send gradients, every step (all-reduce)

How the notebook is organized

01

Data parallel

A baseline, averaged gradients, a summing bug, and real gloo processes.

02

Communication and memory

Training with the ring and counting its bytes, then ZeRO memory per worker and a sharded Adam.

03

Splitting the model

Pipeline and tensor parallel, then DiLoCo with one sync every H steps.

Train on many workers and check every split

Run the whole investigation in the browser, about 50 minutes.

Open the notebook project