Skip to content

Commit 8a5a62b

Browse files
cccclaiDannyYuyang-quic
authored andcommitted
Enable aten.upsample_nearest2d.vec (pytorch#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 682e9e4 commit 8a5a62b

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
@@ -1209,6 +1209,17 @@ def forward(self, x):
12091209
)
12101210

12111211

1212+
class UpsampleNearest2D(torch.nn.Module):
1213+
def __init__(self, sizes=None, scale_factor=None):
1214+
super().__init__()
1215+
self.upsample_neareast_2d = torch.nn.UpsamplingNearest2d( # noqa: TOR101
1216+
size=sizes, scale_factor=scale_factor
1217+
)
1218+
1219+
def forward(self, x):
1220+
return self.upsample_neareast_2d(x)
1221+
1222+
12121223
class RmsNorm(torch.nn.Module):
12131224
def __init__(self):
12141225
super().__init__()

backends/qualcomm/tests/test_qnn_delegate.py

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

510+
def test_qnn_backend_up_sampling_nearest_2d_with_scale_factor(self):
511+
module = UpsampleNearest2D(scale_factor=2) # noqa: F405
512+
sample_input = (torch.randn(1, 16, 72, 104),)
513+
self.lower_module_and_test_output(module, sample_input)
514+
515+
def test_qnn_backend_up_sampling_nearest_2d_with_size(self):
516+
module = UpsampleNearest2D(sizes=(144, 208)) # noqa: F405
517+
sample_input = (torch.randn(1, 16, 72, 104),)
518+
self.lower_module_and_test_output(module, sample_input)
519+
510520
def test_qnn_backend_layer_norm(self):
511521
modules = [LayerNorm(), LayerNorm(bias=False)] # noqa: F405
512522
sample_input = (torch.randn(196, 768),)
@@ -1498,6 +1508,18 @@ def test_qnn_backend_interpolate_nearest_2d(self):
14981508
module = self.get_qdq_module(module, sample_input)
14991509
self.lower_module_and_test_output(module, sample_input)
15001510

1511+
def test_qnn_backend_up_sampling_nearest_2d_with_scale_factor(self):
1512+
module = UpsampleNearest2D(scale_factor=2) # noqa: F405
1513+
sample_input = (torch.randn(1, 16, 72, 104),)
1514+
module = self.get_qdq_module(module, sample_input)
1515+
self.lower_module_and_test_output(module, sample_input)
1516+
1517+
def test_qnn_backend_up_sampling_nearest_2d_with_size(self):
1518+
module = UpsampleNearest2D(sizes=(144, 208)) # noqa: F405
1519+
sample_input = (torch.randn(1, 16, 72, 104),)
1520+
module = self.get_qdq_module(module, sample_input)
1521+
self.lower_module_and_test_output(module, sample_input)
1522+
15011523
def test_qnn_backend_layer_norm(self):
15021524
modules = [LayerNorm(), LayerNorm(bias=False)] # noqa: F405
15031525
sample_input = (torch.randn(196, 768),)

0 commit comments

Comments
 (0)