TrainingExtensions/tensorflow/src/python/aimet_tensorflow/quantsim_config/quantsim_config.py
def _modify_activation_quantize_op(self, input_output_quantize_ops: QuantizerListType, setting_name: str,
                                       quantizer_setting: bool, modified_quantize_ops: Dict[tf.Operation, Set]):
        """
        Modify the appropriate quantize ops for the given quantizer setting.  If a quantize op has already been
        modified, compare the old setting with the new setting and assert if the settings conflict.
        :param input_output_quantize_ops: Tuple containing 2 lists:
            - List of quantize ops to change if op's input quantizer setting is set
            - List of quantize ops to change if op's output quantizer setting is set
        :param setting_name: String representing the setting to be modified
        :param quantizer_setting: Boolean representing the new setting value
        :param modified_quantize_ops: Dictionary of quantize ops mapping to set of settings that have been changed for
            that quantize op already.
        """
        setting_type = get_setting_type(setting_name)

        quantize_ops_to_modify = _get_quantize_ops_to_modify(input_output_quantize_ops, setting_name)
        for quantize_op in quantize_ops_to_modify:
            if quantize_op in modified_quantize_ops and \
                    setting_type in modified_quantize_ops[quantize_op]:
                # Tensor quantizer's setting has already been modified
                if setting_name in [ConfigDictKeys.IS_INPUT_QUANTIZED, ConfigDictKeys.IS_OUTPUT_QUANTIZED]:
                    op_mode_tensor = self._sess.graph.get_tensor_by_name(quantize_op.name + '_op_mode:0')
                    # current_setting will be True if op mode is not passThrough (is enabled), False otherwise
                    current_setting = (self._sess.run(op_mode_tensor) != int(pymo.TensorQuantizerOpMode.passThrough))
                else:
                    op_mode_tensor = self._sess.graph.get_tensor_by_name(quantize_op.name +
                                                                         '_use_symmetric_encoding:0')
                    current_setting = self._sess.run(op_mode_tensor)
                if current_setting != quantizer_setting:
                    logger.error('Conflicting tensor quantizer settings for symmetric encodings')
                    raise AssertionError
            else:
                vars_with_value = {}
                if setting_name in [ConfigDictKeys.IS_INPUT_QUANTIZED, ConfigDictKeys.IS_OUTPUT_QUANTIZED]:
                    if not quantizer_setting:
                        setting = pymo.TensorQuantizerOpMode.passThrough
                    else:
                        setting = pymo.TensorQuantizerOpMode.updateStats
                    vars_with_value[quantize_op.name + '_op_mode'] = int(setting)
                else:
                    vars_with_value[quantize_op.name + '_use_symmetric_encoding'] = quantizer_setting
                update_variables_with_values(self._sess, vars_with_value)
                if quantize_op not in modified_quantize_ops:
                    modified_quantize_ops[quantize_op] = {setting_type}
                else:
                    modified_quantize_ops[quantize_op].add(setting_type)

        Modify the appropriate quantize ops for the given quantizer setting.  If a quantize op has already been
        modified, compare the old setting with the new setting and assert if the settings conflict.
        :param input_output_quantize_ops: Tuple containing 2 lists:
            - List of quantize ops to change if op's input quantizer setting is set
            - List of quantize ops to change if op's output quantizer setting is set
        :param setting_name: String representing the setting to be modified
        :param quantizer_setting: Boolean representing the new setting value
        :param modified_quantize_ops: Dictionary of quantize ops mapping to set of settings that have been changed for
            that quantize op already.
        
Modify the appropriate quantize ops for the given quantizer setting.  If a quantize op has already been
modified, compare the old setting with the new setting and assert if the settings conflict.
Modify the appropriate quantize ops for the given quantizer setting . If a quantize op has already been modified compare the old setting with the new setting and assert if the settings conflict .
def _modify_activation_quantize_op(self, input_output_quantize_ops: QuantizerListType, setting_name: str,
                                       quantizer_setting: bool, modified_quantize_ops: Dict[tf.Operation, Set]):
        setting_type = get_setting_type(setting_name)
        quantize_ops_to_modify = _get_quantize_ops_to_modify(input_output_quantize_ops, setting_name)
        for quantize_op in quantize_ops_to_modify:
            if quantize_op in modified_quantize_ops and \
                    setting_type in modified_quantize_ops[quantize_op]:
                if setting_name in [ConfigDictKeys.IS_INPUT_QUANTIZED, ConfigDictKeys.IS_OUTPUT_QUANTIZED]:
                    op_mode_tensor = self._sess.graph.get_tensor_by_name(quantize_op.name + '_op_mode:0')
                    current_setting = (self._sess.run(op_mode_tensor) != int(pymo.TensorQuantizerOpMode.passThrough))
                else:
                    op_mode_tensor = self._sess.graph.get_tensor_by_name(quantize_op.name +
                                                                         '_use_symmetric_encoding:0')
                    current_setting = self._sess.run(op_mode_tensor)
                if current_setting != quantizer_setting:
                    logger.error('Conflicting tensor quantizer settings for symmetric encodings')
                    raise AssertionError
            else:
                vars_with_value = {}
                if setting_name in [ConfigDictKeys.IS_INPUT_QUANTIZED, ConfigDictKeys.IS_OUTPUT_QUANTIZED]:
                    if not quantizer_setting:
                        setting = pymo.TensorQuantizerOpMode.passThrough
                    else:
                        setting = pymo.TensorQuantizerOpMode.updateStats
                    vars_with_value[quantize_op.name + '_op_mode'] = int(setting)
                else:
                    vars_with_value[quantize_op.name + '_use_symmetric_encoding'] = quantizer_setting
                update_variables_with_values(self._sess, vars_with_value)
                if quantize_op not in modified_quantize_ops:
                    modified_quantize_ops[quantize_op] = {setting_type}
                else:
                    modified_quantize_ops[quantize_op].add(setting_type)
def _modify_activation_quantize_op ( self , input_output_quantize_ops : QuantizerListType , setting_name : str , quantizer_setting : bool , modified_quantize_ops : Dict [ tf . Operation , Set ] ) : setting_type = get_setting_type ( setting_name ) quantize_ops_to_modify = _get_quantize_ops_to_modify ( input_output_quantize_ops , setting_name ) for quantize_op in quantize_ops_to_modify : if quantize_op in modified_quantize_ops and setting_type in modified_quantize_ops [ quantize_op ] : if setting_name in [ ConfigDictKeys . IS_INPUT_QUANTIZED , ConfigDictKeys . IS_OUTPUT_QUANTIZED ] : op_mode_tensor = self . _sess . graph . get_tensor_by_name ( quantize_op . name + '_op_mode:0' ) current_setting = ( self . _sess . run ( op_mode_tensor ) != int ( pymo . TensorQuantizerOpMode . passThrough ) ) else : op_mode_tensor = self . _sess . graph . get_tensor_by_name ( quantize_op . name + '_use_symmetric_encoding:0' ) current_setting = self . _sess . run ( op_mode_tensor ) if current_setting != quantizer_setting : logger . error ( 'Conflicting tensor quantizer settings for symmetric encodings' ) raise AssertionError else : vars_with_value = { } if setting_name in [ ConfigDictKeys . IS_INPUT_QUANTIZED , ConfigDictKeys . IS_OUTPUT_QUANTIZED ] : if not quantizer_setting : setting = pymo . TensorQuantizerOpMode . passThrough else : setting = pymo . TensorQuantizerOpMode . updateStats vars_with_value [ quantize_op . name + '_op_mode' ] = int ( setting ) else : vars_with_value [ quantize_op . name + '_use_symmetric_encoding' ] = quantizer_setting update_variables_with_values ( self . _sess , vars_with_value ) if quantize_op not in modified_quantize_ops : modified_quantize_ops [ quantize_op ] = { setting_type } else : modified_quantize_ops [ quantize_op ] . add ( setting_type )
Modify the appropriate quantize ops for the given quantizer setting.
Modify the appropriate quantize ops for the given quantizer setting .
"""
        Modify the appropriate quantize ops for the given quantizer setting.  If a quantize op has already been
        modified, compare the old setting with the new setting and assert if the settings conflict.
        :param input_output_quantize_ops: Tuple containing 2 lists:
            - List of quantize ops to change if op's input quantizer setting is set
            - List of quantize ops to change if op's output quantizer setting is set
        :param setting_name: String representing the setting to be modified
        :param quantizer_setting: Boolean representing the new setting value
        :param modified_quantize_ops: Dictionary of quantize ops mapping to set of settings that have been changed for
            that quantize op already.
        """ # Tensor quantizer's setting has already been modified # current_setting will be True if op mode is not passThrough (is enabled), False otherwise
self
input_output_quantize_ops
QuantizerListType
Tuple containing 2 lists:
List of quantize ops to change if op's input quantizer setting is set
List of quantize ops to change if op's output quantizer setting is set
Tuple containing 2 lists : List of quantize ops to change if op ' s input quantizer setting is set List of quantize ops to change if op ' s output quantizer setting is set
setting_name
str
String representing the setting to be modified
String representing the setting to be modified
quantizer_setting
bool
Boolean representing the new setting value
Boolean representing the new setting value
modified_quantize_ops
Dict[tf.Operation, Set]
Dictionary of quantize ops mapping to set of settings that have been changed for
that quantize op already.
Dictionary of quantize ops mapping to set of settings that have been changed for that quantize op already .