1111
1212from executorch .backends .nxp .tests .graph_verifier import DetailedGraphVerifier
1313from executorch .backends .nxp .tests .nsys_testing import lower_run_compare
14- from executorch .backends .nxp .tests .ops_aliases import Clamp , Convolution , Log , Relu
14+ from executorch .backends .nxp .tests .ops_aliases import Log
1515from executorch .backends .nxp .tests .use_qat import * # noqa F403
16- from executorch .backends .nxp .tests .dataset_creator import LinearRampDatasetCreator
16+ from executorch .backends .nxp .tests .dataset_creator import (
17+ LinearRampDatasetCreator ,
18+ RandomDatasetCreator ,
19+ )
1720
1821
1922@pytest .fixture (autouse = True )
@@ -31,40 +34,12 @@ def forward(self, x):
3134 return torch .log (x )
3235
3336
34- class ConvBlocksWithLogModule (torch .nn .Module ):
35- def __init__ (self , conv_in_channels : int = 3 ):
36- super ().__init__ ()
37- self .block1 = torch .nn .Sequential (
38- torch .nn .Conv2d (
39- in_channels = conv_in_channels ,
40- out_channels = 3 ,
41- kernel_size = (2 , 2 ),
42- stride = (2 , 2 ),
43- ),
44- torch .nn .ReLU (),
45- )
46- self .block2 = torch .nn .Sequential (
47- torch .nn .Conv2d (
48- in_channels = conv_in_channels ,
49- out_channels = 10 ,
50- kernel_size = (2 , 2 ),
51- stride = (2 , 2 ),
52- ),
53- torch .nn .ReLU (),
54- )
55-
56- def forward (self , x ):
57- x = self .block1 (x )
58- x = x .clamp_min (1e-6 ).log ()
59- return self .block2 (x )
60-
61-
6237class TestLog :
6338 def test__basic_nsys_inference (self , mocker ):
64- # Use 256 elements so that, after quantization to uint8 , the input can
65- # cover the full discrete range [0, 255 ].
39+ # Use 256 elements so that, after quantization to int8 , the input can
40+ # cover the full discrete range [-128, 127 ].
6641 # The dataset is generated as a linear float ramp and later quantized,
67- # which effectively exercises all uint8 values.
42+ # which effectively exercises all int8 values.
6843 input_shape = (256 ,)
6944 model = LogModule ()
7045 graph_verifier = DetailedGraphVerifier (
@@ -74,23 +49,26 @@ def test__basic_nsys_inference(self, mocker):
7449 model ,
7550 input_shape ,
7651 graph_verifier ,
77- dataset_creator = LinearRampDatasetCreator (),
52+ dataset_creator = LinearRampDatasetCreator (low = 0.0 , high = 1.0 ),
7853 )
7954
80- def test__basic_nsys_inference__with_conv (self , mocker ):
81- input_shape = (2 , 3 , 6 , 7 )
82- in_channels = input_shape [1 ]
83- model = ConvBlocksWithLogModule (conv_in_channels = in_channels )
84-
85- # `clamp` and one `relu` ends up in the same delegated partition as `log`
55+ @pytest .mark .parametrize (
56+ "input_shape" ,
57+ [
58+ pytest .param ((17 , 2 ), id = "2D" ),
59+ pytest .param ((1 , 3 , 10 ), id = "3D" ),
60+ pytest .param ((1 , 3 , 16 , 16 ), id = "4D" ),
61+ ],
62+ )
63+ def test__basic_nsys_inference__qat (self , mocker , input_shape , use_qat ):
64+ model = LogModule ()
8665 graph_verifier = DetailedGraphVerifier (
87- mocker ,
88- expected_delegated_ops = {Log : 1 , Relu : 1 , Clamp : 1 },
89- expected_non_delegated_ops = {Relu : 1 , Convolution : 2 },
66+ mocker , expected_delegated_ops = {Log : 1 }, expected_non_delegated_ops = {}
9067 )
91-
9268 lower_run_compare (
9369 model ,
9470 input_shape ,
9571 graph_verifier ,
72+ dataset_creator = RandomDatasetCreator (low = 1.0 , high = 10.0 ),
73+ use_qat = use_qat ,
9674 )
0 commit comments