99
1010import pytest
1111import torch
12- from executorch .backends .espressif import get_esp_fused_quant_recipe
1312from executorch .backends .espressif .quantizer import get_esp_fused_quant_quantizer
14- from executorch .backends .espressif .quantizer .esp_fused_quantizer import _LinearQuantizer
1513from executorch .backends .espressif .test .tester import EspTester
1614from executorch .backends .transforms .fused_quant .graph_utils import get_qparams_from_node
1715from executorch .backends .transforms .permute_pass_utils import get_arg
18- from executorch .backends .xnnpack .quantizer .xnnpack_quantizer import (
19- get_symmetric_quantization_config ,
20- )
21- from executorch .exir ._serialize ._program import deserialize_pte_binary
22- from executorch .export import export
23- from executorch .frontends .fused_quant .quantizer .quantizer import FusedQuantQuantizer
2416from torchao .quantization .pt2e .quantizer import QuantizationAnnotation
2517from torchao .quantization .pt2e .quantizer .quantizer import Q_ANNOTATION_KEY
2618
@@ -34,19 +26,8 @@ def linear():
3426 return model
3527
3628
37- def _linear_quantizer ():
38- return FusedQuantQuantizer (
39- [
40- _LinearQuantizer (get_symmetric_quantization_config (is_per_channel = True )),
41- * get_esp_fused_quant_quantizer ().child_quantizers ,
42- ]
43- )
44-
45-
4629def _quantize (model , inputs ):
47- program = (
48- EspTester (model , inputs ).export_fused_quant (_linear_quantizer ()).get_artifact ()
49- )
30+ program = EspTester (model , inputs ).export_fused_quant ().get_artifact ()
5031 interpreter = torch .fx .Interpreter (program .module (), garbage_collect_values = False )
5132 interpreter .run (* inputs )
5233 return interpreter
@@ -100,7 +81,7 @@ def forward(self, x, weight):
10081
10182 module = torch .export .export (Model (), (torch .ones (2 , 4 ), torch .ones (3 , 4 ))).module ()
10283 with pytest .raises (ValueError , match = "ESP-NN linear.*requires constant weights" ):
103- _linear_quantizer ().annotate (module )
84+ get_esp_fused_quant_quantizer ().annotate (module )
10485
10586
10687@pytest .mark .parametrize ("shared_weight" , [False , True ])
@@ -219,7 +200,7 @@ def forward(self, x):
219200 annotation = QuantizationAnnotation (_annotated = True )
220201 node .meta [Q_ANNOTATION_KEY ] = annotation
221202 bias = get_arg (node , "bias" )
222- _linear_quantizer ().annotate (module )
203+ get_esp_fused_quant_quantizer ().annotate (module )
223204 assert node .meta [Q_ANNOTATION_KEY ] is annotation
224205 assert not annotation .input_qspec_map
225206 assert get_arg (node , "bias" ) is bias
@@ -235,24 +216,3 @@ def test_convolution_bias_remains_float():
235216 )
236217 assert interpreter .env [get_arg (node , "bias" )].dtype == torch .float32
237218 assert get_qparams_from_node (node , "bias" ) is None
238-
239-
240- @torch .no_grad ()
241- def test_default_recipe_keeps_linear_portable (linear ):
242- inputs = (torch .tensor ([[- 2.0 , 3.0 ]]),)
243- session = export (
244- linear ,
245- example_inputs = [inputs ],
246- export_recipe = get_esp_fused_quant_recipe (),
247- )
248- torch .testing .assert_close (
249- session .get_edge_program_manager ().exported_program ().module ()(* inputs ),
250- linear (* inputs ),
251- )
252- plan = deserialize_pte_binary (
253- session .get_executorch_program_manager ().buffer
254- ).program .execution_plan [0 ]
255- assert {op .name for op in plan .operators } == {
256- "aten::permute_copy" ,
257- "aten::addmm" ,
258- }
0 commit comments