Complete training-state inventory
Define the state needed to reproduce the next training transition, rather than equating model weights with a resumable experiment.
On this page
The question for today
What you’ll understand
- Inventory numerical, input, control, and environment state.
- Distinguish a weights export from a training-resume checkpoint.
- Budget a stipulated mixed-precision checkpoint without universal bytes-per-parameter claims.
A checkpoint is a claim about where a computation can continue. Saving the parameters is enough for some inference and warm-start tasks, but a training restart also depends on histories, counters, data position, and the rules that interpret them. Begin with the next update you want to reproduce. Work backward from its inputs until every required value is either preserved, deterministically reconstructed, or explicitly declared outside the recovery contract.
Describe one state transition completely
Treat the training state as more than a tensor collection. Parameters and persistent model buffers affect the forward computation; optimizer moments, master weights, and step counters affect the update. A scheduler supplies the next learning rate, while mixed-precision scaling can decide whether an update is skipped. If the checkpoint lies inside a gradient-accumulation window, accumulated gradients and the microstep position may matter too. A clean update boundary can simplify this inventory, but only when the actual loop makes those intermediate quantities unnecessary.
Inventory randomness and input progress separately. Python, NumPy, CPU generators, CUDA generators, augmentation workers, samplers, shuffle buffers, sequence packers, and external data readers can each carry state. Record a dataset version and logical consumed position, not just the name of a mutable data directory. A rank-local cursor can be meaningful only with the associated sharding policy. Decide whether recovery repeats or skips prefetched records; a fetch already issued is not necessarily a sample whose gradient contributed to a completed update.
Preserve meaning and compatibility alongside values
Checkpoint metadata should identify model configuration, parameter names, tokenizer or feature schema, optimizer type and group settings, scheduler convention, software versions, and supported parallel layout. Record training/evaluation mode and any exponential-moving-average weights or custom callback state that affects the next transition. A tensor with the right shape can still represent a differently ordered vocabulary or expert. Compatibility is a tested contract rather than an inference from a successful deserialization call. Explicitly distinguish an intentional optimizer reset for a new experiment from faithful continuation of the previous run, and give those outputs different recovery labels.
PyTorch 2.14 DCP provides distributed state-dictionary machinery; it does not discover every application-specific cursor or configuration dependency. FSDP state handling must map optimizer state to the intended logical parameters, not to incidental object identities from another process. DeepSpeed weight consolidation is useful for exporting parameters but should not be mistaken for a complete restoration of its engine and training history. Extend the application state deliberately and version that schema so a loader can reject an unsupported interpretation before training begins.
Test the inventory against the next action
A useful inventory names an owner, serialization form, restore action, and oracle for every state category. A scalar global-step field needs a definition: does it count attempted updates, successful optimizer updates, consumed microbatches, or tokens? Those counters can diverge after an overflow or retry. The state of an external side effect, such as a metric stream, may require an idempotency policy instead of being embedded in a tensor file. Record the boundary precisely enough that an operator can explain the next scheduler and sampler actions.
The optimization instrument illustrates dependence on update rules, without saving anything. Reset, set both η=0.5 and x₀=2, predict x₂=0.5, then press Step twice. Separately Reset, set both η=0.25 and x₀=2, predict x₂=1.125, then press Step twice. Each Step advances one iteration of the fixed quadratic descent model. The differing results show why a transition rule belongs in a recovery specification. This toy has no optimizer moments, checkpoint files, sampler, or mixed-precision scaler; an application inventory must cover those separately.
Work it through
Budget an explicitly specified optimizer snapshot
A hypothetical run has 100,000,000 logical parameters. Its checkpoint stores two-byte parameters, a four-byte master copy, and two four-byte moment tensors per parameter. Ignore all other state only for this tensor-budget exercise.
Add the stipulated widths: 2+4+4+4=14 bytes per parameter. The aggregate logical tensor payload is 100,000,000×14=1,400,000,000 bytes.
Convert the total to decimal storage units: 1.4 GB. If these four categories are evenly sharded across eight writers with no replication, each writer owns 175,000,000 payload bytes.
The arithmetic omits gradients, model buffers, metadata, RNG, cursors, and storage overhead. Their sizes may be smaller, but their absence can still make the snapshot unusable for the intended next update.
A bytes-per-parameter estimate is meaningful only after naming the stored categories. Small metadata can be as essential to recovery as a large moment tensor.
The living notebook
Explore the model
Interactive lab · optimization
An update depends on its rule as well as its start
Reset, set both η=0.5 and x₀=2, predict x₂=0.5, then Step twice. Separately Reset, set both η=0.25 and x₀=2, predict x₂=1.125, then Step twice. Step advances one iteration of xₙ=(1−η)ⁿx₀; this toy does not serialize or restore training state.
- Position x0
- 2
- Objective x²/2
- 2
- Iteration behavior
- Stable step
Gradient descent on f(x) = x²/2: xₙ = (1 − η)ⁿx₀. Playback advances two discrete iterations per second. Values outside |x| ≤ 4 are explicitly reported. 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 recoverable state must include the interpretation and update settings that determine its continuation.
Pause & reason
Check your understanding
Your turn
Try it yourself
A run saves after microstep three of a four-microstep accumulation window. Parameters and optimizer moments are present, but accumulated gradients are absent. Can the loader simply execute the fourth microstep and claim faithful continuation?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Ask which earlier contributions the next optimizer update requires.
Compare with the solution
No. The next update would need the contributions from the first three microsteps, their accumulation convention, and the correct microstep counter. The system must preserve that intermediate state, reconstruct it under an explicit replay policy, or choose an earlier clean boundary. Loading the same parameters does not recreate the missing gradient sum.
Keep the idea
Take it with you
- Define recovery by the next valid state transition.
- Inventory optimizer, scaler, randomness, data progress, counters, and configuration explicitly.
- Treat exports and intentional resets as different contracts from faithful resume.
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.