Learn / DGX Spark PyTorch Distributed
PyTorch on two DGX Sparks, part 1: decide and configure
Before you run PyTorch on two DGX Sparks, here's what to decide. We start at the bottom of the stack, with two machines that must run one job.
Chapters
- 0:00Introduction
- 0:06Where this fits: The AI stack
- 0:12First decision: Share the model
- 0:22What is automatic: Done, or your job
- 0:34The data: Divide the samples
- 0:50CPU work: It stays on its Spark
- 1:06Data loading: Data workers
- 1:19Wrap up
Read the transcript
Introduction
Before you run PyTorch on two DGX Sparks, here's what to decide.
Where this fits: The AI stack
We start at the bottom of the stack, with two machines that must run one job.
First decision: Share the model
With DDP, each Spark holds a full copy of the model. FSDP can shard it instead, so each holds part of the weights and training state.
What is automatic: Done, or your job
torchrun starts processes on its own Spark, and numbers them. DDP combines gradients. Your code must pick the GPU, divide the data, and save checkpoints.
The data: Divide the samples
DDP doesn't divide your data. Use a distributed sampler with your data loader. Set the epoch each time round, or the shuffled order repeats. The batch size is per process, so two Sparks take twice as many samples each step.
CPU work: It stays on its Spark
CPU work doesn't move between Sparks. Threads and data workers use their own Spark's processor. With one process on each, torchrun leaves the thread setting as it was. With more than one, and nothing set, it sets one thread each.
Data loading: Data workers
Data loader workers start at zero, so the training process loads the data itself. Add workers in small steps. Each uses processor time and memory. In a container, give them enough shared memory.
Wrap up
The page lists every setting and its default. We haven't run this on hardware.
Sources
- docs.pytorch.org/docs/2.15/elastic/run.html
- github.com/pytorch/pytorch/blob/v2.15.0/torch/distributed/run.py
- docs.pytorch.org/docs/2.15/generated/torch.nn.parallel.DistributedDataParallel.html
- docs.pytorch.org/docs/2.15/fsdp.html
- docs.pytorch.org/docs/2.15/data.html
- docs.pytorch.org/docs/2.15/notes/multiprocessing.html
- docs.nvidia.com/dgx/dgx-spark/hardware.html