Lesson 4 of 5 Training Models with SageMaker AI

Reducing Training Time

This lesson explains how early stopping, distributed training and other techniques shorten training, which lowers cost, shortens experiment cycles and makes frequent retraining practical.

Learning outcomes

After completing this lesson, you will be able to:

  • Apply early stopping with a patience setting.
  • Speed up data loading and compute.
  • Profile training jobs to find bottlenecks before adding hardware.

Early stopping

Early stopping ends training when the validation metric has not improved for a set number of epochs or boosting rounds, called the patience, and keeps the best model seen so far. It saves compute, because training does not continue after the model stops improving, and it also reduces overfitting, because training stops before the model starts memorising the training data.

XGBoost supports early_stopping_rounds, and deep learning frameworks offer early stopping callbacks. At a higher level, SageMaker automatic model tuning can stop whole training jobs that are unlikely to beat the best result so far.

True or false

Early stopping

Exam skills 2.2.4 · 2.2.5

Check how early stopping works.

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

Faster data and compute

Training is often limited by data loading rather than computation. FastFile and Pipe modes start training without copying the dataset; FSx for Lustre delivers high throughput; sharded files and parallel data loaders keep GPUs busy. On the compute side, mixed precision (16-bit floating point with 32-bit master weights) speeds up training on modern GPUs; larger batches use accelerators more fully; and newer instance types such as p5 or Trainium (trn1) may finish faster and cheaper overall.

Sort into groups

Data or compute bottleneck?

Exam skills 2.2.4

Decide whether each fix speeds up data loading or the computation itself.

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

Profiling to find bottlenecks

Before adding hardware to a slow training job, it is worth finding out what limits it. SageMaker Profiler and SageMaker Debugger system monitoring show GPU, CPU, memory and I/O utilisation throughout training. Low GPU utilisation with high I/O wait indicates a data bottleneck: the GPUs wait for data, and faster input, such as Pipe mode, FSx for Lustre or more data-loading workers, is the fix.

High CPU usage in data loading suggests moving augmentation onto the GPUs or adding loader workers. Profiling should come before scaling out, because adding instances to a job limited by I/O adds cost without making it faster. The following table summarises the techniques.

TechniqueReduces time by
Early stoppingEnding training when validation stops improving
FastFile / Pipe modeRemoving dataset download before training
FSx for Lustre, sharded filesFaster data reads
Mixed precisionFaster math on GPUs
Distributed trainingSpreading work across GPUs and instances
Warm poolsRemoving instance start-up between jobs
ProfilingFinding the real bottleneck first

The following diagram compares the duration of a computer vision training job before and after changes to stopping, data loading and precision.

The vision job before and after. Profiling shows GPUs at 35% and validation accuracy flat after epoch 40, so early stopping with patience 5 ends training near epoch 45, FSx for Lustre and more data loader workers raise GPU utilisation to 85%, and mixed precision speeds the maths. The job falls from 30 hours to about 6.
Bar lengths are proportional to hours.
Worked example

A 30-hour job

A vision model trains for 30 hours on one ml.p4d.24xlarge (8 GPUs). Profiling shows GPU utilisation at 35% and validation accuracy stops improving after epoch 40 of 100.

  • Add early stopping with patience 5: training ends near epoch 45, saving more than half the epochs.
  • Move data to FSx for Lustre and use more data loader workers: GPU utilisation rises to 85%.
  • Enable mixed precision for further speed.

The job now takes about 6 hours. Adding a second p4d instance first would have doubled cost while the GPUs still waited on data.

Check yourself

What does low GPU utilisation during training often indicate?

Show answer

An input bottleneck: the GPU waits for data. Profiling confirms it.

Exam Tips

Remember for the exam

  • Stop when validation stops improving: early stopping.
  • Profile first; low GPU utilisation often means an I/O bottleneck.
  • FastFile, Pipe mode and FSx for Lustre speed up data loading.
  • Mixed precision speeds up GPU training.
  • Scaling out does not fix an I/O-bound job.