A rigid training pipeline stops when one worker dies. SWARM sends every batch through whichever workers are alive, and trained a 1B-parameter model on cheap GPUs over a network under 200 Mb/s (megabits per second, slower than many home connections).
Learn how a model too big for one GPU can train across hundreds of unreliable, mismatched machines on ordinary internet links, and why a bigger model makes that easier, not harder.
Pick a design, then slide Workers lost up from 0 to 6. Watch the rigid pipelines go silent while SWARM keeps moving. Then we build it piece by piece: what a pipeline is, why size helps, how to shrink messages, how batches find live workers, and how idle workers move to where they are needed.
You need a rough idea of what a neural network layer does (it turns an input array into an output array) and what a GPU is (a chip that does many multiplications at once). We build the rest from zero.
Based on SWARM Parallelism: Training Large Models Can Be Surprisingly Communication-Efficient by Max Ryabinin, Tim Dettmers, Michael Diskin and Alexander Borzunov (ICML 2023, PMLR 202; code). Every idea is re-taught here in our own words and devices. It is one of the papers linked from the Core Automation post The Hitchhiker’s Guide to Training on Compute Islands; the background for unreliable, mismatched machines is in Heterogeneous and Unreliable Compute.
Toy model, not the paper’s measurements. Twelve workers, four stages, three per stage; each worker is labelled with its speed in samples per second (1 or 2). A rigid chain runs at the speed of its slowest member and stops if any member is gone. SWARM’s stage speed is the sum of its live workers, and the pipeline runs at its slowest stage. This toy leaves out SWARM’s rebalancing, which Chapter 5 adds.
Chapter 0
See why a model too big for one GPU is so hard to train on cheap, unreliable machines
Picture a small lab with one good idea and no supercomputer. The idea needs a language model with billions of parameters. The lab can rent 400 cheap GPUs from a cloud company. Each one costs a few cents an hour. There is a catch, and it decides everything that follows.
The company calls these machines preemptible (also called spot instances). They are cheap because the company can take any of them back at any moment, with little warning. The paper says such machines cost two to ten times less than the dedicated kind. A run of four weeks on 400 of them will see machines vanish every few minutes.
A parameter is one number the model learns, like one knob on a mixing desk. A model with a billion parameters has a billion knobs. Training turns the knobs a little, over and over, until the model's answers improve.
A GPU is the chip that does the arithmetic. It has its own memory (16 GB on the cheap T4 card the paper uses). Training needs far more than the parameters themselves: it also keeps gradients (the direction each knob should move) and the optimizer's running averages. A standard rule for this bookkeeping is about 16 bytes for every parameter (the ZeRO paper counts 2 + 2 + 12). Try it below.
The tall bar is the memory one worker needs to train its share. The lines mark a 16 GB T4 and an 80 GB A100. Make the model bigger, then cut it into more stages.
Illustrative arithmetic: 16 bytes per parameter is the usual mixed-precision Adam count from the ZeRO paper (2 bytes of weights, 2 of gradients, 12 of optimizer state). It ignores activations and any memory tricks. The 16 GB and 80 GB figures are the sizes of a T4 and of the larger A100 card. The paper itself trains a model that is 13B in compute but only 1.01B in stored parameters.
A 13-billion-parameter model needs about 208 GB. No single cheap card holds that. So the model must be cut into pieces, and each piece goes on a different machine. That is model parallelism: many machines each hold part of one model. It differs from data parallelism, where every machine holds a full copy and they swap gradients.
The usual way to cut a model is a pipeline: machine 1 holds the first few layers, machine 2 the next few, and so on. Data enters at machine 1 and passes down the line, like cars on an assembly line. Chapter 1 builds this slowly.
A fixed pipeline has two weaknesses on cheap machines. First, it moves only as fast as its slowest worker, the weakest link. If machine 3 is a slow card, every machine before and after it waits. Second, it breaks when any worker dies. One preempted machine in the chain stops the whole chain. With 400 machines that come and go, a rigid chain would almost never run.
There is also the network. Machines in a supercomputer talk over links of hundreds of gigabits per second. These rented machines may share a home-grade link. A bit is one 0 or 1, and a byte is eight bits. Bandwidth is how many bits per second a link carries: 500 Mb/s means 500 megabits, or 62.5 megabytes, every second. Latency is the delay before the first bit arrives. The paper tests 500 Mb/s links and up to 200 ms of latency.
The authors name their method SWARM parallelism, a backronym for Stochastically Wired Adaptively Rebalanced Model Parallelism. They keep the pipeline, but make it soft. Several workers share each stage, so each stage is a swarm. For every batch, a small router picks a live worker from each swarm, in proportion to its speed. If a worker dies, the router picks another. If a stage runs short of workers, idle workers from other stages move over. Then they add one more trick, compressing the messages, and train a model with 1.01 billion stored parameters (13B in compute) on preemptible T4 GPUs with under 200 Mb/s of network.
The hero at the top is a toy of this: twelve workers, four stages. The rigid design is three fixed chains. SWARM treats each stage as a pool. Each later chapter explains one part of the machinery.
If the words above are new, the lesson Heterogeneous and Unreliable Compute teaches the background at a gentler pace, and Distributed Training covers the data-parallel basics. The Core Automation post The Hitchhiker’s Guide to Training on Compute Islands lists SWARM as the model-parallel example of the new family of methods for poorly connected sites.
Chapter 1
Cut a model into stages, feed it microbatches, and count the idle time that a pipeline creates
A factory makes a car in four steps: frame, engine, paint, wheels. One crew could do all four steps on one car, then start the next. A better plan puts one crew on each step. While the paint crew works on car 1, the engine crew already works on car 2. Every crew stays busy. This is an assembly line, and it is the picture behind pipeline parallelism.
A neural network is a stack of layers. Each layer takes an array of numbers, does arithmetic with its parameters, and hands a new array to the next layer. Cut the stack into groups of layers. Each group is a pipeline stage, and each stage lives on its own machine. The paper’s big model has three such stages of 16 layers each, plus the embedding and output ends.
In the forward pass, stage 1 turns the input tokens into an array of activations and sends it to stage 2. For a batch of 1 sequence of 512 tokens and a hidden size of 4096 (each token is described by 4096 numbers), the array has shape [1, 512, 4096]. That is 2,097,152 numbers. At 2 bytes each, it is 4.19 MB, or 33.6 megabits. At 500 Mb/s it takes about 67 ms to send.
In the backward pass, the last stage computes the loss (how wrong the model was). Then it sends back an array of the same shape, the gradient of the loss with respect to its input. Each stage uses it to find its own parameter gradients and passes one more array upstream. So each hop carries one array forward and one array back, and nothing else. The machines never send their parameters.
One extra detail saves memory. The backward pass needs the activations from the forward pass. Storing them all is costly. With activation checkpointing, each stage keeps only the array it received and recomputes the inside when the gradient arrives. It trades extra arithmetic for less memory. The paper uses it.
If we pushed one batch through, only one machine would work at a time. The other three would sit idle. So we cut the batch into small pieces called microbatches. Stage 1 starts microbatch 2 as soon as it passes microbatch 1 on. Now the stages overlap, as on the assembly line.
The start and the end still cost something. At the start, stage 4 has nothing to do until the first microbatch arrives. At the end, stage 1 is done while stage 4 still finishes. These idle corners are the pipeline bubble. Move the sliders to see it.
Each row is a stage, time runs left to right. Orange cells are a stage computing; the lighter ones are forward passes, the darker ones backward. Gaps are idle time. Change the stages and the microbatches.
A teaching schedule, not the paper’s measurement. It follows the plain GPipe order (all forward passes, then all backward passes), with a backward cell twice as long as a forward cell, and it ignores the cost of sending messages. The paper names the bubble and cites GPipe, but does not give this formula.
Count the idle time. Stage s cannot start until the microbatch has passed through the s stages before it, so the last stage starts k − 1 slots late. The forward pass takes m + k − 1 slots in all, but each stage works in only m of them. Each stage is busy for a share of its time:
k = 4, m = 4: busy = 4 / (4 + 4 − 1) = 4 / 7 = 57%. k = 4, m = 16: 16 / 19 = 84%
The backward pass has the same shape, so the share holds for the whole step. The catch is memory. Each microbatch in flight holds activations, so the device caps m. The paper says this directly: the number of microbatches is limited by device memory, which leaves the bubble.
Data parallelism needs every machine to swap full gradients. The paper (Appendix A) works an example. A 1B-parameter model with 16-bit gradients is 2 GB. Each of 100 machines must send about 2 GB per step. On a slow link that is minutes.
Sharded data parallelism (each machine owns a slice of the model, as in ZeRO and FSDP) must gather slices at every layer. For 1B parameters on 100 Mb/s links the paper estimates 5.5 minutes of waiting per forward and backward pass. Our rough arithmetic is 2 GB × 8 ÷ 100 Mb/s = 160 s each way, 5.3 minutes in all; the gap is units. Either way it is far too long.
Pipeline traffic scales with the activations, not the whole model. That makes the pipeline the best fit for slow links. The older cousin, tensor parallelism (splitting each layer across machines), needs all-to-all messages after every layer. The paper says it stays inside one server for that reason. The full tour of these families is in Parallelism: Pipeline and FSDP.
Chapter 2
Show that compute grows faster than traffic as layers widen, so bigger models need less bandwidth per unit of work
You are moving house. A small box holds little, but you can carry it in one hand. A box twice as wide, tall and deep has eight times the room inside and only four times the cardboard on the outside. Big boxes get more content per square metre of wall. Galileo noticed this about animals in 1638: volume grows with the cube of size, surface only with the square. The paper borrows the name: the square-cube law.
Now swap the box for a pipeline stage. The “content” is the arithmetic the stage does. The “wall” is the data that must cross the network. If the arithmetic grows like a cube and the data like a square, a bigger layer spends a smaller share of its time on the network. That is the surprise in the paper’s title.
The authors start with the simplest possible pipeline. It has k stages. The input is an n×n matrix (a square grid of numbers). Each stage multiplies it by its own n×n matrix of weights, then sends the n×n result to the next stage.
Count the arithmetic. The product has n² output cells. Each cell is a sum of n products, so it takes n multiplications and about n additions. That is roughly 2n³ operations. Count the traffic: one n×n grid of numbers, or n² values. The ratio follows.
n = 1,000: 2,000 operations per value sent. n = 10,000: 20,000. Ten times wider, ten times more work per byte.
The paper stresses that faster matrix algorithms do not change the story, because deep learning on GPUs uses the plain cubic method. The paper cites faster algorithms but notes they pay off only for very large matrices. The best known ones (exponent about 2.37, our note) still do more than the n² operations it takes just to write the values down, so the pattern holds.
Real models are not square matrices. A Transformer layer sees T tokens, each a vector of d numbers (the hidden size). The paper lists the cost in big-O terms: attention takes O(B L² H) and the feed-forward part O(B L H²) compute, but only O(B L H) values cross a stage boundary. B is the batch, L the length and H the hidden size.
We can make the count exact for one microbatch. A Transformer layer holds about 12d² parameters. Training does about 6 operations per parameter per token (2 forward, 4 backward). So a microbatch of T tokens costs 6 · 12d² · T = 72Td² operations. At the boundary the layer sends T·d values forward and gets T·d back, so 2Td values cross in all. The ratio is 36d operations per value. The paper’s Table 6 agrees with the count: a GPT-3-size layer (d = 12,288) has 1.81B parameters and 5.5 × 1012 operations for a 512-token microbatch, and 72 · 512 · 12288² = 5.57 × 1012.
“base” d = 768: 36 × 768 = 27,648 operations per value. “GPT-3” d = 12,288: 36 × 12,288 = 442,368. Sixteen times the work for each value sent.
Chapter 1’s other methods do not enjoy this. Data parallelism sends gradients whose size is the parameter count, so it grows like d², as fast as the compute does. The paper adds that tensor parallelism at 500 Mb/s becomes practical only for layers larger than about 216 units.
The authors checked the law on V100 GPUs, with one stage per server, 512-token inputs and 500 Mb/s links in each direction. The device draws a toy curve from the counts above and puts the paper’s measured GPU utilization on top. Utilization here means the share of time the GPU computes rather than waits.
The curve is a toy from the counts above. The dots are the paper’s measurements at the latency you pick. Drag the hidden size and read both.
Toy curve (illustrative): compute is 72·512·d² operations at 12.5 trillion operations per second (the rate that fits the paper’s GPT-3 timing in Figure 3), traffic is 2·512·d values at 16 bits over a 500 Mb/s link, with no overlap. Dots are Table 1 of the paper: relative GPU utilization at 500 Mb/s for base (d = 768), xxlarge (4,096), GPT-3 (12,288), and “Ours” (4,096 with 3 layers per stage and 8-bit messages). The toy sits below the dots; the paper does not say how much of the gap is overlap, but the rising shape is the same.
The paper’s numbers show the law at work. With no delay, utilization is 18.0% for base, 32.1% for xxlarge and 82.1% for GPT-3 size. At 100 ms of round-trip delay, roughly the delay between continents, GPT-3 size still holds 60.2% while base falls to 2.78%. A wider layer also hides latency, because the fixed cost of a delay is spread over more compute.
The last column, “Ours”, uses the same width as xxlarge but reaches 89.5%. It puts three layers on each stage, which triples the compute per message, and sends 8-bit numbers, which halves the message. Chapter 3 explains that trick.
Chapter 3
Shrink what crosses the network with 8-bit numbers, narrow bottlenecks and shared layers
You want to email a photo over a bad connection. You can send it as it is, or shrink it first. A smaller file arrives sooner, with a little less detail. The same trade is open to a pipeline. Each stage sends an array of activations forward and an array of gradients back. If those arrays are half the size, the network wait halves too.
The paper uses three tools: send numbers with fewer bits, squeeze the array through a narrow layer, and reuse layers so there is less to synchronize. Chapter 2 showed that the “Ours” row reached 89.5% GPU use. These tools are how.
A normal activation is a 16-bit number (2 bytes). Quantization rounds each number to one of 256 levels so it fits in a single byte. The rule is simple. Find the largest absolute value, call it the scale, divide every number by it, and round to a whole number between −127 and 127. The receiver multiplies back.
One problem breaks this rule: outliers. Transformer activations sometimes hold one huge value among thousands of small ones. If the scale is set by the huge one, all the small values land on zero or one, and their detail is lost. The cure is blockwise scaling. Cut the array into short blocks and give each block its own scale. An outlier then ruins only its own block. The paper uses the method of Dettmers et al. (2022), called dynamic 8-bit quantization with blockwise scaling, which spaces its 256 levels unevenly. The device below uses plain even spacing so the effect of blocks is easy to see.
Blue bars are 48 activations. Orange marks are what the receiver rebuilds from 8-bit numbers. Turn the outlier on, then shrink the block size.
Illustrative: 48 seeded random activations with spread 1 and one optional outlier of 300, quantized with even-spaced 8-bit levels and one 16-bit scale per block. The paper’s quantizer spaces its levels unevenly, and its bytes are counted the same way. Error is the mean absolute error on the 47 ordinary values, divided by their mean absolute size.
Cost and benefit, in the paper’s words: this cuts traffic by about 2× from half precision and about 4× from full precision. The extra arithmetic is under 1% of compute, and the authors run it on the CPU, alongside the transfers, so the GPU does not wait.
The second tool changes the model itself, so the model learns to live with it. Place a pair of extra layers at each stage boundary. The first compresses the m-wide output down to c numbers, where c < m. The second decompresses it back to m on the next stage. Only the narrow c-wide array crosses the network. The paper calls this a bottleneck layer.
Bottleneck(x) = LayerNorm( LayerNorm( MLP(x) ) · wc ) · wd, wc has shape [m, c], wd has shape [c, m]
Here x has shape [b, s, m]: batch, sequence, model width. MLP is the stage’s usual feed-forward block. After wc it is [b, s, c], and that is what travels. So the traffic falls by a factor m/c. The authors found the LayerNorm (a step that rescales each vector to a steady size) critical: without it, training diverged. The extra cost is two small matrix products, under 1% of compute for typical sizes.
Maxout compression does the same job without a learned matrix. The maxout function slides over the vector in non-overlapping windows of k numbers and keeps the largest in each. A width of m becomes m/k. The next stage then applies wd, now of shape [m/k, m], to expand it again. For m = 4096 and k = 2, a message of 4096 values becomes 2048.
The authors trained a language model on WikiText-103 with two stages and a 2× compression factor. They measured the perplexity (how surprised the model is; lower is better) after 286 thousand steps, and how many steps it took to reach perplexity 22.
| Method | Perplexity after 286K steps | Steps to perplexity 22 |
|---|---|---|
| No compression | 21.02 | 1× |
| 8-bit compression | 21.13 | 0.97× (not significant) |
| Bottleneck | 21.76 | 1.26× |
| Maxout | 21.83 | 1.28× |
So 8-bit messages are close to free: the model learns as fast per step. The bottleneck and maxout versions are not free. They need 26% and 28% more steps.
Are they still worth it? That depends on how much of each step is network wait.
Say a fraction f of the step time is waiting on the network. Halving the message cuts the step time to 1 − f/2 of before, but the run needs 1.28 times as many steps. Maxout wins when 1.28 × (1 − f/2) < 1, which means f > 0.44. The paper states the same point in words: use them when communication is the limit, and not when bandwidth is plentiful. This break-even is our own arithmetic from the paper’s numbers.
For the big run the authors chose 8-bit only, because it was enough to keep the GPUs busy. They say that if bandwidth still limits, one can stack the bottleneck or maxout on top of it.
The third tool shrinks the other flow of data, the gradient averaging inside each stage. In ALBERT-style layer sharing, all 16 layers in a stage use one set of weights. The stage stores and synchronizes the parameters of one layer, not sixteen. The model has 1.01B stored parameters but the compute of a 13B model, because each layer still runs 16 times. Without sharing, the paper says the gradient traffic inside a stage grows by the number of layers that are no longer shared.
Chapter 4
Route each microbatch to a live worker in proportion to its speed, and ban the ones that fail
A busy restaurant has three waiters. One is quick, one is average, one is new and slow. A host seats the next party. If the host hands out tables in strict turns, the new waiter drowns and the quick one stands idle. A good host asks a better question: who has been given the least work so far, counting how long each job takes that waiter? That is the whole idea of stochastic wiring.
In SWARM, the guests are microbatches (small groups of training sequences). The waiters are the workers, called peers, that serve one pipeline stage. The host is a small process called a trainer. Stage by stage, a trainer picks a peer for each microbatch, so every microbatch gets its own temporary pipeline. Over many microbatches the picks look random, hence stochastic. But they are not random: they follow speed.
A peer is a machine with a GPU that holds the layers of one stage. All the peers of one stage hold the same parameters. They form that stage’s swarm.
A trainer is a process with no GPU and no trainable parameters. It reads data, forms microbatches and routes them through the stages. Because it is so light, one machine can run several trainers. Each trainer works alone, with its own view of the peers.
How does a trainer know which peers exist? Through a distributed hash table (DHT). Think of a phone book that no single machine owns: many machines each keep a piece, and any of them can answer a lookup. Every peer writes a note, “I serve stage 2”, and repeats it every few minutes. A trainer looks up a stage and gets the live peers. A peer that disappears stops renewing its note.
The trainer keeps, for each stage, a priority queue: a list that always lets you pull out the entry with the smallest number. Each peer’s number is the total processing time already given to it. For each peer the trainer also keeps an exponential moving average (EMA) of its response time: a running figure that moves a fraction of the way to each new measurement, so recent speed counts more. The paper sets the weight at 0.1.
To route a microbatch the trainer takes the peer with the smallest total, adds that peer’s average response time to its total, and sends the work there. The scheduler has a mouthful of a name, Interleaved Weighted Round-Robin. It does one simple thing: a peer that takes half as long is picked twice as often. Work through it.
A takes 1 s, B takes 2 s. Both start at 0. Pick A (total 1). Pick B (total 2). Pick A (total 2). A and B tie at 2: pick A (3), then B (4). A is picked 3 times for B’s 2 in these five, and the gap closes to 2:1 over time.
One stage with three peers that take 0.5 s, 1 s and 2 s per microbatch. Send microbatches and watch the counts. Compare plain turns with the paper’s rule. Then ban a peer.
A toy that runs the paper’s Algorithm 1 as written: the peer with the smallest total is picked, then its total grows by its response time. The three response times are made up, held fixed (no moving average), and peers work in parallel, so the finish time is the largest of count × response time over the peers.
With turns, the slow peer gets 7 of 21 microbatches and needs 14 s, while the quick peer stops after 3.5 s. With SWARM’s rule the three peers get about 12, 6 and 3, and all finish near 6 s. Faster peers carry more. Slower peers still help, with a smaller share.
The pseudocode in the paper’s Algorithm 1 is short. The trainer sends the inputs to the chosen peer and waits. If the peer times out or throws an error, the trainer bans it, which sets its priority to infinity so it is never chosen. Then the same microbatch goes to the next-best peer at that stage. The ban ends when the peer announces itself again in the DHT, which happens every few minutes.
python# Algorithm 1 of the paper, one trainer, in Python-like form def choose_server(stage): server, priority = queues[stage].top() # smallest total time so far new_priority = priority + ema[server] # charge it its usual response time for j in blocks_served_by(server): queues[j].update(server, priority=new_priority) return server def forward(inputs): layer_index = 0 while layer_index < N: server = choose_server(layer_index) t = now() try: inputs = server.forward(inputs) # activations out, shape [mb, 512, 4096] layer_index += 1 ema[server] = gamma * (now() - t) + (1 - gamma) * ema[server] except (ServerFault, Timeout): ban_server(server) # priority = infinity, retry this stage return inputs
Two more details matter. First, every peer keeps a queue of microbatches that trainers have sent. If the network stalls for a moment, the GPU keeps working through the queue. Second, because each trainer measures speed from its own seat, a trainer in the same data centre as a peer sees it as fast, and sends it more. The system adjusts to the shape of the network by itself, with no map of the network given to it.
The paper's pseudocode covers the forward pass only. The paper does not say more than this about what happens to a microbatch whose peer dies between its forward and backward pass, so we do not guess.
Chapter 5
Move idle workers from the quietest stage to the busiest one, so the slowest stage stops setting the pace
A supermarket has four checkout lanes. Customers pick the shortest lane, so the lanes stay about equal. Then two cashiers from lane 3 are called away. Lane 3 now has long queues, and customers in the other lanes cannot help. A manager sees this and sends the cashier from the emptiest lane to lane 3. The queue shrinks.
Stochastic wiring (Chapter 4) is the customers picking the shortest lane: it balances load among the peers inside one stage. It cannot help when a whole stage runs short of peers. And a pipeline is only as fast as its slowest stage. If stage 3 can process 2 microbatches per second and every other stage 6, the whole pipeline delivers 2. Adaptive rebalancing is the manager.
The paper's Algorithm 2 runs on every peer, at the same time, every T seconds. T is the rebalancing period; the big experiment uses 300 s. Each round has five steps.
Every peer runs the same code on the same shared numbers, so they all reach the same answer. One peer moves per round, and only that peer stops working while it downloads. The DHT carries only small numbers, so the network cost is low. The cost of a round is O(M · S), where M is the most peers in any stage and S the number of stages. For fewer than 10,000 peers and under 100 stages the paper calls it negligible.
The same protocol welcomes new peers. A new machine joins and takes the place that the rule would pick. A side effect follows: if one stage needs more compute than the others, it ends up with more peers, with no one planning it.
Stragglers are handled with a time-out. A peer that does not report its load in time is left out of that round.
In the device below, 40 identical peers start in four stages of ten. Over an hour, random peers are preempted. The same losses hit all three strategies. Drag the time slider and compare.
The chart shows samples per second over the hour for each strategy, and the ideal line. The bars at the bottom show how many peers each stage holds at the time you pick, for the strategy you choose.
Toy simulation, not the paper’s trace. Every peer does 1 sample per second, a stage’s speed is its peer count, and the pipeline runs at its slowest stage. Each half minute a peer from a random stage is lost with 20% chance (one step of the slider is half a minute). A rebalancing round moves one peer from the stage with the most peers to the one with the fewest, only when they differ by 2 or more; load is taken as the inverse of peer count. No peers join. The paper’s own simulation uses a 32-hour trace of real T4 counts, 10 random seeds, and measures 82.7%, 95.8% and 97.6% of the optimum (Table 5).
The toy shows what the paper reports. Without rebalancing, the pipeline drifts away from the ideal as unlucky stages lose peers. With a round every 300 s it tracks the ideal closely, and with a round every 60 s a little closer. In the paper’s Table 5, performance as a share of the best possible, over the whole experiment, was 82.7% with no rebalancing, 95.8% with T = 300 s and 97.6% with T = 60 s. The gap widens with time: in the last hour the figures were 45.4%, 88.9% and 91.7%, against 99.0%, 99.4% and 99.8% in the first hour.
Shorter T helps, but the gain is modest next to the extra DHT traffic, which is why the authors kept 300 s. The paper also notes that for about 4.5% of the experiment the unbalanced pipeline briefly beat the balanced one, by luck: it happened to lose peers from stages that already had too many.
In the paper’s Figure 6 the authors vary the stage count over 4, 8, 16 and 32, scaling the peers so the starting throughput is equal. Throughput falls as stages are added, with or without rebalancing. The reason is statistical: a pipeline stops at its worst stage, and with more stages there are more chances for a stage to lose a large share of its peers. Rebalancing softens the effect, since the balanced pipeline regains throughput over time, but it does not remove it.
Chapter 6
Follow a batch through the swarm with real tensor shapes, then see why the update matches ordinary training
Follow one batch of text through the swarm, from raw tokens to a changed set of weights. We use the paper’s main model: a Transformer with 3 pipeline stages, hidden size d = 4,096, and 16 layers on each stage. All 16 layers of a stage share one set of weights. The first stage also holds the embedding table, and the last holds the output head.
Count the parameters to see where the 1.01 billion comes from. One layer has about 4d² attention weights and 2 × d × 16,384 feed-forward weights, which is 201 million (Table 6 of the paper lists 201M). Three stages give 603 million. The GPT-2 vocabulary has 50,257 tokens, so each of the two end matrices has 50,257 × 4,096 = 206 million. The total is 1.015 billion, matching the paper’s 1.01B. This split of the total is our arithmetic; the paper gives the total only.
| Message | Shape | Values | 16-bit | 8-bit |
|---|---|---|---|---|
| Activation or gradient, 512 tokens | [1, 512, 4096] | 2,097,152 | 4.19 MB | 2.10 MB |
| Activation or gradient, 2,048 tokens | [1, 2048, 4096] | 8,388,608 | 16.8 MB | 8.39 MB |
| Stage gradient sync, 1 shared layer | 201M weights | 201,000,000 | 402 MB | not 8-bit |
| Same, 16 layers not shared | 3.2B weights | 3,216,000,000 | 6.4 GB | not 8-bit |
The sizes are our arithmetic from the paper’s shapes; the 8-bit column leaves out the small per-block scales. The last two rows show why layer sharing matters: the stage sync is 16 times smaller.
Peers are not equal. A fast peer may handle six microbatches while a slow one handles two. Does that bias the gradient? No, as long as each peer keeps a sum of its sample gradients and the swarm divides the grand total by the batch size. The sum does not care who added which term. Run it below.
Four peers of one stage work at different speeds. Each bar counts the samples that peer has processed. Press Run one step. Then kill a peer mid-step, or switch to the wrong average.
Toy numbers: the four peers do 4, 3, 2 and 1 samples per second, and each sample has a made-up scalar gradient from a seeded random list. A dead peer’s samples are lost and the others cover them, so the global batch is always filled with samples that survived. “Average the peers’ averages” is our illustration of a mistake, not something the paper does.
Without the dying peer, the swarm gradient matches the one-machine gradient to the last digit. With a dying peer, the samples it held are lost, and the others cover for them. The step takes longer, but the batch still holds the full count of surviving samples, so the average is correct. The paper's Appendix E puts it this way: any peer that fails or misses the batch condition is a straggler. It reloads its state from a neighbour before it trains again, and every surviving peer uses the same non-stale gradient.
Averaging the peers’ own averages would be wrong when peers did different numbers of samples: the one-sample peer would count as much as the six-sample peer. The Wrong switch shows the gap.
One last trick. The optimizer step takes time, and GPUs would sit idle. Delayed parameter updates (DPU), borrowed from ZeRO-Offload, run the optimizer step on the CPU while the GPUs start the next batch with weights that are one step old. The paper cites earlier work showing that this changes convergence little. It is the only way SWARM differs from fully synchronous training, and it can be switched off. Without it, the paper states, SWARM makes exactly the same updates as ordinary synchronous training, so it reaches a solution in the same number of steps.
The price is waiting. A small share of peers idle at the end of each step while stragglers catch up. The authors argue that big batches make this affordable, since GPT-3-scale training already uses large batches.
Chapter 7
Read the paper’s tables and curves for what they measure, and what they leave open
A method paper makes claims. This chapter reads the claims against the evidence. The authors ran four kinds of tests: how much a GPU waits (Chapter 2 already covered it), a head-to-head with the standard systems, a month-long run on rented preemptible GPUs, and a study of rebalancing (Chapter 5). We take the middle two here. Read each table by asking one question: what changed between the rows?
The authors first wanted an honest baseline: ideal conditions, with identical, reliable machines. These are the conditions that the standard systems like. Sixteen workers each had a V100 GPU, 500 Mb/s of bandwidth in each direction, and sequences of 512 tokens. They trained four layers of three sizes. They measured the minutes needed to process 6,250 sequences, the largest batch size in the GPT-3 paper.
GPipe is the classic pipeline from Chapter 1. 1F1B is a schedule that alternates one forward and one backward pass to cut the bubble. ZeRO-Offload keeps each machine running the whole model by moving the optimizer and sometimes the parameters to CPU memory, then swaps gradients with peers. A second condition added 100 ± 50 ms of latency to every message.
Bars are minutes per batch of 6,250 sequences (shorter is better). Pick a model size, then add network latency and watch which bars grow.
Values are Table 2 of the paper (minutes per batch of 6,250 sequences of 512 tokens; 16 V100 workers at 500 Mb/s each way; latency 100 ± 50 ms added in the Linux kernel). ZeRO-Offload runs the same with or without latency in the paper’s table.
Here is what the table says. Without latency, SWARM is on par with the baselines built for HPC (high-performance computing) clusters: 168.3 minutes against GPipe’s 164.5 for GPT-3 layers, and 44.2 against 40.1 for xxlarge. With 100 ms of latency, GPipe slows by 33% on GPT-3 layers (164.5 to 218.4) and by 2.7 times on xxlarge (40.1 to 108.8). SWARM slows by 11% and 9%. The cause is the per-peer queue of Chapter 4: when messages arrive late, a SWARM peer keeps working on queued microbatches, while a GPipe stage waits.
The table also shows where SWARM loses. On xxlarge layers ZeRO-Offload is fastest (33.8 minutes against SWARM’s 44.2), and on the full model it also wins (372.0 against 432.2). On GPT-3-size layers it is far behind (272.7 against 168.3), and its gradient exchange takes 25.5 minutes against SWARM’s 7.4. The authors explain: ZeRO-Offload makes every peer aggregate the whole model, while SWARM peers aggregate one stage. Their summary is careful: SWARM is competitive with the baselines even in ideal conditions, and wins when conditions degrade.
The headline experiment trained the 1.01B-parameter model of Chapter 6 on the Pile. SWARM used 400 preemptible T4 GPUs. The baseline was ordinary data-parallel training with offloading on 128 A100 GPUs. Both ran for roughly four weeks. Figure 4 plots training loss against tokens processed, up to about 50 billion tokens, and the two curves are similar. That supports the claim that asynchronous model-parallel training with a rebalancing swarm does not hurt convergence.
Next the authors measured pipeline throughput on three fleets: the 400 T4s, seven servers with eight A100s each, and both together. They compared each with a best case, computed by running one stage three times on one server and multiplying by the node count, as if the network were free.
Bars are samples per second. The pale bar is the best case with a free network; the solid bar is the actual. Switch between the shared-layer model and the default Transformer.
Values are Tables 3 and 4 of the paper. The paper gives no best-case figure for the mixed fleet. With layer sharing, the measured bandwidth on intermediate-stage nodes is 317.8 Mb/s up and 397.9 Mb/s down for T4, and 436.1 and 545.1 for A100; the paper says the optimal total is about 100 Mb/s higher. The abstract’s “less than 200 Mb/s” and these figures are not reconciled in the text, so treat them as two different statements.
With layer sharing and 8-bit messages, the T4 fleet reaches 17.6 samples per second of a best-case 19.2, which is 92%. The A100 fleet gets 16.9 of 25.5, or 66%: faster chips finish their arithmetic sooner and wait longer for the network. The mixed fleet delivers 27.3, which is 79% of the 34.5 that the two fleets give separately. It is higher than either alone, so adding slow T4s to fast A100s helps and does not drag them down.
The default Transformer, without sharing, gets 8.8 on T4 (46% of its best 19.3) and 8.0 on A100 (32% of 25.1). Layer sharing roughly doubles real throughput, though the best case barely moves. The reason is the gradient sync of Chapter 6: it was 16 times bigger.
Read the limits too. The convergence curve is one comparison with one baseline, one model and one dataset. The model has shared layers, which behaves differently from a plain model of 13B parameters. All the tests use Transformers. Figure 6 shows that throughput falls as stages are added. And the authors do not claim a win in the data-centre case: Appendix A says that for homogeneous high-speed clusters, standard sharded data-parallel or pipeline training is more efficient. Chapter 8 collects these limits.
Chapter 8
Learn where SWARM loses, what the authors say to avoid it, and what it costs in practice
A good paper tells you where its method stops working. This one does, mostly in Appendix A, which answers the questions a sceptical reader would ask. We gather those answers, add the limits that follow from the design, and finish with the paper’s cost comparison.
On a fast, uniform cluster. The paper says plainly: by default SWARM is worse than traditional parallelism because of its extra complexity. In Table 2, ZeRO-Offload beats it on xxlarge layers and on the full model. For homogeneous high-performance clusters, standard sharded data-parallel or pipeline-parallel training will be more efficient, because there is nothing to rebalance. SWARM can still help in a supercomputer made of mixed devices.
For smaller models. SWARM is efficient for compute-intensive models above about 1 billion parameters. Below that, a sharded data-parallel method can be better. The square-cube law explains this: narrow layers have little compute per byte sent, so the network dominates (the 18% for “base” in Chapter 2).
When failures are rare. On a huge cluster where an occasional node fails, elastic sharded data parallelism is better than SWARM if the expected number of failures is low. SWARM pays for fault tolerance all the time, even when no fault comes.
Without the compression helpers. The paper's numbers lean on layer sharing and 8-bit messages. Send plain 16-bit activations and the network overhead roughly doubles. Skip layer sharing and the gradient sync inside each stage grows by the number of unshared layers (Chapter 7: 8.8 against 17.6 samples per second on T4s).
The last experiment (Appendix J) trains ALBERT-Large on WikiText-103 until the objective reaches 1.5, and prices the run at public cloud rates. Figure 8 shows the per-step learning curve of SWARM matching ordinary distributed training, within the variation of a random seed.
| Setup | Time to loss 1.5 | Hourly cost | Total cost |
|---|---|---|---|
| 8 × V100, reliable, ordinary training | 175.4 h | $7.834 | $1,374 |
| 8 × V100, preemptible, SWARM | 192.6 h | $5.383 | $1,037 |
| 32 × T4, preemptible, SWARM | 140.8 h | $3.536 | $497.8 |
Read the second row first. On the same eight V100s, SWARM is slower (192.6 hours against 175.4) because it pays for rebalancing and queues. It is still 25% cheaper, since preemptible hours cost less. The third row swaps in 32 cheap T4s. It is both faster (140.8 hours) and cheaper: $497.8 against $1,374, nearly 3 times less. Multiply to check: 140.8 × 3.536 = $497.9. These figures come from the paper’s cloud price estimates at the time, so use the ratios, not the dollars.
Now apply the appendix. Each card describes a situation. Pick the method the paper's reasoning favours.
Read the scenario, then pick one of the three. After each pick you see the paper’s reason.
The answers follow Appendix A of the paper (“When should I avoid using SWARM?” and “Should I use SWARM in a supercomputer?”). The scenarios are made up for practice. Real choices also depend on code, team and budget.
Chapter 9
Keep the numbers, the terms, a checklist, the core code and the way onward on one page
This chapter keeps what you will want on one page: a one-paragraph summary, the numbers, the terms, a checklist for building it, the core as code, and where to go next.
Pipeline parallelism sends activations, not parameters, so its traffic grows slower than its compute as layers widen (the square-cube law). That makes big models friendlier to slow links than small ones. SWARM keeps the pipeline but makes each stage a swarm of interchangeable peers. A trainer routes every microbatch to the peer with the least total time, bans failures, and each peer queues work to hide latency. Every T seconds one peer moves from the lightest stage to the heaviest. Peers sum gradients, All-Reduce inside the stage, and take one synchronous step. 8-bit blockwise messages and shared layers cut the traffic. The result trained a 1.01B-parameter (13B-compute) model on about 400 preemptible T4 GPUs, with a learning curve close to a 128-A100 baseline.
| Quantity | Value | Where |
|---|---|---|
| Model | 1.01B stored parameters, compute of a 13B model | Section 4.3, abstract |
| Main run hardware | about 400 preemptible T4, about 4 weeks, on the Pile; baseline 128 A100 | Section 4.3, Figure 4 |
| Network | under 200 Mb/s (abstract); measured 317.8 up and 397.9 down Mb/s on T4 intermediate stages | Abstract, Table 3 |
| GPU use at 500 Mb/s | 18.0% base, 32.1% xxlarge, 82.1% GPT-3 size, 89.5% “Ours” | Table 1 |
| Same at 100 ms latency | 2.78%, 14.9%, 60.2%, 71.5% | Table 1 |
| 8-bit messages | about 2× smaller than 16-bit; perplexity 21.13 against 21.02; 0.97× steps to 22 | Appendix I, Table 7 |
| Bottleneck, maxout | +26% and +28% steps to perplexity 22 at 2× compression | Table 7 |
| Throughput, T4 fleet | 17.6 of 19.2 samples/s (92%); default Transformer 8.8 of 19.3 | Tables 3, 4 |
| Throughput, A100 and mixed | 16.9 of 25.5; mixed fleet 27.3 | Table 3 |
| Rebalancing | T = 300 s, moving average weight 0.1; 95.8% of optimum against 82.7% without (T = 60 s: 97.6%) | Section 4.3, Table 5 |
| Head-to-head, +100 ms | GPipe +33% (GPT-3 layers), +2.7× (xxlarge); SWARM +11%, +9% | Table 2 |
| Cost to ALBERT loss 1.5 | $497.8 on 32 preemptible T4 against $1,374 on 8 reliable V100 | Appendix J, Table 9 |
| Sharded data parallel at 100 Mb/s | about 5.5 minutes of waiting per forward and backward pass for a 1B model | Appendix A |
| Term | Plain meaning |
|---|---|
| Preemptible instance | A cheap rented machine that the provider can take back at any time. |
| Pipeline stage | A group of consecutive layers that lives on one machine. |
| Microbatch | A small group of sequences sent through the pipeline as one unit. |
| Activation, gradient | The array a stage sends forward, and the array of blame sent back. |
| Bubble | Idle time at the start and end of a pipeline, share (k − 1) / (m + k − 1). |
| Square-cube law | Compute grows with the square of the width, traffic only in a line. |
| Blockwise quantization | Round numbers to 8 bits with one scale per short block. |
| Bottleneck, maxout | Learned or max-based ways to send a narrower array between stages. |
| Layer sharing | Layers of a stage reuse one set of weights, so there is less to sync. |
| Swarm, peer, trainer | The workers of one stage; one such worker; the light process that routes microbatches. |
| DHT | A phone book kept by many machines, used to find the live peers of a stage. |
| IWRR, EMA | Pick by smallest total time; a running average of response time. |
| Ban | Set a failed peer’s priority to infinity until it announces itself again. |
| Rebalancing | Every T seconds, move one peer from the lightest stage to the heaviest. |
| All-Reduce | Every peer ends up with the sum of all peers’ arrays. |
| Straggler | A peer that misses the batch, then reloads its state from a neighbour. |
| DPU | Delayed parameter updates: the optimizer runs while the next batch starts. |
This sketch follows Algorithms 1 and 2 and the quantizer. It runs as written in plain Python. It is a teaching sketch, not the authors' hivemind-based code (linked below).
pythonimport heapq, math, random # 1. Stochastic wiring (Algorithm 1): pick the peer with the smallest total time so far. class Router: def __init__(self, peers, gamma=0.1, eps=1e-3): self.ema = {p: eps for p in peers} # moving average of response time self.total = {p: eps for p in peers} # priority: time already given self.gamma = gamma def choose(self, banned=()): live = [p for p in self.total if p not in banned] p = min(live, key=lambda q: self.total[q]) self.total[p] += self.ema[p] return p def observe(self, p, seconds): self.ema[p] = self.gamma * seconds + (1 - self.gamma) * self.ema[p] # 2. Adaptive rebalancing (Algorithm 2): one peer moves from the lightest to the heaviest stage. def rebalance(queues): """queues[stage] = list of per-peer queue sizes. Returns (from_stage, to_stage, peer) or None.""" load = [sum(q) for q in queues] lo, hi = load.index(min(load)), load.index(max(load)) if lo == hi: return None peer = min(range(len(queues[lo])), key=lambda j: queues[lo][j]) return lo, hi, peer # 3. Blockwise 8-bit quantization of an activation vector (even spacing, for teaching). def quantize(x, block=64): out, scales = [], [] for s in range(0, len(x), block): blk = x[s:s + block] scale = max(abs(v) for v in blk) / 127 or 1.0 out += [round(v / scale) for v in blk] # int8 values in [-127, 127] scales.append(scale) return out, scales def dequantize(q, scales, block=64): return [v * scales[i // block] for i, v in enumerate(q)]
Run the router on three peers with response times 0.5, 1 and 2 seconds for 21 microbatches. It sends 12, 6 and 3 and finishes in 6 seconds, as in Chapter 4.
Credit. SWARM Parallelism: Training Large Models Can Be Surprisingly Communication-Efficient, by Max Ryabinin, Tim Dettmers, Michael Diskin and Alexander Borzunov (HSE University, Yandex, University of Washington). ICML 2023, PMLR 202. arXiv 2301.11913. Code: github.com/yandex-research/swarm. All numbers above come from the paper unless marked as our arithmetic or as a toy; the explanations and devices are ours.
Now press Present or Teach and explain, from memory, why a bigger model needs less bandwidth per unit of work, how one microbatch finds a live peer, and what happens when a whole stage loses its peers. Then go back to the workers at the top, slide the loss to 6, and say why the rigid pipelines stop and SWARM does not.