Skip to content

Commit a8e4be4

Browse files
committed
partition to_dim_order_copy in XNN delegate
1 parent be56146 commit a8e4be4

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

backends/xnnpack/_passes/channels_last_tagged_reshape_pass.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ def call(self, graph_module: torch.fx.GraphModule): # noqa: C901
400400
# The node requires nchw inputs
401401
for input_node in node.all_input_nodes:
402402
self.input_to_nchw(graph_module, input_node, node)
403+
elif node.target == exir_ops.edge.aten._to_copy.default:
404+
if node.meta["val"].is_contiguous():
405+
self.mark_as_nchw_node(node)
406+
else:
407+
self.mark_as_nhwc_node(node)
403408
else:
404409
# The node can have inputs in any format (but all must be the
405410
# same format)

backends/xnnpack/partition/config/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
SoftmaxConfig,
4949
SquareRootConfig,
5050
SubConfig,
51+
ToDimOrderCopyConfig,
5152
UpsampleBilinear2dConfig,
5253
)
5354
from executorch.backends.xnnpack.partition.config.node_configs import (
@@ -97,6 +98,7 @@
9798
PreluConfig,
9899
ReciprocalSquareRootConfig,
99100
ReLUConfig,
101+
ToDimOrderCopyConfig,
100102
# SDPAConfig, TODO: D60553559: preserving SDPA for fairseq fails
101103
SigmoidConfig,
102104
SliceCopyConfig,

backends/xnnpack/partition/config/generic_node_configs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ def supported_precision_types(self) -> List[ConfigPrecisionType]:
364364
return [ConfigPrecisionType.FP32]
365365

366366

367+
class ToDimOrderCopyConfig(GenericNodePartitionerConfig):
368+
target_name = "_to_dim_order_copy.default"
369+
370+
def supported_precision_types(self) -> List[ConfigPrecisionType]:
371+
return [ConfigPrecisionType.FP32]
372+
373+
367374
class MeanDimConfig(GenericNodePartitionerConfig):
368375
target_name = "mean.dim"
369376

backends/xnnpack/test/passes/test_channels_last_tagged_reshape.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ def test_fp32_channels_last_tagged_reshape_pass(self):
173173
.run_method_and_compare_outputs()
174174
)
175175

176+
class LinearConvDimSwap(torch.nn.Module):
177+
def __init__(self):
178+
super().__init__()
179+
self.conv1 = torch.nn.Conv2d(3, 3, 3)
180+
self.linear1 = torch.nn.Linear(4, 3)
181+
182+
def forward(self, x):
183+
y = self.linear1(x)
184+
y = y.to(memory_format=torch.channels_last)
185+
y = y.to(memory_format=torch.contiguous_format)
186+
return self.conv1(y)
187+
188+
LinearConvDimSwapModule = LinearConvDimSwap()
189+
190+
def test_conv_linear_dim_order_swap_partitioner(self):
191+
self.run_tester(self.LinearConvDimSwapModule, (torch.randn(1, 3, 6, 4),))
192+
176193
def test_qs8_channels_last_tagged_reshape_pass(self):
177194
for module, num_reshape in self.modules.items():
178195
(

0 commit comments

Comments
 (0)