Mixed-precision Adam requires bytes per parameter ( B fp16 weights, B fp16 gradients, B fp32 master weights, and B each for Adam moments and ). For a -billion-parameter model across GPUs, how much per-GPU memory do model states take under plain data parallelism and ZeRO stages 1, 2 and 3?
ML system design, Distributed training
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you know where model-state memory goes in mixed-precision Adam, how ZeRO (Zero Redundancy Optimiser) stages 1–3 shard it across GPUs (graphics processing units), and what communication trade-off ZeRO-3 introduces.
Key idea
Plain data parallelism replicates all bytes per parameter on every GPU. ZeRO eliminates that redundancy across GPUs in three stages: ZeRO-1 shards the bytes of optimiser states, ZeRO-2 also shards the -byte gradients, and ZeRO-3 shards the -byte parameters as well, cutting model-state memory by up to while only ZeRO-3 adds extra parameter all-gathers.
Steps
- Baseline plain data parallelism (DP): with parameters and ( fp16, 16-bit floating point, weights fp16 gradients optimiser states in fp32, 32-bit floating point: master weights, first moment , second moment ), every GPU stores (using ).
- ZeRO Stage 1 (shard optimiser states): each of the GPUs stores only of the optimiser states while still keeping full fp16 weights and gradients: Communication volume matches plain DP (each GPU updates its shard and all-gathers updated fp16 weights).
- ZeRO Stage 2 (shard optimiser states and gradients): each GPU keeps full fp16 weights but only of the gradients and optimiser states (using reduce-scatter instead of all-reduce so GPUs discard non-owned gradient shards immediately): still with the same total communication volume as plain DP.
- ZeRO Stage 3 (shard optimiser states, gradients and fp16 weights): every model-state component is split -way across the GPUs:
- Account for ZeRO-3 communication and extra memory: because weights are sharded, each GPU must all-gather a layer's fp16 parameters right before its forward pass and again before its backward pass (then free them), raising communication volume by roughly over DP, ZeRO-1 and ZeRO-2. Also note that all four numbers cover model states only: activations (saved for backprop) and temporary communication buffers sit on top.
Common mistakes
- Counting only for Adam's and and forgetting the fp32 master weight copy, which gives of optimiser states.
- Thinking ZeRO-3 has the same communication cost as ZeRO-1 and ZeRO-2; gathering sharded parameters during both forward and backward passes adds extra all-gather traffic.
- Assuming of sharded model states means a 7B model fits into GPUs under ZeRO-3 without budgeting for activation memory, temporary parameter buffers and framework overhead.
How long your answer should be
3–4 minutes; show the per-parameter formula and GB total for all four cases, plus ZeRO-3's all-gather cost and activations.
Read this
Previous in ML system design: You run data-parallel training on GPUs for a model with billion parameters and fp16 gradients ( bytes each). Using ring all-reduce, how many bytes does each GPU send per step, and how long does communication take at per link?
Next in ML system design: What do p50 and p99 latency mean? Suppose a request fans out to 50 shards in parallel and waits for all of them, and each shard is slow () independently on of calls. What fraction of requests is slow, how would you split a p99 latency budget across ML serving stages, and how can you reduce tail latency?