What's the difference between torch.Tensor._make_subclass and torch.Tensor._make_wrapper_subclass

Hey!

The Extending PyTorch doc does talk about subclasses of Tensor a bit below from where you showed: Extending PyTorch — PyTorch main documentation

  1. These two functions do quite different things. The main difference is that when you do _make_subclass(), the current object is a honest to goodness Tensor with data in its storage and everything. When you do _make_wrapper_subclass(), the current object has no data and it is expected that some field on the Tensor will be another Tensor (hence the outer one being called wrapper) that contains real data.
  2. This is the same as any Python class: new creates a new instance while init initializes it. It makes very little difference unless you’re considering serialization of objects. General Python doc does cover that in details though.
  3. It depends on what you want to do. They are different tools for different jobs. The Extending doc tries to give details, this poster from the PyTorch conference tries to answer that question as well: BackToPython PTC 2022 Poster - Google Slides

Hope this helps

2 Likes