Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions test/objectives/test_cql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,14 @@ def test_dcql_tensordict_run(self, action_spec_type, td_est):
_ = loss_fn(td)
assert loss_fn.tensor_keys.priority in td.keys()

def test_dcql_cql_loss_before_value_loss(self):
actor = self._create_mock_actor(action_spec_type="one_hot")
loss_fn = DiscreteCQLLoss(actor)
loss_fn.set_keys(pred_val="custom_pred_val")
td = self._create_mock_data_dcql(action_spec_type="one_hot")
with pytest.raises(KeyError, match="with key custom_pred_val in"):
loss_fn.cql_loss(td)

@pytest.mark.parametrize("observation_key", ["observation", "observation2"])
@pytest.mark.parametrize("reward_key", ["reward", "reward2"])
@pytest.mark.parametrize("done_key", ["done", "done2"])
Expand Down
2 changes: 1 addition & 1 deletion torchrl/envs/batched_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,7 @@ def _shutdown_workers(self) -> None:
try:
if self.is_closed:
raise RuntimeError(
"calling {self.__class__.__name__}._shutdown_workers only allowed when env.is_closed = False"
f"calling {self.__class__.__name__}._shutdown_workers only allowed when env.is_closed = False"
)
if self._metadata_from_workers:
# Expensive native environments may retain renderer resources
Expand Down
2 changes: 1 addition & 1 deletion torchrl/objectives/cql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ def cql_loss(self, tensordict):
qvalues = tensordict.get(self.tensor_keys.pred_val, default=None)
if qvalues is None:
raise KeyError(
"Couldn't find the predicted qvalue with key {self.tensor_keys.pred_val} in the input tensordict. "
f"Couldn't find the predicted qvalue with key {self.tensor_keys.pred_val} in the input tensordict. "
"This could be caused by calling cql_loss method before value_loss."
)

Expand Down
Loading