Skip to content

Convert scalar to tensor before quantizer annoate #2958

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

Closed
wants to merge 2 commits into from

Conversation

cccclai
Copy link
Contributor

@cccclai cccclai commented Apr 10, 2024

Copy link

pytorch-bot bot commented Apr 10, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/2958

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

❌ 2 New Failures, 1 Unrelated Failure

As of commit de04834 with merge base e733f2d (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 Apr 10, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55946527

cccclai added a commit that referenced this pull request Apr 10, 2024
Differential Revision: [D55946527](https://our.internmc.facebook.com/intern/diff/D55946527/)

ghstack-source-id: 221922774
Pull Request resolved: #2958
@cccclai cccclai requested a review from chunit-quic April 10, 2024 00:02
@cccclai cccclai added the partner: qualcomm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Qualcomm label Apr 10, 2024
@chiwwang
Copy link
Contributor

@shewu-quic @haowhsu-quic

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55946527

cccclai added a commit that referenced this pull request Apr 10, 2024
Pull Request resolved: #2958


ghstack-source-id: 222058912
@exported-using-ghexport

In case like
```
def f(x, 2):
    return x * 2
```
Since 2 is a scalar, we'd need to convert them to tensor so quantizer knows how to handle

Differential Revision: [D55946527](https://our.internmc.facebook.com/intern/diff/D55946527/)
@shewu-quic
Copy link
Collaborator

It seems to convert the scalar node of the binary op into a tensor node and allow the node to be quantized.
Maybe the following two passes are also to achieve this thing.

class AnnotateAndQuantScalar(ExportPass):

class ConvertBinaryOpsWithScalar(ExportPass):

if non_const_arg is None or const_arg is None:
continue

tensor_constant = torch.tensor([const_arg], dtype=torch.float32)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we will want to infer data type from data.

@cccclai
Copy link
Contributor Author

cccclai commented Apr 12, 2024

It seems to convert the scalar node of the binary op into a tensor node and allow the node to be quantized. Maybe the following two passes are also to achieve this thing.

class AnnotateAndQuantScalar(ExportPass):

class ConvertBinaryOpsWithScalar(ExportPass):

Oh I see what's going. The convert_binary_op_with_scalar pass runs after quantization process, however we need to run this pass before the quantizer starts annotating, otherwise the scalar may not have an accurate quantization params.

@cccclai
Copy link
Contributor Author

cccclai commented Jun 6, 2025

Stale PR

1 similar comment
@cccclai
Copy link
Contributor Author

cccclai commented Jun 6, 2025

Stale PR

@cccclai cccclai closed this Jun 6, 2025
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. fb-exported partner: qualcomm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Qualcomm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants