You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support optional_tensor_names in TorchAOBaseTensor
Summary:
Allows subclasses inheriting from TorchAOBaseTensor to have optional tensor attributes, updated
all common util functions to support `optional_tensor_names` list, including `__tensor_flatten__`, `__tensor_unflatten__`, ops like aten._to_copy, contiguous, alias etc.
Test Plan:
python test/test_utils.py
Reviewers:
Subscribers:
Tasks:
Tags:
stack-info: PR: #2710, branch: jerryzh168/stack/17
class variables to define to simplify implmentation of tensor subclasses:
688
+
`tensor_data_names` (List[str]): list of names of all requires tensor_data, order should match
689
+
the `__init__` list of tensor subclass
690
+
`optional_tensor_data_names` (List[str]): it's optional to define this field to have the additional boilerplate functions been implemented for you, but this will be need if there are some optional Tensor attributes, when defined, this will be a list of names of Tensors that can be optional
691
+
`tensor_attribute_names` (List[str]): list of names of non-Tensor attributes,
692
+
order should match the `__init__` list of tensor subclass, following all the `tensor_data_names` arguments and `optional_tensor_data_names`
693
+
694
+
If `tensor_data_names` and `tensor_attribute_names` are defined, there are some additional
695
+
functions that will be added, this includes:
696
+
`__tensor_flatten__`: flattens a subclassed tensor instance, returns a tuple, first element is tensor data names for valid tensor data,
697
+
second element is a list of non-Tensor attributes
698
+
`__tensor_unflatten__`: takes a tensor_data_dict (a map from tensor name to Tensor), and list of non-tensor attributes, returns a new instance of the subclassed tensor
699
+
`_apply_fn_to_data`: takes a function (Tensor -> Tensor), applies function to all tensor data and
700
+
recreate a new subclassed Tensor with the transformed tensor data
701
+
`__repr__`: the string representation of the subclassed tensor instance
0 commit comments