What Is DeepSpeed?
DeepSpeed is Microsoft's open-source library for distributed deep learning training. Its core contribution is ZeRO (Zero Redundancy Optimizer), a set of techniques that eliminate the memory redundancies in standard distributed training and allow models much larger than any single GPU's memory to be trained efficiently.
DeepSpeed integrates with PyTorch and HuggingFace Trainer, so adding it to an existing training script is often a configuration change rather than a code rewrite.
The ZeRO Stages
Standard data parallelism copies the full model to every GPU. ZeRO eliminates this redundancy progressively:
ZeRO Stage 1 - shards optimizer states across GPUs. Each GPU stores optimizer state only for the parameters it's responsible for. Memory reduction: ~4x.
ZeRO Stage 2 - additionally shards gradients. Memory reduction: ~8x.
ZeRO Stage 3 - additionally shards model parameters. Each GPU stores only a fraction of the model weights. Memory reduction: scales linearly with the number of GPUs. With 8 GPUs, each stores 1/8 of the parameters.
{
"zero_optimization": {
"stage": 3,
"offload_optimizer": {
"device": "cpu",
"pin_memory": true
},
"offload_param": {
"device": "cpu",
"pin_memory": true
},
"overlap_comm": true,
"contiguous_gradients": true,
"sub_group_size": 1e9,
"reduce_bucket_size": "auto",
"stage3_prefetch_bucket_size": "auto",
"stage3_param_persistence_threshold": "auto",
"stage3_max_live_parameters": 1e9,
"stage3_max_reuse_distance": 1e9
},
"bf16": {
"enabled": true
},
"train_micro_batch_size_per_gpu": 1,
"gradient_accumulation_steps": 16
}