Node¶
- class onnx_ir.Node(domain: str, op_type: str, inputs: Iterable[Value | None], attributes: Iterable[Attr] = (), *, overload: str = '', num_outputs: int | None = None, outputs: Sequence[Value] | None = None, version: int | None = None, graph: Graph | Function | None = None, name: str | None = None, doc_string: str | None = None, metadata_props: dict[str, str] | None = None)¶
IR Node.
If the
graph
is provided, the node will be added to the graph. Otherwise, user is responsible to callgraph.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 the 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 replace the each of the inputs of
output.uses()
with the new output values by callingreplace_input_with()
on the using nodes of this node’s outputs.- doc_string¶
- append(nodes: Node | Iterable[Node]) None [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'
- Parameters:
nodes – A node or a sequence of nodes to put after this node.
- property attributes: OrderedDict[str, Attr]¶
The attributes of the node.
- display(*, page: bool = False) None [source]¶
Pretty print the node.
This method is used for debugging and visualization purposes.
- 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_props
if 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() tuple[str, str, str] [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() Sequence[Node] [source]¶
Return the predecessor nodes of the node, deduplicated, in a deterministic order.
- prepend(nodes: Node | Iterable[Node]) None [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'
- Parameters:
nodes – A node or a sequence of nodes to put before this node.
- replace_input_with(index: int, value: Value | None) None [source]¶
Replace an input with a new value.
- successors() Sequence[Node] [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.