subclass_zoo
subclass_zoo copied to clipboard
Fix composite compliance
Aka, https://github.com/pytorch/pytorch/issues/69991
Motivation
We should make sure all PyTorch operations are "Composite Compliant". This condition is necessary for operators that look out-of-place to preserve the Tensor Subclass when passed in a Tensor Subclass.
Consider the following hypothetical out-of-place operation:
def my_add(x, y):
result = x.clone()
result.add_(y)
return result
You may expect this to work the same as torch.add. However, if x is not a Tensor Subclass, but y is a Tensor subclass, then this returns us a regular Tensor, NOT a Tensor subclass!