DL0248 Dataloader Bottleneck Triage

Training GPUs sit at 30% utilization. Walk me through how you localize the data-pipeline bottleneck: what do you check, and in what order?

A three-panel question card. The first panel describes the training job: eight A100 GPUs and 64 CPU cores, ResNet-50 at batch 256 per GPU, 1.28 million JPEGs of about 110 KB each on shared NFS with a measured 2.5 GB/s ceiling, and PIL decode, random crop, flip and normalize running on the CPU. The second panel shows a GPU kernel timeline of three steps with short busy blocks and long idle gaps, nvidia-smi reporting 30 percent on all eight GPUs, and a step time of 0.32 seconds or 800 images per second per GPU. The third panel lists five suspects with their current settings: num_workers 4, pin_memory False, JPEG decode and augment on CPU, prefetch_factor at the default of 2, and NFS I/O wait not measured, plus a teammate's suggestion to just set num_workers to 64.

The Problem: An image team trains ResNet-50 on 8 A100s at batch 256 per GPU, reading 1.28M JPEGs from shared NFS with num_workers=4 and pin_memory=False, and every GPU reports 30% utilization with 0.32 s steps. A teammate wants to set num_workers=64, and you have to say which of the five suspects to check first and in what order.

Answer

Low utilization is a symptom, so the first check is whether the input pipeline causes it at all. Replay one batch that already sits on the GPU in a loop: if utilization jumps to about 95%, the loader is guilty, and if it stays near 30% the cause is a host sync point, a small batch, or communication. Next compare two rates, the loader’s throughput measured alone with no model and the GPU’s demand of batch size over synthetic step time, which tells you exactly how much speedup you need. Then sweep num_workers while watching CPU state, because the resource that saturates names the bottleneck. Workers pinned at 100% user CPU mean decode or augmentation is CPU-bound, workers blocked in I/O wait mean storage, and a single busy main process means collate or host-side work. Only after that do you tune the overlap plumbing (pin_memory with non_blocking copies, prefetch_factor, persistent_workers), whose signatures are periodic stalls rather than a uniform slowdown.

(1) Prove It Is The Loader: A synthetic-batch replay splits the hypothesis space in one run, separating data starvation from sync points, launch overhead, and collective communication.
(2) Measure Rates, Not Utilization: nvidia-smi utilization is the sampled fraction of time any kernel runs, not SM occupancy. Log per-step data-wait time and compare loader-only throughput with the GPU’s demand.
(3) Scale Workers To The Core Budget: Sweep num_workers and watch throughput rise linearly, then flatten. Under DDP every rank owns its own loader, so the ceiling is cores per GPU minus one, and going past it oversubscribes the CPU.
(4) Read The CPU State: 100% user CPU points to decode or augmentation, high %iowait with workers in the D state points to storage, and one saturated main process points to collate or the pin-memory thread.
(5) Break Down Per-Sample Cost: Time read, decode, augment, and collate inside one worker. JPEG decode usually dominates, so pre-resized storage, GPU decode, or shipping uint8 beats adding processes.
(6) Tune Overlap Last And Re-Measure: pin_memory, prefetch depth, and persistent workers fix stalls only after capacity matches demand, and the binding constraint moves after every fix.

Mathematical Formulation:
R_{need} = B / t_{gpu}
R_{cpu} = W / t_{cpu}
R_{io} = BW_{io} / (G \cdot s)
R_{load} = \min(R_{cpu}, R_{io})
U \approx \min(1, R_{load} / R_{need})
f_{wait} = t_{wait} / t_{step}

Where:

  • R_{need} is the per-GPU sample rate the model consumes, B is the per-GPU batch size, and t_{gpu} is the step time measured with a GPU-resident synthetic batch.
  • R_{cpu} is the worker-limited rate, with W workers per GPU rank and t_{cpu} the per-sample CPU time summed over read, decode, augment, and the collate share.
  • R_{io} is the storage-limited rate, where BW_{io} is measured storage bandwidth shared by the G GPUs on the node and s is the mean bytes per sample.
  • R_{load} is the delivered loader rate and U the implied utilization, assuming prefetching fully overlaps loading with compute so only the slowest stage matters.
  • f_{wait} is the fraction of each step spent blocked waiting for the next batch, with t_{step} \approx t_{wait} + t_{gpu} when the loader is the bottleneck.

Worked Triage Example (8 GPUs, 64 cores, NFS at 2.5 GB/s):
R_{need} = 256 / 0.10\ \text{s} = 2560\ \text{img/s}
R_{cpu} = 4 / 5.0\ \text{ms} = 800\ \text{img/s}
U \approx 800 / 2560 = 0.31
t_{cpu} = 0.4 + 3.1 + 1.2 + 0.3 = 5.0\ \text{ms}
R_{cpu}(W{=}7) = 7 / 5.0\ \text{ms} = 1400\ \text{img/s}
t_{cpu}' = 0.4 + 1.2 + 0.9 = 2.5\ \text{ms}
R_{cpu}' = 7 / 2.5\ \text{ms} = 2800\ \text{img/s}
R_{io} = 2.5\ \text{GB/s} / (8 \cdot 110\ \text{KB}) = 2841\ \text{img/s}

The synthetic replay runs a step in 0.10 s, so each GPU needs 2,560 img/s. Iterating the loader alone gives 800 img/s, which reproduces the observed 0.32 s step exactly (256 / 800), so the loader is confirmed as the cause. htop shows the workers at 100% user CPU with almost no iowait, and a per-stage timer splits the 5.0 ms per image into 0.4 ms read, 3.1 ms decode, 1.2 ms crop and flip, and 0.3 ms normalize. Raising workers to the core budget of 7 per rank (64 cores across 8 ranks, one core kept for each training process) only reaches 1,400 img/s, about 55%. Storing pre-resized JPEGs cuts decode to 1.2 ms and cropping to 0.9 ms, and normalizing on the GPU removes the last 0.3 ms, which lifts capacity to 2,800 img/s and makes the job GPU-bound. NFS serves only 0.70 GB/s today, but at full speed full-size files would need 2.25 GB/s, 90% of the ceiling, so storage becomes the next constraint unless the smaller pre-resized files restore headroom.

Line chart of loader throughput per GPU against num_workers per GPU rank from 1 to 16. The current pipeline at 5.0 ms per sample rises linearly by 200 images per second per worker to 1,400 at the core budget of 7 workers and then declines slowly as workers oversubscribe the CPU. The fixed pipeline at 2.5 ms per sample rises by 400 per worker to 2,800 at 7 workers, above the dashed GPU demand line at 2,560 and just below the dotted NFS ceiling at 2,841. Markers and annotations show today's point at 4 workers and 800 images per second, about 31 percent, the core-budget point at 1,400 and about 55 percent, and the fixed capacity of 2,800. A right axis shows implied GPU utilization in percent.

Figure 1: Loader capacity per GPU as num_workers grows on the 64-core, 8-GPU node. Today’s 5.0 ms/sample pipeline scales linearly only up to the core budget of 7 workers, stalls at 1,400 img/s (about 55%), and loses throughput when oversubscribed. Only cutting per-sample cost to 2.5 ms lifts capacity above the 2,560 img/s GPU demand, and it lands just under the 2,841 img/s NFS ceiling.

Storage deserves its own check even when the CPU picture looks clear. It is the suspect when workers sit in the D (uninterruptible I/O) state with high %iowait and low user CPU, or when epoch 2 runs much faster than epoch 1 because the page cache now holds the files. On shared filesystems the limit is often metadata operations per second rather than bytes, which is why millions of 110 KB files hurt more than their total size suggests and why sharding them into large sequential files helps. The overlap plumbing comes last because its failures look like periodic stalls. pin_memory=True stages batches in page-locked host memory so .to(device, non_blocking=True) overlaps with compute, and shipping uint8 instead of fp32 shrinks a 256-image batch from 154 MB to 38.5 MB. prefetch_factor (default 2 batches per worker) absorbs bursty sample costs, and persistent_workers=True stops the DataLoader from tearing down and respawning every worker at each epoch boundary.

Five horizontal GPU kernel timelines over three seconds. Row a, loader too slow: short busy blocks separated by long idle gaps every step, 31 percent busy. Row b, loader keeps ahead: nearly continuous busy blocks, 95 percent busy. Row c, prefetch queue drains: continuous busy blocks with an isolated stall every seventh step. Row d, epoch boundary: continuous busy blocks with one long 0.7 second gap where workers respawn. Row e, host sync point: regular small gaps every step that remain at 71 percent busy even with synthetic data.

Figure 2: Timeline shapes from a profiler trace name different causes. A gap every step (a) means the loader is too slow, an isolated stall every few steps (c) means the prefetch queue drains on slow samples, a long gap at each epoch start (d) means workers are respawned, and gaps that survive synthetic data (e) are host sync points rather than the loader.

The table below maps each observable signal to its diagnosis, the measurement that confirms it, and the fix that matches it. Reading it top to bottom is the triage order, because each row is cheap to test and rules out a whole branch before the next one.

Observed signalLikely causeConfirming checkMatching fix
Synthetic replay still near 30%Not the loader: sync points, small batch, launch overhead, collectivesProfiler shows stream synchronizes from .item() or .cpu() between stepsRemove host syncs, larger batch, CUDA graphs, overlap communication
Throughput scales with workers, cores idleToo few workers (num_workers=0 loads in the main process)Loader-only sweep over 2, 4, 8 workers per rankRaise to cores per GPU minus one, never beyond
All workers at 100% user CPUDecode or augmentation is CPU-boundPer-stage timer in one worker; decode dominatesPre-resize offline, GPU decode, uint8 transfer with GPU normalize
Workers in D state, high %iowaitStorage bandwidth or metadata rateiostat await, NFS ops per second, epoch 1 vs epoch 2 speedShard into large files, stage to local NVMe, larger reads
Main process at 100%, workers idleHeavy collate_fn or host-side batch workpy-spy dump of the training processMove work into workers, simplify collate
Stall every k steps or at epoch startPrefetch queue drains, or workers respawnGPU timeline shape in Nsight Systems or torch.profilerRaise prefetch_factor, set persistent_workers=True
Pageable HtoD copy blocks each stepNo pinned memory, fp32 batches on the hostProfiler shows Memcpy HtoD (Pageable) on the critical pathpin_memory=True with non_blocking=True, ship uint8

Login to view more content
Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *