You’re diving right into the tricky bits, but:


__new__ is a class method implicitly (don’t ask).
You can use nn.Parameter as an example. Adapted this gives:

class MyTensor(torch.Tensor):
     def __new__(cls, data, stats, requires_grad=False):
         data = torch.as_tensor(data, dtype=torch.long)
         tensor = torch.Tensor._make_subclass(cls, data, requires_grad)
         tensor.stats = stats
         return tensor

So I’m still not 100% sure what you’re trying to achieve, but if it is a subclass that is similar to nn.Parameter, this would be what I’d use.
Best regards
Thomas