torch.Tensor._make_wrapper_subclass are used in Subclassing
torch.Tensor such as subclass_zoo/quantized_tensor.py at main · albanD/subclass_zoo · GitHub and pytorch/torch/_subclasses/fake_tensor.py at main · pytorch/pytorch · GitHub
What’s the difference between them?
What’s more, is there any document illustrating how to subclassing torch.Tensor. I find there are many discussions such as Subclassing torch.Tensor - PyTorch Forums and examples GitHub - albanD/subclass_zoo, but I can’t find any document about subclassing
torch.Tensor in detail. The document in Extending PyTorch — PyTorch 2.1 documentation is not qualified for users to define subclasses of torch.Tensor. Here are some questions about subclassing torch.Tensor:
_make_wrapper_subclassis used, sometimes
_make_subclassis used, and sometimes neither is used, which confused me a lot.
How should the
__init__methods be defined? In other words, what are the responsibilities of
When should we use
__torch_function__, and when should we use
__torch_dispatch__? Should we prioritize using
__torch_dispatch__according to What (and Why) is __torch_dispatch__?