KatInterview

Debugging an Input-Starved Training Pipeline

Machine LearningModel answer
MediumModel answerMachine Learningdata-loadinggpu-utilizationperformance

Last updated

Diagnose stalled GPU utilization across storage, CPU transforms, and transfer, then design a bounded, reproducible prefetch pipeline.

Context

You own a training job that is technically running, but the accelerators sit idle for a large fraction of each step. Loss curves are noisy, wall-clock time per epoch is far above the estimate, and monitoring shows the GPUs finish their math quickly and then wait for the next batch. Nobody has changed the model recently — the suspicion is that the input pipeline is the bottleneck.

Your Task

Walk through how you would (a) determine where the time actually goes and (b) restructure the data-loading path so that the compute devices stay fed. You are not tied to any particular framework, storage backend, or dataset format.

Constraints and Assumptions

  • Data lives somewhere you must reason about: local SSD, network filesystem, or object storage; the reader cannot assume it is already in page cache.
  • Per-example transformations (decode, resize, augment, tokenize — whichever apply) are CPU-bound and must preserve their current semantics.
  • Batch shapes may vary (variable sequence length, ragged images), so padding and bucketing are in scope.
  • The job may be single-node or multi-worker distributed; sharding must not duplicate or drop samples.
  • Reproducibility matters: same seed plus same config must yield the same sample order and the same augmentation draws, including after a mid-epoch restart.
  • No correctness trade-offs are allowed: no skipping transforms, no silent dropping of the tail batch, no reshuffling that leaks examples across workers.

What Is Expected

  1. A measurement plan that separates the candidate causes rather than guessing.
  2. A prioritized set of fixes with the reasoning behind each, and where each one stops helping.
  3. A short statement of how you would verify both throughput gain and unchanged data semantics.

Hints

Hint 1

Before changing anything, instrument: log time spent per stage (fetch, decode, transform, collate, host-to-device copy) and compare device busy time to step time — let the numbers pick the bottleneck.

Hint 2

An idle GPU usually means the queue in front of it is empty or out of order. Adding a bounded prefetch queue with enough workers to cover transform latency fixes more cases than any single micro-optimization.

Hint 3

The classic regressions from speeding up loading are per-worker random seeds colliding (identical augmentations across workers), sharding off-by-one dropping the last partial shard, and a restart that re-reads a different epoch. Build checks for all three.