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

Add pass for replacing dq-q patterns with rescale #8513

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

Erik-Lundell
Copy link
Collaborator

@Erik-Lundell Erik-Lundell commented Feb 17, 2025

When an int8 op meets an int32 op, the int8 is first dequantized to a float which is then quantized to the desired int8 dtype.

This produces a (int8 dq -> q int32) pattern that
we can replace with a TOSA.RESCALE since they are approximately mathematically equivalent, differing only in how the rounding is done.

This requires a few changes:

  • Introduce custom rescale op
  • Create pass to replace the dq-q pattern with the rescale op
  • Implement node_visitor for rescale op

The change makes it possible to mix int8 and int32 quantization, as showcased in the new test_add_i32_tosa_BI test.

This pr is a reupload after revert #8480

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218

Copy link

pytorch-bot bot commented Feb 17, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 38ac52c with merge base a70c6a3 (image):

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 Feb 17, 2025
@Erik-Lundell Erik-Lundell added ciflow/trunk partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm topic: not user facing and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Feb 17, 2025
@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 Feb 17, 2025
When an int8 op meets an int32 op, the int8 is first
dequantized to a float which is then quantized to the
desired int8 dtype.

This produces a (int8 dq -> q int32) pattern that
we can replace with a TOSA.RESCALE since they are approximately
mathematically equivalent, differing only in how the rounding is done.

This requires a few changes:
- Introduce custom rescale op
- Create pass to replace the dq-q pattern with the rescale op
- Implement node_visitor for rescale op

The change makes it possible to mix int8 and int32 quantization,
as showcased in the new test_add_i32_tosa_BI test.

Signed-off-by: Erik Lundell <erik.lundell@arm.com>
Change-Id: Ifd475ade488fbbeb8395ac883986b19f8edfae5a
@zingo
Copy link
Collaborator

zingo commented Feb 17, 2025

Macos job fail unrelated

@zingo zingo merged commit ed82561 into pytorch:main Feb 17, 2025
108 of 109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants