Skip to main content

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
Use data parallelism for most workloads - it’s easier to implement and sufficient for 90%+ of use cases.

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
Model parallelism is more complex to implement than data parallelism and may not scale as efficiently.

PyTorch Distributed Training

Azure ML supports PyTorch’s native torch.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’s tf.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

For GPU training, always use NCCL:
NCCL is optimized for GPU communication and supports InfiniBand.
For large models, accumulate gradients over multiple batches:
Use FP16 to reduce memory and increase speed:
Optimize data loading for distributed training:

Monitoring Distributed Training

Track distributed training metrics:

Troubleshooting

Increase timeout for large models:
Solutions:
  1. Reduce batch size
  2. Enable gradient checkpointing
  3. Use gradient accumulation
  4. Try DeepSpeed ZeRO
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