Skip to content

Commit df3fa0d

Browse files
NXP backend: Add QAT tests for AvgPool, MaxPool and Mul tensor ops (#19572)
### Summary Add QAT tests for AvgPool, MaxPool and Mul tensor ops for Neutron backend using the new Neutron MLIR flow. ### Test plan Unit tests provided. cc @robert-kalmar
1 parent 87b667b commit df3fa0d

3 files changed

Lines changed: 81 additions & 13 deletions

File tree

backends/nxp/tests/ir/converter/node_converter/test_avg_pool2d_converter.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
ToNHWCPreprocess,
3030
)
3131
from executorch.backends.nxp.tests.graph_verifier import DetailedGraphVerifier
32+
from executorch.backends.nxp.tests.model_output_comparator import (
33+
NumericalStatsOutputComparator,
34+
)
3235
from executorch.backends.nxp.tests.models import AvgPool2dConvModule, AvgPool2dModule
3336

3437
from executorch.backends.nxp.tests.nsys_testing import lower_run_compare
@@ -314,6 +317,23 @@ def test__basic_nsys_inference(self, mocker):
314317
model, input_shape, graph_verifier, use_new_flow_neutron_c=True
315318
)
316319

320+
def test__basic_nsys_inference_qat(self, mocker):
321+
input_shape = (2, 9, 6, 15)
322+
model = AvgPool2dModule(False, 0)
323+
comparator = NumericalStatsOutputComparator()
324+
graph_verifier = DetailedGraphVerifier(
325+
mocker, expected_delegated_ops={AvgPool2D: 1}, expected_non_delegated_ops={}
326+
)
327+
328+
lower_run_compare(
329+
model,
330+
input_shape,
331+
graph_verifier,
332+
output_comparator=comparator,
333+
use_new_flow_neutron_c=True,
334+
use_qat=True,
335+
)
336+
317337
def test__kernel_size_limit(self, mocker):
318338
kernel_size = (1, 4096)
319339
input_shape = (1, 4) + kernel_size

backends/nxp/tests/ir/converter/node_converter/test_max_pool_2d_converter.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
ToChannelLastPreprocess,
1818
)
1919
from executorch.backends.nxp.tests.graph_verifier import DetailedGraphVerifier
20+
from executorch.backends.nxp.tests.model_output_comparator import (
21+
NumericalStatsOutputComparator,
22+
)
2023
from executorch.backends.nxp.tests.nsys_testing import lower_run_compare
2124
from executorch.backends.nxp.tests.ops_aliases import (
2225
ExecutorchDelegateCall,
@@ -280,6 +283,25 @@ def test__basic_nsys_inference(self, mocker):
280283
model = MaxPool2dModule()
281284
self.assert_delegated(model, input_shape, mocker)
282285

286+
def test__basic_nsys_inference_qat(self, mocker):
287+
input_shape = (2, 11, 7, 16) # The old flow limited the batch size to 1.
288+
model = MaxPool2dModule()
289+
comparator = NumericalStatsOutputComparator()
290+
graph_verifier = DetailedGraphVerifier(
291+
mocker,
292+
expected_delegated_ops={MaxPool2DWithIndices: 1, GetItem: 1},
293+
expected_non_delegated_ops={},
294+
)
295+
296+
lower_run_compare(
297+
model,
298+
input_shape,
299+
graph_verifier,
300+
output_comparator=comparator,
301+
use_new_flow_neutron_c=True,
302+
use_qat=True,
303+
)
304+
283305
def test__kernel_size_limit(self, mocker):
284306
kernel_size = (1, 4096)
285307
input_shape = (1, 4) + kernel_size

backends/nxp/tests/ir/converter/node_converter/test_mul_tensor_converter.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
ToChannelFirstPreprocess,
2121
ToChannelLastPreprocess,
2222
)
23-
from executorch.backends.nxp.tests.graph_verifier import BaseGraphVerifier
23+
from executorch.backends.nxp.tests.graph_verifier import DetailedGraphVerifier
24+
from executorch.backends.nxp.tests.model_output_comparator import (
25+
NumericalStatsOutputComparator,
26+
)
2427
from executorch.backends.nxp.tests.models import (
2528
MulTensorConvModule,
2629
MulTensorModule,
@@ -229,19 +232,42 @@ class TestMulTensorNewNeutronFlow:
229232
pytest.param((1, 4, 8, 8), id="4D."),
230233
],
231234
)
232-
def test__basic_nsys_inference(self, x_input_shape):
235+
def test__basic_nsys_inference(self, x_input_shape, mocker):
236+
x_input_spec = ModelInputSpec(x_input_shape)
237+
model = MulTensorModule()
238+
graph_verifier = DetailedGraphVerifier(
239+
mocker, expected_delegated_ops={MulTensor: 1}, expected_non_delegated_ops={}
240+
)
241+
242+
lower_run_compare(
243+
model,
244+
[x_input_spec, x_input_spec],
245+
graph_verifier,
246+
use_new_flow_neutron_c=True,
247+
)
248+
249+
@pytest.mark.parametrize(
250+
"x_input_shape",
251+
[
252+
pytest.param((1, 4, 8), id="3D."),
253+
pytest.param((1, 4, 8, 8), id="4D."),
254+
],
255+
)
256+
def test__basic_nsys_inference_qat(self, x_input_shape, mocker):
233257
x_input_spec = ModelInputSpec(x_input_shape)
234258
model = MulTensorModule()
235-
graph_verifier = BaseGraphVerifier(
236-
exp_num_delegate_call_nodes=1,
237-
exp_non_delegated_nodes=[],
259+
comparator = NumericalStatsOutputComparator()
260+
graph_verifier = DetailedGraphVerifier(
261+
mocker, expected_delegated_ops={MulTensor: 1}, expected_non_delegated_ops={}
238262
)
239263

240264
lower_run_compare(
241265
model,
242266
[x_input_spec, x_input_spec],
243267
graph_verifier,
268+
output_comparator=comparator,
244269
use_new_flow_neutron_c=True,
270+
use_qat=True,
245271
)
246272

247273
@pytest.mark.parametrize(
@@ -259,11 +285,10 @@ def test__basic_nsys_inference(self, x_input_shape):
259285
),
260286
],
261287
)
262-
def test__correct_broadcast(self, input_spec):
288+
def test__correct_broadcast(self, input_spec, mocker):
263289
model = MulTensorModule()
264-
graph_verifier = BaseGraphVerifier(
265-
exp_num_delegate_call_nodes=1,
266-
exp_non_delegated_nodes=[],
290+
graph_verifier = DetailedGraphVerifier(
291+
mocker, expected_delegated_ops={MulTensor: 1}, expected_non_delegated_ops={}
267292
)
268293

269294
lower_run_compare(
@@ -308,16 +333,17 @@ def test__incorrect_broadcast(self, input_spec):
308333
),
309334
],
310335
)
311-
def test__w_conv(self, x_input_shape):
336+
def test__w_conv(self, x_input_shape, mocker):
312337
model = MulTensorConvModule()
313338

314339
n, c, h, w = x_input_shape
315340
y_input_spec = ModelInputSpec((n, 8, h, w))
316341
x_input_spec = ModelInputSpec(x_input_shape)
317342

318-
graph_verifier = BaseGraphVerifier(
319-
exp_num_delegate_call_nodes=1,
320-
exp_non_delegated_nodes=[],
343+
graph_verifier = DetailedGraphVerifier(
344+
mocker,
345+
expected_delegated_ops={MulTensor: 1, Convolution: 1},
346+
expected_non_delegated_ops={},
321347
)
322348

323349
lower_run_compare(

0 commit comments

Comments
 (0)