TrainingExtensions/tensorflow/src/python/aimet_tensorflow/quantsim.py
def _create_and_place_quantize_op(self, quant_op_name: str, preceeding_tensor,
                                      op_mode_var: tf.Variable, tensor_quant_ref: tf.Variable,
                                      encoding_min: tf.Variable, encoding_max: tf.Variable, bit_width: tf.Variable,
                                      use_symmetric_encoding: tf.Variable):
        """
        Create a QcQuantize op and place it on CPU/CPU and with the right custom-gradient function registered
        """
        # pylint: disable=too-many-arguments

        def create_quantize_op():
            op = qcops.qc_quantize(name=quant_op_name, in_tensor=preceeding_tensor,
                                   op_mode=op_mode_var,
                                   tensor_quantizer_reference=tensor_quant_ref,
                                   encoding_min=encoding_min, encoding_max=encoding_max,
                                   bit_width=bit_width,
                                   use_symmetric_encoding=use_symmetric_encoding)
            return op

        if not self._use_cuda:
            with tf.device('/cpu:0'):
                if self._quant_scheme in [QuantScheme.training_range_learning_with_tf_init,
                                          QuantScheme.training_range_learning_with_tf_enhanced_init]:
                    with self.session.graph.gradient_override_map(
                            {"QcQuantize": "QcQuantizeRangeLearningCustomGradient"}):
                        q_op_out = create_quantize_op()
                else:
                    q_op_out = create_quantize_op()

        # GPU device assignment for QcQuantize op
        else:
            if self._quant_scheme in [QuantScheme.training_range_learning_with_tf_init,
                                      QuantScheme.training_range_learning_with_tf_enhanced_init]:
                with self.session.graph.gradient_override_map(
                        {"QcQuantize": "QcQuantizeRangeLearningCustomGradient"}):
                    q_op_out = create_quantize_op()
            else:
                q_op_out = create_quantize_op()

        return q_op_out

        Create a QcQuantize op and place it on CPU/CPU and with the right custom-gradient function registered
        
Create a QcQuantize op and place it on CPU/CPU and with the right custom-gradient function registered
Create a QcQuantize op and place it on CPU / CPU and with the right custom - gradient function registered
def _create_and_place_quantize_op(self, quant_op_name: str, preceeding_tensor,
                                      op_mode_var: tf.Variable, tensor_quant_ref: tf.Variable,
                                      encoding_min: tf.Variable, encoding_max: tf.Variable, bit_width: tf.Variable,
                                      use_symmetric_encoding: tf.Variable):
        def create_quantize_op():
            op = qcops.qc_quantize(name=quant_op_name, in_tensor=preceeding_tensor,
                                   op_mode=op_mode_var,
                                   tensor_quantizer_reference=tensor_quant_ref,
                                   encoding_min=encoding_min, encoding_max=encoding_max,
                                   bit_width=bit_width,
                                   use_symmetric_encoding=use_symmetric_encoding)
            return op
        if not self._use_cuda:
            with tf.device('/cpu:0'):
                if self._quant_scheme in [QuantScheme.training_range_learning_with_tf_init,
                                          QuantScheme.training_range_learning_with_tf_enhanced_init]:
                    with self.session.graph.gradient_override_map(
                            {"QcQuantize": "QcQuantizeRangeLearningCustomGradient"}):
                        q_op_out = create_quantize_op()
                else:
                    q_op_out = create_quantize_op()
        else:
            if self._quant_scheme in [QuantScheme.training_range_learning_with_tf_init,
                                      QuantScheme.training_range_learning_with_tf_enhanced_init]:
                with self.session.graph.gradient_override_map(
                        {"QcQuantize": "QcQuantizeRangeLearningCustomGradient"}):
                    q_op_out = create_quantize_op()
            else:
                q_op_out = create_quantize_op()
        return q_op_out
def _create_and_place_quantize_op ( self , quant_op_name : str , preceeding_tensor , op_mode_var : tf . Variable , tensor_quant_ref : tf . Variable , encoding_min : tf . Variable , encoding_max : tf . Variable , bit_width : tf . Variable , use_symmetric_encoding : tf . Variable ) : def create_quantize_op ( ) : op = qcops . qc_quantize ( name = quant_op_name , in_tensor = preceeding_tensor , op_mode = op_mode_var , tensor_quantizer_reference = tensor_quant_ref , encoding_min = encoding_min , encoding_max = encoding_max , bit_width = bit_width , use_symmetric_encoding = use_symmetric_encoding ) return op if not self . _use_cuda : with tf . device ( '/cpu:0' ) : if self . _quant_scheme in [ QuantScheme . training_range_learning_with_tf_init , QuantScheme . training_range_learning_with_tf_enhanced_init ] : with self . session . graph . gradient_override_map ( { "QcQuantize" : "QcQuantizeRangeLearningCustomGradient" } ) : q_op_out = create_quantize_op ( ) else : q_op_out = create_quantize_op ( ) else : if self . _quant_scheme in [ QuantScheme . training_range_learning_with_tf_init , QuantScheme . training_range_learning_with_tf_enhanced_init ] : with self . session . graph . gradient_override_map ( { "QcQuantize" : "QcQuantizeRangeLearningCustomGradient" } ) : q_op_out = create_quantize_op ( ) else : q_op_out = create_quantize_op ( ) return q_op_out
Create a QcQuantize op and place it on CPU/CPU and with the right custom-gradient function registered
Create a QcQuantize op and place it on CPU / CPU and with the right custom - gradient function registered
"""
        Create a QcQuantize op and place it on CPU/CPU and with the right custom-gradient function registered
        """ # pylint: disable=too-many-arguments # GPU device assignment for QcQuantize op
self
quant_op_name
str
preceeding_tensor
op_mode_var
tf.Variable
tensor_quant_ref
tf.Variable
encoding_min
tf.Variable
encoding_max
tf.Variable
bit_width
tf.Variable
use_symmetric_encoding
tf.Variable