-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add boilerplate code #1635
base: gh/jainapurva/3/base
Are you sure you want to change the base?
Add boilerplate code #1635
Conversation
torchao/utils.py
Outdated
aten = torch.ops.aten | ||
|
||
|
||
@implements(aten.detach.default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing here is what would happen when a tensor subclasses TorchAOBaseTensor and tried to overwrite these functions, to allow child tensor classes to overwrite these functions I think we'd have to copy the table
Line 402 in 7b0d2ce
cls._ATEN_OP_OR_TORCH_FN_TABLE = {} |
def _implements(cls, aten_ops_or_torch_fns):
# making sure we are querying the attribute from current class, not parent
# please check if this works
if "_ATEN_OP_OR_TORCH_FN_TABLE" not in dir(cls):
# copy the table from parent
def _dispatch__torch_function__(cls, func, types, args=(), kwargs=None):
# making sure we are querying the attribute from current class, not parent
# please check if this works
if "_ATEN_OP_OR_TORCH_FN_TABLE" not in dir(cls):
# copy the table from parent if it exists
torchao/utils.py
Outdated
class TorchAOBaseTensor(torch.Tensor): | ||
"""A util tensor subclass that provides commonly used functions | ||
new tensor subclass can inherit it to get all the utility functions | ||
new tensor subclass can inherit it to get all the utility functions, and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the pros and cons of using inheritance here versus just having utility functions and tensors using what they need from utility functions, without inheritance? It might be hard to come up with a TorchAOBaseTensor
which is generic enough to truly handle all the important use cases in torchao.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, we could have both I think, e.g. _get_to_kwargs
can be a standalone util function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per my understanding:
Option 1: We can move out all the util functions, and make an independent tensor-subclass (inheriting from torch.Tensor), then developer will have to define/inherit util functions.
Option 2: We can add the minimum needed util functions in TorchAOBaseTensor, so that it gives a base start to developer and build on top of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depends on how much can be reused by other tensor subclasses I think, if the TorchAOBaseTensor is very small then it may not make sense to have it any more and it will not be useful for existing inference tensor subclasses. I feel it might be better to have both the current TorchAOBaseTensor and some utils that can be reused by other tensor subclasses as a starting point and then adapt based on use cases
49c8514
to
d42c725
Compare
Stack from ghstack (oldest at bottom):