Skip to content

[Feature Request] Automatic tensordict creator #518

Closed
@vmoens

Description

@vmoens

Motivation

It would be great to have a helper function that automatically creates a TensorDict out of a dict with a predefined set of rules.
This should not be the default way of creating TensorDict instances but it should be used in several other helper functions through the library to make the usage of TensorDict-based classes easier.

Intended usage

The function should work like this:

d = {"a": torch.randn(3, 4, 5), "b": torch.randn(3, 4, 2)}
tensordict = make_tensordict(d)

this should return a tensordict with the maximum batch size (in this case [3, 4]) and the device (if any) of its content (in this case, "cpu").

It should be possible to parameterize some behaviours, e.g. say how many dimensions should the function look at when determining the batch size, or overriding the device.

This funciton should be implemented in the tensordict utils.py file.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions