def _quantize(cls, params, in_qs, stats, **kwargs): _, dtype = cls.get_float_opts(**kwargs) names = { val: idx for idx, val in enumerate(LSTMParameters.INPUT_NAMES) } edges = kwargs['G'].indexed_in_edges(params.name) in_qs = deepcopy(in_qs) scale_pairs = { chan: ('i_2_%s_w' % chan, 'r_2_%s_w' % chan) for chan in ['i', 'o', 'c', 'f'] } for scale_pair in scale_pairs.values(): w_q = in_qs[names[scale_pair[0]]] in_qs[names[scale_pair[0]]] = QType(min_val=w_q.min_val, max_val=w_q.max_val, dtype=dtype, dont_generate_value=True) w_q = in_qs[names[scale_pair[1]]] in_qs[names[scale_pair[1]]] = QType( min_val=w_q.min_val, max_val=w_q.max_val, dtype=dtype, concatenated_nodes=[ edges[names[scale_pair[0]]].from_node.name ]) if params.lstm_output_c_state: out_qs = [QType(dtype=dtype), QType(dtype=dtype)] else: out_qs = [QType(dtype=dtype)] return QRec.float(in_qs=in_qs, out_qs=out_qs, float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): force_out_qs, dtype = cls.get_float_opts(**kwargs) if force_out_qs and all(qtype.dtype != dtype for qtype in force_out_qs if qtype is not None): return None return QRec.float(in_qs=[QType(dtype=dtype), QType(dtype=dtype), QType(dtype=dtype), QType(dtype=np.int16), QType(dtype=dtype), QType(dtype=np.int16), QType(dtype=dtype), QType(dtype=dtype)], out_qs=[QType(dtype=dtype)], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): _, dtype = cls.get_float_opts(**kwargs) out_qs = [deepcopy(in_qs[0])] opts = kwargs['opts'] if opts['hwc']: cls.check_order(params, AT_HWC_KER_IN_ORDER, AT_HWC_KER_OUT_ORDER) else: cls.check_order(params, AT_CHW_KER_IN_ORDER, AT_CHW_KER_OUT_ORDER) return QRec.float(in_qs=in_qs, out_qs=out_qs, float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): force_out_qs, dtype = cls.get_float_opts(**kwargs) if force_out_qs and all(qtype.dtype != dtype for qtype in force_out_qs if qtype is not None): return None # all inputs and outputs are set to the required float type return QRec.float(in_qs=[QType(dtype=dtype) for _ in range(3)], out_qs=[QType(dtype=dtype)], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): force_out_qs, dtype = cls.get_float_opts(**kwargs) if force_out_qs: o_q = force_out_qs[0] else: o_q = QType(dtype=dtype) o_q.is_constant = True return QRec.float(in_qs=None, out_qs=[o_q], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): params = cast(QuantizeParameters, params) force_out_qs, dtype = cls.get_float_opts(**kwargs) if force_out_qs: o_q = deepcopy(force_out_qs[0]) else: o_q = QType(dtype=dtype, min_val=in_qs[0].min_val, max_val=in_qs[0].max_val) params.from_qtype = in_qs[0] params.to_qtype = o_q return QRec.float(in_qs=in_qs, out_qs=[o_q], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): force_out_qs, dtype = cls.get_float_opts(**kwargs) if force_out_qs and any(qtype.dtype != dtype for qtype in force_out_qs if qtype is not None): return None # all inputs and outputs are set to the required float type opts = kwargs['opts'] if opts['hwc']: cls.check_order(params, AT_HWC_KER_IN_ORDER, AT_HWC_KER_OUT_ORDER) else: cls.check_order(params, AT_CHW_KER_IN_ORDER, AT_CHW_KER_OUT_ORDER) return QRec.float(in_qs=[QType(dtype=dtype) for _ in range(3)], out_qs=[QType(dtype=dtype)], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): force_out_qs, dtype = cls.get_float_opts(**kwargs) if force_out_qs and all(qtype.dtype != dtype for qtype in force_out_qs if qtype is not None): return None # use cur_G not G here since this may be called inside a fusion # cur_G == G or fusion subgraph if inside fusion G = kwargs['cur_G'] in_len = len(G.indexed_in_edges(params.name)) out_len = len(G.indexed_out_edges(params.name)) # all inputs and outputs are set to the required float type return QRec.float(in_qs=[QType(dtype=dtype) for _ in range(in_len)], out_qs=[QType(dtype=dtype) for _ in range(out_len)], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): force_out_qs, dtype = cls.get_float_opts(**kwargs) if force_out_qs and any(qtype.dtype != dtype for qtype in force_out_qs if qtype is not None): return None opts = kwargs['opts'] if opts['hwc']: cls.check_order(params, [['h', 'w', 'c']], [['h', 'w', 'c']]) elif params.in_dims_hint: cls.check_order(params, [['c', 'h', 'w']], [['c', 'h', 'w']]) # all inputs and outputs are set to the required float type return QRec.float(in_qs=[QType(dtype=dtype)], out_qs=[QType(dtype=dtype)], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): _, dtype = cls.get_float_opts(**kwargs) names = {val: idx for idx, val in enumerate(RNNParameters.INPUT_NAMES)} edges = kwargs['G'].indexed_in_edges(params.name) in_qs = deepcopy(in_qs) w_q = in_qs[names['i_2_i_w']] in_qs[names['i_2_i_w']] = QType.from_min_max_sq( w_q.min_val, w_q.max_val, dtype=dtype, dont_generate_value=True) w_q = in_qs[names['r_2_i_w']] in_qs[names['r_2_i_w']] = QType.from_min_max_sq( w_q.min_val, w_q.max_val, dtype=dtype, concatenated_nodes=[edges[names['i_2_i_w']].from_node.name]) return QRec.float(in_qs=in_qs, out_qs=[QType(dtype=dtype)], float_dtype=dtype)
def _quantize(cls, params, in_qs, stats, **kwargs): _, dtype = cls.get_float_opts(**kwargs) force_out_qs = kwargs.get('force_out_qs') if stats is None or 'expression' not in stats: raise ValueError( f'no valid range information is present for {params.name}') symbol_control = SymbolStats(stats['expression']) # preload the input and output quantization # This will force variables to the right scales in the expression quantizer # first the input prequant = { params.input_symbols[idx]: in_q for idx, in_q in enumerate(in_qs) } # now the output o_qs = [] for idx, sym_name in enumerate(params.output_symbols): if force_out_qs and force_out_qs[idx]: o_q = force_out_qs[idx] else: cls.check_valid_ranges(params, stats, idx=idx, dirs='out') o_q = QType(dtype=dtype) prequant[sym_name] = o_q o_qs.append(o_q) qfunc_col = params.func_col.quantize(FloatQuantization, symbol_control, quantize_inputs=False, qtypes=prequant) return QRec.float(in_qs=in_qs, out_qs=o_qs, float_dtype=dtype, qfunc_col=qfunc_col)
def _quantize(cls, params, in_qs, stats, **kwargs): _, dtype = cls.get_float_opts(**kwargs) out_qs = kwargs['out_qs'] return QRec.float(in_qs=in_qs, out_qs=out_qs, float_dtype=dtype)