ZeRO, FSDP & Sharded Training

Stop every GPU holding a full copy of the model, and big models suddenly fit.

🔴 advanced5 min readscaling
Normal multi-GPU training gives every GPU a full copy of the model, its gradients and the optimiser's extra state, which wastes huge amounts of memory. ZeRO and PyTorch's FSDP split those copies up instead, so each GPU holds only its own share and fetches the rest only when it needs it. Stage 1 splits the optimiser state, stage 2 also splits the gradients, and stage 3 splits the weights themselves. That is how models with billions of parameters fit across ordinary GPU clusters.

The Memory Redundancy Problem in DDP

Standard Distributed Data Parallelism (DDP) is memory inefficient:

In DDP across N=64N = 64 GPUs, every single GPU stores an identical copy of:

  1. Model Parameters: 1×1\times Memory.
  2. Gradients: 1×1\times Memory.
  3. Adam Optimizer States: 4×4\times Memory (16 bytes per param16\text{ bytes per param} for FP32 master weights, momentum, and variance).

Duplicating this 6×6\times memory overhead identically across 64 GPUs wastes massive VRAM capacity.

ZeRO (Zero Redundancy Optimizer - Microsoft DeepSpeed, 2020) and Fully Sharded Data Parallel (PyTorch FSDP) eliminate memory redundancy by sharding state memory across GPUs.

┌─────────────────────────────────────────────────────────────┐
│ 1. ZeRO STAGE 1: OPTIMIZER STATE SHARDING (ZeRO-1)          │
│ Shards Adam optimizer states across N GPUs. Cuts RAM by 4x! │
├─────────────────────────────────────────────────────────────┤
│ 2. ZeRO STAGE 2: GRADIENT SHARDING (ZeRO-2)                 │
│ Shards optimizer states AND gradients across N GPUs.        │
├─────────────────────────────────────────────────────────────┤
│ 3. ZeRO STAGE 3 / FSDP: PARAMETER SHARDING (ZeRO-3)         │
│ Shards optimizer states, gradients, AND model parameters!   │
│ No duplicated model state: memory per GPU ~ 1/N.            │
└─────────────────────────────────────────────────────────────┘

How ZeRO Stage 3 / FSDP Works Just-in-Time

If model parameters are sharded so GPU 0 holds only 1/N1/N of the model, how does GPU 0 run a forward pass through Layer 15?

Using Just-In-Time (JIT) Parameter Prefetching via AllGather:

  FORWARD PASS AT LAYER 15:
  1. GPU 0 executes AllGather ──► Fetches Layer 15 parameters from peer GPUs just-in-time!
  2. Compute Layer 15 Forward Pass activations.
  3. IMMEDIATELY DROP Layer 15 parameters from GPU 0 memory!
  BACKWARD PASS AT LAYER 15:
  1. GPU 0 executes AllGather ──► Fetches Layer 15 parameters again just-in-time!
  2. Compute Layer 15 Backward Pass gradients.
  3. Execute ReduceScatter ──► Send computed gradients to their assigned shard owner GPUs!
  4. IMMEDIATELY DROP Layer 15 parameters from GPU 0 memory!

Stage Comparison Matrix

StrategySharded ComponentsVRAM Reduction per GPUCommunication Volume
Standard DDPNone (100% Duplicate)1×1\times (Baseline)Low (AllReduce Gradients)
ZeRO-1Optimizer States4×4\times ReductionLow (Same as DDP)
ZeRO-2Optimizer States + Gradients5×5\times ReductionLow (Same as DDP)
ZeRO-3 / FSDPOptimizer + Gradients + ParametersN×N\times Linear Reduction!+50%+50\% Communication Overhead

DeepSpeed vs PyTorch FSDP

Say this out loud

ZeRO and PyTorch FSDP eliminate memory redundancy in data parallel training by sharding optimizer states, gradients, and model parameters across GPUs. ZeRO 3 / FSDP shards 100 percent of model states, using AllGather communication to fetch layer parameters just-in-time during forward and backward passes, enabling training of massive LLMs with linear VRAM reduction.

Followups to expect

  1. What is ZeRO-Offload / FSDP CPU Offloading? Offloading sharded optimizer states and gradient updates to CPU System RAM, allowing 13B parameter fine-tuning on a single NVidia RTX 4090 GPU.
  2. How does FSDP handle Activation Checkpointing? FSDP wraps activation checkpointing around individual sharded FSDP modules, discarding intermediate layer activations to achieve maximum memory efficiency.

Check yourself

Question 1 of 3

What primary memory inefficiency in standard Distributed Data Parallelism (DDP) does ZeRO / FSDP eliminate?

More in Deep Learning

See all →
Activation Functions4 minDropout4 minBackpropagation5 min