Skip to content
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

[AFQ] Optimize tensor_flatten for runtime #1114

Open
wants to merge 1 commit into
base: gh/IvanKobzarev/2/base
Choose a base branch
from

Conversation

IvanKobzarev
Copy link

@IvanKobzarev IvanKobzarev commented Oct 18, 2024

Stack from ghstack (oldest at bottom):

tensor_flatten is called at runtime when inputs are subclasses e.g. AffineQuantizedTensor

In case of using float8_dynamic_activation_float8_weight quantization, the activations will also be AQT.

There was external complain, that unwrap_tensor_subclasses sometimes exceeds in duration that compiled region execution.

Profiling shows that tensor_flatten attribute access will go through torch_function handling (AQT has it).
If to remove this torch_function dispatch for each getattr at runtime - tensor_flatten becomes (in my measurements x9 faster)

Screenshot 2024-10-18 at 14 31 33

IvanKobzarev added a commit that referenced this pull request Oct 18, 2024
ghstack-source-id: f028ae1d0afb3aaea9a4afebe29b114de80b5d9e
Pull Request resolved: #1114
Copy link

pytorch-bot bot commented Oct 18, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1114

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit d44ddab with merge base 3475aed (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 18, 2024
Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to do the same for TensorImpl tensor subclasses?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants