77import pytest
88import torch
99
10- from executorch .backends .nxp .tests .executorch_pipeline import to_edge_program
10+ from executorch .backends .nxp .tests .executorch_pipeline import (
11+ to_edge_program ,
12+ to_quantized_edge_program ,
13+ )
1114from executorch .backends .nxp .tests .executors import (
1215 convert_run_compare ,
1316 ToNCHWPreprocess ,
@@ -60,16 +63,10 @@ def test_constant_pad_nd_conversion__default_constant():
6063 pytest .param ([2 , 4 ], list (range (4 )), id = "2D, padding N, H" ),
6164 pytest .param ([2 , 4 , 6 ], list (range (2 )), id = "3D, padding H" ),
6265 pytest .param ([2 , 4 , 6 ], list (range (4 )), id = "3D, padding C, H" ),
63- pytest .param ([2 , 4 , 6 ], list (range (6 )), id = "3D, padding N, C, H" ),
6466 pytest .param ([2 , 4 , 6 , 8 ], list (range (2 )), id = "4D, padding W" ),
6567 pytest .param ([2 , 4 , 6 , 8 ], list (range (4 )), id = "4D, padding H, W" ),
66- pytest .param ([2 , 4 , 6 , 8 ], list (range (6 )), id = "4D, padding C, H, W" ),
67- pytest .param ([2 , 4 , 6 , 8 ], list (range (8 )), id = "4D, padding N, C, H, W" ),
6868 pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (2 )), id = "5D, padding D" ),
6969 pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (4 )), id = "5D, padding W, D" ),
70- pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (6 )), id = "5D, padding H, W, D" ),
71- pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (8 )), id = "5D, padding C, H, W, D" ),
72- pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (10 )), id = "5D, padding N, C, H, W, D" ),
7370 ],
7471)
7572def test_constant_pad_nd_conversion__format_less (input_shape , paddings ):
@@ -87,13 +84,12 @@ def test_constant_pad_nd_conversion__format_less(input_shape, paddings):
8784 [
8885 pytest .param ([1 , 4 , 6 , 8 ], list (range (2 )), id = "4D, padding W" ),
8986 pytest .param ([1 , 4 , 6 , 8 ], list (range (4 )), id = "4D, padding H, W" ),
90- pytest .param ([1 , 1 , 6 , 8 ], [1 , 2 , 3 , 4 , 2 , 1 ], id = "4D, padding C, H, W" ),
91- # pytest.param([1, 1, 6, 8], [1, 2, 3, 4, 2, 1, 5, 6], id='4D, padding N, C, H, W'), # Batch size must stay 0.
9287 ],
9388)
9489def test_constant_pad_nd_conversion__channels_first (input_shape , paddings ):
90+ model = ConstantPadNDConvModule (paddings )
9591 edge_program = to_edge_program (
96- ConstantPadNDConvModule ( paddings ) , input_shape
92+ model , input_shape
9793 ).exported_program () # Extra `Conv` after the padding.
9894
9995 input_data = np .random .random (input_shape ).astype (np .float32 )
@@ -104,3 +100,24 @@ def test_constant_pad_nd_conversion__channels_first(input_shape, paddings):
104100 tflite_input_preprocess = ToNHWCPreprocess (),
105101 tflite_output_preprocess = ToNCHWPreprocess (),
106102 )
103+
104+
105+ @pytest .mark .parametrize (
106+ "input_shape, paddings" ,
107+ [
108+ pytest .param ([2 , 4 , 6 ], list (range (6 )), id = "3D, padding N, C, H" ),
109+ pytest .param ([2 , 4 , 6 , 8 ], list (range (6 )), id = "4D, padding C, H, W" ),
110+ pytest .param ([2 , 4 , 6 , 8 ], list (range (8 )), id = "4D, padding N, C, H, W" ),
111+ pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (6 )), id = "5D, padding H, W, D" ),
112+ pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (8 )), id = "5D, padding C, H, W, D" ),
113+ pytest .param ([1 , 2 , 3 , 4 , 5 ], list (range (10 )), id = "5D, padding N, C, H, W, D" ),
114+ pytest .param ([1 , 1 , 6 , 8 ], [1 , 2 , 3 , 4 , 2 , 1 ], id = "4D, padding C, H, W" ),
115+ ],
116+ )
117+ def test_constant_pad_nd__unsupported_paddings (input_shape , paddings ):
118+ model = ConstantPadNDModule (paddings )
119+ exec_program = to_quantized_edge_program (model , input_shape ).exported_program ()
120+
121+ nodes = list (exec_program .graph .nodes )
122+ # There is at least one non-delegated Pad node
123+ assert any (node .name == "aten_constant_pad_nd_default" for node in nodes )
0 commit comments