Skip to content

Commit

Permalink
Update XNN delegate to handle non-decomposed upsample ops
Browse files Browse the repository at this point in the history
Differential Revision: D68374352

Pull Request resolved: #7770
  • Loading branch information
GregoryComer authored Jan 21, 2025
1 parent 230858d commit 466d98f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backends/xnnpack/_passes/convert_to_upsample_bilinear2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# pyre-unsafe

import torch
from executorch.backends.xnnpack._passes.xnnpack_pass import XNNPACKPass
from executorch.backends.xnnpack.partition.graphs import bilinear_2d
Expand All @@ -23,6 +25,10 @@ def create_upsample_bilinear_2d(
align_corners: bool,
):
output = internal_match.returning_nodes[0]
if output.target == exir_ops.edge.aten.upsample_bilinear2d.vec:
# Op was not decomposed, do nothing
return

output_shape = output.meta["val"].shape
output_h = output_shape[-2]
output_w = output_shape[-1]
Expand Down
16 changes: 12 additions & 4 deletions backends/xnnpack/test/ops/test_bilinear2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# pyre-unsafe

import unittest

import torch
Expand Down Expand Up @@ -131,11 +133,17 @@ def test_fp32_bilinear2d_dynamic_bilinear2d_not_partitioned(self):
3: torch.export.Dim("w", min=1, max=12),
}
}
(
artifact_str = str(
Tester(self.StaticResizeBilinear2dModule(), example_inputs)
.export(Export(dynamic_shapes))
.to_edge_transform_and_lower()
# NOTE The decomposition is partially delegated. This will need to be replaced
# with the aten upsample op once decomp is removed.
.check("executorch_exir_dialects_edge__ops_aten_index_Tensor")
.get_artifact()
.exported_program()
)
# NOTE The decomposition can be partially delegated. This will need to be replaced
# with the aten upsample op once decomp is removed.
self.assertTrue(
"executorch_exir_dialects_edge__ops_aten_index_Tensor" in artifact_str
or "executorch_exir_dialects_edge__ops_aten_upsample_bilinear2d_vec"
in artifact_str
)
2 changes: 1 addition & 1 deletion exir/emit/test/test_emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ class M(torch.nn.Module):
def forward(self, x):
return torch.nn.functional.interpolate(x, scale_factor=2)

x = (torch.randn(1, 1, 2, 2),)
x = (torch.randn(1, 1, 2, 2, 2),)
program = (
to_edge(export(M(), x, strict=True)).to_executorch().executorch_program
)
Expand Down

0 comments on commit 466d98f

Please sign in to comment.