23  The Multi-Kitten Assembly Line

Distributed Training and ZeRO

⏳ 2026 Edition: Last verified: 2026-02-24

Prerequisites: Chapter 22

Technical Keywords: Distributed Training, AllReduce, Distributed Data Parallel (DDP), Fully Sharded Data Parallel (FSDP), Tensor Parallelism (TP), Pipeline Parallelism (PP), ZeRO Stages


🧭 Advanced Track Navigation Core Track completion is defined by Checkpoints 1-4. This chapter belongs to the Advanced Track. Safe to skim on first pass; not required for checkpoints.

A 70-Billion parameter model takes up about 140 Gigabytes of memory just to store its weights (W). An NVIDIA H100 GPU only has 80 Gigabytes of VRAM.

You literally cannot fit the kitten’s brain inside a single skull.

To train a Frontier Model, we must slice the mathematical brain into pieces and distribute it across thousands of GPUs working in perfect, microsecond synchronization. This is Distributed Training.


23.1 Distributed Data Parallel (DDP): Cloning the Kitten

If your model is small enough to fit on one GPU, but you want to train it faster, you use DDP.

  1. You clone the exact same kitten (Model) onto 8 different GPUs.
  2. You give GPU-1 the first 32 pages of the dataset. You give GPU-2 the next 32 pages, and so on.
  3. Every GPU does its own Forward Pass and Backpropagation.
  4. The AllReduce Step: Before anyone updates their weights, the 8 GPUs pause, shout their calculated Gradients (the slopes) to each other across the network cables, average them together, and then all 8 take the exact same optimized step.
  • Pro: Super fast.
  • Con: The entire model must fit on a single GPU. Useless for 70B parameter LLMs.

23.2 Tensor Parallelism (TP): Slicing the Matrix

If the W matrix (from Chapter 8) is too big for one GPU, we physically slice it in half (Narayanan et al., 2021)!

Remember z = W \cdot x? If we slice W horizontally (top rows on GPU-1, bottom rows on GPU-2), both GPUs multiply against x simultaneously and concatenate their output slices over an ultra-fast cable (NVLink) via AllGather. Conversely, if we slice W vertically along the input dimension (matching a split input x), each GPU computes a partial sum and they add those partial results together via AllReduce.

  • Pro: Allows you to run massive matrices.
  • Con: The GPUs have to communicate constantly, every single millisecond. If you do this across slow cables between two different server racks, the math grinds to a halt. TP is usually restricted to GPUs inside the exact same physical server box.

23.3 Pipeline Parallelism (PP): The Bucket Brigade

What if the model has 80 layers (Transformer Blocks)?

We put Layers 1-10 on GPU-1. We put Layers 11-20 on GPU-2.

GPU-1 calculates the first 10 layers, then passes the Hidden State (h) over the network to GPU-2, and goes to sleep. GPU-2 takes over. This is Pipeline Parallelism (Narayanan et al., 2021).

Diagram showing layers split across GPUs in a pipeline

Pipeline Parallelism — layers distributed across GPUs.

Catastrophic Failure: The Pipeline Bubble

If GPU-1 passes the data to GPU-2, GPU-1 is now sitting completely idle doing nothing while it waits for the rest of the network to finish the Forward Pass and the Backpropagation! This wasted idle time is called the Pipeline Bubble. The Fix: We chop the data into tiny “micro-batches” so GPU-1 can immediately start working on the next sentence while GPU-2 is working on the first one, keeping the assembly line constantly fed.


23.4 FSDP and ZeRO: Shredding the Backpack

During training, storing the Weights (W) is only 20% of the memory problem. The other 80% is the “Backpack”—the Gradients, the Optimizer States (Momentum from Chapter 3), and the internal Activations.

Microsoft invented ZeRO (Zero Redundancy Optimizer), which powers PyTorch’s FSDP (Fully Sharded Data Parallel) (Rajbhandari et al., 2020).

Instead of cloning the model like DDP, FSDP takes the entire model and the massive backpack and completely shreds it across 1,000 GPUs.

  • GPU-1 only holds 0.1% of the weights.
  • When GPU-1 needs to do math, it rapidly requests the other 99.9% of the weights from the other 999 GPUs, does the math, and immediately deletes them from its RAM.

It is a miracle of software engineering. It trades massive amounts of network bandwidth to save massive amounts of GPU memory.


23.5 3D Parallelism: The Megatron Strategy

For large frontier runs, you don’t pick just one of these. You often use all of them at once (3D Parallelism): 1. Tensor Parallel slices the massive matrices across the 8 GPUs inside a single server box (ultra-fast intra-node). 2. Pipeline Parallel sends the layers across different server boxes in the warehouse (inter-node). 3. Data Parallel (ZeRO) clones this entire massive pipeline across thousands of servers to process terabytes of data simultaneously.

Rosetta Stone

Kitten World Math/Concept When to use it?
“Cloned kittens, different books” DDP Model fits on 1 GPU, want to train faster.
“Slice the heavy matrix in half” Tensor Parallel Matrix is too big; GPUs share an ultra-fast NVLink.
“Assembly line layers” Pipeline Parallel Model is too deep; split layers across slow network cables.
“Shred the massive backpack” FSDP / ZeRO Stage 3 Training a 70B+ model across a massive cluster.

23.6 Removing the Training Wheels

The Real Engineering

We talked about slicing the brain across GPUs. In 3D Parallelism, Tensor Parallelism shards the actual weight matrices across GPUs using All-Reduce operations. Pipeline Parallelism splits the Transformer layers across nodes, using micro-batches to maximize utilization. Fully Sharded Data Parallel (FSDP / ZeRO) eliminates memory redundancy by sharding the optimizer states and gradients across all GPUs, gathering them via network communication only exactly when needed for the computation.

23.7 Paws and Reflect: Chapter 23 Quiz

1. You are training on 8 GPUs using standard DDP. GPU-1 finishes calculating its gradients for its batch of data. Can it immediately update its weights and move on to the next batch? No! DDP requires the “AllReduce” step. GPU-1 must wait for GPUs 2-8 to finish, so they can average all their gradients together and take the exact same mathematical step. If they step independently, they become 8 completely different models.
2. Why is Tensor Parallelism (TP) a terrible idea if your GPUs are in two different physical data centers in different cities? Because TP requires the GPUs to send half-calculated matrices back and forth during every single matrix multiplication. The latency of the internet between cities would cause the GPUs to spend 99.9% of their time waiting, and 0.1% doing math.
3. What is the “Pipeline Bubble” in Pipeline Parallelism? The wasted idle time when the first GPU in the pipeline finishes its layer and has to wait for the data to travel all the way to the end of the network and back before it gets a new gradient to work on.

23.8 Chapter 23 Summary

You’ve learned how to build a planetary-scale supercomputer:

  • The Memory Wall: A 100B model cannot physically fit on a single GPU.
  • DDP: Cloning the model to chew through data faster.
  • Tensor Parallel (TP): Physically slicing massive matrices horizontally and vertically across GPUs sharing an ultra-fast cable.
  • Pipeline Parallel (PP): Splitting the network layer-by-layer across different servers, utilizing micro-batches to prevent idle “Bubbles.”
  • ZeRO / FSDP: Shredding the massive memory footprint of the optimizer states across thousands of GPUs, allowing practically infinite model sizes.

AI Safety Thread: Chapter 23

Hardware Concentration & Regulatory Capture: Because 3D Parallelism requires $100 million clusters of NVIDIA H100s, only three or four massive corporations in the world can actually train Frontier Models. This can create centralization of power. If an AI safety breakthrough occurs, or a catastrophic failure is discovered, the public may have limited ability to audit or verify it, because the public does not own the infrastructure. Furthermore, large corporations can lobby governments to write AI regulations that require massive compute to comply with (e.g., expensive auditing sweeps), which can disadvantage open-source developers.


Next: Chapter 24: The Treat Dispenser at Scale: Inference, vLLM, and PagedAttention