Custom Op - General
General Custom Ops
qonnx.custom_op.general.bipolar_quant
- class qonnx.custom_op.general.bipolar_quant.BipolarQuant(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOpBipolar quantization operation for QONNX. Takes four inputs: - input tensor to quantize - the scale
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.bipolar_quant.binary_quant(inp_tensor, scale)
qonnx.custom_op.general.debugmarker
- class qonnx.custom_op.general.debugmarker.DebugMarker(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOp- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.genericpartition
- class qonnx.custom_op.general.genericpartition.GenericPartition(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOpClass that corresponds to the meta/container node GenericPartition which is a placeholder for a group of nodes that have been separated out into an ONNX model of its own.
- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.im2col
- class qonnx.custom_op.general.im2col.Im2Col(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOp- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.im2col.compute_conv_output_dim(ifm_dim, k, stride, total_pad=0, dilation=1)
Returns spatial output dimension size for convolution with given params. total_pad gives the total amount of padding along the entire axis (both sides included).
- qonnx.custom_op.general.im2col.get_im2col_indices_nchw(x_shape, field_height, field_width, padding=0, stride_h=1, stride_w=1, dilation_h=1, dilation_w=1)
Returns im2col indices.
- qonnx.custom_op.general.im2col.im2col_indices_nchw(x, ifm_h, ifm_w, field_height, field_width, padding=[0, 0, 0, 0], stride_h=1, stride_w=1, pad_val=0, dilation_h=1, dilation_w=1)
Performs im2col on image (2D tensor, possibly with 1-length dummy dimensions) x with given field height and width, as well as values for padding and stride size. Returns result of im2col.
qonnx.custom_op.general.maxpoolnhwc
- class qonnx.custom_op.general.maxpoolnhwc.MaxPoolNHWC(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOp- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.maxpoolnhwc.compute_pool_output_dim(ifm_dim, k, stride, pad=0, ceil_mode=0)
Return spatial output dimension size for pooling with given params.
qonnx.custom_op.general.multithreshold
- class qonnx.custom_op.general.multithreshold.MultiThreshold(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOpClass that corresponds to a multithresholding node.
- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.multithreshold.multithreshold(v, thresholds, out_scale=None, out_bias=None, channels_last=False)
Given a set of threshold values t={t_0, t_1 … t_n} the successive thresholding maps any real number x to an integer in the interval [0, n], where the returned integer is the number of thresholds x is greater than or equal to.
The output tensor will be scaled by out_scale and biased by out_bias.
qonnx.custom_op.general.quant
qonnx.custom_op.general.quantavgpool2d
- class qonnx.custom_op.general.quantavgpool2d.QuantAvgPool2d(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOpCustomOp that corresponds to the quantized average pooling layer from Brevitas
- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- get_accum_size()
- 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_shifts()
- 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.trunc
- class qonnx.custom_op.general.trunc.Trunc_v1(onnx_node, onnx_opset_version=1)
Bases:
CustomOpGeneric truncation operation for QONNX. Takes four inputs: - input tensor to truncate - the scale - the zero-point - the truncation bit-width
The output is a tensor of the same shape as the input tensor, with truncated values.
- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.
- class qonnx.custom_op.general.trunc.Trunc_v2(onnx_node, onnx_opset_version=1)
Bases:
CustomOpGeneric truncation operation for QONNX. Takes four inputs: - input tensor to truncate - the scale - the zero-point - the truncation scale - the truncation bit-width
The output is a tensor of the same shape as the input tensor, with truncated values.
- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.trunc.trunc_v1(inp_tensor, scale, zeropt, input_bit_width, output_bit_width, rounding_mode)
- qonnx.custom_op.general.trunc.trunc_v2(inp_tensor, scale, zeropt, input_bit_width, narrow, signed, output_scale, output_bit_width, rounding_mode)
qonnx.custom_op.general.xnorpopcount
- class qonnx.custom_op.general.xnorpopcount.XnorPopcountMatMul(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOpClass that corresponds to a XNOR-popcount matrix multiplication node.
- execute_node(context, graph)
Execute this CustomOp instance, given the execution context and ONNX graph.
- 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.
- 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.xnorpopcount.xnorpopcountmatmul(inp0, inp1)
Simulates XNOR-popcount matrix multiplication as a regular bipolar matrix multiplication followed by some post processing.