PythiloLesson 8 of 9 · progress kept in this browser

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)))
This example uses torch. Run it in the Pythilo app, where these features are available.
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.

This lesson uses torch, which Python in this browser does not include. Read it here, and run and check it in the Pythilo app on iPhone or iPad.