Multi-GPU Training
Overview
Multi-GPU Training is an approach to training AI models where the computational load is distributed among multiple GPUs. It is used to accelerate training, handle models that do not fit into the memory of a single device, and reduce experimentation time.
Distribution Strategies
| Strategy | Description | Application |
|---|---|---|
| Data Parallelism | A copy of the model on each GPU, data is split into batches | Models that fit in the memory of one GPU |
| Model Parallelism | Layers of the model are distributed across GPUs | Models that exceed the memory of one GPU |
| Pipeline Parallelism | A variant of Model Parallelism with micro-batch pipeline processing | Reducing GPU idle time |
| Tensor Parallelism | Splitting operation matrices between GPUs | Accelerating individual operations |
| Fully Sharded Data Parallelism (FSDP) | Sharding of parameters, gradients, and optimizer states | Efficient memory usage |
Key Aspects
- Gradient Synchronization: After each step, gradients are averaged between devices (all-reduce).
- Scalability: Efficiency grows nonlinearly due to communication overhead.
- Training Speed: Increasing batch size often requires adjusting the learning rate.
- Tools: PyTorch DDP, DeepSpeed, Horovod, TensorFlow MirroredStrategy.