Unit 10 of 10 · about 3 hours · implement

Checkpointing model, optimizer, replay and RNG, and separating evaluation exploration

A checkpoint without replay or RNG state resumes a different experiment. Evaluation that still explores measures luck, not learning.

You'll be able to

  • List the full resume state: model, optimizer, replay, RNG streams and counters.
  • Separate training exploration from evaluation and hold the evaluation protocol fixed.
  • Interrupt and resume a run with identical continuation.

Covers

Checkpointing model, optimizer, replay and random stateTraining and evaluation exploration separation
1

Read

In this order, only the parts listed

0 of 3 done

  1. Training versus inference modesHands-on Modern RL - From Q-Learning to DQN

    The Learning versus Inference comparison: exploratory collection with replay and target updates during training, pure greedy action with no updates during evaluation (page read 2026-10-14)

  2. What a model-only checkpoint omitsCleanRL DQN

    The save line at commit fe8d8a0 (line 223, torch.save of the Q-network state dict only). Fine for publishing a policy, but with no optimizer, replay or RNG state it cannot resume training identically.

  3. Seeding and deterministic evaluationGymnasium - Env.reset and seeding

    The Env.reset entry and its seed parameter (page read 2026-10-14): an integer seed resets np_random, while seed=None on an existing generator continues it. Fix environment, policy, seed set and episode count for evaluation; keep training-time randomness out.

2

Focus on

  • Resume state means parameters, optimizer state, replay contents and cursor, every RNG stream, and the step and exploration-schedule positions. Missing one piece continues a different trajectory.
  • Both reference scripts persist the model only. That publishes a policy but does not resume an experiment.
  • Evaluation fixes the policy to greedy, the seed set, the episode count and the environment version. Training and wrapper changes must not leak in.
  • The checkpoint must record the same identity fields the trajectory schema demands: environment, policy, seed and code versions.
Common mistakes · 3
  • Equating a saved model with reproducibility. Weights without optimizer, replay and RNG state restart the trajectory elsewhere.
  • Evaluating with training for fairness. Shared noise still inflates variance and can flip close rankings; report greedy scores and training curves separately.
  • Re-seeding evaluation environments per checkpoint. Sampling differences then masquerade as policy differences.
3

Try it yourself

Closed-book, before checking anything

Write the checkpoint dictionary keys for a CartPole DQN (parameters, optimizer, replay contents and cursor, Python, NumPy and Torch RNG states, global step, position), interrupt a run at an episode boundary (or also save the environment state), and show the resumed loss trajectory matches the uninterrupted one.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.A resumed run from a model-only checkpoint diverges from the original curve. Bug?Answer

    Not necessarily. Optimizer momentum, replay contents and RNG streams restarted fresh, so the trajectory differs by construction. Persist full state or record the difference.

  2. 2.Evaluation uses like training. What is the cost?Answer

    Random actions contaminate the score. Small-sample comparisons then measure exploration luck instead of policy quality.

  3. 3.Which RNG streams must a CPU CartPole checkpoint capture?Answer

    Python random, NumPy and Torch generators, plus the environment's np_random and the action space's own generator: action sampling, buffer sampling, initialization and environment stochasticity each draw from one.

  4. 4.The environment version bumps mid-project. Keep the old checkpoints?Answer

    Keep them but re-evaluate under the new version with fixed seeds. Never mix returns across versions in one curve.

You're done when

An interrupted and resumed run continues the identical loss trajectory, and every reported score comes from the fixed greedy protocol.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the section
  • CleanRL DQNCleanRL · support

    Read the single-file DQN implementation and documented benchmark details after the blank-file update passes. Trace replay, target, seeding, termination and evaluation semantics. The script expects the final_info and final_observation keys of older Gymnasium releases; on Gymnasium 1.x (next-step autoreset) it logs no episode returns and raises KeyError at truncation, so run it in an environment with gymnasium==0.29.1 or patch those lines and say so.

  • Hands-on Modern RL - From Q-Learning to DQNWalking Labs · support

    Use Sections 5.1 to 5.4, with the masked target on the components page (the formula on the first page omits the terminal mask). code/chapter04_dqn/dqn_cartpole.py trains CartPole on CPU in about two minutes. Treat score claims as hypotheses requiring local seed and version evidence. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

  • Gymnasium - Env.reset and seedingFarama Foundation · reference

    Read the Env.reset entry for the seeding contract: an integer seed resets the environment PRNG np_random, and a later reset with seed=None continues it, so seed once right after creation.

Also in this section

  • Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Value-Based RL and Q-Learning in PracticeUC Berkeley · primary

    Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lecture 7 (value-based RL) and Lecture 8 (Q-learning in practice: replay, target networks, double Q-learning). Work the DQN part of Homework 3 (src/agents/dqn_agent.py, CartPole then LunarLander with double DQN) on CPU or one small GPU; the Atari run is optional. The homework pins gym==0.25.2, which fails on NumPy 2, so port it to Gymnasium (terminated and truncated) or pin numpy<2 in its own environment, and turn off its forced WandB logging.

  • Reinforcement Learning: An Introduction (2nd ed.) - Chapters 9 and 11Richard Sutton and Andrew Barto · required

    The authors post the full second edition free at incompleteideas.net; cite the printed page numbers. Study Sections 9.1 to 9.4 (value error, semi-gradient TD, linear methods) and Sections 11.1 to 11.3 and 11.6 (off-policy divergence, the deadly triad, why the Bellman error is not learnable). Reproduce Baird's counterexample (Section 11.2, Figure 11.1) and show the weights diverge under off-policy semi-gradient TD.

  • Stanford CS224R Spring 2026 - Q-Learning and Off-Policy MethodsStanford University · support

    Use Lecture 06 (Q-learning) and the TA Q-learning tutorial (material/CS224R_Tutotial_Max.pdf) as a second derivation of fitted Q-iteration, targets and overestimation. Its homeworks run on cloud GPUs; follow the Stanford honor code for course materials.

  • Playing Atari with Deep Reinforcement LearningDeepMind · required

    Read the algorithm, replay and target-network design plus experimental protocol. Reproduce DQN on a small discrete environment, then ablate replay and target networks rather than attempting an Atari score reproduction.

  • Deep Reinforcement Learning with Double Q-LearningDeepMind · required

    Derive the action-selection and action-evaluation split, construct a noisy maximization example and compare DQN with Double DQN using identical samples and tuning budgets.

  • Dueling Network Architectures for Deep Reinforcement LearningWang et al. (ICML 2016) · support

    Read the dueling architecture and its aggregation equations (the mean-subtracted form). Implement it as an optional head and test that the value and advantage streams are identifiable only up to the stated constraint.

  • Deep-ML - Function Approximation and DQN ProblemsDeep-ML · support

    Use named problems as closed-book checks after your own implementation passes: 530 (semi-gradient TD(0)), 556 (deadly-triad instability), 557 (Baird's counterexample), 537 (experience replay) and 477 (double Q-learning). Read each problem's tests before trusting its statement.

  • Reinforcement Learning Control Laboratory - Deep Value CoreRoadmap-Final · required

    Implement DQN and Double DQN with replay and target state, fixed-batch target tests, checkpoint and resume, overestimation evidence and injected online-target, detach, action-gather and replay defects.

  • Gymnasium - Time Limits and Vector AutoresetFarama Foundation · reference

    Read Termination, Truncation, Importance in learning code and Solution in the time-limits tutorial, plus the vector autoreset note at https://farama.org/Vector-Autoreset-Mode. Next-step autoreset is the default for Gymnasium 1.x vector environments; on Gymnasium 1.4.0 the step after an episode ends returns reward 0 with both flags false and is not a transition.