TrainingExtensions/tensorflow/src/python/aimet_tensorflow/quantsim.py
def _add_quant_nodes_recurrent(self, conn_graph: ConnectedGraph, default_param_bw: int, default_output_bw: int) \
            -> Tuple[List[str], List[int], List[str]]:
        """
        Utility to add quant nodes to recurrent module
        :param conn_graph: Connected graph of the model
        :param default_param_bw: default param bitwidth
        :param default_output_bw: default output bitwidth
        :return: Tuple[List[str], List[int], List[str]], param op names, input indices and activation op names
        """
        # pylint: disable=protected-access
        # pylint: disable=too-many-locals

        # Register custom handlers to select internal ops to quantize in a given recurrent module type
        switcher = {
            "SimpleRNN": _select_simple_rnn_internal_ops_to_quantize,
            "LSTM": _select_lstm_internal_ops_to_quantize
        }

        ops_with_param_names = []
        input_indices = []
        activation_op_names = []

        for op in conn_graph.get_all_ops().values():
            #  we can configure custom layer selectors per recurrent type or use default one
            if op.type in SUPPORTED_RECURRENT_TYPES:

                internal_ops = op.internal_ops

                # select internal ops to quantize in this recurrent type
                select_internal_ops_to_quantize = switcher.get(op.type)
                module_ops_with_param_names, module_op_input_indices, module_activation_op_names = \
                    select_internal_ops_to_quantize(self.session.graph, internal_ops)

                # insert the quant nodes
                self._insert_param_quantization_ops(module_ops_with_param_names, module_op_input_indices,
                                                    default_param_bw, internal_ops, in_loop_context=True)

                self._insert_activation_quantization_ops(module_activation_op_names, default_output_bw,
                                                         in_loop_context=True)

                # if there are multiple recurrent modules, we want a list containing all the param
                # and activation info
                if module_ops_with_param_names and module_op_input_indices:
                    ops_with_param_names.extend(module_ops_with_param_names)
                    input_indices.extend(module_op_input_indices)
                if module_activation_op_names:
                    activation_op_names.extend(module_activation_op_names)

        return ops_with_param_names, input_indices, activation_op_names

        Utility to add quant nodes to recurrent module
        :param conn_graph: Connected graph of the model
        :param default_param_bw: default param bitwidth
        :param default_output_bw: default output bitwidth
        :return: Tuple[List[str], List[int], List[str]], param op names, input indices and activation op names
        
Utility to add quant nodes to recurrent module
Utility to add quant nodes to recurrent module
def _add_quant_nodes_recurrent(self, conn_graph: ConnectedGraph, default_param_bw: int, default_output_bw: int) \
            -> Tuple[List[str], List[int], List[str]]:
        switcher = {
            "SimpleRNN": _select_simple_rnn_internal_ops_to_quantize,
            "LSTM": _select_lstm_internal_ops_to_quantize
        }
        ops_with_param_names = []
        input_indices = []
        activation_op_names = []
        for op in conn_graph.get_all_ops().values():
            if op.type in SUPPORTED_RECURRENT_TYPES:
                internal_ops = op.internal_ops
                select_internal_ops_to_quantize = switcher.get(op.type)
                module_ops_with_param_names, module_op_input_indices, module_activation_op_names = \
                    select_internal_ops_to_quantize(self.session.graph, internal_ops)
                self._insert_param_quantization_ops(module_ops_with_param_names, module_op_input_indices,
                                                    default_param_bw, internal_ops, in_loop_context=True)
                self._insert_activation_quantization_ops(module_activation_op_names, default_output_bw,
                                                         in_loop_context=True)
                if module_ops_with_param_names and module_op_input_indices:
                    ops_with_param_names.extend(module_ops_with_param_names)
                    input_indices.extend(module_op_input_indices)
                if module_activation_op_names:
                    activation_op_names.extend(module_activation_op_names)
        return ops_with_param_names, input_indices, activation_op_names
def _add_quant_nodes_recurrent ( self , conn_graph : ConnectedGraph , default_param_bw : int , default_output_bw : int ) -> Tuple [ List [ str ] , List [ int ] , List [ str ] ] : switcher = { "SimpleRNN" : _select_simple_rnn_internal_ops_to_quantize , "LSTM" : _select_lstm_internal_ops_to_quantize } ops_with_param_names = [ ] input_indices = [ ] activation_op_names = [ ] for op in conn_graph . get_all_ops ( ) . values ( ) : if op . type in SUPPORTED_RECURRENT_TYPES : internal_ops = op . internal_ops select_internal_ops_to_quantize = switcher . get ( op . type ) module_ops_with_param_names , module_op_input_indices , module_activation_op_names = select_internal_ops_to_quantize ( self . session . graph , internal_ops ) self . _insert_param_quantization_ops ( module_ops_with_param_names , module_op_input_indices , default_param_bw , internal_ops , in_loop_context = True ) self . _insert_activation_quantization_ops ( module_activation_op_names , default_output_bw , in_loop_context = True ) if module_ops_with_param_names and module_op_input_indices : ops_with_param_names . extend ( module_ops_with_param_names ) input_indices . extend ( module_op_input_indices ) if module_activation_op_names : activation_op_names . extend ( module_activation_op_names ) return ops_with_param_names , input_indices , activation_op_names
Utility to add quant nodes to recurrent module
Utility to add quant nodes to recurrent module
"""
        Utility to add quant nodes to recurrent module
        :param conn_graph: Connected graph of the model
        :param default_param_bw: default param bitwidth
        :param default_output_bw: default output bitwidth
        :return: Tuple[List[str], List[int], List[str]], param op names, input indices and activation op names
        """ # pylint: disable=protected-access # pylint: disable=too-many-locals # Register custom handlers to select internal ops to quantize in a given recurrent module type #  we can configure custom layer selectors per recurrent type or use default one # select internal ops to quantize in this recurrent type # insert the quant nodes # if there are multiple recurrent modules, we want a list containing all the param # and activation info
Tuple[List[str], List[int], List[str]], param op names, input indices and activation op names
Tuple [ List [ str ] List [ int ] List [ str ]] param op names input indices and activation op names
self
conn_graph
ConnectedGraph
Connected graph of the model
Connected graph of the model
default_param_bw
int
default param bitwidth
default param bitwidth
default_output_bw
int
default output bitwidth
default output bitwidth