01-data-parallelism-gradient-averaging's DDP-style data parallelism has a hidden cost this question makes explicit: every single GPU keeps a full, redundant copy of the model's parameters, gradients, AND optimizer state (for Adam, that's fp32 copies of the parameters, momentum, and variance — far bigger than the parameters themselves). ZeRO (Zero Redundancy Optimizer) asks a simple question: if every GPU needs the FULL model to do a forward pass, but only needs its OWN SHARE of the optimizer's bookkeeping, why replicate the bookkeeping at all?
Implement per_gpu_memory_bytes(num_params, num_gpus, zero_stage), following the ZeRO paper's exact mixed-precision-Adam memory model for stages 0 (no sharding) through 3 (shard everything), and memory_reduction_factor, quantifying the savings against stage 0.
zero_stage=0: (2 + 2 + 12) * num_params — full replication, no sharding at all (16Ψ bytes, the ZeRO paper's baseline figure).zero_stage=1 (P_os): shard only the optimizer state: (2 + 2) * num_params + 12 * num_params / num_gpus.zero_stage=2 (P_os+g): also shard gradients: 2 * num_params + (2 + 12) * num_params / num_gpus.zero_stage=3 (P_os+g+p): shard everything: (2 + 2 + 12) * num_params / num_gpus.zero_stage raises ValueError.Open one at a time. Each gives away a little more than the last.
Only the pieces that get "sharded" at a given stage get divided by num_gpus; everything not yet sharded at that stage stays fully replicated (multiplied by num_params alone, no division).
Sanity check: at num_gpus=1, every stage's formula collapses back to exactly zero_stage=0's — sharding across one GPU is sharding across nobody.
No results yet
Run your code to check it against the examples, or submit to run every test.