Function¶
- class onnx_ir.Function(domain, name, overload='', *, graph, attributes)¶
IR functions.
Like a graph, a function can have nodes that are not topologically sorted. It is the responsibility of the user to maintain a topological order of the nodes.
Note that there is not a
nodeattribute in the Function. The Function can be seen as a Sequence of nodes and should be used as such. For example, to obtain all nodes as a list, calllist(function).- Parameters:
- all_nodes()[source]¶
Get all nodes in the graph and its subgraphs in O(#nodes + #attributes) time.
This is an alias for
onnx_ir.traversal.RecursiveGraphIterator(graph). Consider usingonnx_ir.traversal.RecursiveGraphIteratorfor more advanced traversals on nodes.Added in version 0.1.2.
- append(node, /)[source]¶
Append a node to the function in O(1) time.
- Parameters:
node (Node)
- Return type:
None
- property attributes: Attributes¶
The function attribute definitions.
- clone(deep_copy=False)[source]¶
Create a deep copy of this function in O(#nodes + #values) time.
All nodes, values, and subgraphs are cloned. The cloned function will have the same structure as this function, but all nodes and values will be different objects.
Tensors in initializers and constant values will be shared.
Added in version 0.1.14.
- count(value) integer -- return number of occurrences of value¶
- display(*, page=False)¶
Pretty print the object.
- Parameters:
page (bool) – Whether to page the output.
- Return type:
None
- property graph: Graph¶
The underlying Graph object that contains the nodes of this function.
Only use this graph for identity comparison:
if value.graph is function.graph: # Do something with the value that belongs to this function
Otherwise use the Function object directly to access the nodes and other properties.
Added in version 0.1.7.
- index(value[, start[, stop]]) integer -- return first index of value.¶
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- property inputs: MutableSequence[Value]¶
The function input values.
- insert_after(node, new_nodes, /)[source]¶
Insert new nodes after the given node in O(#new_nodes) time.
- insert_before(node, new_nodes, /)[source]¶
Insert new nodes before the given node in O(#new_nodes) time.
- property meta: MetadataStore¶
The metadata store for intermediate analysis.
Write to the
metadata_propsif you would like the metadata to be serialized to the ONNX proto.
- property metadata_props: dict[str, str]¶
The metadata properties of the function.
The metadata properties are used to store additional information about the function. Unlike
meta, this property is serialized to the ONNX proto.
- property outputs: MutableSequence[Value]¶
The function output values.
- remove(nodes, /, safe=False)[source]¶
Remove nodes from the graph in O(#num of nodes) time.
If any errors are raise, to ensure the graph is not left in an inconsistent state, the graph is not modified.
- Parameters:
safe (bool) –
If True, performs the following actions before removal:
1. It checks to make sure there are no users of the node that are not to be removed before removing it. 2. It checks the node does not contribute to any graph outputs. 3. It removes references to all inputs so it is no longer a user of other nodes.
- Raises:
ValueError – If any node to remove does not belong to this graph.
ValueError – (When
safe=True) If the node does not belong to this graph or if there are users of the node.ValueError – (When
safe=True) If the node is still being used by other nodes not to be removed.
- Return type:
None