Skip to content

Commit 427a14d

Browse files
GregoryComerYIWENX14
authored andcommitted
Update XNN delegate to handle non-decomposed upsample ops
Differential Revision: D68374352 Pull Request resolved: #7770
1 parent c570fbf commit 427a14d

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

backends/xnnpack/_passes/convert_to_upsample_bilinear2d.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
# pyre-unsafe
8+
79
import torch
810
from executorch.backends.xnnpack._passes.xnnpack_pass import XNNPACKPass
911
from executorch.backends.xnnpack.partition.graphs import bilinear_2d
@@ -23,6 +25,10 @@ def create_upsample_bilinear_2d(
2325
align_corners: bool,
2426
):
2527
output = internal_match.returning_nodes[0]
28+
if output.target == exir_ops.edge.aten.upsample_bilinear2d.vec:
29+
# Op was not decomposed, do nothing
30+
return
31+
2632
output_shape = output.meta["val"].shape
2733
output_h = output_shape[-2]
2834
output_w = output_shape[-1]

backends/xnnpack/test/ops/test_bilinear2d.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
# pyre-unsafe
8+
79
import unittest
810

911
import torch
@@ -131,11 +133,17 @@ def test_fp32_bilinear2d_dynamic_bilinear2d_not_partitioned(self):
131133
3: torch.export.Dim("w", min=1, max=12),
132134
}
133135
}
134-
(
136+
artifact_str = str(
135137
Tester(self.StaticResizeBilinear2dModule(), example_inputs)
136138
.export(Export(dynamic_shapes))
137139
.to_edge_transform_and_lower()
138-
# NOTE The decomposition is partially delegated. This will need to be replaced
139-
# with the aten upsample op once decomp is removed.
140-
.check("executorch_exir_dialects_edge__ops_aten_index_Tensor")
140+
.get_artifact()
141+
.exported_program()
142+
)
143+
# NOTE The decomposition can be partially delegated. This will need to be replaced
144+
# with the aten upsample op once decomp is removed.
145+
self.assertTrue(
146+
"executorch_exir_dialects_edge__ops_aten_index_Tensor" in artifact_str
147+
or "executorch_exir_dialects_edge__ops_aten_upsample_bilinear2d_vec"
148+
in artifact_str
141149
)

exir/emit/test/test_emit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ class M(torch.nn.Module):
642642
def forward(self, x):
643643
return torch.nn.functional.interpolate(x, scale_factor=2)
644644

645-
x = (torch.randn(1, 1, 2, 2),)
645+
x = (torch.randn(1, 1, 2, 2, 2),)
646646
program = (
647647
to_edge(export(M(), x, strict=True)).to_executorch().executorch_program
648648
)

0 commit comments

Comments
 (0)