parameters: (self, graph)
return_statement: return graph
docstring: Quantize the graph for running MKL-DNN INT8 inference. According
          to activation quantization type, the graph will transform fake
          quantize ops to quantize ops and remove the fake dequantize ops.
  
          Args:
              graph(IrGraph): the applied graph.
docstring_summary: Quantize the graph for running MKL-DNN INT8 inference. According
          to activation quantization type, the graph will transform fake
          quantize ops to quantize ops and remove the fake dequantize ops.
docstring_tokens: Quantize the graph for running MKL - DNN INT8 inference . According to activation quantization type the graph will transform fake quantize ops to quantize ops and remove the fake dequantize ops .
function: def apply(self, graph):
          """
          Quantize the graph for running MKL-DNN INT8 inference. According
          to activation quantization type, the graph will transform fake
          quantize ops to quantize ops and remove the fake dequantize ops.
  
          Args:
              graph(IrGraph): the applied graph.
          """
  
          assert isinstance(graph,
                            IrGraph), 'graph must be the instance of IrGraph.'
          ops = graph.all_op_nodes()
  
          persistable_vars = [p.name() for p in graph.all_persistable_nodes()]
          # Collect the _in_scales and _max_range to calculate the new scales for MKL-DNN
          # INT8 conv2d and mul
          for op_node in ops:
              if op_node.name() in self._dequantize_type:
                  input_name = op_node.input("X")[0]
                  scale_name = op_node.input("Scale")[0]
                  self._in_scale[input_name] = self._load_param(self._scope,
                                                                scale_name)[0]
                  self._max_range[input_name] = op_node.op().attr("max_range")
                  self._new_output[input_name] = op_node.output("Out")[0]
  
              if op_node.name() in self._quantize_dequantize_type:
                  inputs = op_node.op().input_names()
                  attrs = op_node.op().attr_names()
                  input_name = op_node.input("X")[0]
                  scale_name = op_node.input("InScale")[0]
                  self._in_scale[input_name] = self._load_param(self._scope,
                                                                scale_name)[0]
                  #  self._max_range[input_name] = op_node.op().attr("max_range")
                  self._new_output[input_name] = op_node.output("Out")[0]
  
          for op_node in ops:
              if op_node.name() in self._quantizable_ops:
                  if op_node.name() in self._conv_ops:
                      self._transform_to_conv_mkldnn(graph, op_node)
                  elif op_node.name() in self._pool_ops:
                      self._transform_to_pool_mkldnn(graph, op_node)
                  else:
                      self._transform_to_mul_mkldnn(graph, op_node)
              elif op_node.name() in self._quantize_type:
                  self._transform_to_quantize_mkldnn(graph, op_node)
              elif op_node.name() in self._dequantize_type:
                  self._remove_fake_dequantize_op(graph, op_node)
              self._remove_unused_var_nodes(graph)
          return graph
function_tokens: def apply ( self , graph ) : assert isinstance ( graph , IrGraph ) , 'graph must be the instance of IrGraph.' ops = graph . all_op_nodes ( ) persistable_vars = [ p . name ( ) for p in graph . all_persistable_nodes ( ) ] # Collect the _in_scales and _max_range to calculate the new scales for MKL-DNN # INT8 conv2d and mul for op_node in ops : if op_node . name ( ) in self . _dequantize_type : input_name = op_node . input ( "X" ) [ 0 ] scale_name = op_node . input ( "Scale" ) [ 0 ] self . _in_scale [ input_name ] = self . _load_param ( self . _scope , scale_name ) [ 0 ] self . _max_range [ input_name ] = op_node . op ( ) . attr ( "max_range" ) self . _new_output [ input_name ] = op_node . output ( "Out" ) [ 0 ] if op_node . name ( ) in self . _quantize_dequantize_type : inputs = op_node . op ( ) . input_names ( ) attrs = op_node . op ( ) . attr_names ( ) input_name = op_node . input ( "X" ) [ 0 ] scale_name = op_node . input ( "InScale" ) [ 0 ] self . _in_scale [ input_name ] = self . _load_param ( self . _scope , scale_name ) [ 0 ] #  self._max_range[input_name] = op_node.op().attr("max_range") self . _new_output [ input_name ] = op_node . output ( "Out" ) [ 0 ] for op_node in ops : if op_node . name ( ) in self . _quantizable_ops : if op_node . name ( ) in self . _conv_ops : self . _transform_to_conv_mkldnn ( graph , op_node ) elif op_node . name ( ) in self . _pool_ops : self . _transform_to_pool_mkldnn ( graph , op_node ) else : self . _transform_to_mul_mkldnn ( graph , op_node ) elif op_node . name ( ) in self . _quantize_type : self . _transform_to_quantize_mkldnn ( graph , op_node ) elif op_node . name ( ) in self . _dequantize_type : self . _remove_fake_dequantize_op ( graph , op_node ) self . _remove_unused_var_nodes ( graph ) return graph