diff --git a/onnxscript/ir/_core.py b/onnxscript/ir/_core.py index d900277fbe..f699916f0c 100644 --- a/onnxscript/ir/_core.py +++ b/onnxscript/ir/_core.py @@ -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__ = ( @@ -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. @@ -1476,6 +1479,7 @@ def __repr__(self) -> str: @property def name(self) -> str | None: + """Optional name of the node.""" return self._name @name.setter @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -1619,12 +1650,21 @@ 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 @@ -1632,9 +1672,17 @@ 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: