- Use native PyTorch Distributed Data Parallel (DDP)
- Scale training with Hugging Face Accelerate
- Configure Slurm jobs for multi-GPU and multi-node training
- Debug common distributed training issues
**Time**: About 60 minutes
**Prerequisites**: Complete [Slurm Basics](/tutorials/slurm/) and [Python Environments](/tutorials/python/) first. Familiarity with PyTorch is assumed.
---
## When to use multiple GPUs
Training on multiple GPUs makes sense when:
-**Training is slow**: A single GPU takes hours or days per epoch
-**Model fits in memory**: The model fits on one GPU, but you want faster training
-**Large batch sizes**: You need larger effective batch sizes for better convergence
Multiple GPUs do **not** help when:
- Your model doesn't fit on a single GPU (you need model parallelism instead)
- Data loading is the bottleneck
- Training is already fast (overhead may slow things down)
### Scaling strategies
| Strategy | What it does | When to use |
|----------|--------------|-------------|
| **Data Parallel** | Same model on each GPU, different data batches | Most common, covered here |
| **Model Parallel** | Model split across GPUs | Very large models (LLMs) |
| **Pipeline Parallel** | Model layers on different GPUs | Very deep networks |
This tutorial focuses on **data parallelism** - the most common and easiest approach.
### How data parallelism works
1. The model is replicated on each GPU
2. Each GPU processes a different batch of data
3. Gradients are synchronized across GPUs
4. Weights are updated identically on all GPUs
With 4 GPUs and batch size 32 per GPU, you effectively train with batch size 128.
---
## Part 1: PyTorch Lightning
[PyTorch Lightning](https://lightning.ai/docs/pytorch/stable/) is the easiest way to scale training. It handles distributed training automatically - you write single-GPU code, Lightning handles the rest.