DeepSpeed Explained
1. What is DeepSpeed?
1.1 Core Concept
DeepSpeed is a deep learning optimization library developed by Microsoft. Through ZeRO (Zero Redundancy Optimizer) technology and multiple parallelism strategies, it makes large-scale model training more efficient and easier to use.
1.2 Key Advantages
| Advantage | Description | |-----------|-------------| | GPU memory savings | Per-GPU memory usage drops significantly as GPU count increases | | Training acceleration | Efficient parallelism strategies and memory management | | Model scaling | Supports training of larger models |
1.3 ZeRO Architecture
Model states are sharded across GPUs, eliminating memory redundancy:
| Sharding Type | Description | |---------------|-------------| | Parameter sharding (P) | Model parameters are distributed across GPUs | | Gradient sharding (G) | Distributed computation and storage of gradients | | Optimizer state sharding (O) | Distributed storage and management of optimizer states |
---
2. Common Misconception vs. Reality
2.1 Misconception: Memory Is Split Evenly
❌ Wrong idea:
> "When training on multiple GPUs, memory is automatically divided, so each GPU only carries 1/N of the memory load."
2.2 Reality: Each GPU Is Independent
✅ Actual situation:
> "Every GPU stores the complete model parameters and optimizer states—memory is not automatically split."
> "Multiple GPUs are mainly used to speed up training."
---
3. DeepSpeed Stage Comparison
Stage 0 (Default)
- Every GPU stores the full model parameters
- Per-GPU memory: ~15.25G
- One copy of parameters distributed across all GPUs
- Per-GPU memory: ~12.6G
- Parameters shared; optimizer states distributed
- Per-GPU memory: ~10.4G
- Recommended!
- Model split by layers; parameters flow on demand
- Per-GPU memory: ~8.15G
- Maximum memory savings
- ZeRO: sharding of parameters, gradients, and optimizer states
- Mixed-precision training: automatic loss scaling and dynamic precision management
- Parallelism: combinations of tensor, pipeline, and data parallelism
- Memory optimization: activation recomputation and memory fragmentation management
Stage 1
Stage 2 ⭐ Recommended
Stage 3
---
4. Core Features
Source: Easy AI tutorial series