Log inStart free
LESSON 11.11 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

ZeRO and FSDP

Watch ZeRO split the training memory of one model over several GPUs.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 11.11 · ZERO BAYZERO-3 · 3 GPUS · 128 B PER GPU
01
Stage 1 of 6 · Model states
ZeRO-3 cuts the optimizer states, gradients and parameters into 3 shards. Each GPU holds 128 B, not 384 B.
Explain it simply

Training keeps three things per parameter: the parameter, its gradient and the optimizer states. They take 12 bytes: a 4-byte parameter copy and Adam's two averages. ZeRO cuts the optimizer states, the gradients and the parameters into three shards, one per GPU. 2, 3 or 6 GPUs split each layer's 6 numbers evenly. Each GPU holds 128 B.

3 GPU columns and a one-GPU column. Each column has a parameter grid, a gradient grid and an optimizer grid. ZeRO-3 keeps 128 B per GPU.

parameters, optimizer statesgradientscollective, copy or new valueempty buffernot held
parameters2 B eachL1L2L3L4gradients2 B eachL1L2L3L4optimizerstates12 B eachL1L2L3L4memoryGPU 0samples 1–3GPU 1samples 4–6GPU 2samples 7–81 GPUsamples 1–8128 B128 B128 B384 Bmodel statesZeRO-3: 16 B + 16 B + 96 B = 128 B per GPUparameters2 B eachL1L2L3L4gradients2 B eachL1L2L3L4optimizerstates12 B eachL1L2L3L4memoryGPU 0samples 1–3GPU 1samples 4–6GPU 2samples 7–81 GPUsamples 1–8128 B128 B128 B384 Bmodel statesZeRO-3: 16 B + 16 B + 96 B = 128 B per GPU
Toy: the 11.C1 network (24 parameters, 8 samples), Adam step 2; 16 B per parameter (mixed precision)
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
M=2 Ψp+2 Ψg+12 Ψo\sy{mem}{ink}{M} = 2\,\sy{p}{param}{\Psi_p} + 2\,\sy{g}{grad}{\Psi_g} + 12\,\sy{o}{param}{\Psi_o}
M=2⋅8+2⋅8+12⋅8=128 BM = 2\cdot 8 + 2\cdot 8 + 12\cdot 8 = 128\,\text{B}

Memory per GPU counts 2, 2 and 12 bytes per number kept.

Common mix-ups

MYTHWith FSDP, each GPU runs only its own part of the model.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With ZeRO-3, what happens to the memory per GPU if 3 GPUs become 6?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.