One 80 GB GPU can train at most 5 billion parameters with Adam. Shard the training state across 64 GPUs with ZeRO-3, and the limit is 320 billion.
Learn four ways to split training over many GPUs, how the GPUs talk, and how to stop each GPU from holding a full copy.
Pick a strategy, then drag the GPU count. Watch one GPU's share of GPT-3's training state fall toward the 80 GB line. Then we build, piece by piece, the splits, the messages and the shards that make it work.
You need the training loop (forward pass, backward pass, gradient step) and a little Python. We build the rest from zero.
Based on Lecture 19 of MIT 6.5940: TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. Lecture 19 slides. Every idea is re-taught here in our own words and devices. It follows Diffusion Models II.
GPT-3 has 175 billion parameters. Bytes per parameter are the lecture's: 2 for weights, 2 for gradients, 12 for Adam, and the ZeRO formulas of Chapter 6. A bar above 400 GB is cut, keeps the mix of its parts, and carries its total. Activations are not counted.
Chapter 0
Count the GPU hours a big model needs, and measure how close many GPUs come to the ideal speedup
Your manager asks what you did last month. "I trained the model for one epoch." What is the plan for next month? "Train it for one more epoch." The lecture opens with this joke because it is real: big models take months on one GPU.
Better models cost more compute. The lecture's table counts GPU hours, the hours one GPU would need, measured on an NVIDIA A100.
| Model | Parameters | GPU hours |
|---|---|---|
| ResNet-50 | 26 million | 31 |
| BERT-Base | 108 million | 84 |
| GPT-3 | 175 billion | 3,100,000 |
One GPU would need about 355 years for GPT-3. Distributed training splits one training job over many GPUs. The ideal is simple: a job of 10 GPU days on 1,024 GPUs finishes in 14 minutes. Your time costs more than the hardware.
Real runs fall short of the ideal. The lecture's example trains a video model, TSM, on the SUMMIT supercomputer (6 V100 GPUs per node). How close it comes is the scaling efficiency: the speedup you measure, divided by the speedup the extra GPUs promise.
E equals T-zero over T-N, divided by N over N-zero.
Divide the old time T-zero by the new time T-N to get the speedup. Divide N by N-zero to get the speedup you paid for. E is the first over the second.
TSM on 6 GPUs took 49 hours 50 minutes. On 1,536 GPUs it took 14 minutes, the slide's 211 times speedup. The GPUs grew 256 times, so E = 211 / 256 = 0.82.
The purple line is the ideal time. The dots are the measured runs. Drag the GPU count and read the gap.
Measured points are the lecture's TSM runs (slide 10): 6, 768 and 1,536 GPUs, with top-1 accuracy 74.1%, 74.1% and 74.0%. The ideal line divides the 6-GPU time by the growth in GPUs.
The failure is a run that adds GPUs and barely speeds up. Measure E at two sizes. If it drops, the GPUs spend time talking, not computing. Chapters 3 to 5 cut that talk.
Chapter 1
Cut the data, the layers, the matrices or the tokens, and see what each GPU then holds
You have three GPUs and one training job. The job has two parts: a model (layers of weights) and the data (a batch of examples). The data moves through the model as a tensor of shape [batch, tokens, hidden]. You can cut either part.
The lecture names four cuts. Each one is a parallelism: a rule for which piece of the work each GPU does.
Left is the data tensor, right is a six-layer model. Each GPU's colour marks what it holds. Pick a cut.
A schematic of the lecture's four pictures (slides 13 to 31), drawn with three GPUs. Real models have far more layers.
| Cut | Each GPU holds | What must travel |
|---|---|---|
| Data | the whole model, part of the batch | gradients, once per step |
| Pipeline | some layers, the whole batch in turn | activations between neighbours |
| Tensor | a slice of every layer | partial results, inside each layer |
| Sequence | the whole model, part of the tokens | keys and values for attention |
Data and sequence parallelism cut the data. Pipeline and tensor parallelism cut the model. Only the model cuts make the model smaller on each GPU.
A worked number. Take a batch of shape [16, 10, 512]: 16 examples of 10 tokens with 512 numbers each. Data parallelism on 4 GPUs gives each [4, 10, 512]. Now take one text of 100,000 tokens. The batch is 1, so data parallelism cannot cut it. Sequence parallelism on 4 GPUs gives each 25,000 tokens.
The failure: you pick data parallelism for a model that does not fit one GPU. Symptom: an out-of-memory error on every GPU at once. Measure: each GPU holds the full model, so memory per GPU does not change with N. Fix: a model cut, or ZeRO in Chapter 6.
Chapter 2
Run the five-step loop by hand: replicate, split, compute, push and sum, update
Four workers each read a different slice of the data. They must still train one model, not four. Who keeps the one true copy?
The classic answer is a parameter server: one central machine that holds the model. The workers are the GPUs. Each holds a local copy of the model and a slice of the dataset. One training step has five parts:
The server sits on top, four workers below. Press Step to move through the five parts, or Play to watch them run.
Illustrative: one weight, four made-up gradients and a learning rate of 0.1. The five steps are the lecture's (slide 41).
Call the weight w and the learning rate η. Worker j computes a gradient gj on its slice.
w becomes w minus eta times one over N times the sum over j of g-j.
Add the N gradients g-j and divide by N. Multiply by eta. Subtract that from w.
With made-up numbers: w = 1.00, eta = 0.1, gradients 0.4, 0.2, 0.6 and 0.2. The average is 0.35, so w = 1.00 − 0.035 = 0.965.
One GPU does three things per step: sample, compute, update. The distributed loop adds two synchronization steps, pull and push, where workers wait for the network.
pythonfor i in range(T): # on worker j w = server.pull() # sync 1: replicate x, y = shard_j.sample() # this worker's slice g = grad(loss, x, y, w) # local gradient server.push_and_sum(g) # sync 2: server averages, then steps
The failure is a slow worker. Symptom: three GPUs sit idle at every push. Measure: time each worker's compute step. Fix: split evenly, as step 2 says, so every slice takes the same time.
Chapter 3
Learn the seven verbs GPUs use to move tensors, and name the two the parameter server uses
Four GPUs each hold one number: 1, 2, 3 and 4. You want the total on every GPU. What messages do you send? Libraries such as MPI, Gloo and NCCL give you a fixed set of verbs, called communication primitives.
| Primitive | Shape | What happens |
|---|---|---|
| Send, Recv | one to one | one process passes a tensor to another |
| Scatter | one to many | one GPU sends a different piece to each |
| Gather | many to one | one GPU collects every piece |
| Reduce | many to one | like gather, but adds or averages on the way |
| Broadcast | one to many | one GPU sends the same copy to all |
| All-Reduce | many to many | a reduce whose result lands on every GPU |
| All-Gather | many to many | a gather whose result lands on every GPU |
Four GPUs start with 1, 2, 3 and 4. Pick a verb and watch the lines carry the numbers from Before to After.
The values 1, 2, 3, 4 and the reduce to 10 are the lecture's example (slide 46). Send goes from GPU 0 to GPU 3, as on slide 44. A real tensor has millions of numbers; the pattern is the same.
The worked number from the lecture: gather turns [1] [2] [3] [4] into [1, 2, 3, 4]. Reduce turns them into [1 + 2 + 3 + 4] = [10]. Reduce sends the same messages as gather, but each message adds as it lands, so the result stays one number long.
Now name the parameter server's two steps. Replicate and pull is a broadcast: the server sends the same weights to all workers. Push and sum is a reduce: every worker's gradient flows to the server, which averages them.
The failure: you reduce where you need an all-reduce. Symptom: only GPU 0 holds the summed gradient, so the other GPUs step with their own gradient and the copies drift apart. Measure: compare a checksum of the weights across GPUs after a few steps. Fix: an all-reduce, so every GPU gets the same sum.
Chapter 4
Find the server's bottleneck, then compare three ways to all-reduce on time, peak load and total traffic
Add workers to a parameter server and each worker's job stays the same: send one gradient, get one copy of the weights. The server's job grows. Call the size of one gradient D and the number of workers N.
B-server equals N times D.
Each of the N workers sends one gradient of size D, so the server takes in N times D. The pull sends the same amount back out.
With made-up numbers: D = 100 MB and N = 64 workers. The server takes in 6.4 GB per step, while each worker sends only 100 MB.
The lecture calls this O(N) at the server and O(1) at each worker. The big-O label says how a cost grows with N, ignoring constant factors. Can the workers add their gradients with no server at all? That is an all-reduce, and there are three ways to run one.
The top shows one step's messages. The bars show the lecture's three costs on a log scale. Pick a scheme, then drag N.
Bar lengths are the lecture's big-O table (slide 57) with every constant set to 1, so they compare growth, not seconds. The message picture shows at most 8 nodes.
Ring keeps the peak load flat because each piece is a 1/N chunk of the gradient. Our own count: 2(N − 1) steps, so each GPU sends 2(N − 1)/N × D in total. For N = 8 and D = 4 GB that is 7 GB, under 2D at any N.
The failure: ring's time is O(N). Symptom: at 1,024 GPUs a ring needs 2,046 steps, and each step pays a fixed start-up cost. Measure: time the all-reduce of a tiny tensor as N grows. Fix: combine ring's low load with parallel's few steps. That is the next chapter.
Chapter 5
Pair the GPUs at offset 1, then 2, then 4, and watch every GPU collect every colour
Eight GPUs each hold one colour of data. You want every GPU to hold the mix of all eight. Ring passes the colours one hop at a time. Can each step double what a GPU holds?
Recursive halving all-reduce, from the MPICH work of Thakur, Rabenseifner and Gropp, does exactly that. In step 1 each GPU swaps with the neighbour at offset 1 (GPU 1 with 2, 3 with 4). Both now hold two colours. In step 2 they swap at offset 2, and hold four. In step 3, at offset 4: all eight.
Each square is a GPU, and its stripes are the colours it holds. Press Step to run one exchange. Pick 4, 8 or 16 GPUs.
The offsets 1, 2 and 4 and the 8-node picture are the lecture's (slides 58 to 66). The 4 and 16 GPU cases follow the same rule.
Each step doubles the colours, so N colours take as many steps as you must double 1 to reach N.
Steps equals log base two of N.
Count how many times you double 1 to reach N. That count is the number of steps.
N = 8 gives 3 steps. N = 1,024 gives 10 steps, where our ring count from Chapter 4 gives 2,046.
Why is this not free? In each step a GPU sends everything it has summed so far, a full-size tensor. Our own count: about D × log2 N bytes per GPU, against ring's under 2D. Halving wins when there are many GPUs and the message is small. Ring wins when the message is large.
The failure: N is not a power of two. Symptom: with 6 GPUs, GPU 3's partner at offset 4 would be GPU 7, which does not exist. Measure: check N for a power of two before the run. A simple fix: let two GPUs first hand their data to partners, run the exchange on 4, then send them the result. That adds two steps.
Chapter 6
Count 16 bytes per parameter, then shard Adam, then the gradients, then the weights
GPT-3 has 175 billion parameters. At 2 bytes each in FP16, the weights alone are 350 GB. The best GPU in the lecture, an A100, has 80 GB. Training also needs the gradients and the optimizer states.
The lecture counts the training state per parameter, with Adam in mixed precision. Weights take 2 bytes and gradients 2 bytes. The optimizer states take 12: an FP32 copy of the weights, the momentum and the variance. That is 16 bytes. Plain data parallelism keeps all 16 on every GPU: N identical copies.
ZeRO, from DeepSpeed, removes the copies. Each stage shards one more part: it cuts that part into N pieces and gives each GPU one piece.
| Stage | Shards | Bytes per parameter | Largest model, N = 64 |
|---|---|---|---|
| Baseline | nothing | 2 + 2 + 12 = 16 | 5 billion |
| ZeRO-1 | Adam | 2 + 2 + 12/N = 4.2 | 19 billion |
| ZeRO-2 | Adam, gradients | 2 + 2/N + 12/N = 2.2 | 36 billion |
| ZeRO-3 | Adam, gradients, weights | 16/N = 0.25 | 320 billion |
The last column comes from one division. Call one GPU's memory C and the bytes per parameter b.
Psi-max equals C over b.
Find b for your stage and N. Divide the memory C by b. The answer is psi-max.
ZeRO-3 on 64 GPUs: b = 16 / 64 = 0.25 bytes, so psi-max = 80 GB / 0.25 = 320 billion. GPT-3 at 175 billion fits.
Each curve is one stage's largest model as N grows, on log scales. Pick a stage and drag N.
The formulas and the N = 64 values (5, 19, 36 and 320 billion) are the lecture's (slides 69 to 73). We compute other N live. Activations are not counted.
In PyTorch, ZeRO-3 is FSDP, FullyShardedDataParallel. With weights sharded, a GPU must fetch a layer's other shards before it runs that layer. ZeRO-3 trades that traffic for memory.
The failure: ZeRO-1 and ZeRO-2 hit a floor. Symptom: you double the GPUs and the largest model barely grows. Measure: b tends to 4 for ZeRO-1 and 2 for ZeRO-2, so psi-max stops at 20 and 40 billion. Fix: ZeRO-3, whose b keeps falling as 16/N.
Chapter 7
Cut the model by layer, see three GPUs wait, then cut the batch into micro-batches to fill the gaps
GPT-3's 350 GB of weights do not fit one GPU. Cut the layers into 8 groups and put one group on each of 8 GPUs: 350 / 8 = 43.75 GB each, under 80 GB. This is pipeline parallelism. Each group is a stage.
Now run one batch. Stage 1 runs its forward pass, then hands the activations to stage 2, and so on. The backward pass comes back in reverse. At any moment only one stage works. The idle slots form the bubble. With 4 stages, each GPU is busy one quarter of the time: 25%.
GPipe (Huang et al.) fixes most of it. Cut the batch into micro-batches: [16, 10, 512] becomes four of [4, 10, 512]. Stage 1 starts micro-batch 2 while stage 2 runs micro-batch 1. The weights do not change inside a batch, so this is safe. Call the stages S and the micro-batches m.
U equals m over m plus S minus one.
Each stage does m useful slots on the way forward. The pass takes m plus S minus 1 slots, because the last stage starts S minus 1 slots late. U is useful over total.
The lecture's case, S = 4. With m = 1, U = 1 / 4 = 25%. With m = 4, U = 4 / 7 = 57%, the slide's 2.5 times improvement. With m = 16, U = 16 / 19 = 84%.
Each row is a stage, each cell a time slot. Purple is forward, yellow is backward, grey is idle. Drag both sliders.
The GPipe schedule as the lecture draws it (slide 80), with every forward and backward slot the same length. That is a simplification; a real backward pass takes longer. The 25% and 57% are the slide's.
The failure is a thin pipeline. Symptom: GPUs show low use though every GPU holds work. Measure: count m and S, and compute U. Fix: raise m. U still never reaches 1, because S − 1 slots always fill and drain.
Chapter 8
Split one layer's matrix by columns, the next by rows, and join the answer with one all-reduce
The pipeline still idles. Can every GPU work on the same layer at the same time? Yes, if you cut inside the layer. Tensor parallelism splits a weight matrix into N chunks, one per GPU. Megatron-LM (Shoeybi et al.) does this for the two linear layers of a transformer's feed-forward block.
The lecture's example has shapes [1, 2] @ [2, 6] @ [6, 2]. The input X is 1 by 2. The first weight A is 2 by 6. The second weight B is 6 by 2.
Z equals the sum over i of act of X times A-i, times B-i.
Each GPU multiplies X by its columns A-i, applies act, and multiplies by its rows B-i. The all-reduce adds the partial answers into Z.
With the made-up numbers in the device and act = ReLU, two GPUs give Z1 = [5, 6] and Z2 = [2, 4]. Their sum is [7, 10], the same as one GPU.
Each colour band is one GPU's slice: columns of A, rows of B. Pick how many GPUs share the block.
Shapes are the lecture's example (slide 84). We made up the numbers inside. ReLU stands in for GeLU so the sums stay whole.
Attention splits the same way. The Q, K and V projections split by columns, which is by heads. Each GPU runs softmax(Q KT) V on its own heads with no messages. The output projection splits by rows, then one all-reduce.
The failure: split A by rows. Then each GPU holds a partial sum before the activation. ReLU(−3 + 5) = 2, but ReLU(−3) + ReLU(5) = 5. Measure: compare with the one-GPU output. Fix: columns first, so the activation sees whole numbers.
Chapter 9
Split a long text's tokens over GPUs, then fix attention with an all-to-all or a ring of keys and values
A training text can pass 100,000 tokens. Call the tokens T and the GPUs N. Sequence parallelism gives each GPU a block of tokens.
T-local equals T over N.
Cut the T tokens into N equal blocks. Each GPU keeps T-local of them.
T = 100,000 tokens and N = 8 GPUs give 12,500 tokens per GPU.
The fully connected layers act on each token alone, so they run like data parallelism. Attention is the hard part: every query needs the keys and values of every token, and those sit on other GPUs. The lecture gives two answers.
The grid is queries against keys; a filled cell has its scores. Pick a method and press Step.
Three GPUs and three heads, as in the lecture's pictures (slides 93 to 96). The ring order follows slides 94 to 96: GPU 1 holds KV1, then KV2, then KV3.
A worked number for the ring. With T = 100,000 and N = 8, each step scores a block of 12,500 queries against 12,500 keys: about 156 million scores. Eight steps cover the whole grid. The next block travels while the GPU computes, so the transfer hides behind the math when the link is fast enough.
Ulysses has a rule from the lecture: the GPU count equals the sequence partitions equals the head partitions. The failure follows. Symptom: a model with 32 heads on 64 GPUs cannot run Ulysses alone. Measure: check that the heads divide evenly over N. Fix: use Ring Attention, which has no head limit.
Chapter 10
Keep the numbers, the terms, the checklist and the core code in one place
Data and sequence parallelism split the data. Pipeline parallelism splits the model by layer. Tensor parallelism splits it by tensor. The primitives move the pieces, and ZeRO removes the copies. Part II of this lecture is not out yet; this page covers Part I only.
| What | Value | Where |
|---|---|---|
| GPT-3 on one A100 | 3.1 million GPU hours, about 355 years | Chapter 0, slide 6 |
| TSM on SUMMIT | 49 h 50 min on 6 GPUs, 14 min on 1,536 (211 times), 74.1% to 74.0% | Chapter 0, slide 10 |
| Parameter server load | worker O(1), server O(N) | Chapter 4, slide 52 |
| All-reduce costs (time, peak, total) | sequential N, N, N; ring N, 1, N; parallel 1, N, N squared | Chapter 4, slide 57 |
| Recursive halving | log2 N steps | Chapter 5, slide 66 |
| Training state | 16 bytes per parameter: 2 + 2 + 12 | Chapter 6, slide 69 |
| Largest model on 80 GB, N = 64 | 5, 19, 36, 320 billion (baseline, ZeRO-1, 2, 3) | Chapter 6, slide 73 |
| Pipeline busy fraction, 4 stages | 25% naive, 57% with 4 micro-batches | Chapter 7, slide 80 |
| GPT-3 weights over 8 stages | 350 / 8 = 43.75 GB per GPU | Chapter 7, slide 75 |
| Ulysses rule | GPUs = sequence partitions = head partitions | Chapter 9, slide 93 |
| Term | Meaning |
|---|---|
| Parameter server | One machine that holds the model and sums the workers' gradients. |
| All-reduce | Sum a tensor across GPUs and leave the sum on every GPU. |
| All-to-all | Every GPU sends a different piece to every other GPU. |
| Shard | Cut a tensor into N pieces and give each GPU one. |
| FSDP | PyTorch's FullyShardedDataParallel, an implementation of ZeRO-3. |
| Bubble | The idle slots while a pipeline fills and drains. |
| Micro-batch | A slice of the batch that moves through the pipeline on its own. |
pythonimport math def bytes_per_param(stage, n): # Adam, mixed precision w, g, o = 2, 2, 12 # weights, gradients, optimizer states if stage >= 1: o /= n # ZeRO-1 shards Adam if stage >= 2: g /= n # ZeRO-2 shards gradients if stage >= 3: w /= n # ZeRO-3 shards weights (FSDP) return w + g + o def largest_model(stage, n, gpu_gb=80): # billions of parameters return gpu_gb / bytes_per_param(stage, n) def busy(m, s): return m / (m + s - 1) # GPipe busy fraction def ring_bytes(d, n): return 2 * (n - 1) / n * d # sent per GPU def halving_steps(n): return int(math.log2(n)) print([round(largest_model(z, 64)) for z in range(4)]) # [5, 19, 36, 320] print(busy(1, 4), round(busy(4, 4), 2)) # 0.25 0.57 print(ring_bytes(4, 8), halving_steps(1024)) # 7.0 10
Real runs stack these cuts. The library has a fuller tour in CS 336, data and tensor parallelism and CS 336, pipeline and FSDP. Long-context attention is in Long-Context LLMs.
This lesson follows Lecture 19 of MIT 6.5940: TinyML and Efficient Deep Learning Computing (Fall 2026), taught by Song Han and the MIT HAN Lab. Read the lecture on the course site, which links the slides. The lecture cites TSM (Lin et al., 2019), the parameter server (Li et al., 2014) and MPICH collectives (Thakur et al., 2005). It also cites GPipe (Huang et al., 2018), Megatron-LM (Shoeybi et al., 2019) and ZeRO (Rajbhandari et al., 2019). For long sequences it cites DeepSpeed Ulysses (Jacobs et al., 2023) and Ring Attention (Liu et al., 2023). All explanations, devices and worked examples here are our own, except where we say a number is the slide's.
Now press Teach. Explain from memory the 16 bytes per parameter, what each ZeRO stage shards, and why ring and halving trade steps for bytes. Then go back to the GPT-3 bars at the top and find the fewest GPUs that fit.