Distributed GPU Training Guide
Distributed training splits the training workload across multiple GPUs or nodes, dramatically reducing training time for large models and datasets.Azure Machine Learning supports distributed training with PyTorch DDP, DeepSpeed, TensorFlow, and Horovod for both data parallelism and model parallelism.
What is Distributed Training?
In distributed training, you split the workload across multiple mini processors called worker nodes. These nodes work in parallel to speed up model training.Data Parallelism
Same model on each node, different data subsets
Model Parallelism
Model split across nodes, same data
Data Parallelism
The data is divided into partitions equal to the number of available nodes. Each node gets a copy of the model and trains on its data subset. Requirements:- Each node must have enough memory for the full model
- Nodes synchronize gradients at batch completion
- Best for models that fit in single GPU memory
Model Parallelism
The model is segmented into parts that run concurrently on different nodes with the same data. Use when:- Model is too large for single GPU
- Need to train models >10GB
- Have very deep networks
PyTorch Distributed Training
Azure ML supports PyTorch’s nativetorch.distributed for distributed training.
Process Group Initialization
Create process group for worker communication:Environment Variables
Azure ML automatically sets these variables:Distributed Training Script
Submit PyTorch Distributed Job
process_count_per_instance should equal the number of GPUs per node. Azure ML handles setting all environment variables automatically.DeepSpeed
DeepSpeed enables training massive models with near-linear scalability.DeepSpeed Configuration
DeepSpeed Training Script
Submit DeepSpeed Job
TensorFlow Distributed Training
Use TensorFlow’stf.distribute.Strategy for distributed training:
Submit TensorFlow Job
InfiniBand for High-Performance Training
InfiniBand provides ultra-low latency networking for distributed training.Supported VM Series
Enable InfiniBand
InfiniBand can reduce communication overhead by 10-30x compared to Ethernet for all-reduce operations.
Best Practices
Use NCCL Backend
Use NCCL Backend
For GPU training, always use NCCL:NCCL is optimized for GPU communication and supports InfiniBand.
Gradient Accumulation
Gradient Accumulation
For large models, accumulate gradients over multiple batches:
Mixed Precision Training
Mixed Precision Training
Use FP16 to reduce memory and increase speed:
Data Loading
Data Loading
Optimize data loading for distributed training:
Monitoring Distributed Training
Track distributed training metrics:Troubleshooting
NCCL Timeout
NCCL Timeout
Increase timeout for large models:
Out of Memory
Out of Memory
Solutions:
- Reduce batch size
- Enable gradient checkpointing
- Use gradient accumulation
- Try DeepSpeed ZeRO
Slow Training
Slow Training
Check:
- Data loading bottlenecks
- Network bandwidth utilization
- GPU utilization percentage
- Use larger batch sizes if possible
Next Steps
Deploy Models
Deploy trained models to production
MLOps
Automate training pipelines
Model Optimization
Optimize models for inference
Azure AI Examples
Complete distributed training examples