Mixed-precision Adam requires 16 bytes per parameter (2 B fp16 weights, 2 B fp16 gradients, 4 B fp32 master weights, and 4 B each for Adam moments m and v). For a 7-billion-parameter model across N=8 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 N GPUs (graphics processing units), and what communication trade-off ZeRO-3 introduces.

Key idea

Plain data parallelism replicates all 16 bytes per parameter on every GPU. ZeRO eliminates that redundancy across N GPUs in three stages: ZeRO-1 shards the 12 bytes of optimiser states, ZeRO-2 also shards the 2-byte gradients, and ZeRO-3 shards the 2-byte parameters as well, cutting model-state memory by up to N× while only ZeRO-3 adds extra parameter all-gathers.

Steps

  1. Baseline plain data parallelism (DP): with P=7×109 parameters and 16 B/param (2 B fp16, 16-bit floating point, weights + 2 B fp16 gradients + 12 B optimiser states in fp32, 32-bit floating point: 4 B master weights, 4 B first moment m, 4 B second moment v), every GPU stores 16×7×109 B=112 GB (using 1 GB=109 B).
  2. ZeRO Stage 1 (shard optimiser states): each of the N=8 GPUs stores only 1/8 of the 12 B optimiser states while still keeping full fp16 weights and gradients: 2+2+128=5.5 B/param  ⟹  5.5×7=38.5 GB per GPU. Communication volume matches plain DP (each GPU updates its shard and all-gathers updated fp16 weights).
  3. ZeRO Stage 2 (shard optimiser states and gradients): each GPU keeps full fp16 weights but only 1/8 of the gradients and optimiser states (using reduce-scatter instead of all-reduce so GPUs discard non-owned gradient shards immediately): 2+2+128=3.75 B/param  ⟹  3.75×7=26.25 GB per GPU, still with the same total communication volume as plain DP.
  4. ZeRO Stage 3 (shard optimiser states, gradients and fp16 weights): every model-state component is split N-way across the 8 GPUs: 2+2+128=2 B/param  ⟹  2×7=14 GB per GPU.
  5. 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 1.5× 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

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 N=8 GPUs for a model with P=1 billion parameters and fp16 gradients (2 bytes each). Using ring all-reduce, how many bytes does each GPU send per step, and how long does communication take at 100 GB/s 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 (>100 ms) independently on 1% of calls. What fraction of requests is slow, how would you split a 200 ms p99 latency budget across ML serving stages, and how can you reduce tail latency?