parameters: (self, block, idx, var,
                                                  quant_bits)
return_statement: return quant_var, scale
docstring: Insert fake_quantize_moving_average_abs_max
docstring_summary: Insert fake_quantize_moving_average_abs_max
docstring_tokens: Insert fake_quantize_moving_average_abs_max
function: def _insert_quant_moving_average_abs_max_op(self, block, idx, var,
                                                  quant_bits):
          """Insert fake_quantize_moving_average_abs_max
          """
          quant_var = block.create_var(
              name=_quantized_var_name(var.name),
              type=var.type,
              shape=var.shape,
              dtype=var.dtype)
          state = self.helper.create_global_variable(
              name=unique_name.generate('state'),
              persistable=True,
              dtype=var.dtype,
              shape=[1])
          self.helper.set_variable_initializer(
              state, initializer=Constant(value=1))
          accum = self.helper.create_global_variable(
              name=unique_name.generate('accum'),
              persistable=True,
              dtype=var.dtype,
              shape=[1])
          self.helper.set_variable_initializer(
              accum, initializer=Constant(value=1))
          scale = self.helper.create_parameter(
              attr=ParamAttr(
                  name=_quantized_scale_name(var.name),
                  initializer=Constant(0.001),
                  trainable=False),
              shape=[1],
              dtype=var.dtype)
          scale.stop_gradient = True
  
          ins = {'X': var, 'InScale': scale}
          outs = {'Out': quant_var, 'OutScale': scale}
          if not self.is_test:
              ins['InState'] = state
              ins['InAccum'] = accum
              outs['OutState'] = state
              outs['OutAccum'] = accum
  
          attrs = {
              'bit_length': quant_bits,
              'moving_rate': self.moving_rate,
              'is_test': self.is_test
          }
  
          quant_op = block._insert_op(
              idx,
              type='fake_quantize_moving_average_abs_max',
              attrs=attrs,
              inputs=ins,
              outputs=outs)
  
          return quant_var, scale
function_tokens: def _insert_quant_moving_average_abs_max_op ( self , block , idx , var , quant_bits ) : quant_var = block . create_var ( name = _quantized_var_name ( var . name ) , type = var . type , shape = var . shape , dtype = var . dtype ) state = self . helper . create_global_variable ( name = unique_name . generate ( 'state' ) , persistable = True , dtype = var . dtype , shape = [ 1 ] ) self . helper . set_variable_initializer ( state , initializer = Constant ( value = 1 ) ) accum = self . helper . create_global_variable ( name = unique_name . generate ( 'accum' ) , persistable = True , dtype = var . dtype , shape = [ 1 ] ) self . helper . set_variable_initializer ( accum , initializer = Constant ( value = 1 ) ) scale = self . helper . create_parameter ( attr = ParamAttr ( name = _quantized_scale_name ( var . name ) , initializer = Constant ( 0.001 ) , trainable = False ) , shape = [ 1 ] , dtype = var . dtype ) scale . stop_gradient = True ins = { 'X' : var , 'InScale' : scale } outs = { 'Out' : quant_var , 'OutScale' : scale } if not self . is_test : ins [ 'InState' ] = state ins [ 'InAccum' ] = accum outs [ 'OutState' ] = state outs [ 'OutAccum' ] = accum attrs = { 'bit_length' : quant_bits , 'moving_rate' : self . moving_rate , 'is_test' : self . is_test } quant_op = block . _insert_op ( idx , type = 'fake_quantize_moving_average_abs_max' , attrs = attrs , inputs = ins , outputs = outs ) return quant_var , scale