1010
1111import torch
1212import torch .fx
13- from executorch .backends .arm .quantizer import arm_quantizer_utils
14- from executorch .backends .arm .quantizer .quantization_config import QuantizationConfig
13+ from executorch .backends .arm .quantizer import QuantizationConfig
1514from executorch .backends .arm .tosa_utils import get_node_debug_info
1615from torch .ao .quantization .quantizer import QuantizationSpecBase , SharedQuantizationSpec
1716from torch .ao .quantization .quantizer .utils import (
2019)
2120from torch .fx import Node
2221
22+ from .arm_quantizer_utils import (
23+ is_annotated ,
24+ is_ok_for_quantization ,
25+ is_output_annotated ,
26+ mark_node_as_annotated ,
27+ )
28+
2329logger = logging .getLogger (__name__ )
2430
2531
@@ -69,7 +75,7 @@ def _is_ok_for_quantization(
6975 """
7076 # Check output
7177 if quant_properties .quant_output is not None :
72- if not arm_quantizer_utils . is_ok_for_quantization (node , gm ): # type: ignore[attr-defined]
78+ if not is_ok_for_quantization (node , gm ): # type: ignore[attr-defined]
7379 logger .debug (
7480 f"Could not quantize node due to output: "
7581 f"{ get_node_debug_info (node , gm )} "
@@ -87,7 +93,7 @@ def _is_ok_for_quantization(
8793
8894 for n_arg in _as_list (node .args [quant_property .index ]):
8995 assert isinstance (n_arg , Node )
90- if not arm_quantizer_utils . is_ok_for_quantization (n_arg , gm ): # type: ignore[attr-defined]
96+ if not is_ok_for_quantization (n_arg , gm ): # type: ignore[attr-defined]
9197 logger .debug (
9298 f'could not quantize node due to input "{ node } ": '
9399 f"{ get_node_debug_info (node , gm )} "
@@ -99,7 +105,7 @@ def _is_ok_for_quantization(
99105
100106
101107def _annotate_input (node : Node , quant_property : _QuantProperty ):
102- assert not arm_quantizer_utils . is_annotated (node )
108+ assert not is_annotated (node )
103109 if quant_property .optional and (
104110 quant_property .index >= len (node .args )
105111 or node .args [quant_property .index ] is None
@@ -114,11 +120,11 @@ def _annotate_input(node: Node, quant_property: _QuantProperty):
114120 assert isinstance (n_arg , Node )
115121 _annotate_input_qspec_map (node , n_arg , qspec )
116122 if quant_property .mark_annotated :
117- arm_quantizer_utils . mark_node_as_annotated (n_arg ) # type: ignore[attr-defined]
123+ mark_node_as_annotated (n_arg ) # type: ignore[attr-defined]
118124
119125
120126def _annotate_output (node : Node , quant_property : _QuantProperty ):
121- assert not arm_quantizer_utils . is_annotated (node )
127+ assert not is_annotated (node )
122128 assert not quant_property .mark_annotated
123129 assert not quant_property .optional
124130 assert quant_property .index == 0 , "Only one output annotation supported currently"
@@ -343,7 +349,7 @@ def any_or_hardtanh_min_zero(n: Node):
343349 elif node .target in _one_to_one_shared_input_or_input_act_qspec :
344350 input_qspec = (
345351 SharedQuantizationSpec (node .args [0 ]) # type: ignore[arg-type]
346- if arm_quantizer_utils . is_output_annotated (node .args [0 ]) # type: ignore
352+ if is_output_annotated (node .args [0 ]) # type: ignore
347353 else input_act_qspec
348354 )
349355 quant_properties .quant_inputs = [_QuantProperty (0 , input_qspec )] # type: ignore[arg-type]
@@ -396,7 +402,7 @@ def any_or_hardtanh_min_zero(n: Node):
396402 if not isinstance (node .args [0 ], Node ):
397403 return None
398404
399- if not arm_quantizer_utils . is_output_annotated (node .args [0 ]): # type: ignore[attr-defined]
405+ if not is_output_annotated (node .args [0 ]): # type: ignore[attr-defined]
400406 return None
401407
402408 shared_qspec = SharedQuantizationSpec (node .args [0 ])
@@ -426,7 +432,7 @@ def annotate_graph( # type: ignore[return]
426432 if node .op != "call_function" :
427433 continue
428434
429- if arm_quantizer_utils . is_annotated (node ):
435+ if is_annotated (node ):
430436 continue
431437
432438 if filter_fn is not None and not filter_fn (node ):
@@ -442,7 +448,7 @@ def annotate_graph( # type: ignore[return]
442448 if quant_properties .quant_output is not None :
443449 _annotate_output (node , quant_properties .quant_output )
444450
445- arm_quantizer_utils . mark_node_as_annotated (node ) # type: ignore[attr-defined]
451+ mark_node_as_annotated (node ) # type: ignore[attr-defined]
446452
447453 # Quantization does not allow kwargs for some reason.
448454 # Remove from ops we know have and where we know it does not break anything.
0 commit comments