[Feature Request] Calling `tensordictmodule.forward(...)` with keyword arguments and not tensordict
Open
@vmoens is already working on this.
Since Oct 24, 2022.
enhancement
- Dominant language
- Python
- Stars
- 3.6k
- Forks
- 484
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 207
Description
Motivation
To make TensorDictModule easier to access, a cool feature would be to be able to call the forward method with the tensors and not the tensordict, e.g.
>>> # currently
>>> tdm = TensorDictModule(module, ["a"], ["b"])
>>> tensordict = TensorDict({"a": torch.zeros(3, 4)}, [3])
>>> tdm(tensordict) # populates the "b" key
>>> tensordict2 = tdm(a=torch.zeros(3, 4))
>>> assert (tensordict == tensordict2).all()
Solution
This solution should take the form of a decorator:
@dispatch_kwargs
def forward(self, tensordict):
do_stuff()
where @dispatch_kwargs will call make_tensordict from the kwargs provided and call the function with the tensordict that has been created.
Additional context
The solution should cover TensorDictSequential and ProbabilisticTensorDict too.
It could also be nice to support sorted inputs (args and not only kwargs).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.