Skip to content

Conversation

@Erik-Lundell
Copy link
Collaborator

@Erik-Lundell Erik-Lundell commented Feb 12, 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.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218

@pytorch-bot
Copy link

pytorch-bot bot commented Feb 12, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 1c39228 with merge base 8d96d74 (image):

NEW FAILURE - The following job has failed:

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 12, 2025
@Erik-Lundell Erik-Lundell added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk 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 12, 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 12, 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 zingo merged commit 0740a11 into pytorch:main Feb 13, 2025
108 of 109 checks passed
from typing import Tuple

import torch
from executorch.backends.arm.arm_backend import get_tosa_version
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to have broken the unittest-arm job:
https://github.com/pytorch/executorch/actions/runs/13311971065/job/37176555490#step:15:11475

_______________________ ERROR collecting ops/test_add.py _______________________
ImportError while importing test module '/pytorch/executorch/backends/arm/test/ops/test_add.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/conda/envs/py_3.10/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
backends/arm/test/ops/test_add.py:12: in <module>
    from executorch.backends.arm.arm_backend import get_tosa_version
E   ImportError: cannot import name 'get_tosa_version' from 'executorch.backends.arm.arm_backend' (/opt/conda/envs/py_3.10/lib/python3.10/site-packages/executorch/backends/arm/arm_backend.py)

Copy link
Collaborator

@zingo zingo Feb 13, 2025

Choose a reason for hiding this comment

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

Yes i also think it did, sorry for the messup. I confirm with a revert to make sure it fixes it. If so lets merge the revert and fix/retry this PR again later.

zingo added a commit that referenced this pull request Feb 13, 2025
dbort pushed a commit that referenced this pull request Feb 14, 2025
Revert "Arm backend: Add pass for replacing dq-q patterns with rescale (#8415)"

This reverts commit 0740a11, which broke some tests
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.

4 participants