When I design my network I need to work with “complex” data whose leaf attributes are tensors. For example, CameraSpecification contains attributes:

position, a tensor
transform, a tensor
intrinsics,  data of another type CameraIntrinsics containing:

fov, a tensor
pixel_coordinates, a tensor



Then these two classes are nothing but groups of tensors, so in theory they can be safely transferred between CPU and GPU and can be generated during forward(). However, if I generate them during forward(), I will have to move the tensor attributes of them using to(). This is especially inconvenient when I use PytorchLightning. Is there a more elegant way to group tensors and to group groups of tensors? Thank you!