AI Infra Interviews logo
← Distributed Training & Parallelism / 04
easyMicrosoftMeta

Explain ZeRO stages 1, 2 and 3. How much memory does each stage leave per GPU for a 70B model?

Track which state remains replicated at each ZeRO stage. Compute a declared 70B memory recipe, then add live gathers, activations and buffers before deciding fit.

Updated Oct 2026 · Learn how AI infrastructure works through explanations, worked examples and diagrams, then practise applying it to interview questions.

TL;DR: ZeRO stage 1 shards optimizer state, stage 2 also shards gradients, and stage 3 also shards parameters at rest. Under one explicit 16-byte-per-parameter recipe, 70.6B parameters at 64 ranks need 295.64 GB, 156.64 GB and 17.65 GB of persistent payload per rank respectively. These are not peak allocation or proof that a training configuration fits.

How to approach it

List the recipe's actual dtypes and copies before using a bytes-per-parameter rule. Identify which terms stay replicated, derive each stage, then add transient live state. End with the communication and runtime tradeoff of the least-sharded feasible candidate.

A strong answer

A spreadsheet says stage 3 needs less than 18 GB per GPU, yet training still runs out of memory. The spreadsheet counted stored shards, while execution also needed gathered parameters and activations. Model Memory Footprint establishes the accounting boundary; ZeRO and FSDP explains sharded ownership.

ZeRO (Zero Redundancy Optimizer) removes duplicate copies of training state across data-parallel ranks, giving each rank one shard instead of a full copy. The DeepSpeed ZeRO overview defines the incremental stages. For this worked example, assume BF16 parameters and gradients, an FP32 master parameter copy, and two FP32 Adam moments. Other recipes differ; 16 bytes is not a universal mixed-precision requirement.

W = 2 bytes of parameters
G = 2 bytes of gradients
O = 4 master + 4 first moment + 4 second moment = 12 bytes
unsharded payload = W + G + O = 16 bytes/parameter
N = 70.6e9 parameters; n = 64 data-parallel ranks
stage 1 = N×(W+G+O/n) = 295.6375 GB/rank
stage 2 = N×(W+(G+O)/n) = 156.64375 GB/rank
stage 3 = N×(W+G+O)/n = 17.65 GB/rank
sanity: 64×17.65 = 1,129.6 GB, the original total payload.
What remains replicated?Stage 1W: fullG: fullO: ¼Stage 2W: fullG: ¼O: ¼Stage 3, at restW: ¼G: ¼O: ¼Toy: four data-parallel ranks.W weights · G gradients · O optimizerStage 3 gathers parameters for use;peak memory exceeds stored shards.

The graphic uses four ranks so ownership is easy to see; the numeric example uses 64. Stage 1 leaves four bytes per parameter replicated under this recipe. Stage 2 leaves two, not four. Their asymptotic floors for 70.6B are therefore 282.4 GB and 141.2 GB respectively, before the remaining shards. Neither floor fits one 80 GB device without additional measures.

RanksStage 3 persistent payload
8141.2 GB
1670.6 GB
3235.3 GB
6417.65 GB

Even 70.6 GB below a nominal 80 GB device capacity is only a candidate: gathered units, activations, temporary kernels, communication buffers, allocator behavior and other reservations still need room. There is no universal practical floor of 32 GPUs independent of the model implementation and workload.

A simple communication model helps describe the cost. Let P be parameter bytes and G gradient bytes for a full corresponding model partition, with q=(n−1)/n. A ring reduce-scatter sends qG per rank; one parameter all-gather sends qP. If parameters are gathered once for forward and again for backward, the illustrative send total is q(2P+G). When P=G this is 1.5 times a ring gradient all-reduce's 2qG. Retaining gathered parameters, prefetching, accumulation and different dtypes change the count.

That is not a universal ZeRO-3 traffic multiplier. Stage 2 can reduce and release gradient buckets while retaining only its ownership shard; temporary full tensors or bucket buffers can still exist. Stage 3 divides stored state among ranks, but live allocations can exceed one rank’s share during execution. A device memory reading alone cannot tell you which stage is configured.

Inspect the framework configuration, parameter ownership, allocator peak and collective timeline. Compare candidates at equal numerical settings and batch. Parameter prefetch can hide waits but increases live memory. If stage 2 meets the memory requirement and runs faster, stage 3 has no automatic advantage; if stage 2 cannot fit, its speed on a smaller workload is not a valid comparison.

What interviewers probe next

  • “Are results bitwise identical to DDP?” The intended update can match, but reduction order and numerical implementations can change floating-point results. Test with an appropriate tolerance and training-quality check.
  • “Are activations divided by n?” Not merely because parameters are sharded. Activation memory depends on the computation, micro-batch, sequence and checkpointing policy.
  • “Can optimizer sharding help before stage 3?” Yes. For a 7B version of this recipe at eight ranks, stage 1 is 7×(4+12/8)=38.5 GB before execution extras.

Common mistakes

  • Applying the 16-byte recipe without checking the optimizer and dtypes.
  • Saying stage 2 still replicates full reduced gradients at rest.
  • Treating stored-shard arithmetic as a peak-memory measurement.

Key takeaways

  • The stated 64-rank recipe gives 295.64, 156.64 and 17.65 GB per rank across stages 1–3.
  • Stage 2's replicated floor is two bytes per parameter under this recipe.
  • Gather lifetimes and activations decide whether the static estimate fits in practice.
You can read the first 10 answers per topic without an account. Signing in increases that to 20, includes lessons marked Plus, and saves your progress so you can return to topics you want to review.no card · Google sign-in · nothing to cancel
HOW DID IT GO?
0
READING SIGNED OUT

Signing in doubles your free answers, from 10 to 20 per topic, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free

Work through the numbers

Change the assumptions in a free calculator, then explain what the result establishes and what still needs measurement.

UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

Explain which state each stage shards, derive the memory recipe and account for the full tensors gathered during execution. Compare feasible configurations at the same batch and precision.

DISCUSSION · 0

No comments yet — be the first to share your approach.