-
Notifications
You must be signed in to change notification settings - Fork 413
[BugFix] Heterogeneous envs compatibility #1204
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
Conversation
Test env makes sense. Would it make sense to support agents with also different number of dims? |
Is this something we should expect to happen or can we consider that if someone is doing that they're on the wrong track? |
I can imagine one agent having a camera (eg shape 64,64,3) and the other agent having normal position obs (eg shape 10) |
I would name one |
So in case we have
The agent dimension will be different for each key. So at that point we cannot group these into agent_fetures in the extreme case we could have each agent with a semantically different space and then each agent has its own key |
What do you mean? You can do
If you index that spec, it will give you 2 different sub-specs. The keys don't have to match. >>> from torchrl.data import CompositeSpec, UnboundedContinuousTensorSpec as Spec
>>> import torch
>>> spec1 = CompositeSpec(obs1=Spec(shape=(3,)))
>>> spec2 = CompositeSpec(obs2=Spec(shape=(4,)))
>>> s = torch.stack([spec1, spec2], 0)
>>> rs = s.rand()
>>> print(rs)
LazyStackedTensorDict(
fields={
},
batch_size=torch.Size([2]),
device=cpu,
is_shared=False)
>>> print(rs[0])
CompositeSpec(
obs1: UnboundedContinuousTensorSpec(
shape=torch.Size([3]),
space=None,
device=cpu,
dtype=torch.float32,
domain=continuous), device=cpu, shape=torch.Size([]))
>>> print(rs[1])
CompositeSpec(
obs2: UnboundedContinuousTensorSpec(
shape=torch.Size([4]),
space=None,
device=cpu,
dtype=torch.float32,
domain=continuous), device=cpu, shape=torch.Size([])) |
Ah. I wasn’t aware stacking was so advanced. Basically it can abstract also over heterogenous dicts and not only heterogeneous lists. Looks good then. |
We should fix prints though, put in parenthesis fields that are present in some but not all children or smth |
Depends on pytorch/tensordict#416 |
exclude_action: bool = True, | ||
reward_key: NestedKey = "reward", | ||
done_key: NestedKey = "done", | ||
action_key: NestedKey = "action", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmoens Would it be possible to merge a version of step_mdp that works with nested key before this whole PR? the fact that this function does not currently support nested is causing me all sorts of issues with collectors and so on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure makes sense
I believe this PR can be split in several smaller ones, let's see what we can do
Depends on pytorch/tensordict#400
cc @matteobettini can you have a look at the env I designed in the tests to see if it makes sense?