Open rehno-lindeque opened 1 month ago
Hello,
Yeah we do indeed check if the content match when using torch.stack. This is to avoid creating countless copies of the same non-tensor data when all the content match, or a more consistent behaviour with index + stack. What we want is for this to work:
td = TensorDict(a=set(), batch_size=[2])
td_reconstruct = torch.stack([td[0], td[1]])
td_reconstruct["a"] is td["a"]
Currently we use __eq__
to compare the contents of the NonTensorData but that's not great. is
would lead to a better behaviour (and faster execution).
To summarize the current state, we have
from tensordict import TensorDict
import torch
# 1. This gives a stack
a0 = set()
a1 = set([1])
torch.stack([TensorDict(a=a0), TensorDict(a=a1)])
# 2. This does not give a stack - but maybe it should?
a0 = set()
a1 = set()
torch.stack([TensorDict(a=a0), TensorDict(a=a1)])
# 3. This gives a stack
a0 = set()
a1 = set()
TensorDict.lazy_stack([TensorDict(a=a0), TensorDict(a=a1)])
# 4. This does not give a stack - but maybe it should?
a0 = set()
a1 = set()
TensorDict.maybe_dense_stack([TensorDict(a=a0), TensorDict(a=a1)])
and we want to change the behaviour of 2. and 4.
@rehno-lindeque I implemented this in #1083. Given the bc-breaking nature of this change I can only fully change the behaviour two major releases from now (v0.8), but I think your use case will be covered as soon as v0.7.
Describe the bug
Hi, please let me know if I'm using this feature incorrectly or if this is well known.
I've been unable to get
NonTensorStack
to work in various contexts.The simplest example I can come up with is this one:
I expected all of these examples to produce a
NonTensorStack
, yet onlyb_stack
appears to produce what I was expecting:I think I'd have hoped to see
torch.stack((a,a), dim=0).data == [{}, {}]
torch.stack((b,b), dim=0).data == [[{}], [{}]]
torch.stack((a_stack,a_stack), dim=0).data == [{}, {}]
This may be a separate issue, but even for the final case that appears to somewhat work...
there's still a number of issues that make it unusable for even the most basic use cases...
Thanks!
Checklist