TrainingExtensions/tensorflow/src/python/aimet_tensorflow/quantsim.py
def _insert_param_quantization_ops(self, op_names: List[str], indices: List[int], default_param_bw: int,
                                       inner_ops: List[str] = None, in_loop_context: bool = False):
        """
        Inserts quantization ops for individual parameters
        :param ops: List of ops whose parameters are being quantized
        :param indices: List of input indices (one-to-one for each entry in ops)
        :param default_param_bw : default param bitwidth
        :param in_loop_context: True, if the ops belong to loop control flow context
        :return: None
        """
        ops = [self.session.graph.get_operation_by_name(op_name) for op_name in op_names]
        assert len(ops) == len(indices)

        for op, index in zip(ops, indices):
            # Modify the weight/bias inputs to use the quantized inputs
            can_modify_op, param_in = QuantizationSimModel._get_op_to_modify_with_param_in(op, index)

            if param_in is not None:
                quant_op_name = self._get_quantized_name(param_in.op.name)
                _logger.info("Adding weight quantization op %s", quant_op_name)
                op_mode = libpymo.TensorQuantizerOpMode.oneShotQuantizeDequantize

                if in_loop_context:
                    q_op_out = self._insert_param_quantizer_loop_context(inner_ops, param_in, quant_op_name,
                                                                         op_mode, self._param_quantizers,
                                                                         QuantizerType.param,
                                                                         default_param_bw)
                else:
                    q_op_out = self._insert_post_training_quant_op(param_in, quant_op_name,
                                                                   op_mode, self._param_quantizers, QuantizerType.param,
                                                                   default_param_bw)

                nodes_modified_count = graph_editor.reroute_ts(tf_ops.convert_to_tensor(q_op_out), param_in,
                                                               can_modify=can_modify_op)
                if nodes_modified_count != 1:
                    raise ValueError('Input ' + param_in.name + ' not quantized!')

        Inserts quantization ops for individual parameters
        :param ops: List of ops whose parameters are being quantized
        :param indices: List of input indices (one-to-one for each entry in ops)
        :param default_param_bw : default param bitwidth
        :param in_loop_context: True, if the ops belong to loop control flow context
        :return: None
        
Inserts quantization ops for individual parameters
Inserts quantization ops for individual parameters
def _insert_param_quantization_ops(self, op_names: List[str], indices: List[int], default_param_bw: int,
                                       inner_ops: List[str] = None, in_loop_context: bool = False):
        ops = [self.session.graph.get_operation_by_name(op_name) for op_name in op_names]
        assert len(ops) == len(indices)
        for op, index in zip(ops, indices):
            can_modify_op, param_in = QuantizationSimModel._get_op_to_modify_with_param_in(op, index)
            if param_in is not None:
                quant_op_name = self._get_quantized_name(param_in.op.name)
                _logger.info("Adding weight quantization op %s", quant_op_name)
                op_mode = libpymo.TensorQuantizerOpMode.oneShotQuantizeDequantize
                if in_loop_context:
                    q_op_out = self._insert_param_quantizer_loop_context(inner_ops, param_in, quant_op_name,
                                                                         op_mode, self._param_quantizers,
                                                                         QuantizerType.param,
                                                                         default_param_bw)
                else:
                    q_op_out = self._insert_post_training_quant_op(param_in, quant_op_name,
                                                                   op_mode, self._param_quantizers, QuantizerType.param,
                                                                   default_param_bw)
                nodes_modified_count = graph_editor.reroute_ts(tf_ops.convert_to_tensor(q_op_out), param_in,
                                                               can_modify=can_modify_op)
                if nodes_modified_count != 1:
                    raise ValueError('Input ' + param_in.name + ' not quantized!')
def _insert_param_quantization_ops ( self , op_names : List [ str ] , indices : List [ int ] , default_param_bw : int , inner_ops : List [ str ] = None , in_loop_context : bool = False ) : ops = [ self . session . graph . get_operation_by_name ( op_name ) for op_name in op_names ] assert len ( ops ) == len ( indices ) for op , index in zip ( ops , indices ) : can_modify_op , param_in = QuantizationSimModel . _get_op_to_modify_with_param_in ( op , index ) if param_in is not None : quant_op_name = self . _get_quantized_name ( param_in . op . name ) _logger . info ( "Adding weight quantization op %s" , quant_op_name ) op_mode = libpymo . TensorQuantizerOpMode . oneShotQuantizeDequantize if in_loop_context : q_op_out = self . _insert_param_quantizer_loop_context ( inner_ops , param_in , quant_op_name , op_mode , self . _param_quantizers , QuantizerType . param , default_param_bw ) else : q_op_out = self . _insert_post_training_quant_op ( param_in , quant_op_name , op_mode , self . _param_quantizers , QuantizerType . param , default_param_bw ) nodes_modified_count = graph_editor . reroute_ts ( tf_ops . convert_to_tensor ( q_op_out ) , param_in , can_modify = can_modify_op ) if nodes_modified_count != 1 : raise ValueError ( 'Input ' + param_in . name + ' not quantized!' )
Inserts quantization ops for individual parameters
Inserts quantization ops for individual parameters
"""
        Inserts quantization ops for individual parameters
        :param ops: List of ops whose parameters are being quantized
        :param indices: List of input indices (one-to-one for each entry in ops)
        :param default_param_bw : default param bitwidth
        :param in_loop_context: True, if the ops belong to loop control flow context
        :return: None
        """ # Modify the weight/bias inputs to use the quantized inputs
None
self
op_names
List[str]
indices
List[int]
List of input indices (one-to-one for each entry in ops)
List of input indices ( one - to - one for each entry in ops )
default_param_bw
int
default param bitwidth
default param bitwidth
inner_ops
List[str]
in_loop_context
bool
True, if the ops belong to loop control flow context
True if the ops belong to loop control flow context
ops
List of ops whose parameters are being quantized
List of ops whose parameters are being quantized