-
Notifications
You must be signed in to change notification settings - Fork 751
Arm backend: Support channels-last input and output #14400
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
GregoryComer
merged 1 commit into
release/1.0
from
cherry-pick-14259-by-pytorch_bot_bot_
Sep 18, 2025
Merged
Changes from all commits
Commits
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
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,123 @@ | ||
| # Copyright 2024-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 torch | ||
| from executorch.backends.arm.test import common | ||
|
|
||
| from executorch.backends.arm.test.tester.test_pipeline import ( | ||
| EthosU55PipelineINT, | ||
| EthosU85PipelineINT, | ||
| TosaPipelineFP, | ||
| TosaPipelineINT, | ||
| ) | ||
|
|
||
|
|
||
| input_t1 = Tuple[torch.Tensor] # Input x | ||
|
|
||
|
|
||
| class ChannelsLastInput(torch.nn.Module): | ||
| """ | ||
| Test a complex case with (channels last, channels first) input, | ||
| and (channels first, channels last) output. | ||
| """ | ||
|
|
||
| inputs: input_t1 = ( | ||
| torch.arange(1, 25, dtype=torch.float32) | ||
| .reshape((1, 2, 3, 4)) | ||
| .to(memory_format=torch.channels_last), | ||
| torch.arange(1, 25, dtype=torch.float32).reshape((1, 2, 3, 4)), | ||
| ) | ||
|
|
||
| def forward(self, x, y): | ||
| x = x * x | ||
| return y, x | ||
|
|
||
|
|
||
| class ChannelsFirstOutput(torch.nn.Module): | ||
| """ | ||
| Test coverting to channels_first inside the delegate. | ||
| """ | ||
|
|
||
| inputs: input_t1 = ( | ||
| torch.arange(1, 25, dtype=torch.float32) | ||
| .reshape((1, 2, 3, 4)) | ||
| .to(memory_format=torch.channels_last), | ||
| ) | ||
|
|
||
| def forward(self, x): | ||
| x = x.clone(memory_format=torch.contiguous_format) * x | ||
| return x | ||
|
|
||
|
|
||
| class ChannelsLastOutput(torch.nn.Module): | ||
| """ | ||
| Test changing of dim_order inside the delegate. | ||
| """ | ||
|
|
||
| inputs: input_t1 = (torch.arange(1, 9, dtype=torch.float32).reshape((1, 2, 2, 2)),) | ||
|
|
||
| def forward(self, x): | ||
| x = x * x | ||
| x = x.clone(memory_format=torch.channels_last) | ||
| return x | ||
|
|
||
|
|
||
| class ChannelsLastInsidePartition(torch.nn.Module): | ||
| """ | ||
| Test dim_order changes inside the partiton, but no dim_order changes at input/output. | ||
| """ | ||
|
|
||
| inputs: input_t1 = (torch.randn((1, 2, 3, 3)),) | ||
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.conv2d = torch.nn.Conv2d(in_channels=2, out_channels=2, kernel_size=(3, 3)) | ||
|
|
||
| def forward(self, x): | ||
| return ( | ||
| self.conv2d(x.clone(memory_format=torch.channels_last)).clone( | ||
| memory_format=torch.contiguous_format | ||
| ) | ||
| * 1 | ||
| ) | ||
|
|
||
|
|
||
| test_modules = { | ||
| "channels_last_input": ChannelsLastInput, | ||
| "channels_first_output": ChannelsFirstOutput, | ||
| "channels_last_output": ChannelsLastOutput, | ||
| "channels_last_inside_partition": ChannelsLastInsidePartition, | ||
| } | ||
|
|
||
|
|
||
| @common.parametrize("module", test_modules) | ||
| def test_dim_order_tosa_FP(module): | ||
| pipeline = TosaPipelineFP[input_t1](module(), module.inputs, []) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @common.parametrize("module", test_modules) | ||
| def test_dim_order_tosa_INT(module): | ||
| pipeline = TosaPipelineINT[input_t1]( | ||
| module(), module.inputs, [], symmetric_io_quantization=True | ||
| ) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @common.XfailIfNoCorstone300 | ||
| @common.parametrize("module", test_modules) | ||
| def test_dim_order_u55_INT(module): | ||
| pipeline = EthosU55PipelineINT[input_t1](module(), module.inputs, []) | ||
| pipeline.run() | ||
|
|
||
|
|
||
| @common.XfailIfNoCorstone320 | ||
| @common.parametrize("module", test_modules) | ||
| def test_dim_order_u85_INT(module): | ||
| pipeline = EthosU85PipelineINT[input_t1](module(), module.inputs, []) | ||
| pipeline.run() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we (somehow) check if the assumptions in the blob about the input tensor dim_order are satisfied? It can silently do wrong compute is my concern.