Skip to content

[IR] Docs for Node #2297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion onnxscript/ir/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,9 @@ class Node(_protocols.NodeProtocol, _display.PrettyPrintable):
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 calling :meth:`replace_input_with` on the using nodes
of this node's outputs.

.. note:
When the ``domain`` is `"ai.onnx"`, it is normalized to `""`.
"""

__slots__ = (
Expand Down Expand Up @@ -1333,7 +1336,7 @@ def __init__(

Args:
domain: The domain of the operator. For onnx operators, this is an empty string.
When it is "ai.onnx", it is normalized to "".
When it is `"ai.onnx"`, it is normalized to `""`.
op_type: The name of the operator.
inputs: The input values. When an input is ``None``, it is an empty input.
attributes: The attributes. RefAttr can be used only when the node is defined in a Function.
Expand Down Expand Up @@ -1476,6 +1479,7 @@ def __repr__(self) -> str:

@property
def name(self) -> str | None:
"""Optional name of the node."""
return self._name

@name.setter
Expand All @@ -1484,6 +1488,11 @@ def name(self, value: str | None) -> None:

@property
def domain(self) -> str:
"""The domain of the operator. For onnx operators, this is an empty string.

.. note:
When domain is `"ai.onnx"`, it is normalized to `""`.
"""
return self._domain

@domain.setter
Expand All @@ -1492,6 +1501,13 @@ def domain(self, value: str) -> None:

@property
def version(self) -> 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.
"""
return self._version

@version.setter
Expand All @@ -1500,6 +1516,7 @@ def version(self, value: int | None) -> None:

@property
def op_type(self) -> str:
"""The name of the operator called."""
return self._op_type

@op_type.setter
Expand All @@ -1508,6 +1525,7 @@ def op_type(self, value: str) -> None:

@property
def overload(self) -> str:
"""The overload name when the node is invoking a function."""
return self._overload

@overload.setter
Expand All @@ -1516,6 +1534,12 @@ def overload(self, value: str) -> None:

@property
def inputs(self) -> 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
:meth:`replace_input_with` on the using nodes of this node's outputs.
"""
return self._inputs

@inputs.setter
Expand Down Expand Up @@ -1596,6 +1620,12 @@ def append(self, /, nodes: Node | Iterable[Node]) -> None:

@property
def outputs(self) -> 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
:meth:`replace_input_with` on the using nodes of this node's outputs.
"""
return self._outputs

@outputs.setter
Expand All @@ -1604,6 +1634,7 @@ def outputs(self, _: Sequence[Value]) -> None:

@property
def attributes(self) -> OrderedDict[str, Attr | RefAttr]:
"""The attributes of the node."""
return self._attributes

@property
Expand All @@ -1619,22 +1650,39 @@ def meta(self) -> _metadata.MetadataStore:

@property
def metadata_props(self) -> 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.
"""
if self._metadata_props is None:
self._metadata_props = {}
return self._metadata_props

@property
def graph(self) -> Graph | None:
"""The graph that the node belongs to.

If the node is not added to any graph, this property is None.
"""
return self._graph

@graph.setter
def graph(self, value: Graph | None) -> None:
self._graph = value

def op_identifier(self) -> _protocols.OperatorIdentifier:
"""Return the operator identifier of the node.

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

def display(self, *, page: bool = False) -> None:
"""Pretty print the node.

This method is used for debugging and visualization purposes.
"""
# Add the node's name to the displayed text
print(f"Node: {self.name!r}")
if self.doc_string:
Expand Down
Loading