Skip to content

Conversation

martinlsm
Copy link
Collaborator

@martinlsm martinlsm commented Sep 25, 2025

Some TOSA ops do not support INT8 as inputs and outputs. Instead, only INT32 is supported as a whole number type. Prior to this patch, affected node visitors inserted rescale ops between the data types INT8 and INT32 before and after the operator such that it will accept its input and output.

Change this by moving the insertion of the rescale ops to a new pass called InsertRescaleInt32Pass. This will further enable optimizations to the graph by fusing the rescale nodes.

Only comparison, ABS, MAXIMUM and MINIMUM operators are handled in this patch; the remaining ones are left out to be done in another patch.

Test plan

This is refactoring which means that external behavior is not altered. A new pass InsertRescaleInt32Pass has been added and it comes with a new unit test in backends/arm/test/passes/test_insert_rescale_i32_pass.py.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218

Copy link

pytorch-bot bot commented Sep 25, 2025

🔗 Helpful Links

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

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

❌ 2 New Failures, 1 Unrelated Failure

As of commit 0b65f38 with merge base f81e834 (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.

@meta-cla meta-cla 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 Sep 25, 2025
@martinlsm
Copy link
Collaborator Author

@pytorchbot label ciflow/trunk

@martinlsm
Copy link
Collaborator Author

@pytorchbot label "partner: arm"

@pytorch-bot pytorch-bot bot added the partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm label Sep 25, 2025
@martinlsm
Copy link
Collaborator Author

failures look unrelated

@digantdesai digantdesai added the release notes: none Do not include this in the release notes label Sep 29, 2025
dtype=torch.int32,
)

if target in [
Copy link
Contributor

Choose a reason for hiding this comment

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

may be this boat has sailed already but for logical grouping perspective, I would rather keep the util call in respective ops instead of a pass.. but that's just me. Not a strong objection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@digantdesai Not sure what you mean fully. Can you elaborate a bit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of inserting rescale ops in the tosa graph through this pass, I would prefer (mild preference) of keeping the way things were, i.e. an op lowering (op_.py) would inject an op when needed.

This is mainly to keep things together logically and keep the tosa graph 'sound' after each op lowering.

That said I understand the code duplication aspect, but that could be tackled with keeping these insert rescale as util functions.

Again, not a strong objection. Stamping to unblock you, and leaving it up to you to decide.

Thanks!

Martin Lindström and others added 2 commits September 30, 2025 11:10
Some TOSA ops do not support INT8 as inputs and outputs. Instead, only
INT32 is supported as a whole number type. Prior to this patch, affected
node visitors inserted rescale ops between the data types INT8 and INT32
before and after the operator such that it will accept its input and
output.

Change this by moving the insertion of the rescale ops to a new pass
called InsertRescaleInt32Pass. This will further enable optimizations to
the graph by fusing the rescale nodes.

Only comparison operators are handled in this patch; the remaining ones
are left out to be done in another patch.

Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com>
Change-Id: I6bb8a10a0b453ae9fd8b8604d64cc5103a4da050
Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com>
Co-authored-by: Oscar Andersson <Oscar.Andersson@arm.com>
Change-Id: I62fdc5bea75361d6c32711968bdc1c9d03677ccc
@martinlsm martinlsm changed the title Arm backend: Move rescale ops out of comparison visitors Arm backend: Move rescale ops out of ABS and comparison visitors Sep 30, 2025
Signed-off-by: Martin Lindström <Martin.Lindstroem@arm.com>
Change-Id: I5ee8f97590ce599a9dfc60ced0775654fa565c4e
@martinlsm martinlsm changed the title Arm backend: Move rescale ops out of ABS and comparison visitors Arm backend: Move rescale ops out of node visitors Oct 1, 2025
martinlsm and others added 4 commits October 1, 2025 10:41
Signed-off-by: Martin Lindstroem <Martin.Lindstroem@arm.com>
Co-authored-by: Oscar Andersson <Oscar.Andersson@arm.com>
Change-Id: I38d63015e03e59c267338c84d64731b050854d06
@zingo zingo merged commit 2c603e4 into pytorch:main Oct 7, 2025
278 of 281 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 release notes: none Do not include this in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants