Skip to content
Road to Intelligence

Concept · Chapter 9: How an LLM Is Actually Built

Data Parallelism and All-Reduce

Must knowKnow well12 minDifficulty

Data parallelism runs a copy of the model on every GPU, gives each a different slice of the batch, and averages their gradients with an all-reduce before every update, so all copies stay identical.

The problem

A trillion-token run would take centuries on one GPU; the work has to be shared across thousands of them without changing what is computed.

The solution

Split each batch across GPUs, let each compute gradients on its share, average the gradients across all GPUs with a collective all-reduce, and apply the same update everywhere.

The consequence

Training scales to thousands of GPUs with no change to the maths, but every GPU needs the whole model's states and the network must carry a full set of gradients every step.

Map, then reduce

To a data engineer this is familiar. Each GPU (a mapper) takes its shard of the batch, runs the forward and backward passes, and produces a full set of gradients. Then all GPUs reduce: they average those gradients, and every GPU applies the same averaged update. Because the average of per-shard gradients equals the gradient of the whole batch, the result is exactly what one enormous GPU would have computed.

Tiny example. Four GPUs each process 4 sequences of 4,096 tokens: 16 sequences and 65,536 tokens per step. Each GPU's gradient for some weight is 0.8, 1.2, 1.0 and 1.0; the all-reduce gives every GPU the average, 1.0, and every copy takes the identical step.

global batch=micro-batch×accumulation steps×data-parallel GPUs\text{global batch} = \text{micro-batch} \times \text{accumulation steps} \times \text{data-parallel GPUs}

All-reduce

An all-reduce is a collective operation: every participant contributes a vector and every participant receives the sum (or average). Efficient implementations pass pieces around a ring or tree so that each GPU sends and receives roughly twice the size of the gradients however many GPUs there are, which is why the pattern scales to thousands.

Four GPUs, one four-layer model · what each GPU holds
GPU 1batch slice 1L1L2L3L4GPU 2batch slice 2L1L2L3L4GPU 3batch slice 3L1L2L3L4GPU 4batch slice 4L1L2L3L4all-reduce gradients once per step
Each GPU holds
A full copy of the model, and a different slice of the batch.
What they exchange
Once per step, every GPU averages its gradients with all the others (an all-reduce), so all copies stay identical.
Used
Always, as the outermost layer of parallelism: it is how a run uses thousands of GPUs.
The catch
The whole model, its gradients and optimizer states must fit on every GPU.

Real runs combine them. Llama 3 405B used tensor parallelism across the 8 NVLink-connected GPUs of each server, 16 pipeline stages, and sharded data parallelism (FSDP) across the rest, plus a fourth kind, context parallelism, for very long sequences: up to 16,384 GPUs.

The catches

Memory. Every GPU holds a full copy of the weights, gradients and optimizer states: 16 bytes per parameter. For anything beyond a few billion parameters that doesn't fit, which is what sharded training fixes.

Batch size. Adding GPUs adds to the global batch. Goyal and colleagues showed that very large batches can match small-batch accuracy if the learning rate is scaled with the batch size and warmed up gradually Established, but there are limits beyond which bigger batches stop helping.

Lockstep. Every GPU waits for the slowest at each all-reduce, and in synchronous training a single GPU failure may require restarting the entire job Established, a theme of training stability.

Why should I care?

As a researcher

It is why batch size and learning rate become entangled with the number of GPUs, and why large-batch training became a research topic.

As an engineer

It is the first and simplest scaling tool (DistributedDataParallel in PyTorch), and the same map-then-reduce pattern as distributed data processing.

Modern systems that depend on it

  • ZeRO and FSDP
  • global batch size
  • 3D parallelism
  • the compute budget

Historical context

Before

One GPU per training run, or ad hoc parameter servers that collected and redistributed gradients.

After

Synchronous data parallelism with efficient all-reduce collectives, as the outer layer of every large run.

Used today

Every multi-GPU training job. In Llama 3 405B, data parallelism (with sharding) spanned up to 128 groups of 128 GPUs.

What to remember

  • Each GPU: full model, different data. After backward: all-reduce (average) the gradients.
  • Mathematically the same as one big batch on one GPU.
  • Global batch = micro-batch × gradient-accumulation steps × number of data-parallel GPUs.
  • Catch: every GPU must hold the full model states (fixed by sharding).

Key papers

Optional

Accurate, Large Minibatch SGD: Training ImageNet in 1 Hour

Priya Goyal, Piotr Dollár et al. · 2017

Showed how to train with very large batches across many GPUs without losing accuracy, using a linear learning-rate scaling rule and a gradual warmup.

~25 min readarXiv:1706.02677✓ verified 2026-10-04
Essential

ZeRO: Memory Optimizations Toward Training Trillion Parameter Models

Samyam Rajbhandari, Jeff Rasley et al. · 2019

Explained where training memory goes (16 bytes per parameter with mixed-precision Adam) and how to remove the redundant copies. Its stages became DeepSpeed's ZeRO and PyTorch's FSDP.

How to read it: Section 3 ('Where did all the memory go?') and Figure 1 are the essentials; the rest is engineering detail.

~40 min readarXiv:1910.02054✓ verified 2026-10-04
Important

Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LM

Deepak Narayanan, Mohammad Shoeybi et al. · 2021

Showed how to compose tensor, pipeline and data parallelism to train trillion-parameter models efficiently on thousands of GPUs.

How to read it: Read the takeaways in Section 3; they summarise how to choose the parallel sizes.

~45 min readarXiv:2104.04473✓ verified 2026-10-04
Essential

The Llama 3 Herd of Models

Aaron Grattafiori, Abhimanyu Dubey et al. · 2024

The most complete public account of building a frontier-scale model end to end: data pipeline, scaling-law experiments, 16,384-GPU training, failures and all.

How to read it: It is 90+ pages. For this chapter read Section 3 (pre-training) only: data, scaling laws, infrastructure and the training recipe.

~2 h readarXiv:2407.21783✓ verified 2026-10-04

Watch