Curriculum / Part 3 · How AI workloads use storage
Lesson 12

Training data loading

How training jobs read data: loader workers, prefetching, shuffling, and why millions of small files starve GPUs while shards keep them busy.

⏱ 40 min5-question quizLab 3.1

The simple version

Imagine feeding a hungry crowd one grape at a time, where every grape is in its own tiny box that must be found, opened and thrown away. Even with lots of helpers, most of the time goes on boxes, not grapes. Put the grapes in big crates instead and a few helpers keep everyone fed.

The data loader

Frameworks read data in background workers while the GPU computes. In PyTorch, DataLoader(num_workers=…, pin_memory=True, prefetch_factor=…) controls how many worker processes read and decode samples, whether batches go into page-locked memory for faster host-to-GPU copies, and how many batches each worker prepares ahead.

step time ≈ max(GPU compute time, data time)

Loading overlaps with compute. If the loader needs 0.82 s per step and compute needs 0.40 s, the GPUs sit idle about half the time: 0.40 ÷ 0.82 ≈ 49% busy.

How much data does training need?

bytes/s = GPUs × samples/s per GPU × bytes per sample

Example (stated assumptions): 8 GPUs × 2,500 images/s each × 110 KiB ≈ 2.3 GB/s per node. Modest bandwidth. But it is also 20,000 file opens per second per node. Across 128 nodes that is 2.56 million opens per second hitting the filesystem's metadata service.

That second number is usually the problem. Small files turn a bandwidth problem into a metadata problem (Lesson 19).

Shards and shuffling

Packing samples into large archive shards (for example tar files of a few hundred MB, the approach WebDataset popularised) turns millions of opens into a few long sequential reads. Randomness is kept by shuffling the order of shards and mixing samples in an in-memory shuffle buffer, rather than seeking to random files.

One file per sampleShards
Opens per epochOne per sample (millions)One per shard (thousands)
Read patternSmall random readsLarge sequential reads
ShufflePer-sample, exactShard order + shuffle buffer (approximate)
BottleneckMetadata service, IOPSBandwidth

Proving the GPUs are waiting

Watch GPU activity with nvidia-smi dmon -s u (the sm column is streaming-multiprocessor utilisation). A saw-tooth or consistently low value while the framework reports long "data" time means the loader, not the model, is the limit. Profilers in the training framework can split step time into data wait and compute.

Tools

nvidia-smi dmon -s u
Per-second GPU utilisation; idle gaps often mean data waits.
lfs df -i
Inode/metadata capacity on Lustre MDTs and OSTs.
simtrain (simulator only)
Modelled training harness in the Storage School lab: data time vs compute.

Quiz

Lab

Lab 3.1 · Starved dataloader

A vision model trains from /lustre/datasets/imagenet-raw: 1.28 million JPEGs averaging 110 KiB. nvidia-smi shows the GPUs mostly idle. The same images also exist as 1,024 tar shards in /lustre/datasets/imagenet-shards.

Start lab 3.1 →

Try it now in the simulator (opens with the command ready; press Enter):

$ simtrain --data /lustre/datasets/imagenet-raw$ simtrain --data /lustre/datasets/imagenet-shards