← 返回 microsoft 的题目列表Implement a resumable data loader
类型:online_judge
Coding: Implement a resumable DataLoader
Implement an iterable ResumableDataLoader that yields batches and can resume exactly from a checkpoint after interruption.
Requirements
Constructor arguments:
data: a random-access sequence of length N.
batch_size: positive integer.
shuffle: boolean; if True, each epoch must iterate in a reproducible shuffled order determined by seed.
seed: integer RNG seed for reproducible shuffling.
Iteration:
Each iteration yields a batch (Python list).
The last batch may be smaller than batch_size.
Checkpointing:
state_dict() returns a JSON-serializable object containing the minimal state needed to resume.
load_state_dict(state) restores state so the next iteration continues exactly where it left off.
Epoch semantics:
After all N samples are consumed, the epoch ends; subsequent iteration continues to the next epoch.
If shuffle=True, each epoch has a different but reproducible order (e.g., permutation derived from seed and epoch).
I/O for this exercise (stdin/stdout)
Input:
Line 1: N batch_size shuffle seed
Line 2: N integers (data values)
Line 3: steps_before_ckpt (#batches to emit before checkpoint)
Line 4: steps_after_resume (#batches to emit after resume)
Output:
Emit batches before checkpoint, one per line
Then a line ---
Then emit batches after resuming, one per line
Constraints
1 <= N <= 2e5, 1 <= batch_size <= 1024
Preprocessing O(N) or less; resume should be O(1) or linear in batch size.
Example
Input:
10 4 0 42
0 1 2 3 4 5 6 7 8 9
2
2
Output:
0 1 2 3
4 5 6 7
---
8 9
0 1 2 3
Example
Input
10 4 0 42
0 1 2 3 4 5 6 7 8 9
2
2
Output
0 1 2 3
4 5 6 7
---
8 9
0 1 2 3