Extend TorchAOBaseTensor docstring with subclassing and safetensors docs#3846
Conversation
Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3846
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 8cbfd83 Pull Request resolved: #3846
…fetensors docs" Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: baa54d8 Pull Request resolved: #3846
andrewor14
left a comment
There was a problem hiding this comment.
Looks good. I think this will also be helpful in a developer facing doc somewhere.
| ``optional_tensor_data_names``, ``optional_tensor_attribute_names``) on the subclass, | ||
| which is already required for the other utility functions above. | ||
|
|
||
| 2. Register the subclass in ``torchao/prototype/safetensors/safetensors_utils.py``: |
There was a problem hiding this comment.
does this belong here or in torchao/prototype/safetensors?
There was a problem hiding this comment.
it's fine to include here I feel, since it's for TorchAOBaseTensor users. but both are fine for me, let me know if you had a strong preference here
going to merge first, we can move this later if needed
📄 Doc Preview (workflow_dispatch)You triggered a doc build manually via workflow_dispatch. Use this link instead: https://docs-preview.pytorch.org/pytorch/ao/21844186169/index.html |
…fetensors docs" Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 5e3d3bd Pull Request resolved: #3846
📄 Doc Preview (workflow_dispatch)You triggered a doc build manually via workflow_dispatch. Use this link instead: https://docs-preview.pytorch.org/pytorch/ao/21844523865/index.html |
…fetensors docs" Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 3022eb3 Pull Request resolved: #3846
📄 Doc Preview (workflow_dispatch)You triggered a doc build manually via workflow_dispatch. Use this link instead: https://docs-preview.pytorch.org/pytorch/ao/21844996663/index.html |
…ocs (#3846) * Extend TorchAOBaseTensor docstring with subclassing and safetensors docs Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned] * Update on "Extend TorchAOBaseTensor docstring with subclassing and safetensors docs" Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned] * Update on "Extend TorchAOBaseTensor docstring with subclassing and safetensors docs" Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned] * Update on "Extend TorchAOBaseTensor docstring with subclassing and safetensors docs" Summary: Extend the TorchAOBaseTensor docstring to document: - Subclassing and op inheritance: how subclasses automatically inherit __torch_dispatch__ and __torch_function__ implementations from parents, with independent dispatch tables and MRO-based resolution for multiple inheritance. Includes a concrete Parent/Child example. - Safetensors support: the two steps needed to enable safetensors serialization for a new tensor subclass (define class attributes + register in allowlists), and how this enables save_pretrained/push_to_hub with safe_serialization=True in HF Transformers. - Minor fixes to the existing example: torch.Tensor → TorchAOBaseTensor, missing comma in __init__ signature. Test Plan: visual inspection of doc preview for the PR Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
Stack from ghstack (oldest at bottom):
Summary:
Extend the TorchAOBaseTensor docstring to document:
multiple inheritance. Includes a concrete Parent/Child example.
safe_serialization=True in HF Transformers.
Test Plan:
visual inspection of doc preview for the PR
Reviewers:
Subscribers:
Tasks:
Tags: