Restart from a consistent model and input boundary
Capture traversal, shuffle, random, and buffered state together with the training checkpoint so restart neither skips prefetched work nor invents an exact replay guarantee.
On this page
The question for today
What you’ll understand
- Distinguish the next source read from the next unconsumed training occurrence.
- Enumerate the state required for the declared replay contract.
- Explain topology and version limits in loader restoration.
A model checkpoint represents ten completed batches, but its saved data cursor points two batches farther ahead because workers were prefetching. Restarting at that cursor skips data the restored model never learned from. Saving an epoch number and initial seed is also insufficient for many shuffled, stateful pipelines. The checkpoint must describe a consistent relationship between model state and the remaining occurrence stream, including whatever buffered or random state is necessary to reproduce that relationship under the supported restart conditions.
Define the committed consumer boundary
Specify what a training checkpoint means: completed optimizer steps, gradient-accumulation progress, relevant scheduler state, and the input occurrences represented by that saved model state. A source read cursor can be ahead because of prefetch or asynchronous transforms. A delivered batch can also be pending accumulation rather than included in a completed optimizer update. Decide whether to save those pending tensors and states or replay them from an earlier consistent boundary. A local integer called step is meaningful only with its batch and rank interpretation, especially when multiple ranks contribute to one update.
For a deterministic index stream, one recovery design saves the consumed position and reconstructs later work through deterministic replay. Another saves the source cursor plus all buffered, shuffled, and in-flight state needed to emit the same next occurrence. Both need a documented contract. Advancing only the source cursor while discarding its prefetched records creates a gap. Rewinding input while retaining later model effects can create repeated updates. Coordinate checkpoint publication so a restart cannot accidentally pair a newer input snapshot with an older model file or a partially written state bundle.
A seed is not the current random state
A shuffle buffer contains a particular set and order of pending records after a particular number of draws. The initial seed describes how a random process starts, not necessarily its current state or the records already consumed. Stateful transforms may use several libraries' RNGs, and worker scheduling can change which state produces which sample. Capture the required state or use a supported stateless occurrence-based transformation contract. Exact replay may also require deterministic source listing, fixed inputs, and compatible algorithm versions. Do not promise identical model results merely because the input order replays; compute kernels have their own reproducibility limits.
TorchData 0.11.0 StatefulDataLoader documents state_dict and load_state_dict, custom sampler and dataset hooks, and aggregation across local worker processes rather than training ranks. Its iterable-state examples require the same worker count on restore. Default fast-forward behavior and custom efficient state restoration have different costs and guarantees. A topology change therefore needs an explicitly supported repartitioning strategy or a restart policy rather than blind reuse of local worker cursors. Test the exact loader, dataset, transforms, and version combination used by the experiment; API availability is not proof that every custom stateful operation is captured.
Verify replay with identities and a small restart test
Run an identifiable short experiment, save at a known boundary, record the next sequence of occurrence identities and transform outputs, then restore and compare under the declared topology. Include a nonempty shuffle buffer and nonzero prefetch so the test exercises the difficult state. Check dataset and tokenizer versions and reject incompatible restores explicitly. Record whether the goal is exact next-occurrence replay, bounded repetition, or a fresh epoch; these are different accepted behaviors. Measure restart cost as well, since fast-forwarding a large remote stream can be correct but operationally expensive.
The modular lab demonstrates why one displayed state can omit execution history. Reset, set both modulus m=8 and step a=3, predict residues after three and eleven additions, then Step. Both positions have residue one because the orbit repeats every eight additions. This exact additive process is not a loader checkpoint or RNG. It illustrates that saving only the visible residue cannot distinguish those histories. A real checkpoint must retain enough traversal and random state for its next-output contract, rather than assume a short label or epoch counter encodes the full pending stream.
Work it through
Do not skip the prefetched gap
A fictional single-rank deterministic traversal uses forty samples per batch. Its saved model state includes ten complete batches, or 400 consumed occurrences. The reader has already fetched through occurrence 480. Index occurrences from one, and assume no partial gradient accumulation.
The committed consumer boundary is 400, so the next required occurrence after restoring that model is 401.
The source read-ahead gap is 480−400=80 occurrences, equal to two batches. Restarting a bare source cursor after 480 while discarding those buffered occurrences skips them.
Restore the pending 401–480 state together with the reader cursor, or reconstruct from the consumed boundary using the supported deterministic replay design. Keep that input state paired with the same saved model boundary.
The checkpoint must preserve or reconstruct the eighty read-ahead occurrences. The reader cursor alone points past work absent from the restored model.
The living notebook
Explore the model
Interactive lab · modular
The same visible label can hide different histories
Reset, set both m=8 and step a=3, predict, then Step through three and eleven additions. Both residues are 1; the period is 8. This is an exact additive orbit, not a checkpoint serializer, sampler, or RNG-state simulation.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA short visible state can be ambiguous. Preserve the actual traversal, pending-buffer, random, and topology state required by the supported restart contract.
Pause & reason
Check your understanding
Your turn
Try it yourself
A fixed traversal checkpoint represents 300 consumed occurrences. Its source reader has fetched through 360, using batches of twenty. What is the read-ahead gap, and which occurrence should come next after restoring the saved model?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute the gap independently of the cursor chosen for storage.
Compare with the solution
The gap is 60 occurrences, or three batches. The next required occurrence is 301 under the stated sequential contract. Preserve or reconstruct 301–360; a bare cursor after 360 would omit them from the restored training history.
Keep the idea
Take it with you
- Checkpoint model and input progress at a consistent consumer boundary.
- Traversal cursors, pending buffers, RNGs, versions, and topology may all affect replay.
- Validate the exact supported restoration contract with a nontrivial restart test.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.