







multi-GPU compute strategies
Why Scale Beyond a Single GPU?
- Necessity: Model doesn't fit in single GPU memory.
- Benefit: Even for small models, multi-GPU training speeds up training time.
Strategy 1: Data Parallelism with DDP
- Important to understand efficient GPU utilization strategies.
🔧 DDP (Distributed Data Parallel – PyTorch)
- Approach: Replicates the full model on each GPU.
- Model copied to each GPU.
- Data batches split and sent to each GPU.
- Each GPU processes data in parallel.
- Gradients are synchronized and averaged.
- Each model copy is updated identically.
- Limitation: Model must fit in each GPU’s memory (including optimizer states and gradients).

Strategy 2: Model Sharding with FSDP
🔧 FSDP (Fully Sharded Data Parallel – PyTorch)
- Based on ZeRO (Zero Redundancy Optimizer) by Microsoft (2019).
- Reduces redundant memory use by sharding model states across GPUs.
🧠 Memory Components in Training
- Weights (Parameters) – Blue
- Gradients – Yellow
- Optimizer States – Green
Optimizer states take 2x the space of weights

ZeRO Stages
| Stage | Sharded Component | Memory Reduction |
| 1 | Optimizer States | Up to 4× |
| 2 | Optimizer States + Gradients | Up to 8× |
| 3 | All (Weights, Gradients, Optimizer States) | Linear with #GPUs (e.g., 64× for 64 GPUs) |
SDP vs DDP
- DDP: Replicates full model on each GPU.
- Shards data and model states.
- Dynamically materializes shards during forward/backward pass.
- Releases non-local data post-computation.
- Option to cache data during backward pass.
Trade-offs
- More sharding → Less memory use.
- But ↑ GPU-to-GPU communication overhead.
- FSDP can offload computation to CPU to save GPU memory.
- 1 = Full replication (like DDP).
- Max GPUs = Full sharding.
- In-between = Hyper sharding.
Trade-offs
- More sharding → Less memory use.
- But ↑ GPU-to-GPU communication overhead.
- FSDP can offload computation to CPU to save GPU memory.
- 1 = Full replication (like DDP).
- Max GPUs = Full sharding.
- In-between = Hyper sharding.