Supporting custom attributes with `__torch_function__` tensor subclasses
#117.806 geöffnet am 19. Jan. 2024
Repository-Metriken
- Stars
- Â (99.916 Stars)
- PR-Merge-Metriken
- Â (Durchschn. Merge 1T 10h)Â (42 gemergte PRs in 30 T)
Beschreibung
đ The feature, motivation and pitch
Currently we only support accessing attributes that are defined on the base torch._tensor implementation. Since some torch function subclasses define custom attributes it's a good idea to support accessing these as well.
See https://github.com/pytorch/pytorch/blob/a468b9fbdf75b2da128e5fac4284ebbb981cd31a/torch/_dynamo/variables/torch_function.py#L180C1-L215C1 for the current implementation.
Ideally we should support two cases 1) if a user defines a custom attribute that does not invoke torch_function on access (this is the default for an arbitrary attribute) and 2) if the user explicitly adds this decorator to an attribute, we should support tracing through it and dispatching appropriately or shortcutting to the dynamo handling of it to be consistent.
Alternatives
No response
Additional context
No response
cc @hameerabbasi @rgommers @peterbell10 @ezyang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng