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 graph is provided, the node will be added to the graph. Otherwise, the user is responsible for calling graph.append(node) (or other mutation methods in Graph) 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 calling replace_input_with(). You can also use the replace_all_uses_with() method to replace all uses of the output values.

Note

When the domain is "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'
Parameters:

nodes (Node | Iterable[Node]) – A node or a sequence of nodes to put after this node.

Return type:

None

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 Attr objects.

Use node.attributes.add(attr) to add an attribute to the node. Use node.attributes.get_int(name, default) to get an integer attribute value. Refer to the Attributes for 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 domain: str¶

The domain of the operator. For onnx operators, this is an empty string.

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.

property name: str | None¶

Optional name of the node.

op_identifier()[source]¶

Return the operator identifier of the node.

The operator identifier is a tuple of the domain, op_type and overload.

Return type:

tuple[str, str, str]

property op_type: str¶

The name of the operator called.

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.

property overload: str¶

The overload name when the node is invoking a function.

predecessors()[source]¶

Return the predecessor nodes of the node, deduplicated, in a deterministic order.

Return type:

Sequence[Node]

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'
Parameters:

nodes (Node | Iterable[Node]) – A node or a sequence of nodes to put before this node.

Return type:

None

replace_input_with(index, value)[source]¶

Replace an input with a new value.

Parameters:
Return type:

None

successors()[source]¶

Return the successor nodes of the node, deduplicated, in a deterministic order.

Return type:

Sequence[Node]

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.