-
Notifications
You must be signed in to change notification settings - Fork 722
Milestone2.1: Partition to_dim_order_copy op in XNN delegate #12220
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from executorch.backends.xnnpack.test.tester import Tester | ||
|
|
||
|
|
||
| class TestChannelsLastTaggedReshapePass(unittest.TestCase): | ||
| def setUp(self): | ||
| torch._dynamo.reset() | ||
|
|
||
| def run_tester(self, module, inputs): | ||
| tester = Tester( | ||
| module.eval(), | ||
| inputs, | ||
| ) | ||
| tester.export().to_edge_transform_and_lower().check_not( | ||
| ["executorch_exir_dialects_edge__ops_aten__to_copy_default"] | ||
| ).to_executorch().serialize().run_method_and_compare_outputs() | ||
|
|
||
| class ChannelLastBeforeLinear(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.linear = torch.nn.Linear(3, 3) | ||
|
|
||
| def forward(self, x): | ||
| y = x.to(memory_format=torch.channels_last) | ||
| return self.linear(y) | ||
|
|
||
| ChannelLastBeforeLinearModule = ChannelLastBeforeLinear() | ||
|
|
||
| def test_channel_last_before_linear(self): | ||
| self.run_tester(self.ChannelLastBeforeLinearModule, (torch.randn(1, 3, 3, 3),)) | ||
|
|
||
| class ContiguousBeforeConv(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.conv = torch.nn.Conv2d(3, 3, 3) | ||
|
|
||
| def forward(self, x): | ||
| y = x.to(memory_format=torch.contiguous_format) | ||
| return self.conv(y) | ||
|
|
||
| ContiguousBeforeConvModule = ContiguousBeforeConv() | ||
|
|
||
| def test_contiguous_before_conv(self): | ||
| self.run_tester(self.ContiguousBeforeConvModule, (torch.randn(1, 3, 6, 6),)) | ||
|
|
||
| class DtypeAndMemoryFormatConversion(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.conv = torch.nn.Conv2d(3, 3, 3) | ||
|
|
||
| def forward(self, x): | ||
| y = x.to(torch.float, memory_format=torch.channels_last) | ||
| return self.conv(y) | ||
|
|
||
| DtypeAndMemoryFormatConversionModule = DtypeAndMemoryFormatConversion() | ||
|
|
||
| def test_dtype_and_memory_format_conversion(self): | ||
| self.run_tester( | ||
| self.DtypeAndMemoryFormatConversionModule, | ||
| (torch.randint(0, 10, (1, 3, 6, 6), dtype=torch.int32),), | ||
| ) | ||
|
|
||
| class DtypeAndMemoryFormatWithLinear(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.linear = torch.nn.Linear(3, 3) | ||
|
|
||
| def forward(self, x): | ||
| y = x.to(torch.float, memory_format=torch.channels_last) | ||
| return self.linear(y) | ||
|
|
||
| DtypeAndMemoryFormatWithLinearModule = DtypeAndMemoryFormatWithLinear() | ||
|
|
||
| def test_dtype_and_memory_format_with_linear(self): | ||
| self.run_tester( | ||
| self.DtypeAndMemoryFormatWithLinearModule, | ||
| (torch.randint(0, 10, (1, 3, 3, 3), dtype=torch.int16),), | ||
| ) | ||
|
|
||
| class QuantizedToCopy(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.conv = torch.nn.Conv2d(3, 3, 3) | ||
| self.conv2 = torch.nn.Conv2d(3, 3, 3) | ||
|
|
||
| def forward(self, x): | ||
| y = self.conv(x) | ||
| y = y.to(memory_format=torch.contiguous_format) | ||
| return self.conv2(y) | ||
|
|
||
| QuantizedToCopyModule = QuantizedToCopy() | ||
|
|
||
| def test_quantized_to_copy(self): | ||
| tester = Tester( | ||
| self.QuantizedToCopyModule.eval(), | ||
| (torch.randn(1, 3, 9, 9),), | ||
| ) | ||
|
|
||
| tester.quantize().export().to_edge_transform_and_lower().check_not( | ||
| [ | ||
| "executorch_exir_dialects_edge__ops_aten__to_copy_default", | ||
| "executorch_exir_dialects_edge__ops_quantized_decomposed_quantize_per_tensor_default", | ||
| ] | ||
| ).to_executorch().serialize().run_method_and_compare_outputs(qtol=0.01) | ||
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.
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.
As I said earlier, using
to_copyis OK but we can just as easily move toto_dim_order_copyand remove the dim_order ops revert pass.