Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/onnx_ir/_convenience/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ def create_value_mapping(graph: _core.Graph) -> dict[str, _core.Value]:
and the first value with that name is returned. Values with empty names
are excluded from the mapping.

.. versionchanged:: 0.1.2
Values from subgraphs are now included in the mapping.

Args:
graph: The graph to extract the mapping from.

Expand Down Expand Up @@ -410,6 +413,8 @@ def get_const_tensor(
it will propagate the shape and type of the constant tensor to the value
if `propagate_shape_type` is set to True.

.. versionadded:: 0.1.2

Args:
value: The value to get the constant tensor from.
propagate_shape_type: If True, the shape and type of the value will be
Expand Down
25 changes: 22 additions & 3 deletions src/onnx_ir/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,10 @@ def tobytes(self) -> bytes:


class PackedTensor(TensorBase, _protocols.TensorProtocol, Generic[TArrayCompatible]): # pylint: disable=too-many-ancestors
"""A tensor that stores 4bit datatypes in packed format."""
"""A tensor that stores 4bit datatypes in packed format.

.. versionadded:: 0.1.2
"""

__slots__ = (
"_dtype",
Expand Down Expand Up @@ -2335,6 +2338,12 @@ class Graph(_protocols.GraphProtocol, Sequence[Node], _display.PrettyPrintable):
seen as a Sequence of nodes and should be used as such. For example, to obtain
all nodes as a list, call ``list(graph)``.

.. versionchanged:: 0.1.1
Values with non-none producers will be rejected as graph inputs or initializers.

.. versionadded:: 0.1.1
Added ``add`` method to initializers and attributes.

Attributes:
name: The name of the graph.
inputs: The input values of the graph.
Expand Down Expand Up @@ -2545,12 +2554,17 @@ def all_nodes(self) -> Iterator[Node]:
Consider using
:class:`onnx_ir.traversal.RecursiveGraphIterator` for more advanced
traversals on nodes.

.. versionadded:: 0.1.2
"""
# NOTE: This is a method specific to Graph, not required by the protocol unless proven
return onnx_ir.traversal.RecursiveGraphIterator(self)

def subgraphs(self) -> Iterator[Graph]:
"""Get all subgraphs in the graph in O(#nodes + #attributes) time."""
"""Get all subgraphs in the graph in O(#nodes + #attributes) time.

.. versionadded:: 0.1.2
"""
seen_graphs: set[Graph] = set()
for node in onnx_ir.traversal.RecursiveGraphIterator(self):
graph = node.graph
Expand Down Expand Up @@ -3216,12 +3230,17 @@ def all_nodes(self) -> Iterator[Node]:
Consider using
:class:`onnx_ir.traversal.RecursiveGraphIterator` for more advanced
traversals on nodes.

.. versionadded:: 0.1.2
"""
# NOTE: This is a method specific to Graph, not required by the protocol unless proven
return onnx_ir.traversal.RecursiveGraphIterator(self)

def subgraphs(self) -> Iterator[Graph]:
"""Get all subgraphs in the function in O(#nodes + #attributes) time."""
"""Get all subgraphs in the function in O(#nodes + #attributes) time.

.. versionadded:: 0.1.2
"""
seen_graphs: set[Graph] = set()
for node in onnx_ir.traversal.RecursiveGraphIterator(self):
graph = node.graph
Expand Down
2 changes: 2 additions & 0 deletions src/onnx_ir/_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def itemsize(self) -> float:
def bitwidth(self) -> int:
"""Returns the bit width of the data type.

.. versionadded:: 0.1.2

Raises:
TypeError: If the data type is not supported.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
class CommonSubexpressionEliminationPass(ir.passes.InPlacePass):
"""Eliminate common subexpression in ONNX graphs.

.. versionadded:: 0.1.1

.. versionchanged:: 0.1.3
Constant nodes with values smaller than ``size_limit`` will be CSE'd.

Attributes:
size_limit: The maximum size of the tensor to be csed. If the tensor contains
number of elements larger than size_limit, it will not be cse'd. Default is 10.
Expand Down
2 changes: 2 additions & 0 deletions src/onnx_ir/passes/common/initializer_deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class DeduplicateInitializersPass(ir.passes.InPlacePass):

To deduplicate initializers from subgraphs, use :class:`~onnx_ir.passes.common.LiftSubgraphInitializersToMainGraphPass`
to lift the initializers to the main graph first before running pass.

.. versionadded:: 0.1.3
"""

def __init__(self, size_limit: int = 1024):
Expand Down
5 changes: 5 additions & 0 deletions src/onnx_ir/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ def from_onnx_text(

Read more about the textual representation at: https://onnx.ai/onnx/repo-docs/Syntax.html

.. versionchanged:: 0.1.2
Added the ``initializers`` argument.

Args:
model_text: The ONNX textual representation of the model.
initializers: Tensors to be added as initializers. If provided, these tensors
Expand Down Expand Up @@ -237,6 +240,8 @@ def to_onnx_text(
) -> str:
"""Convert the IR model to the ONNX textual representation.

.. versionadded:: 0.1.2

Args:
model: The IR model to convert.
exclude_initializers: If True, the initializers will not be included in the output.
Expand Down