-
Notifications
You must be signed in to change notification settings - Fork 725
Arm backend: Annotate ADD/SUB with indepenedent observers #13516
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
Merged
zingo
merged 3 commits into
pytorch:main
from
gggekov:Meta_fusing_conv1d_relu_residual_add
Sep 2, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # Copyright 2025 Arm Limited and/or its affiliates. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| from typing import Tuple | ||
|
|
||
| import pytest | ||
|
|
||
| import torch | ||
| import torch.nn as nn | ||
| from executorch.backends.arm.test import common | ||
|
|
||
| from executorch.backends.arm.test.tester.test_pipeline import ( | ||
| EthosU55PipelineINT, | ||
| EthosU85PipelineINT, | ||
| TosaPipelineFP, | ||
| TosaPipelineINT, | ||
| ) | ||
|
|
||
|
|
||
| # Model with Conv1D - ReLU sequence and a residual add. | ||
| # Testing the annotation of Conv1D-ReLU(to be fused) and annotation of add. | ||
| # ReLU outputs positive numbers and linear outputs positive and negative numbers, so they | ||
| # should have different quantisation parameters. If the ReLU gets wrong quantisation parameters(e.g. qmin!=zp) | ||
| # because of a shared observer of a following operators(e.g. add), the Conv1D-ReLU sequence is not fused | ||
| # and is left in FP32. As a result, the test fails. | ||
| class AddDifferentRanges(torch.nn.Module): | ||
| def __init__(self, in_channels, out_channels, kernel_size, input_dim): | ||
| super().__init__() | ||
| self.conv1 = nn.Conv1d(in_channels, out_channels, kernel_size) | ||
| self.relu = torch.nn.ReLU() | ||
| self.linear = nn.Linear(out_channels, out_channels) | ||
|
|
||
| def forward(self, x): | ||
| # Permute: (N, T, C) -> (N, C, T) | ||
| x = x.permute(0, 2, 1) | ||
| x = self.conv1(x) | ||
| x = self.relu(x) | ||
| x = x.permute(0, 2, 1) | ||
| out = x + self.linear(x) | ||
| return out | ||
|
|
||
|
|
||
| input_t = Tuple[torch.Tensor] | ||
| model = AddDifferentRanges(in_channels=3, out_channels=16, kernel_size=3, input_dim=10) | ||
| model_inputs = (torch.randn(1, 10, 3),) | ||
| quant_test_data = { | ||
| "per_channel_quantization=true": True, | ||
| "per_channel_quantization=false": False, | ||
| } | ||
|
|
||
|
|
||
| def test_tosa_FP(): | ||
| pipeline = TosaPipelineFP[input_t]( | ||
| model, | ||
| model_inputs, | ||
| aten_op=[], | ||
| exir_op=[], | ||
| use_to_edge_transform_and_lower=True, | ||
| ) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @common.parametrize("per_channel_quantization", quant_test_data) | ||
| def test_tosa_INT(per_channel_quantization): | ||
| pipeline = TosaPipelineINT[input_t]( | ||
| model, | ||
| model_inputs, | ||
| aten_op=[], | ||
| exir_op=[], | ||
| use_to_edge_transform_and_lower=True, | ||
| per_channel_quantization=per_channel_quantization, | ||
| qtol=0, | ||
| ) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @pytest.mark.slow | ||
| @common.XfailIfNoCorstone300 | ||
| @common.parametrize("per_channel_quantization", quant_test_data) | ||
| def test_tosa_u55_INT(per_channel_quantization): | ||
| pipeline = EthosU55PipelineINT[input_t]( | ||
| model, | ||
| model_inputs, | ||
| [], | ||
| [], | ||
| run_on_fvp=True, | ||
| use_to_edge_transform_and_lower=True, | ||
| per_channel_quantization=per_channel_quantization, | ||
| qtol=0, | ||
| ) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @pytest.mark.slow | ||
| @common.XfailIfNoCorstone320 | ||
| @common.parametrize("per_channel_quantization", quant_test_data) | ||
| def test_tosa_u85_INT(per_channel_quantization): | ||
| pipeline = EthosU85PipelineINT[input_t]( | ||
| model, | ||
| model_inputs, | ||
| [], | ||
| [], | ||
| run_on_fvp=True, | ||
| use_to_edge_transform_and_lower=True, | ||
| per_channel_quantization=per_channel_quantization, | ||
| qtol=0, | ||
| ) | ||
| pipeline.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Copyright 2025 Arm Limited and/or its affiliates. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| from typing import Tuple | ||
|
|
||
| import pytest | ||
|
|
||
| import torch | ||
| from executorch.backends.arm.test import common | ||
| from executorch.backends.arm.test.tester.test_pipeline import ( | ||
| EthosU55PipelineINT, | ||
| EthosU85PipelineINT, | ||
| TosaPipelineFP, | ||
| TosaPipelineINT, | ||
| ) | ||
|
|
||
| from torchvision import transforms # type: ignore[import-untyped] | ||
| from torchvision.models import resnet18, ResNet18_Weights | ||
|
|
||
| model = resnet18(weights=ResNet18_Weights) | ||
| model = model.eval() | ||
| normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) | ||
|
|
||
| model_inputs = (normalize(torch.randn((1, 3, 224, 224))),) | ||
|
|
||
| input_t = Tuple[torch.Tensor] | ||
|
|
||
|
|
||
| quant_test_data = { | ||
| "per_channel_quantization=true": True, | ||
| "per_channel_quantization=false": False, | ||
| } | ||
|
|
||
|
|
||
| def test_resnet_tosa_FP(): | ||
| pipeline = TosaPipelineFP[input_t]( | ||
| model, | ||
| model_inputs, | ||
| aten_op=[], | ||
| exir_op=[], | ||
| use_to_edge_transform_and_lower=True, | ||
| ) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @common.parametrize("per_channel_quantization", quant_test_data) | ||
| def test_resnet_tosa_INT(per_channel_quantization): | ||
| pipeline = TosaPipelineINT[input_t]( | ||
| model, | ||
| model_inputs, | ||
| aten_op=[], | ||
| exir_op=[], | ||
| use_to_edge_transform_and_lower=True, | ||
| per_channel_quantization=per_channel_quantization, | ||
| atol=0.5, | ||
| qtol=1, | ||
| ) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @pytest.mark.slow | ||
| @common.XfailIfNoCorstone300 | ||
| @common.parametrize("per_channel_quantization", quant_test_data) | ||
| def test_resnet_u55_INT(per_channel_quantization): | ||
| pipeline = EthosU55PipelineINT[input_t]( | ||
| model, | ||
| model_inputs, | ||
| aten_ops=[], | ||
| exir_ops=[], | ||
| run_on_fvp=True, | ||
| use_to_edge_transform_and_lower=True, | ||
| per_channel_quantization=per_channel_quantization, | ||
| atol=0.5, | ||
| qtol=1, | ||
| ) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @pytest.mark.slow | ||
| @pytest.mark.xfail( | ||
| reason="For resnet18 for Ethos-U85, the SRAM memory footprint is very high. The compiler team is investigating." | ||
| ) | ||
| @common.XfailIfNoCorstone320 | ||
| @common.parametrize("per_channel_quantization", quant_test_data) | ||
| def test_resnet_u85_INT(per_channel_quantization): | ||
| pipeline = EthosU85PipelineINT[input_t]( | ||
| model, | ||
| model_inputs, | ||
| aten_ops=[], | ||
| exir_ops=[], | ||
| run_on_fvp=True, | ||
| use_to_edge_transform_and_lower=True, | ||
| per_channel_quantization=per_channel_quantization, | ||
| atol=0.5, | ||
| qtol=1, | ||
| ) | ||
| pipeline.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.