Custom Op - General (FINN)
FINN General Custom Ops
finn.custom_op.general.pwpolyfunction
PWPolyFunction ONNX custom op for piecewise polynomial activations.
This module provides the ONNX graph execution layer for PWPolyF, analogous to how qonnx.custom_op.general provides execution for Brevitas-exported ops.
- class finn.custom_op.general.pwpolyfunction.PWPolyFunction(onnx_node: NodeProto, onnx_opset_version: int = 1)
Bases:
CustomOpONNX custom op for piecewise polynomial activation functions.
This op is exported by the PWPolyFActivation PyTorch module and can be executed during ONNX graph simulation. It approximates GELU, SiLU, Sigmoid, and Tanh using piecewise polynomials.
- execute_node(context, graph)
Execute the PWPolyF operation using numpy.
- 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)
Infer and set output datatype (always FLOAT32).
- make_shape_compatible_op(model)
Return a standard op that produces the same output shape.
PWPolyFunction is an element-wise activation, so output shape equals input shape. Using Identity allows shape inference to work even when input shape is unknown.
- verify_node()
Verify node attributes are valid.