parameters: (model, quantize_info)
return_statement: return adjusted_quantize_info
docstring: Adjust the shift cut of layer.
  
    shift_cut = wp + ip - op
  
    DPU compiler constraints of shift_cut:
      1. 0 <= shift_cut <= 16
docstring_summary: Adjust the shift cut of layer.
docstring_tokens: Adjust the shift cut of layer .
function: def _adjust_shift_cut(model, quantize_info):
    """Adjust the shift cut of layer.
  
    shift_cut = wp + ip - op
  
    DPU compiler constraints of shift_cut:
      1. 0 <= shift_cut <= 16
    """
    adjusted_quantize_info = copy.deepcopy(quantize_info)
  
    for i in range(1, len(model.layers)):
      layer = model.layers[i]
      if not isinstance(layer, vitis_quantize_wrapper.QuantizeWrapper):
        continue
  
      # Only adjust shift_cut and shift_bias for Conv-like layers
      if not (isinstance(layer.layer, keras.layers.Conv2D) or
              isinstance(layer.layer, keras.layers.DepthwiseConv2D) or
              isinstance(layer.layer, keras.layers.Conv2DTranspose) or
              isinstance(layer.layer, keras.layers.Dense)):
        continue
  
      ip, wp, op, bp = _get_iwob_pos(layer, adjusted_quantize_info)
  
      if isinstance(wp, np.ndarray):
        logger.debug('Not support adjust shift cut for per_channel quantization.')
        return adjusted_quantize_info
  
      if not _is_valid(ip, wp, op):
        logger.debug('Skip shift cut adjustment for layer {}, '
                     'its quantize pos is [i={}, w={}, b={}, o={}]'.format(
                         layer.name, ip, wp, bp, op))
        return adjusted_quantize_info
  
      min_sc = 0
      max_sc = 16
      sc = wp + ip - op
  
      new_sc = None
      if sc < min_sc:
        new_sc = min_sc
      elif sc > max_sc:
        new_sc = max_sc
  
      if new_sc is not None:
        new_wp = new_sc + op - ip
        _set_pos(layer, adjusted_quantize_info, 'w', new_wp)
        logger.debug('Shift cut of layer {} is {}. It exceeds range [{}, {}]. '
                     'Modify wpos from {} to {}.'.format(layer.name, int(sc),
                                                         int(min_sc), int(max_sc),
                                                         int(wp), int(new_wp)))
    return adjusted_quantize_info
function_tokens: def _adjust_shift_cut ( model , quantize_info ) : adjusted_quantize_info = copy . deepcopy ( quantize_info ) for i in range ( 1 , len ( model . layers ) ) : layer = model . layers [ i ] if not isinstance ( layer , vitis_quantize_wrapper . QuantizeWrapper ) : continue # Only adjust shift_cut and shift_bias for Conv-like layers if not ( isinstance ( layer . layer , keras . layers . Conv2D ) or isinstance ( layer . layer , keras . layers . DepthwiseConv2D ) or isinstance ( layer . layer , keras . layers . Conv2DTranspose ) or isinstance ( layer . layer , keras . layers . Dense ) ) : continue ip , wp , op , bp = _get_iwob_pos ( layer , adjusted_quantize_info ) if isinstance ( wp , np . ndarray ) : logger . debug ( 'Not support adjust shift cut for per_channel quantization.' ) return adjusted_quantize_info if not _is_valid ( ip , wp , op ) : logger . debug ( 'Skip shift cut adjustment for layer {}, ' 'its quantize pos is [i={}, w={}, b={}, o={}]' . format ( layer . name , ip , wp , bp , op ) ) return adjusted_quantize_info min_sc = 0 max_sc = 16 sc = wp + ip - op new_sc = None if sc < min_sc : new_sc = min_sc elif sc > max_sc : new_sc = max_sc if new_sc is not None : new_wp = new_sc + op - ip _set_pos ( layer , adjusted_quantize_info , 'w' , new_wp ) logger . debug ( 'Shift cut of layer {} is {}. It exceeds range [{}, {}]. ' 'Modify wpos from {} to {}.' . format ( layer . name , int ( sc ) , int ( min_sc ) , int ( max_sc ) , int ( wp ) , int ( new_wp ) ) ) return adjusted_quantize_info