Repository navigation
Conversation
DQN.load and NFSP.restore read the keys "model_state_dict" and "optimizer_state_dict", but save writes "model" and "optimiser", so loading always raised KeyError. NFSP.save also used checkpoint_dir as both a directory (for the inner DQN) and a file (for torch.save), so it always raised RuntimeError. DQN.load now reads the keys save writes, which leaves the file format unchanged. NFSP.save creates checkpoint_dir and writes q_network.pt and avg_network.pt into it; restore reads the same files. Both accept str paths. nfsp_leduc_pytorch.py now checkpoints each player to its own subdirectory. Adds save/load round-trip tests for DQN and NFSP.
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
The DQN checkpoint still does not preserve the target network. save() writes only _q_network, and load() copies that state into both networks, so resuming between target updates silently resets the lagged target to the online network and changes subsequent learning. Could the target state be saved/restored separately, with the regression comparing the restored target to the original _target_q_network?
DQN.save wrote only the online Q-network and load copied it into both networks, so resuming between target updates reset the lagged target network and changed subsequent learning. This also affected the inner DQN of NFSP. save now stores the target network under "target_model" and load restores it. Checkpoints without that key, such as those written by v2.0.2, fall back to the previous behaviour.
|
Fair point. Tests are updated, and One related gap I've left out of this PR: It's not visible right now because |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Rechecked current b8aa626. DQN checkpoints now store the target network separately, load restores it when present, and older checkpoints fall back to the online model for compatibility. The regression directly compares the restored target state to the original lagged target network. This resolves the learning-state reset I raised.
In v2.0.2 and on master,
pytorch.dqn.DQN.loadandpytorch.nfsp.NFSP.save/restorefail on every call.Reproduction (v2.0.2):
Cause (introduced in #1419):
savewrites the keysmodel/optimiser, butload/restorereadmodel_state_dict/optimizer_state_dict.NFSP.saveusescheckpoint_dirboth as a directory (for the inner DQN) and as a file (fortorch.save).Fix:
DQN.loadreads the keyssavewrites.savenow also stores the target network, andloadrestores it, so resuming between target updates no longer resets it. Files written by v2.0.2 still load; they never stored the target, so it starts from the online network.NFSPtreatscheckpoint_diras a directory: it creates the directory, writesq_network.pt(inner DQN) andavg_network.pt(average network), and acceptsstrpaths as the JAX version does.nfsp_leduc_pytorch.pynow checkpoints each player to its own subdirectory. Before, both players shared one path.I chose this NFSP layout; happy to change it.
Tests: new save→load/restore round-trip tests in
dqn_pytorch_test.pyandnfsp_pytorch_test.py, including the target networks. Failed before this change and now passing.Not included: saving the replay and reservoir buffers.