-
Notifications
You must be signed in to change notification settings - Fork 752
Arm backend: Support channels-last input and output #14259
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
facebook-github-bot
merged 7 commits into
pytorch:main
from
AdrianLundell:export-D82171193
Sep 17, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
861e98a
Arm backend: Refactor compile spec handling (Try 2) (#14191)
mergennachin c996232
Arm backend: Support channels-last input and output
AdrianLundell bccaa2a
Merge branch 'main' into export-D82171193
zingo 9a4440e
Merge branch 'main' of https://github.com/pytorch/executorch into exp…
AdrianLundell cc7d899
Fix upsteam review comments
AdrianLundell 843e600
Fix mypy linter error
AdrianLundell adec5aa
Merge branch 'main' into export-D82171193
AdrianLundell 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.
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.
this implies it can handle anything i.e. transpose op is inserted if it was needed. But what about asserting expectations. I.e. if user exported with NCHW and we inserted a transpose_to_nhwc AoT, what if now user supplied NHWC (instead of assumed NCHW), shouldn't we validate since we don't "check and optionally transpose" at runtime.
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.
Good point and I agree, however since we are past the branch cutoff date and we need this patch to unblock a major use case for us, may I ask to ignore this for now and fix this in a later PR?
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.
No worries. I assumed that and stamped already :)
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.
Does the stamp mean we can merge, or do we still wait och Meta to merge?
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.
haha good I was in the non-GA mode already where stamp --> you merge --> Internal failure --> we revert
But looking at the activity from @mergennachin he is, rightfully, still in GA mental mode for this GA critical PR. So if the internal CI is clean, he or I can merge this.
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.
Thanks, Im happy and you handle it fast so no problem, I just want to avoid an n"o one does it" situation 😆 as there might be a merge/sync to 1.0 coming up.
And I also dont expect any PR not 1.0 milestone tagged to be be merged. If so its just a bonus.