rl: [BUG] Stacked tensordicts with nested keys crash `env.step()`
Describe the bug
Due to multiagent applications my env needs to return tensordict_out = torch.stack(agent_tds,dim=0)
from env._step()
with nested keys.
This creates a LazyStackedTensorDict
.
The subsequent logic of env.step()
performs certain operations on the tensordict_out
which crash if the latter has nested keys.
This can be solved by calling to_tensordict()
before the end of the _step()
but this is possible only when the stack is homogenous and not wheen it is heterogenous as in #766.
To Reproduce
Create LazyStackedTensorDict
and return it in the _step
implementation
test/test_libs.py:525 (TestVmas.test_vmas_seeding[flocking])
Traceback (most recent call last):
File "/Users/Matteo/PycharmProjects/torchrl/test/test_libs.py", line 537, in test_vmas_seeding
tdrollout.append(env.rollout(max_steps=10))
File "/Users/Matteo/PycharmProjects/torchrl/torchrl/envs/common.py", line 605, in rollout
tensordict = self.step(tensordict)
File "/Users/Matteo/PycharmProjects/torchrl/torchrl/envs/common.py", line 343, in step
tensordict_out_select = tensordict_out.select(*obs_keys)
File "/Users/Matteo/PycharmProjects/tensordict/tensordict/tensordict.py", line 4325, in select
raise TypeError(
TypeError: All keys passed to LazyStackedTensorDict.select must be strings. Found ('info', 'velocity_rew') of type <class 'tuple'>. Note that LazyStackedTensorDict does not yet support nested keys.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 22 (22 by maintainers)
The code snippet I am using is the main with #785 and #788 merged (in order to have vmas and allow it to work).
then you just need to run
simple_crypto
has heterogenous spaces andflocking
, for example, not