Unit 6 of 10 · about 4 hours · explain, measure

Hard and Polyak target updates, target lag, replay ratio and update-to-data ratio

The target network sets how fast the label may move. Too fresh chases its tail, too stale teaches yesterday's values, and too many updates per sample overfits the buffer.

You'll be able to

  • Explain hard copies versus Polyak averaging and compute one Polyak step by hand.
  • Define target lag, replay ratio and update-to-data ratio, and predict what raising each does.
  • Measure stability across target frequencies on CartPole with matched step budgets.

Covers

Target networks and hard update intervalsPolyak target updatesTarget lag, replay ratio and update-to-data ratio
1

Read

In this order, only the parts listed

0 of 4 done

  1. Target networks: why labels must move slowlyBerkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Value-Based RL and Q-Learning in Practice

    Lecture 8 (Q-Learning in Practice), Part 1, slides 2 to 8: the moving-target problem, no gradient through the target, hard copies every 10,000 steps, and the Polyak-averaging alternative

  2. The three-process view and the update-to-data ratioBerkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Value-Based RL and Q-Learning in Practice

    Lecture 8, Part 2, slides 9 to 13: data collection, target updates and regression as three processes, the update-to-data ratio (written "update-to-date" on slide 12), and the overfitting warning for too-high values

  3. One concrete operating pointCleanRL DQN

    The dqn.py experiment command (target network frequency 500) and the implementation note that target updates are Polyak updates with a default tau of 1.0, which is a full hard copy (page read 2026-10-14). The same defaults (target_network_frequency = 500, tau = 1.0) sit at lines 57 and 59 of dqn.py.

  4. Freezing targets as the DQN fixStanford CS224R Spring 2026 - Q-Learning and Off-Policy Methods

    Lecture 06 (Q-learning), slides 16 and 17: the lecture plan and freezing target parameters with periodic updates (the DQN algorithm)

2

Focus on

  • A hard copy sets every steps and holds labels fixed between copies. Polyak sets every update. With the Polyak form is a hard copy.
  • The lecture's 10,000-step period and CleanRL's 500-step default are different operating points, not conflicting truths. The right lag depends on update frequency and task speed.
  • Replay ratio (update-to-data ratio) is gradient updates per environment step. Raising it learns faster per sample but costs compute and can overfit buffer noise.
  • Fitted Q-iteration is the extreme of many updates per collection round; online Q-learning is the other. DQN sits between them.
Common mistakes · 3
  • Reading small as slow learning. It means slow label movement; per-sample learning can still be fast through the update ratio.
  • Copying targets every step for freshness. That deletes the stabilization the target network exists for.
  • Comparing two update ratios by episode count. Episodes hide the compute and data difference; match environment steps and report wall time.
3

Try it yourself

Closed-book, before checking anything

Closed-book, compute one Polyak step with , and : show 1.005. Then state what does to the same formula.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.CleanRL sets tau=1.0 yet calls it a Polyak update. Contradiction?Answer

    No. The update has Polyak form, and with it copies fully, which equals a hard update every target_network_frequency steps.

  2. 2.You raise the update ratio from 1 to 8 with episodes matched and declare victory. What is wrong?Answer

    Environment steps and compute differ eightfold. Match the interaction budget and report wall time before claiming efficiency.

  3. 3.Values look stale with targets copied every 10,000 steps. First knob?Answer

    Shorten the target period while watching TD-error variance. Fresher labels track faster but move more.

  4. 4.Why does the lecture warn that too high an update ratio overfits?Answer

    Repeated updates on the same buffer rows fit sampling noise and a stale distribution instead of the task.

5

Practice

  • Berkeley CS285 Homework 3: DQN on CartPole

    The blocks marked Section 2.4 in hw3/src/agents/dqn_agent.py with hw3/experiments/dqn/cartpole.yaml (CartPole-v1, target_update_period: 1000, 100k steps). Sweep the target period at matched step budgets. Run it in the homework's own uv sync environment (Python 3.10, gym==0.25.2, numpy<2.0.0) or port it to Gymnasium

    Keep the sweep curves. The section mini-project reuses target-lag evidence with the same matched-budget discipline.

You're done when

You predict the direction of a lag change and an update-ratio change before running, and a matched-step CartPole sweep confirms both.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the 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.

  • 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.

  • 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.

Also in this section

  • 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.

  • 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.

  • 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.

  • 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.

  • 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.