← Microsoft Interview Insights
This one is trickier than it looks because saving 'current index' is not enough.
Start by clarifying requirements and assumptions, then propose a design that separates the permutation generation, index tracking, and RNG state management. Explain how to checkpoint and restore these components, and discuss multi-worker and multi-epoch correctness with deterministic replay.
Pro tip: Emphasize that determinism requires controlling all sources of randomness (e.g., shuffling, worker seeding) and that checkpointing must capture the exact state of the permutation and RNG, not just the current index. Mention that using a seeded RNG and storing the seed plus the number of random draws is a robust approach.
Ask about dataset size, shuffling strategy, multi-worker setup, and whether exact determinism is required across different hardware. Confirm that checkpointing should be lightweight and portable.
Propose a DataLoader that maintains a permutation array, a current index, and an RNG state. Use a seeded RNG to generate the permutation and to seed workers. For multi-worker, assign each worker a disjoint subset of indices.
Checkpoint the permutation (or the seed and epoch number), current index, and RNG state. On restore, recreate the permutation and RNG, and fast-forward the index. Ensure the checkpoint is serializable and versioned.
Guarantee that given the same checkpoint, the sequence of batches is identical. This requires deterministic worker seeding, consistent data ordering, and no reliance on non-deterministic operations.
For multi-worker, use a shared seed and worker-specific offsets to avoid overlap. For multi-epoch, reshuffle at each epoch using a deterministic seed derived from the base seed and epoch number. Discuss trade-offs between storing full permutation vs. regenerating from seed.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.