Skip to content

Commit 25a8a7e

Browse files
authored
[IR] Docs for Node (#2297)
Create more docstrings for node and clarify the domain normalization behavior.
1 parent 9543c24 commit 25a8a7e

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

onnxscript/ir/_core.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,9 @@ class Node(_protocols.NodeProtocol, _display.PrettyPrintable):
12961296
To change the output values, create a new node and replace the each of the inputs of ``output.uses()`` with
12971297
the new output values by calling :meth:`replace_input_with` on the using nodes
12981298
of this node's outputs.
1299+
1300+
.. note:
1301+
When the ``domain`` is `"ai.onnx"`, it is normalized to `""`.
12991302
"""
13001303

13011304
__slots__ = (
@@ -1333,7 +1336,7 @@ def __init__(
13331336
13341337
Args:
13351338
domain: The domain of the operator. For onnx operators, this is an empty string.
1336-
When it is "ai.onnx", it is normalized to "".
1339+
When it is `"ai.onnx"`, it is normalized to `""`.
13371340
op_type: The name of the operator.
13381341
inputs: The input values. When an input is ``None``, it is an empty input.
13391342
attributes: The attributes. RefAttr can be used only when the node is defined in a Function.
@@ -1476,6 +1479,7 @@ def __repr__(self) -> str:
14761479

14771480
@property
14781481
def name(self) -> str | None:
1482+
"""Optional name of the node."""
14791483
return self._name
14801484

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

14851489
@property
14861490
def domain(self) -> str:
1491+
"""The domain of the operator. For onnx operators, this is an empty string.
1492+
1493+
.. note:
1494+
When domain is `"ai.onnx"`, it is normalized to `""`.
1495+
"""
14871496
return self._domain
14881497

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

14931502
@property
14941503
def version(self) -> int | None:
1504+
"""Opset version of the operator called.
1505+
1506+
If ``None``, the version is unspecified and will follow that of the graph.
1507+
This property is special to ONNX IR to allow mixed opset usage in a graph
1508+
for supporting more flexible graph transformations. It does not exist in the ONNX
1509+
serialization (protobuf) spec.
1510+
"""
14951511
return self._version
14961512

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

15011517
@property
15021518
def op_type(self) -> str:
1519+
"""The name of the operator called."""
15031520
return self._op_type
15041521

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

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

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

15171535
@property
15181536
def inputs(self) -> Sequence[Value | None]:
1537+
"""The input values of the node.
1538+
1539+
The inputs are immutable. To change the inputs, create a new node and
1540+
replace the inputs of the using nodes of this node's outputs by calling
1541+
:meth:`replace_input_with` on the using nodes of this node's outputs.
1542+
"""
15191543
return self._inputs
15201544

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

15971621
@property
15981622
def outputs(self) -> Sequence[Value]:
1623+
"""The output values of the node.
1624+
1625+
The outputs are immutable. To change the outputs, create a new node and
1626+
replace the inputs of the using nodes of this node's outputs by calling
1627+
:meth:`replace_input_with` on the using nodes of this node's outputs.
1628+
"""
15991629
return self._outputs
16001630

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

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

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

16201651
@property
16211652
def metadata_props(self) -> dict[str, str]:
1653+
"""The metadata properties of the node.
1654+
1655+
The metadata properties are used to store additional information about the node.
1656+
Unlike ``meta``, this property is serialized to the ONNX proto.
1657+
"""
16221658
if self._metadata_props is None:
16231659
self._metadata_props = {}
16241660
return self._metadata_props
16251661

16261662
@property
16271663
def graph(self) -> Graph | None:
1664+
"""The graph that the node belongs to.
1665+
1666+
If the node is not added to any graph, this property is None.
1667+
"""
16281668
return self._graph
16291669

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

16341674
def op_identifier(self) -> _protocols.OperatorIdentifier:
1675+
"""Return the operator identifier of the node.
1676+
1677+
The operator identifier is a tuple of the domain, op_type and overload.
1678+
"""
16351679
return self.domain, self.op_type, self.overload
16361680

16371681
def display(self, *, page: bool = False) -> None:
1682+
"""Pretty print the node.
1683+
1684+
This method is used for debugging and visualization purposes.
1685+
"""
16381686
# Add the node's name to the displayed text
16391687
print(f"Node: {self.name!r}")
16401688
if self.doc_string:

0 commit comments

Comments
 (0)