Node¶
- class onnx_ir.Node(domain, op_type, inputs, attributes=(), *, overload='', num_outputs=None, outputs=None, version=None, graph=None, name=None, doc_string=None, metadata_props=None)¶
IR Node.
Tip
For a more convenient way (that supports Python objects as attributes) to create a node, use the
onnx_ir.node()constructor.If
graphis provided, the node will be added to the graph. Otherwise, the user is responsible for callinggraph.append(node)(or other mutation methods inGraph) to add the node to the graph.After the node is initialized, it will add itself as a user of its input values.
The output values of the node are created during node initialization and are immutable. To change the output values, create a new node and, for each use of the old outputs (
output.uses()), replace the input in the consuming node by callingreplace_input_with(). You can also use thereplace_all_uses_with()method to replace all uses of the output values.Note
When the
domainis"ai.onnx", it is normalized to"".- Parameters:
- doc_string¶
- append(nodes)[source]¶
Insert a node after this node in the list of nodes in the graph.
It is the same as calling
graph.insert_after(self, nodes).Example:
Before: previous_node -> self previous_node' -> node -> next_node' After: previous_node -> self -> node previous_node' -> next_node'
- property attributes: Attributes¶
The attributes of the node as
dict[str, Attr]with additional access methods.Use it as a dictionary with keys being the attribute names and values being the
Attrobjects.Use
node.attributes.add(attr)to add an attribute to the node. Usenode.attributes.get_int(name, default)to get an integer attribute value. Refer to theAttributesfor more methods.
- display(*, page=False)[source]¶
Pretty print the node.
This method is used for debugging and visualization purposes.
- Parameters:
page (bool)
- Return type:
None
- property graph: Graph | None¶
The graph that the node belongs to.
If the node is not added to any graph, this property is None.
- property inputs: Sequence[Value | None]¶
The input values of the node.
The inputs are immutable. To change the inputs, create a new node and replace the inputs of the using nodes of this node’s outputs by calling
replace_input_with()on the using nodes of this node’s outputs.
- 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 node.
The metadata properties are used to store additional information about the node. Unlike
meta, this property is serialized to the ONNX proto.
- op_identifier()[source]¶
Return the operator identifier of the node.
The operator identifier is a tuple of the domain, op_type and overload.
- property outputs: Sequence[Value]¶
The output values of the node.
The outputs are immutable. To change the outputs, create a new node and replace the inputs of the using nodes of this node’s outputs by calling
replace_input_with()on the using nodes of this node’s outputs.
- predecessors()[source]¶
Return the predecessor nodes of the node, deduplicated, in a deterministic order.
- prepend(nodes)[source]¶
Insert a node before this node in the list of nodes in the graph.
It is the same as calling
graph.insert_before(self, nodes).Example:
Before: previous_node -> self previous_node' -> node -> next_node' After: previous_node -> node -> self previous_node' -> next_node'
- successors()[source]¶
Return the successor nodes of the node, deduplicated, in a deterministic order.
- property version: int | None¶
Opset version of the operator called.
If
None, the version is unspecified and will follow that of the graph. This property is special to ONNX IR to allow mixed opset usage in a graph for supporting more flexible graph transformations. It does not exist in the ONNX serialization (protobuf) spec.