Lesson 5 of 5 Training Models with SageMaker AI

Choosing Data Parallel or Model Parallel Distributed Training

This lesson explains how distributed training spreads work across several GPUs or instances, shortening training on large datasets and making it possible to train models too large for one GPU.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain data parallel training.
  • Explain model parallel training, including tensor and pipeline parallelism.
  • Describe when SageMaker HyperPod suits very large training.

Data parallelism

In data parallel training, every GPU holds a full copy of the model and processes a different slice of each batch. After each step, gradients are averaged across GPUs (an all-reduce operation) so all copies stay identical. It is the right approach when the model fits in one GPU's memory but the dataset is large. SageMaker AI supports PyTorch DistributedDataParallel (DDP), Horovod and the SageMaker distributed data parallelism library, which optimises all-reduce on AWS networking. The effective batch size grows with the number of GPUs, so the learning rate often needs adjusting.

Scenario questions

Data or model parallel?

Exam skills 2.2.4

Choose the distributed training strategy for each case.

Log in to try this activity Interactive activities are free with an account.

Model parallelism

When a model is too large to fit in one GPU's memory, model parallel training splits the model itself across GPUs. Tensor parallelism splits individual layers, dividing their matrix operations across GPUs. Pipeline parallelism places groups of consecutive layers on different GPUs and streams micro-batches through them, so all GPUs work at once.

Sharded data parallelism, such as fully sharded data parallel (FSDP), splits the model's parameters, gradients and optimiser states across GPUs, gathering them only when needed, which greatly reduces memory per GPU. The SageMaker model parallelism library implements these techniques for PyTorch. Data parallelism, by contrast, copies the whole model to each GPU and splits the data, which speeds up training of models that already fit.

The following diagram compares how two training jobs, one with a 300-million-parameter model and one with a 70-billion-parameter model, use their GPUs.

The two jobs need different strategies. Job 1's 300-million-parameter model fits on one GPU, so data parallelism gives every GPU a full copy and a different slice of each batch, and gradients are averaged with all-reduce. Job 2's 70-billion-parameter model does not fit, so it is split across GPUs with sharding and tensor parallelism; data parallelism would run out of memory.
GPU counts are illustrative.

SageMaker HyperPod

Training or fine-tuning very large models can take weeks on hundreds of accelerators, and at that scale hardware failures are routine. SageMaker HyperPod provides persistent clusters of accelerated instances, orchestrated with Slurm or Amazon EKS, for such long-running, large-scale training.

HyperPod monitors the health of each instance, replaces faulty nodes automatically and resumes jobs from their last checkpoints, so a failure costs minutes rather than days of training. HyperPod recipes provide tested training configurations for popular models. The following table summarises the distributed training options.

SituationApproach
Model fits on one GPU; large datasetData parallelism
Model too large for one GPUModel parallelism (tensor, pipeline, sharded)
Weeks-long FM training with automatic recoverySageMaker HyperPod
Encrypt traffic between nodesInter-container traffic encryption
True or false

SageMaker HyperPod

Exam skills 2.2.4 · 3.1.1

Check when SageMaker HyperPod suits a training workload.

Log in to try this activity Interactive activities are free with an account.
Worked example

Choosing a strategy

Two jobs need speeding up. Job 1 fine-tunes a 300-million-parameter vision model on 50 million images. Job 2 fine-tunes a 70-billion-parameter language model whose weights alone exceed one GPU's memory.

JobStrategyReason
Job 1Data parallel across 4 instances of 8 GPUsModel fits; data is the bottleneck
Job 2Sharded data parallel plus tensor parallelism on HyperPod or training jobs, or LoRA to reduce memoryModel does not fit on one GPU

Applying data parallelism to Job 2 would fail with out-of-memory errors, because each GPU must hold a full model copy.

Check yourself

Which strategy suits a model too large for one GPU?

Show answer

Model parallelism or sharded data parallelism. Data parallelism suits a model that fits on one GPU with large data.

Exam Tips

Remember for the exam

  • Model fits on one GPU, large data: data parallelism.
  • Model too large for one GPU: model parallelism or sharded data parallelism.
  • Data parallelism increases effective batch size; adjust the learning rate.
  • Long-running large-scale training with automatic node recovery: SageMaker HyperPod.
  • Encrypt inter-node traffic when data is sensitive.