Skip to content

Commit 1011fdc

Browse files
authored
Enable aten.upsample_nearest2d.vec (#9067)
Summary: As title, fix some edge cases and add two unit tests ``` buck test 'fbcode//mode/dev-nosan' fbcode//executorch/backends/qualcomm/tests/fb:test_qnn_delegate_simulator -- --exact 'executorch/backends/qualcomm/tests/fb:test_qnn_delegate_simulator - test_qnn_backend_up_sampling_nearest_2d_with_size (executorch.backends.qualcomm.tests.fb.test_qnn_delegate_simulator.TestQNNQuantizedOperatorSimulator)' buck test 'fbcode//mode/dev-nosan' fbcode//executorch/backends/qualcomm/tests/fb:test_qnn_delegate_simulator -- --exact 'executorch/backends/qualcomm/tests/fb:test_qnn_delegate_simulator - test_qnn_backend_up_sampling_nearest_2d_with_size (executorch.backends.qualcomm.tests.fb.test_qnn_delegate_simulator.TestQNNFloatingPointOperatorSimulator)' ``` Differential Revision: D70796006
1 parent dd9a85a commit 1011fdc

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

backends/qualcomm/_passes/layout_transform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class LayoutTransform(ExportPass):
4242
exir_ops.edge.aten.pixel_unshuffle.default,
4343
exir_ops.edge.aten.upsample_bilinear2d.default,
4444
exir_ops.edge.aten.upsample_nearest2d.default,
45+
exir_ops.edge.aten.upsample_nearest2d.vec,
4546
}
4647

4748
layout_agnostic_ops = {

backends/qualcomm/builders/op_upsample_nearest2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@register_node_visitor
1818
class ResizeBilinear(NodeVisitor):
19-
target = ["aten.upsample_nearest2d.default"]
19+
target = ["aten.upsample_nearest2d.default", "aten.upsample_nearest2d.vec"]
2020

2121
def __init__(self, *args) -> None:
2222
super().__init__(*args)

backends/qualcomm/tests/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,17 @@ def forward(self, x):
12011201
)
12021202

12031203

1204+
class UpsampleNearest2D(torch.nn.Module):
1205+
def __init__(self, sizes=None, scale_factor=None):
1206+
super().__init__()
1207+
self.upsample_neareast_2d = torch.nn.UpsamplingNearest2d( # noqa: TOR101
1208+
size=sizes, scale_factor=scale_factor
1209+
)
1210+
1211+
def forward(self, x):
1212+
return self.upsample_neareast_2d(x)
1213+
1214+
12041215
class RmsNorm(torch.nn.Module):
12051216
def __init__(self):
12061217
super().__init__()

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,16 @@ def test_qnn_backend_interpolate_nearest_2d(self):
502502
sample_input = (torch.randn(2, 3, 4, 5),)
503503
self.lower_module_and_test_output(module, sample_input)
504504

505+
def test_qnn_backend_up_sampling_nearest_2d_with_scale_factor(self):
506+
module = UpsampleNearest2D(scale_factor=2) # noqa: F405
507+
sample_input = (torch.randn(1, 16, 72, 104),)
508+
self.lower_module_and_test_output(module, sample_input)
509+
510+
def test_qnn_backend_up_sampling_nearest_2d_with_size(self):
511+
module = UpsampleNearest2D(sizes=(144, 208)) # noqa: F405
512+
sample_input = (torch.randn(1, 16, 72, 104),)
513+
self.lower_module_and_test_output(module, sample_input)
514+
505515
def test_qnn_backend_layer_norm(self):
506516
modules = [LayerNorm(), LayerNorm(bias=False)] # noqa: F405
507517
sample_input = (torch.randn(196, 768),)
@@ -1485,6 +1495,18 @@ def test_qnn_backend_interpolate_nearest_2d(self):
14851495
module = self.get_qdq_module(module, sample_input)
14861496
self.lower_module_and_test_output(module, sample_input)
14871497

1498+
def test_qnn_backend_up_sampling_nearest_2d_with_scale_factor(self):
1499+
module = UpsampleNearest2D(scale_factor=2) # noqa: F405
1500+
sample_input = (torch.randn(1, 16, 72, 104),)
1501+
module = self.get_qdq_module(module, sample_input)
1502+
self.lower_module_and_test_output(module, sample_input)
1503+
1504+
def test_qnn_backend_up_sampling_nearest_2d_with_size(self):
1505+
module = UpsampleNearest2D(sizes=(144, 208)) # noqa: F405
1506+
sample_input = (torch.randn(1, 16, 72, 104),)
1507+
module = self.get_qdq_module(module, sample_input)
1508+
self.lower_module_and_test_output(module, sample_input)
1509+
14881510
def test_qnn_backend_layer_norm(self):
14891511
modules = [LayerNorm(), LayerNorm(bias=False)] # noqa: F405
14901512
sample_input = (torch.randn(196, 768),)

0 commit comments

Comments
 (0)