Skip to content

Fix DQN w RNN tutorial #3462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: RC-TEST-2.8
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions intermediate_source/dqn_with_rnn_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@
# will return a new instance of the LSTM (with shared weights) that will
# assume that the input data is sequential in nature.
#
policy = Seq(feature, lstm.set_recurrent_mode(True), mlp, qval)
from torchrl.modules import set_recurrent_mode

with set_recurrent_mode(True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to be set during the loss computation.

The policy module given to the collector and to the loss will be the same. The decorator is to be set to True whenever a recurrent call is required (typically within the loss).

policy = Seq(feature, lstm, mlp, qval)

######################################################################
# Because we still have a couple of uninitialized parameters we should
Expand Down Expand Up @@ -389,7 +392,10 @@
# For the sake of efficiency, we're only running a few thousands iterations
# here. In a real setting, the total number of frames should be set to 1M.
#
collector = SyncDataCollector(env, stoch_policy, frames_per_batch=50, total_frames=200, device=device)

collector = SyncDataCollector(
env, stoch_policy, frames_per_batch=50, total_frames=200, device=device
)
rb = TensorDictReplayBuffer(
storage=LazyMemmapStorage(20_000), batch_size=4, prefetch=10
)
Expand Down Expand Up @@ -464,5 +470,5 @@
#
# Further Reading
# ---------------
#
#
# - The TorchRL documentation can be found `here <https://pytorch.org/rl/>`_.
Loading