13
13
from executorch .backends .xnnpack .test .tester import Partition , Tester
14
14
15
15
16
- class TestXNNPACKAdd (unittest .TestCase ):
17
- class AddModule (torch .nn .Module ):
16
+ class TestAdd (unittest .TestCase ):
17
+ class Add (torch .nn .Module ):
18
18
def __init__ (self ):
19
19
super ().__init__ ()
20
20
@@ -25,15 +25,10 @@ def forward(self, x, y):
25
25
z = z + z
26
26
return z
27
27
28
- def test_add (self ):
29
- """
30
- This test is the simplest test by manually lowering some submodules, we can use paritioner for auto detecting lowerable parts
31
- """
32
- add_module = self .AddModule ()
33
- model_inputs = (torch .ones (1 ), torch .ones (1 ))
34
-
28
+ def test_fp32_add (self ):
29
+ inputs = (torch .ones (1 ), torch .ones (1 ))
35
30
(
36
- Tester (add_module , model_inputs )
31
+ Tester (self . Add (), inputs )
37
32
.export ()
38
33
.check_count ({"torch.ops.aten.add.Tensor" : 4 })
39
34
.to_edge ()
@@ -47,16 +42,14 @@ def test_add(self):
47
42
.compare_outputs ()
48
43
)
49
44
50
- def test_add_quantized (self ):
51
- add_module = self .AddModule ()
52
- model_inputs = (torch .ones (1 ), torch .ones (1 ))
53
-
45
+ def test_qs8_add (self ):
46
+ inputs = (torch .ones (1 ), torch .ones (1 ))
54
47
(
55
- Tester (add_module , model_inputs )
56
- .quantize ()
57
- .check (["torch.ops.quantized_decomposed" ])
48
+ Tester (self .Add (), inputs )
49
+ .quantize2 ()
58
50
.export ()
59
51
.check_count ({"torch.ops.aten.add.Tensor" : 4 })
52
+ .check (["torch.ops.quantized_decomposed" ])
60
53
.to_edge ()
61
54
.check_count ({"executorch_exir_dialects_edge__ops_aten_add_Tensor" : 4 })
62
55
.partition (Partition (partitioner = XnnpackQuantizedPartitioner ))
@@ -69,22 +62,48 @@ def test_add_quantized(self):
69
62
.compare_outputs ()
70
63
)
71
64
72
- def test_add_quantized_pt2e (self ):
73
- add_module = self .AddModule ()
74
- model_inputs = (torch .ones (1 ), torch .ones (1 ))
65
+ class AddRelu (torch .nn .Module ):
66
+ def forward (self , x , y ):
67
+ z = x + y
68
+ return torch .nn .functional .relu (z )
75
69
70
+ def test_fp32_add_relu (self ):
71
+ inputs = (torch .randn (1 , 1 , 4 , 4 ), torch .randn (1 , 1 , 4 , 4 ))
76
72
(
77
- Tester (add_module , model_inputs )
73
+ Tester (self .AddRelu (), inputs )
74
+ .export ()
75
+ .check_count ({"torch.ops.aten.add.Tensor" : 1 })
76
+ .check_count ({"torch.ops.aten.relu.default" : 1 })
77
+ .to_edge ()
78
+ .check_count ({"executorch_exir_dialects_edge__ops_aten_add_Tensor" : 1 })
79
+ .check_count ({"executorch_exir_dialects_edge__ops_aten_relu_default" : 1 })
80
+ .partition ()
81
+ .check_not (["executorch_exir_dialects_edge__ops_aten_add_Tensor" ])
82
+ .check_not (["executorch_exir_dialects_edge__ops_aten_relu_default" ])
83
+ .check_count ({"torch.ops.executorch_call_delegate" : 1 })
84
+ .to_executorch ()
85
+ .serialize ()
86
+ .run_method ()
87
+ .compare_outputs ()
88
+ )
89
+
90
+ def test_qs8_add_relu (self ):
91
+ inputs = (torch .randn (1 , 1 , 4 , 4 ), torch .randn (1 , 1 , 4 , 4 ))
92
+ (
93
+ Tester (self .AddRelu (), inputs )
78
94
.quantize2 ()
79
95
.export ()
80
- .check_count ({"torch.ops.aten.add.Tensor" : 4 })
96
+ .check_count ({"torch.ops.aten.add.Tensor" : 1 })
97
+ .check_count ({"torch.ops.aten.relu.default" : 1 })
81
98
.check (["torch.ops.quantized_decomposed" ])
82
99
.to_edge ()
83
- .check_count ({"executorch_exir_dialects_edge__ops_aten_add_Tensor" : 4 })
100
+ .check_count ({"executorch_exir_dialects_edge__ops_aten_add_Tensor" : 1 })
101
+ .check_count ({"executorch_exir_dialects_edge__ops_aten_relu_default" : 1 })
84
102
.partition (Partition (partitioner = XnnpackQuantizedPartitioner ))
85
- .check_count ({"torch.ops.executorch_call_delegate" : 1 })
86
103
.check_not (["executorch_exir_dialects_edge__ops_aten_add_Tensor" ])
104
+ .check_not (["executorch_exir_dialects_edge__ops_aten_relu_default" ])
87
105
.check_not (["torch.ops.quantized_decomposed" ])
106
+ .check_count ({"torch.ops.executorch_call_delegate" : 1 })
88
107
.to_executorch ()
89
108
.serialize ()
90
109
.run_method ()
0 commit comments