Practice in Lab: Project: resume AdamW, sampling and dropout exactly →
Project: resume AdamW, sampling and dropout exactly
Resuming weights alone is not resuming an experiment. AdamW moments, dropout randomness and the next sampled examples affect every subsequent update. This project captures an owned checkpoint at an update boundary and restores randomness after model construction has consumed random numbers. Checks compare uninterrupted training with two resumed segments, including exact losses, sampled indices and parameter tensors. The guarantee is bounded to this CPU model, fixed data and runtime. It does not claim bitwise portability across devices, library releases, multiprocessing loaders or distributed workers.
import torch
state = torch.get_rng_state().clone()
first = torch.rand(2)
torch.set_rng_state(state)
print(torch.equal(first, torch.rand(2)))Review the design
State the recovery boundary and record preprocessing, dataset identity, sampling and optimizer progress. Filesystem atomicity and durable checkpoint publication are separate production concerns.
Your task
Train CPU Sequential(Linear(2,4),Tanh,Dropout(.25),Linear(4,1)) with AdamW lr=.02 and weight_decay=.01. Each step draws randperm(N)[:min(3,N)] and minimizes mean squared error. Return checkpoint (model/optimizer deep copies, CPU rng clone, cumulative step, SHA256 of json.dumps([xs,ys],sort_keys=True,allow_nan=False).encode()), losses and sampled batches. On resume initialize objects, load model and copied optimizer state, then restore captured RNG before the next draw. Preserve caller RNG with fork_rng. Reject changed data, invalid steps or nonfinite/misaligned two-feature data. Zero steps capture state without updating.
The explanation opens here once every check passes.