qonnx.custom_op.general.quant (module)
- class qonnx.custom_op.general.quant.Quant(onnx_node, onnx_opset_version=11)
Bases:
qonnx.custom_op.base.CustomOpGeneric quantization operation for QONNX. Takes four inputs: - input tensor to quantize - the scale - the zero-point - the bit-width
The output is a tensor of the same shape as the input tensor, with quantized values.
- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- get_integer_datatype(model)
- get_nodeattr_types()
Returns a dict of permitted attributes for node, where: ret_dict[attribute_name] = (dtype, require, default_value, <allowed_values>) - dtype indicates which member of the ONNX AttributeProto will be utilized - require indicates whether this attribute is required - default_val indicates the default value that will be used if the attribute is not set - <allowed_values> (if specified) indicates that this attribute can only be set to one of the values in the set <allowed_values>. If not specified, all values permitted by dtype are allowed.
- get_output_dtype(model)
- infer_node_datatype(model)
Set the DataType annotations corresponding to the outputs of this node.
- make_shape_compatible_op(model)
Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.
- verify_node()
Verifies that all attributes the node needs are there and that particular attributes are set correctly. Also checks if the number of inputs is equal to the expected number.
- qonnx.custom_op.general.quant.max_int(signed: bool, narrow_range: bool, bit_width: int) → int
Compute the maximum integer representable by a given number of bits. :param signed: Indicates whether the represented integer is signed or not. :type signed: bool :param narrow_range: Indicates whether to narrow the maximum unsigned value :type narrow_range: bool :param represented by 1.: :param bit_width: Number of bits available for the representation. :type bit_width: int
- Returns
Maximum integer that can be represented according to the input arguments.
- Return type
Tensor
Examples
>>> max_int(signed=True, narrow_range=True, bit_width=8) int(127) >>> max_int(signed=False, narrow_range=True, bit_width=8) int(254) >>> max_int(signed=True, narrow_range=False, bit_width=8) int(127) >>> max_int(signed=False, narrow_range=False, bit_width=8) int(255)
- qonnx.custom_op.general.quant.min_int(signed: bool, narrow_range: bool, bit_width: int) → int
Compute the minimum integer representable by a given number of bits. :param signed: Indicates whether the represented integer is signed or not. :type signed: bool :param narrow_range: Indicates whether to narrow the minimum value :type narrow_range: bool :param represented by 1.: :param bit_width: Number of bits available for the representation. :type bit_width: int
- Returns
Maximum unsigned integer that can be represented according to the input arguments.
- Return type
int
Examples
>>> min_int(signed=True, narrow_range=True, bit_width=8) int(-127) >>> min_int(signed=False, narrow_range=True, bit_width=8) int(0) >>> min_int(signed=True, narrow_range=False, bit_width=8) int(-128) >>> min_int(signed=False, narrow_range=False, bit_width=8) int(0)
- qonnx.custom_op.general.quant.quant(inp_tensor, scale, zeropt, bitwidth, signed, narrow, rounding_mode)
- qonnx.custom_op.general.quant.resolve_rounding_mode(mode_string)
Resolve the rounding mode string of Quant and Trunc ops to the corresponding numpy functions.