Skip to content
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

[Fix] Remove loss device #1395

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Changes from 1 commit
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
Next Next commit
amend
Signed-off-by: Matteo Bettini <matbet@meta.com>
  • Loading branch information
matteobettini committed Jul 19, 2023
commit 208c600f9d5b66386e5cc54719dfa7e85443c947
14 changes: 2 additions & 12 deletions torchrl/objectives/dqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,13 @@ def forward(self, tensordict: TensorDictBase) -> TensorDict:
a tensor containing the DQN loss.

"""
if self.device is not None:
warnings.warn(
"The use of a device for the objective function will soon be deprecated",
category=DeprecationWarning,
)
device = self.device
else:
device = tensordict.device
tddevice = tensordict.to(device)

td_copy = tddevice.clone(False)
td_copy = tensordict.clone(False)
self.value_network(
td_copy,
params=self.value_network_params,
)

action = tddevice.get(self.tensor_keys.action)
action = tensordict.get(self.tensor_keys.action)
pred_val = td_copy.get(self.tensor_keys.action_value)

if self.action_space == "categorical":
Expand Down