Skip to content

Commit f906c61

Browse files
cccclaifacebook-github-bot
authored andcommitted
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 380f372 commit f906c61

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,15 @@ def forward(self, x):
11781178
mode="nearest",
11791179
)
11801180

1181+
class UpsampleNearest2D(torch.nn.Module):
1182+
def __init__(self, sizes=None, scale_factor=None):
1183+
super().__init__()
1184+
self.upsample_neareast_2d = torch.nn.UpsamplingNearest2d( # noqa: TOR101
1185+
size=sizes, scale_factor=scale_factor
1186+
)
1187+
1188+
def forward(self, x):
1189+
return self.upsample_neareast_2d(x)
11811190

11821191
class RmsNorm(torch.nn.Module):
11831192
def __init__(self):

backends/qualcomm/tests/test_qnn_delegate.py

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

478+
def test_qnn_backend_up_sampling_nearest_2d_with_scale_factor(self):
479+
module = UpsampleNearest2D(scale_factor=2) # noqa: F405
480+
sample_input = (torch.randn(1, 16, 72, 104),)
481+
self.lower_module_and_test_output(module, sample_input)
482+
483+
def test_qnn_backend_up_sampling_nearest_2d_with_size(self):
484+
module = UpsampleNearest2D(sizes=(144, 208)) # noqa: F405
485+
sample_input = (torch.randn(1, 16, 72, 104),)
486+
self.lower_module_and_test_output(module, sample_input)
487+
478488
def test_qnn_backend_layer_norm(self):
479489
modules = [LayerNorm(), LayerNorm(bias=False)] # noqa: F405
480490
sample_input = (torch.randn(196, 768),)
@@ -1430,6 +1440,18 @@ def test_qnn_backend_interpolate_nearest_2d(self):
14301440
module = self.get_qdq_module(module, sample_input)
14311441
self.lower_module_and_test_output(module, sample_input)
14321442

1443+
def test_qnn_backend_up_sampling_nearest_2d_with_scale_factor(self):
1444+
module = UpsampleNearest2D(scale_factor=2) # noqa: F405
1445+
sample_input = (torch.randn(1, 16, 72, 104),)
1446+
module = self.get_qdq_module(module, sample_input)
1447+
self.lower_module_and_test_output(module, sample_input)
1448+
1449+
def test_qnn_backend_up_sampling_nearest_2d_with_size(self):
1450+
module = UpsampleNearest2D(sizes=(144, 208)) # noqa: F405
1451+
sample_input = (torch.randn(1, 16, 72, 104),)
1452+
module = self.get_qdq_module(module, sample_input)
1453+
self.lower_module_and_test_output(module, sample_input)
1454+
14331455
def test_qnn_backend_layer_norm(self):
14341456
modules = [LayerNorm(), LayerNorm(bias=False)] # noqa: F405
14351457
sample_input = (torch.randn(196, 768),)

0 commit comments

Comments
 (0)