pytorch/pytorch

Supporting custom attributes with `__torch_function__` tensor subclasses

Open

#117 806 ouverte le 19 janv. 2024

Voir sur GitHub
 (17 commentaires) (0 réactions) (1 assigné)Python (27 795 forks)batch import
enhancementgood first issuemodule: __torch_function__module: dynamotriaged

Métriques du dépôt

Stars
 (99 916 stars)
Métriques de merge PR
 (Merge moyen 1j 10h) (42 PRs mergées en 30 j)

Description

🚀 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

Guide contributeur