Model and Inference EngineeringTraining data and objectivesPrincipal
When can out-of-order data loading change the training mixture rather than only throughput?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A text/code training job enables delivery from whichever loader worker finishes first. Code examples are slower to fetch, and the run stops at a fixed optimizer-step budget. Design a consumed-data trace, identify the boundary that can underrepresent slow examples, and preserve throughput without losing scheduled-but-unconsumed work on restart.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Imagine a mixed text and code training job. Code records take longer to fetch and tokenize. To keep GPUs busy, the team lets whichever worker finishes first deliver the next batch. That can be a good throughput choice, but now completion time helps decide which samples arrive early. If training stops after a fixed number of steps, restarts often, or draws a fresh prefetch queue every epoch boundary, slow records can be underrepresented among consumed tokens even though the source manifest has the right mixture. PyTorch's DataLoader documentation warns that in_order=False can harm reproducibility and skew the data fed to the trainer when the input is imbalanced. The exact bias in this scenario needs measurement.
I would count consumed sample IDs and tokens by source, length and processing-time bucket, not just queued or scheduled examples. Record enqueue, worker finish, batch consumption and drop or cancellation events for a small run. Compare the expected manifest distribution with the first N optimizer steps under ordered and unordered loading. If all records are eventually consumed exactly once before a full epoch finishes, reordering alone changes sequence order but does not necessarily change the epoch's final counts. It can still affect training dynamics. The stronger mixture bias needs a stop, truncation, retry or queue-reset boundary that actually discards or postpones slow samples.
A tiny fixture with one example consumed per update can schedule T1, C1, T2, C2, with T items fast and C items slow. An ordered loader’s first two consumed examples are T1 and C1. An unordered loader can deliver T1 and T2 first, so a two-step stop consumes no code. If all four are eventually consumed once, the full-epoch counts are again balanced. The stop boundary converts a timing difference into sample selection in this example.
Checkpoint accounting must use the realized consumption boundary. A prefetch cursor may already have scheduled C1 and C2 without the optimizer consuming them. Saving only that advanced cursor can skip those records on resume. Restarting the schedule from an earlier point can repeat fast records. Record consumed IDs or an equivalent deterministic schedule position with the pending-work protocol, and test crash recovery against the expected stream.
To keep the speedup, assign a deterministic sample schedule and bound out-of-order completion, or account for completed-but-not-consumed records across checkpoints. Persist sampler position and pending work consistently. Another option is to balance preprocessing costs across workers or pretokenize the expensive slice. Verify both achieved throughput and token mix on a fixed training budget, then compare evaluation on the slice that was previously delayed.
"But the random seed is fixed" is not enough. The seed can fix which samples were scheduled while worker timing decides which ones the optimizer saw before the stop. Every training rank has a different shard. Why are its random augmentations identical? is about identical augmentation randomness across ranks. This one is about the delivered training distribution when loader completion order becomes part of the selection process.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux