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
4 changes: 4 additions & 0 deletions rllib/algorithms/ppo/torch/ppo_torch_rl_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def _compute_values(self, batch, device=None):

# Separate vf-encoder.
if hasattr(self.encoder, "critic_encoder"):
if self.is_stateful():
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome! Ran into this issue yesterday as well (and continued testing then with a shared value function :) ).

# The recurrent encoders expect a `(state_in, h)` key in the
# input dict while the key returned is `(state_in, critic, h)`.
batch[Columns.STATE_IN] = batch[Columns.STATE_IN][CRITIC]
encoder_outs = self.encoder.critic_encoder(batch)[ENCODER_OUT]
# Shared encoder.
else:
Expand Down
4 changes: 3 additions & 1 deletion rllib/policy/sample_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ def _batch_slice(self, slice_: slice) -> "SampleBatch":

# Exclude INFOs from regular array slicing as the data under this column might
# be a list (not good for `tree.map_structure` call).
infos = self.get(SampleBatch.INFOS)
# Furthermore, slicing does not work when the data in the column is
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense!

Copy link
Contributor

Choose a reason for hiding this comment

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

You mean a SampleBatch with B=0, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

B>0. But in this case the infos are a list of dicts. When they are empty, tree.map_structure(infos) works, but when they are filled, tree.map_structure will fail as it tries to apply the slicing on singular values slicing fails.

# singular (not a list or array).
infos = self.pop(SampleBatch.INFOS, None)
data = tree.map_structure(lambda value: value[start:stop], self)
if infos is not None:
data[SampleBatch.INFOS] = infos[start:stop]
Expand Down