Unit 7 of 14 · about 3 hours · measure

Data loader, storage and host-transfer bottlenecks

An idle accelerator is often a starved one. This unit proves the feed path before touching kernels or collectives.

You'll be able to

  • Separate input starvation from compute and communication bounds with loader and transfer evidence.
  • Tune workers, pinned memory and prefetch from a measured loader sweep, not defaults.
  • Distinguish storage throughput limits from host-transfer and preprocessing limits.

Covers

Data-loader, storage and host-transfer bottlenecks
1

Read

In this order, only the parts listed

0 of 3 done

  1. Data pipeline tuning and diagnosisAI Systems Performance Engineering - Chapters 1 to 5, 13 and 14

    Chapter 5, GPU-Based Storage I/O Optimizations, section Tuning the Data Pipeline, with Efficient Data Loading and Preprocessing, Scaling Out Workers as You Scale Out Number of GPUs, and Diagnosing Communication- Versus Compute-Bound Workloads

  2. Asynchronous DataLoader tuningMachine Learning Engineering Open Book - Network, Debug, Training Performance and Orchestration

    DataLoader section with num_workers, pinned memory and non_blocking device copy, plus the num-workers-bench.py and pin-memory-non-block-bench.py results

  3. Storage benchmarking for trainingMachine Learning Engineering Open Book - Network, Debug, Training Performance and Orchestration

    Benchmarks section with fio for throughput, IOPS and latency, and DLIO for the training-like I/O pattern without accelerators

2

Focus on

  • With num_workers=0 the accelerator blocks on fetch and transforms. Sweep workers and watch iteration time plus CPU saturation; two workers often suffice and more can hang dual loaders.
  • pin_memory=True with non_blocking=True plus prefetch hides host-to-device transfer. Measure with and without: a nonblocking copy from pageable memory buys nothing, pinned memory alone keeps most of the gain, and the pair is best.
  • Sequential versus random reads, local NVMe versus shared filesystem, and preprocessing on CPU versus GPU are different limits. fio tests the device; DLIO tests the training pattern.
Common mistakes · 3
  • Adding workers until the problem disappears. Dual-loader hangs and diminishing returns need a measured optimum, not a maximum.
  • Setting pin_memory=True without non_blocking=True. Pinned staging without asynchronous copy still blocks the transfer.
  • Blaming the interconnect for storage starvation. A slow filesystem or random-read pattern starves every rank identically.
3

Try it yourself

Closed-book, before checking anything

From a blank file, sweep num_workers from 0 to 4 on a synthetic transform-bound loader, plot mean iteration time with pin_memory on and off, and name the count where the curve flattens with CPU saturation as evidence.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Iteration time falls from 5.4 s to 0.8 s as workers go 0 to 3, then stalls. What do you conclude?Answer

    Input was the bound up to 3 workers, then compute or another stage dominates. Adding a fourth worker buys nothing; confirm with CPU saturation and trace attribution.

  2. 2.Why pair pin_memory with non_blocking?Answer

    Pinned memory lets the copy run as DMA from page-locked memory, which is faster, and non_blocking=True lets it overlap compute. A nonblocking copy from pageable memory is still a staged synchronous copy, and pinned memory alone speeds the copy but still blocks.

  3. 3.When does fio mislead about training input?Answer

    When the pattern differs: fio reports device throughput and IOPS, while training does small random reads with preprocessing. DLIO emulates the loader pattern.

5

Practice

  • Stas Bekman DataLoader benches: num-workers-bench and pin-memory-non-block-bench

    Run num-workers-bench.py with 0 to 4 workers and pin-memory-non-block-bench.py with and without pinned async copy; report iteration times with hardware and PyTorch version

    Both scripts need CUDA as written: they time with CUDA events and move batches to cuda:0. On a CPU-only machine, port the num_workers sweep to time.perf_counter first; the pinned-memory comparison needs a GPU. Treat the 5.4 to 0.8 s fall as the guide's example, not your target.

You're done when

Your loader sweep names the bound (workers, transfer or storage) with iteration times and CPU evidence, and the chosen settings survive a repeat run.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 9 more in the section
  • AI Systems Performance Engineering - Chapters 1 to 5, 13 and 14Chris Fregly (O'Reilly) · required

    Use Chapter 1 for goodput and reproducibility, Chapters 2 to 5 for topology, orchestration, communication, storage and the data pipeline, Chapter 13 for PyTorch profiling and scaling, and the Chapter 14 sections on graph breaks and recompilation. Run only the companion labs for the bottleneck you observe, preserve workload correctness and record hardware assumptions.

  • Machine Learning Engineering Open Book - Network, Debug, Training Performance and OrchestrationStas Bekman · required

    Use network/debug/README.md, the hang, crash and OOM sections of debug/pytorch.md, training/performance/README.md, storage/README.md and orchestration/slurm/users.md as an incident-driven reference. Build one symptom-to-evidence-to-cause runbook rather than reading every page.

Also in this section

  • Machine Learning Systems Volume II - Fleet Orchestration and Performance EngineeringML Systems Textbook · primary

    Read Scheduling Problem, Orchestration Paradigms, Topology-Aware Scheduling, Elastic Scheduling, Cost Optimization, Multi-Tenancy and Quotas and Debugging Cluster Utilization, then Memory Wall and Roofline Diagnosis, Graph Compilation, Communication-Computation Overlap, System Profiling and Measurement at Scale at https://mlsysbook.ai/vol2/performance_engineering/performance_engineering.html. Use the framework to choose one bottleneck-specific lab and one rollback metric.

  • PyTorch Flight Recorder TutorialsPyTorch · support

    Read the environment-variable Flight Recorder tutorial (trace buffer, dump on timeout, fr_trace analysis), then the newer tutorial at https://docs.pytorch.org/tutorials/intermediate/debug_hangs_with_flight_recorder.html, which needs torchcomms and can run on CPU with Gloo. Diagnose one injected hang from per-rank dumps.

  • MegaScale: Scaling Large Language Model Training to More Than 10,000 GPUsJiang et al. (NSDI 2024) · support

    Read the efficiency optimizations, the fault-tolerance loop (heartbeats, diagnostics, fast restart) and the straggler and diagnosis tooling. Its MFU and scale numbers are its own cluster's results.

  • Revisiting Reliability in Large-Scale Machine Learning Research ClustersKokolis et al. (2024) · support

    Read the failure taxonomy, mean time to failure versus job size and the scheduler-side metrics. Use them to model goodput with failures for one job size.

  • How to Scale Your Model - Chapters 1, 5, 9 and 12Google DeepMind · required

    Use rooflines, training cost models, profiling workflow and GPU topology to predict the dominant limit of one run. Compare the prediction with a trace and quantify the residual before proposing a change.

  • CS336 Assignment 2 (Spring 2026) - Profiling and Parallelism AnalysisStanford University · required

    Revisit Section 2 profiling and Section 8 communication analysis. Produce warmup-controlled timing, Nsight or PyTorch traces, memory evidence and analytic DP, FSDP, TP and 2D comparisons on configurations you can execute honestly.

  • Ultra-Scale Playbook - Benchmarking ConfigurationsHugging Face · support

    Study the configuration-search experiments and Lessons learned on benchmarking as method. Its heatmaps are its own H100 cluster's results; reproduce the method on a tiny legal search space, separating analytic predictions, simulations and measurements.

  • TorchTitanPyTorch · depth

    Read docs/debugging.md (memory snapshots, fake-backend modes, Flight Recorder dumps) and the CPU unit tests under tests/unit_tests/cpu/, then the configuration, metrics, profiling, checkpoint and parallelization seams at a pinned commit. Select one bounded issue or measurable improvement and follow the contribution standards; do not attempt a wholesale rewrite.

  • Distributed Training Systems LaboratoryRoadmap-Final · support

    Complete the capstone with a fixed workload, correctness oracle, analytic plan, fault campaign, aligned traces and one real-code extension. Label CPU simulation, single-GPU evidence and multi-GPU evidence separately.