Unit 5 of 10 · about 3 hours · explain, implement
Transition immutability, replay aliasing, replay age and policy drift
A replay buffer is a dataset with an expiration date. One stored fake transition or a diet of ancient data silently changes the objective.
You'll be able to
- State what a stored transition must contain and why stored fields are never edited in place.
- Explain replay age and policy drift: old transitions come from worse policies.
- Detect an autoreset artifact and a stale-data slowdown in your own buffer.
Covers
Read
In this order, only the parts listed
0 of 3 done
- What a stored transition containsHands-on Modern RL - From Q-Learning to DQN
Experience Replay: the five-tuple table, the capacity range ( to ), and the stale-experience warning for oversized buffers (page read 2026-10-14)
- Termination, truncation and the autoreset stepGymnasium - Time Limits and Vector Autoreset
Termination, Truncation, Importance in learning code, and Solution (page read 2026-10-14). The autoreset behavior is on https://farama.org/Vector-Autoreset-Mode, not this page: in a vector environment under the default next-step autoreset of Gymnasium 1.x, the step after an episode ends returns reward 0 with both flags false (measured in Reproduce). That output is not a transition and must not be stored.
- What version-skewed storage code looks likeCleanRL DQN
Lines 176 to 187 of
dqn.pyat commit fe8d8a0: thefinal_infologging branch and thefinal_observationstorage fix. CleanRL pinsgymnasium==0.29.1, where those keys exist. On Gymnasium 1.x they are gone, so the logging branch never fires and the storage line raisesKeyErrorat the first truncation.
Focus on
- A transition is an immutable record. Overwriting a stored next-state (for example with a reset observation) rewrites history, and every reuse of that row learns from a fabricated pair.
- Termination cuts bootstrapping through . Truncation keeps it. Storing both the same way undervalues every state near a time limit.
- Capacity sets the age distribution, not just memory. Too small loses diversity; too large preserves data from long-obsolete policies that drags current values.
- CleanRL
dqn.pyexpects same-step info keys, so on Gymnasium 1.x it logs no episode returns and crashes at truncation. Pingymnasium==0.29.1or patch those lines.
Common mistakes · 3
- Treating the autoreset output as a transition. Reward 0 with cleared flags is the reset handshake, not experience.
- Quoting capacity without interaction rate. A million stored transitions from a random early policy is mostly drift, not diversity.
- Assuming more replay is always more stable. Stale data from a far worse policy can anchor values away from the current policy's truth.
Try it yourself
Closed-book, before checking anything
CartPole-v1 with max_episode_steps=5 in a one-environment SyncVectorEnv (default next-step autoreset) and reset with seed=0. Show steps 0 to 4 returning reward 1.0 with truncation at step 4, and the next step returning reward 0.0 with both flags false. State which of the six outputs is storable: only the first five. A single unvectorized environment never autoresets, so the handshake appears only in the vector env.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.The vector env returns reward 0.0 with both flags false right after an episode ended. Store it?Answer
No. That is the next-step autoreset output: a fresh observation with a dummy reward, not a transition the policy experienced.
2.A stored transition's next-state is later overwritten with the reset observation. What breaks?Answer
Its TD target bootstraps from an unrelated state. Every sample reusing that row learns from a fabricated pair.
3.The buffer holds a million transitions but the policy improved sharply 50k steps ago. Concern?Answer
Most samples come from the old policy. Gradients optimize a stale distribution and can slow or drag the new policy's values.
4.CleanRL
dqn.pyprintsSPSbut no episodic returns on your install. First check?AnswerThe Gymnasium version. On 1.x the
final_infobranch never fires, so confirm the version before touching the algorithm.
You're done when
You can name the producing policy, episode and environment version for any buffer row, and your autoreset probe drops the fake transition.
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_infoandfinal_observationkeys of older Gymnasium releases; on Gymnasium 1.x (next-step autoreset) it logs no episode returns and raisesKeyErrorat truncation, so run it in an environment withgymnasium==0.29.1or 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.pytrains 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; itscode/chapterNNfolders do not follow the site chapter numbers. - 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.
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 pinsgym==0.25.2, which fails on NumPy 2, so port it to Gymnasium (terminatedandtruncated) or pinnumpy<2in 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 - Env.reset and seedingFarama Foundation · reference
Read the
Env.resetentry for the seeding contract: an integer seed resets the environment PRNGnp_random, and a laterresetwithseed=Nonecontinues it, so seed once right after creation.