2626
2727
2828class PreservingNode :
29- """ Only needed for repr(node) to work. """
3029 pass
3130
3231
3332class NoActivationQuantNode :
34- """ Only needed for repr(node) to work. """
3533 pass
3634
3735
@@ -56,24 +54,32 @@ def test_activation_preserving_with_2_inputs(self, fw_info_mock):
5654 """ Tests that . """
5755 n1 = build_node ('in1_node' )
5856 n2 = build_node ('in2_node' )
59- n3 = build_node ('qp_node' )
60- n4 = build_node ('qp2_node' )
61- graph = Graph ('g' , input_nodes = [n1 , n2 ], nodes = [n3 ], output_nodes = [n4 ],
57+ n3 = build_node ('qp_node' , layer_class = PreservingNode )
58+ n4 = build_node ('qp2_node' , layer_class = PreservingNode )
59+ qp3 = build_node ('qp3_node' , layer_class = PreservingNode )
60+ qp4 = build_node ('qp4_node' , layer_class = PreservingNode )
61+ graph = Graph ('g' , input_nodes = [n1 , n2 ], nodes = [n3 , qp3 ], output_nodes = [n4 , qp4 ],
6262 edge_list = [Edge (n1 , n3 , 0 , 0 ), Edge (n2 , n3 , 0 , 0 ),
63- Edge (n3 , n4 , 0 , 0 )])
64- op_config_kwargs = {"activation_n_bits" : 7 ,
65- "supported_input_activation_n_bits" : 7 ,
66- "enable_activation_quantization" : False ,
67- "quantization_preserving" : True }
68- fqc = Mock (filterlayer2qco = {DummyLayer : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** op_config_kwargs )])},
69- layer2qco = {DummyLayer : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** op_config_kwargs )])})
63+ Edge (n3 , n4 , 0 , 0 ),
64+ Edge (n1 , qp3 , 0 , 0 ), Edge (qp3 , qp4 , 0 , 0 )])
65+ q_op_config_kwargs = {"activation_n_bits" : 7 , "supported_input_activation_n_bits" : 7 ,
66+ "enable_activation_quantization" : True , "quantization_preserving" : False }
67+ qp_op_config_kwargs = {"activation_n_bits" : 7 , "supported_input_activation_n_bits" : 7 ,
68+ "enable_activation_quantization" : False , "quantization_preserving" : True }
69+ _filters = {DummyLayer : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** q_op_config_kwargs )]),
70+ PreservingNode : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** qp_op_config_kwargs )])}
71+ fqc = Mock (filterlayer2qco = _filters , layer2qco = _filters )
72+
7073 fw_info_mock = Mock (spec = FrameworkInfo , kernel_channels_mapping = {DummyLayer : 0 },
7174 activation_quantizer_mapping = {QuantizationMethod .POWER_OF_TWO : lambda x : 0 },
7275 get_kernel_op_attributes = lambda x : [None ])
73- set_quantization_configs_to_node (n3 , graph , QuantizationConfig (), fw_info_mock , fqc )
74- set_quantization_configs_to_node (n4 , graph , QuantizationConfig (), fw_info_mock , fqc )
76+ qc = QuantizationConfig ()
77+ for n in graph .get_topo_sorted_nodes ():
78+ set_quantization_configs_to_node (n , graph , qc , fw_info_mock , fqc )
7579 assert not n3 .is_quantization_preserving () and not n3 .is_activation_quantization_enabled ()
7680 assert not n4 .is_quantization_preserving () and not n4 .is_activation_quantization_enabled ()
81+ assert qp3 .is_quantization_preserving ()
82+ assert qp4 .is_quantization_preserving ()
7783
7884 def test_node_quantization_by_next_nodes (self , fw_info_mock ):
7985 """
@@ -100,19 +106,13 @@ def test_node_quantization_by_next_nodes(self, fw_info_mock):
100106 "supported_input_activation_n_bits" : [8 ],
101107 "enable_activation_quantization" : False ,
102108 "quantization_preserving" : False }
109+ _filters = {
110+ DummyLayer : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** first_node_config_kwargs )]),
111+ PreservingNode : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** preserving_node_config_kwargs )]),
112+ NoActivationQuantNode : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** no_quant_node_config_kwargs )]),
113+ }
103114
104- fqc = Mock (
105- filterlayer2qco = {
106- DummyLayer : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** first_node_config_kwargs )]),
107- PreservingNode : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** preserving_node_config_kwargs )]),
108- NoActivationQuantNode : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** no_quant_node_config_kwargs )]),
109- },
110- layer2qco = {
111- DummyLayer : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** first_node_config_kwargs )]),
112- PreservingNode : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** preserving_node_config_kwargs )]),
113- NoActivationQuantNode : QuantizationConfigOptions (quantization_configurations = [self ._get_op_config (** no_quant_node_config_kwargs )]),
114- }
115- )
115+ fqc = Mock (filterlayer2qco = _filters , layer2qco = _filters )
116116 fw_info_mock = Mock (spec = FrameworkInfo , kernel_channels_mapping = {DummyLayer : 0 },
117117 activation_quantizer_mapping = {QuantizationMethod .POWER_OF_TWO : lambda x : 0 },
118118 get_kernel_op_attributes = lambda x : [None ])
0 commit comments