Custom Op

Submodules

Custom Op Nodes

Base Class

class qonnx.custom_op.base.CustomOp(onnx_node, onnx_opset_version=11)

Bases: ABC

CustomOp class all custom op nodes are based on. Contains different functions every custom node should have. Some as abstract methods, these have to be filled when writing a new custom op node.

abstract execute_node(context, graph)

Execute this CustomOp instance, given the execution context and ONNX graph.

get_nodeattr(name)

Get a node attribute by name. Data is stored inside the ONNX node’s AttributeProto container. Attribute must be part of get_nodeattr_types. Default value is returned if attribute is not set.

get_nodeattr_allowed_values(name)

Return set of allowed values for given attribute, None if not specified.

get_nodeattr_def(name)

Return 4-tuple (dtype, required, default_val, allowed_values) for attribute with name. allowed_values will be None if not specified.

abstract 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.

abstract infer_node_datatype(model)

Set the DataType annotations corresponding to the outputs of this node.

make_const_shape_op(shape)

Return an ONNX node that generates the desired output shape for shape inference.

abstract make_shape_compatible_op(model)

Returns a standard ONNX op which is compatible with this CustomOp for performing shape inference.

set_nodeattr(name, value)

Set a node attribute by name. Data is stored inside the ONNX node’s AttributeProto container. Attribute must be part of get_nodeattr_types.

abstract 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.registry

qonnx.custom_op.registry.getCustomOp(node, onnx_opset_version=11, brevitas_exception=True)

Return a QONNX CustomOp instance for the given ONNX node, if it exists.