Skip to content

Commit 38c5e26

Browse files
committed
NXP backend: Add test cases for new Neutron C flow
1 parent 85d0772 commit 38c5e26

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import numpy as np
77
import pytest
88
import torch
9-
109
from executorch.backends.nxp.backend.edge_program_converter import (
1110
EdgeProgramToIRConverter,
1211
)
@@ -180,3 +179,48 @@ def test_convert_clamp__no_delegation__unsupported_bounds(min, max):
180179

181180
# Make sure the `clamp` was NOT delegated.
182181
assert graph_contains_any_of_ops(delegated_ep.graph, [Clamp])
182+
183+
184+
@pytest.mark.parametrize(
185+
"min, max",
186+
[
187+
pytest.param(10, 17, id="min = 10, max = 17 (Max/Min)"),
188+
pytest.param(0, 1, id="min = 0, max = 1 (Relu0To1)"),
189+
pytest.param(-1, 1, id="min = -1, max = 1 (ReluN1To1)"),
190+
pytest.param(0, None, id="min = 0, max = None (Relu)"),
191+
# Float bounds
192+
pytest.param(10.0, 17.0, id="min = 10, max = 17 (Max/Min)"),
193+
pytest.param(0.0, 1.0, id="min = 0, max = 1 (Relu0To1)"),
194+
pytest.param(-1.0, 1.0, id="min = -1, max = 1 (ReluN1To1)"),
195+
pytest.param(0.0, None, id="min = 0, max = None (Relu)"),
196+
],
197+
)
198+
def test_convert_clamp__new_neutron_c_flow(mocker, min, max):
199+
input_shape = (23,)
200+
model = AddClampModule(min, max)
201+
202+
converter_spy = mocker.spy(EdgeProgramToIRConverter, "convert_program")
203+
delegated_ep = to_quantized_edge_program(
204+
model, input_shape, use_new_flow_neutron_c=True
205+
).exported_program()
206+
207+
# Make sure the `clamp` was delegated.
208+
assert graph_contains_any_of_ops(delegated_ep.graph, [ExecutorchDelegateCall])
209+
assert not graph_contains_any_of_ops(delegated_ep.graph, [Clamp])
210+
211+
# Verify correct behavior of the converted NeutronIR model.
212+
intermediate_ep = converter_spy.call_args.args[1]
213+
neutron_ir_model, _ = converter_spy.spy_return
214+
215+
input_data = (
216+
np.random.random(input_shape).astype(np.float32) * 256.0 - 128.0
217+
).astype(np.int8)
218+
219+
# Make sure the tested program contains the `clamp`.
220+
assert graph_contains_any_of_ops(intermediate_ep.graph, [Clamp])
221+
222+
convert_run_compare(
223+
intermediate_ep,
224+
tfl_model=neutron_ir_model,
225+
input_data=input_data,
226+
)

0 commit comments

Comments
 (0)